[lib.timeid] updated 'uint' to 'uint32'

This commit is contained in:
xdrm-brackets 2018-04-22 18:44:32 +02:00
parent 27dcb81e5f
commit fdab12841c
2 changed files with 9 additions and 9 deletions

View File

@ -10,11 +10,11 @@ import (
*
* @wsize<float64> Window Size in seconds
*
* @return id<uint> Current time id
* @return parity<uint> Current time parity
* @return id<uint32> Current time id
* @return parity<uint32> Current time parity
*
---------------------------------------------------------*/
func Generate(wsize float64) (uint, uint){
func Generate(wsize float64) (uint32, uint32){
/* (1) If wsize is 0 (div by zero possible error) */
if wsize == 0 { return 0, 0 }
@ -23,7 +23,7 @@ func Generate(wsize float64) (uint, uint){
timestamp := float64( time.Now().Unix() );
/* (3) Calculate the time id */
var id = uint( timestamp / wsize );
var id = uint32( timestamp / wsize );
/* (4) Calculate parity */
var parity = id % 2;
@ -35,17 +35,17 @@ func Generate(wsize float64) (uint, uint){
/* (2) Try to guess a previous time id from its parity
*
* @wsize<float64> Window Size in seconds
* @parity<uint> Received parity
* @parity<uint32> Received parity
*
* @return id<uint> The guessed time id
* @return id<uint32> The guessed time id
*
---------------------------------------------------------*/
func Guess(wsize float64, parity uint) uint{
func Guess(wsize float64, parity uint32) uint32{
/* (1) Get current time id */
var idNow, parityNow = Generate(wsize);
/* (2) Update ID with tidNow parity difference */
return idNow - uint(math.Abs( float64(parityNow) - float64(parity) ));
return idNow - uint32(math.Abs( float64(parityNow) - float64(parity) ));
}

View File

@ -14,7 +14,7 @@ func TestGuessing(t *testing.T){
time.Sleep( time.Duration(windowSize) * time.Second);
var guessedId uint = Guess(windowSize, parity);
var guessedId = Guess(windowSize, parity);
if id != guessedId {
t.Errorf("Wrong guessed id, expected '%d' ; got '%d'", id, guessedId);