initial commits

master
Charles Iliya Krempeaux 2021-11-08 12:51:03 -08:00
parent 8d6bd13393
commit e8051cb87e
2 changed files with 32 additions and 6 deletions

View File

@ -12,10 +12,10 @@ var (
func generate() uint64 {
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 value uint64 = compile(uint64(unixtimestamp), chaos)

34
id.go
View File

@ -1,5 +1,9 @@
package xim
import (
"time"
)
// ID represents a xim-id.
//
// It is a scheme used to generate quazimonotonicallyincreasingunique identifier.
@ -49,22 +53,44 @@ func Generate() ID {
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:
//
// 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)
//
// 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 value uint64 = generateformoment(when)
var value uint64 = generateforunixtime(when)
return something(value)
}