[lib.timeid] updated 'uint' to 'uint32'
This commit is contained in:
parent
27dcb81e5f
commit
fdab12841c
|
@ -10,11 +10,11 @@ import (
|
||||||
*
|
*
|
||||||
* @wsize<float64> Window Size in seconds
|
* @wsize<float64> Window Size in seconds
|
||||||
*
|
*
|
||||||
* @return id<uint> Current time id
|
* @return id<uint32> Current time id
|
||||||
* @return parity<uint> Current time parity
|
* @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) */
|
/* (1) If wsize is 0 (div by zero possible error) */
|
||||||
if wsize == 0 { return 0, 0 }
|
if wsize == 0 { return 0, 0 }
|
||||||
|
@ -23,7 +23,7 @@ func Generate(wsize float64) (uint, uint){
|
||||||
timestamp := float64( time.Now().Unix() );
|
timestamp := float64( time.Now().Unix() );
|
||||||
|
|
||||||
/* (3) Calculate the time id */
|
/* (3) Calculate the time id */
|
||||||
var id = uint( timestamp / wsize );
|
var id = uint32( timestamp / wsize );
|
||||||
|
|
||||||
/* (4) Calculate parity */
|
/* (4) Calculate parity */
|
||||||
var parity = id % 2;
|
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
|
/* (2) Try to guess a previous time id from its parity
|
||||||
*
|
*
|
||||||
* @wsize<float64> Window Size in seconds
|
* @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 */
|
/* (1) Get current time id */
|
||||||
var idNow, parityNow = Generate(wsize);
|
var idNow, parityNow = Generate(wsize);
|
||||||
|
|
||||||
/* (2) Update ID with tidNow parity difference */
|
/* (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) ));
|
||||||
|
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ func TestGuessing(t *testing.T){
|
||||||
|
|
||||||
time.Sleep( time.Duration(windowSize) * time.Second);
|
time.Sleep( time.Duration(windowSize) * time.Second);
|
||||||
|
|
||||||
var guessedId uint = Guess(windowSize, parity);
|
var guessedId = Guess(windowSize, parity);
|
||||||
|
|
||||||
if id != guessedId {
|
if id != guessedId {
|
||||||
t.Errorf("Wrong guessed id, expected '%d' ; got '%d'", id, guessedId);
|
t.Errorf("Wrong guessed id, expected '%d' ; got '%d'", id, guessedId);
|
||||||
|
|
Loading…
Reference in New Issue