initial commits
parent
8d6bd13393
commit
e8051cb87e
|
@ -12,10 +12,10 @@ var (
|
||||||
func generate() uint64 {
|
func generate() uint64 {
|
||||||
|
|
||||||
var now int64 = time.Now().Unix()
|
var now int64 = time.Now().Unix()
|
||||||
return generateformoment(now)
|
return generateforunixtime(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateformoment(unixtimestamp int64) uint64 {
|
func generateforunixtime(unixtimestamp int64) uint64 {
|
||||||
var chaos uint64 = randomness.Uint64()
|
var chaos uint64 = randomness.Uint64()
|
||||||
|
|
||||||
var value uint64 = compile(uint64(unixtimestamp), chaos)
|
var value uint64 = compile(uint64(unixtimestamp), chaos)
|
||||||
|
|
34
id.go
34
id.go
|
@ -1,5 +1,9 @@
|
||||||
package xim
|
package xim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// ID represents a xim-id.
|
// ID represents a xim-id.
|
||||||
//
|
//
|
||||||
// It is a scheme used to generate quazi‐monotonically‐increasing‐unique identifier.
|
// It is a scheme used to generate quazi‐monotonically‐increasing‐unique identifier.
|
||||||
|
@ -49,22 +53,44 @@ func Generate() ID {
|
||||||
return something(value)
|
return something(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateForMoment returns a new xim-id that has embedded in it the time given by the unix-timestamp in the variable ‘unixtimestamp’.
|
// GenerateForTime returns a new xim-id that has embedded in it the time given by the value in the input-variable ‘when’.
|
||||||
|
//
|
||||||
|
// Example usage:
|
||||||
|
//
|
||||||
|
// var moment time.Time = ???
|
||||||
|
//
|
||||||
|
// // ...
|
||||||
|
//
|
||||||
|
// var id xim.ID = xim.GenerateForTime(moment)
|
||||||
|
//
|
||||||
|
// fmt.Println("xim-id =", id)
|
||||||
|
//
|
||||||
|
// The chaos part of this xim-id will be chosen randomly (just like with xim.Generate()).
|
||||||
|
func GenerateForTime(when time.Time) ID {
|
||||||
|
|
||||||
|
var unixtimestamp int64 = when.Unix()
|
||||||
|
|
||||||
|
var value uint64 = generateforunixtime(unixtimestamp)
|
||||||
|
|
||||||
|
return something(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateForUnixTime returns a new xim-id that has embedded in it the time given by the unix-timestamp in the input-variable ‘unixtimestamp’.
|
||||||
//
|
//
|
||||||
// Example usage:
|
// Example usage:
|
||||||
//
|
//
|
||||||
// var unixTimeStamp int32 = 1636403305 // I.e., Monday, November 8, 2021 12:28:25 PM GMT-08:00
|
// var unixTimeStamp int32 = 1636403305 // I.e., Monday, November 8, 2021 12:28:25 PM GMT-08:00
|
||||||
//
|
//
|
||||||
// var id xim.ID = xim.GenerateForMoment(unixTimeStamp)
|
// var id xim.ID = xim.GenerateForUnixTime(unixTimeStamp)
|
||||||
//
|
//
|
||||||
// fmt.Println("xim-id =", id)
|
// fmt.Println("xim-id =", id)
|
||||||
//
|
//
|
||||||
// The chaos part of this xim-id will be chosen randomly (just like with xim.Generate()).
|
// The chaos part of this xim-id will be chosen randomly (just like with xim.Generate()).
|
||||||
func GenerateForMoment(unixtimestamp int32) ID {
|
func GenerateForUnixTime(unixtimestamp int32) ID {
|
||||||
|
|
||||||
var when int64 = int64(unixtimestamp)
|
var when int64 = int64(unixtimestamp)
|
||||||
|
|
||||||
var value uint64 = generateformoment(when)
|
var value uint64 = generateforunixtime(when)
|
||||||
|
|
||||||
return something(value)
|
return something(value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue