Documentation
¶
Index ¶
- Constants
- Variables
- func BytesAppendForward(buf []byte, l int) []byte
- func GetTimeFormSerialUUID(val Uuid) time.Time
- func GetTimeFromID(id int64) time.Time
- func LimitID(t time.Time) (id int64)
- func NextID() int64
- type SnowflakeGenerator
- func (fg *SnowflakeGenerator) GetTimeFromID(id int64) time.Time
- func (fg *SnowflakeGenerator) LimitID(t time.Time) (id int64)
- func (fg *SnowflakeGenerator) Next() int64
- func (fg *SnowflakeGenerator) NextLock() (id int64, owerload bool)
- func (fg *SnowflakeGenerator) NextRaw() (id int64, owerload bool)
- type UInt128
- func UInt128FromBytes(buf [16]byte) (i UInt128)
- func UInt128FromInt(value int) (i UInt128)
- func UInt128FromText(value string, base int, ignoreFail bool) (i UInt128, err error)
- func UInt128FromTextByte(value []byte, base int, ignoreFail bool) (i UInt128, err error)
- func UInt128FromTextByteMust(value []byte, base int, ignoreFail bool) (i UInt128)
- func UInt128FromTextMust(value string, base int, ignoreFail bool) (i UInt128)
- func UInt128FromUint64(value uint64) (i UInt128)
- func (i UInt128) Add(y UInt128) (result UInt128)
- func (i UInt128) AddOverflow(y UInt128, carry uint64) (result UInt128, carryOut uint64)
- func (i UInt128) AddUInt64(y uint64) (result UInt128)
- func (i UInt128) AsBytes() (result [16]byte)
- func (i UInt128) BytesLen() int
- func (i UInt128) Copy() UInt128
- func (i UInt128) Div(y UInt128) (quo UInt128, rem UInt128)
- func (i UInt128) DivUint64(y uint64) (quo UInt128, rem UInt128)
- func (i UInt128) Equal(val UInt128) bool
- func (i *UInt128) FromBytes(buf [16]byte) *UInt128
- func (i *UInt128) FromText(value string, base int, ignoreFail bool) error
- func (i *UInt128) FromTextByte(value []byte, base int, ignoreFail bool) error
- func (i UInt128) GetBit(pos int) bool
- func (i UInt128) Int() int
- func (i UInt128) IsEmpty() bool
- func (i UInt128) IsUint64() bool
- func (i UInt128) Less(val UInt128) bool
- func (i UInt128) Link() *UInt128
- func (i UInt128) MarshalJSON() ([]byte, error)
- func (i UInt128) MoveBitDown(move int) (result UInt128)
- func (i *UInt128) MoveBitDown1Internal()
- func (i UInt128) MoveBitUp(move int) (result UInt128)
- func (i UInt128) Mul(y UInt128) (result UInt128)
- func (i UInt128) MulOverflow(y UInt128) (hi, lo UInt128)
- func (i UInt128) MulUInt64(y uint64) (result UInt128)
- func (i UInt128) Power(e UInt128) (p UInt128)
- func (i UInt128) Root(base uint64) (r UInt128)
- func (i *UInt128) Set(val *UInt128) *UInt128
- func (i *UInt128) SetBit(pos int, val bool)
- func (i *UInt128) SetBit0(pos int)
- func (i *UInt128) SetBit1(pos int)
- func (i *UInt128) SetBytes(buf []byte) *UInt128
- func (i *UInt128) SetUint64(val *uint64) *UInt128
- func (i UInt128) Sqrt() (r UInt128)
- func (i UInt128) String() string
- func (i UInt128) Sub(y UInt128) (result UInt128)
- func (i UInt128) SubOverflow(y UInt128, borrow uint64) (result UInt128, borrowOut uint64)
- func (i UInt128) Text(base int) string
- func (i UInt128) UInt64() uint64
- func (i *UInt128) UnmarshalJSON(input []byte) error
- type Uuid
- func LimitSerialUUID(timeCalc time.Time) (res Uuid)
- func NextUUID() (res Uuid)
- func RandUUID() (res Uuid)
- func UuidFromText(value string, base int, ignoreFail bool) (i Uuid, err error)
- func UuidFromTextByte(value []byte, base int, ignoreFail bool) (i Uuid, err error)
- func UuidFromTextByteMust(value []byte, base int, ignoreFail bool) (i Uuid)
- func UuidFromTextMust(value string, base int, ignoreFail bool) (i Uuid)
- func (i Uuid) AsUUID() string
- func (i Uuid) Equal(val Uuid) bool
- func (i Uuid) Less(val Uuid) bool
- func (i Uuid) Link() *Uuid
- func (i Uuid) MarshalJSON() ([]byte, error)
- func (i Uuid) StepPart() uint64
- func (i Uuid) String() string
- func (i Uuid) Text(base int) string
- func (i Uuid) TimePart() time.Time
- func (i Uuid) UniquePart() uint64
- func (i *Uuid) UnmarshalJSON(input []byte) error
- type UuidMap
- type UuidRealRandomGenerator
- type UuidSerialGenerator
Constants ¶
const ( // DefaultTimeShift 2010-11-04, 01:42:54 UTC // ~69 years in 4 bit DefaultTimeShift = 1288834974657 )
const DefaultUuidRealRandomGeneratorBlocks = 4
const DefaultUuidRealRandomGeneratorSize = 1000
const Mval uint64 = ((1 << 2) << 4) << 8
const Nval uint64 = 1 << 63
const UuidSize = 16
Variables ¶
var DefaultRandomUuidGenerator = &UuidRealRandomGenerator{}
var DefaultSnowflakeGenerator = &SnowflakeGenerator{ TimeShift: DefaultTimeShift, }
var DefaultUuidGenerator = &UuidSerialGenerator{}
Functions ¶
func BytesAppendForward ¶
func GetTimeFormSerialUUID ¶ added in v0.0.3
func GetTimeFromID ¶ added in v0.0.4
GetTimeFromID - get time from id
Types ¶
type SnowflakeGenerator ¶ added in v0.0.4
type SnowflakeGenerator struct { Mx sync.Mutex // TimeShift - time shift / Use 1288834974657 for default generator TimeShift int64 // DataCenterID - data center id 0-31 (valid values) DataCenterID int64 // ServerID - server id 0-31 (valid values) ServerID int64 // contains filtered or unexported fields }
SnowflakeGenerator - generator IDs 1 - 0 | 41 - time in milliseconds | 5 - data center | 5 server | 12 sequence ~69 years in 4 bit
func (*SnowflakeGenerator) GetTimeFromID ¶ added in v0.0.4
func (fg *SnowflakeGenerator) GetTimeFromID(id int64) time.Time
GetTimeFromID - get time from id
func (*SnowflakeGenerator) LimitID ¶ added in v0.0.4
func (fg *SnowflakeGenerator) LimitID(t time.Time) (id int64)
LimitID - generates min id for time
func (*SnowflakeGenerator) Next ¶ added in v0.0.4
func (fg *SnowflakeGenerator) Next() int64
Next - gets next id: 1 - 0 | 41 - time in milliseconds | 5 - data center | 5 server | 12 sequence ~69 years in 4 bit
func (*SnowflakeGenerator) NextLock ¶ added in v0.0.4
func (fg *SnowflakeGenerator) NextLock() (id int64, owerload bool)
Next - gets next id: 1 - 0 | 41 - time in milliseconds | 5 - data center | 5 server | 12 sequence ~69 years in 4 bit
func (*SnowflakeGenerator) NextRaw ¶ added in v0.0.4
func (fg *SnowflakeGenerator) NextRaw() (id int64, owerload bool)
NextRaw - gets next id: 1 - 0 | 41 - time in milliseconds | 5 - data center | 5 server | 12 sequence ~69 years in 4 bit
type UInt128 ¶
type UInt128 [2]uint64
UInt128 128 bit unsigned integer
func UInt128FromBytes ¶
func UInt128FromInt ¶ added in v0.0.8
func UInt128FromText ¶ added in v0.0.6
func UInt128FromTextByte ¶ added in v0.0.6
func UInt128FromTextByteMust ¶ added in v0.0.7
func UInt128FromTextMust ¶ added in v0.0.7
func UInt128FromUint64 ¶ added in v0.0.8
func (UInt128) AddOverflow ¶
Add creates result to the sum i+y, carry is 0
func (*UInt128) FromTextByte ¶
func (UInt128) MarshalJSON ¶
MarshalJSON() implements json.Marshaler.
func (UInt128) MoveBitDown ¶
MoveBitDown creates result >> (move)
func (*UInt128) MoveBitDown1Internal ¶
func (i *UInt128) MoveBitDown1Internal()
MoveBitDown creates result >> (1)
func (UInt128) MulOverflow ¶
Mul creates result to the mult i * y
func (UInt128) SubOverflow ¶
Sub creates result to the difference i-y, borrow is 0
func (*UInt128) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Uuid ¶
type Uuid struct {
UInt128
}
func LimitSerialUUID ¶ added in v0.0.3
LimitSerialUUID - Limit (min) Serial id limit by date with format xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx M 0100 (version 4) N 10 (variant 1) tttttttt-tttt-Msss-Nrrr-rrrrrrrrrrrr M - 0100 (version 4) N - 10ss (variant 1) t - time (unix milli) s - step r - random value (Generated on Init)
func NextUUID ¶
func NextUUID() (res Uuid)
NextUUID - Next Serial id from DefaultUuidGenerator xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx M 0100 (version 4) N 10 (variant 1) tttttttt-tttt-Msss-Nrrr-rrrrrrrrrrrr M - 0100 (version 4) N - 10ss (variant 1) t - time (unix milli) s - step r - random value (Generated on Init)
func RandUUID ¶ added in v0.0.2
func RandUUID() (res Uuid)
RandUUID - Next Random id from DefaultRandomUuidGenerator xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx M 0100 (version 4) N 10 (variant 1) rrrrrrrr-rrrr-Mrrr-Nrrr-rrrrrrrrrrrr M - 0100 (version 4) N - 10rr (variant 1) r - random value
func UuidFromText ¶ added in v0.0.6
func UuidFromTextByte ¶ added in v0.0.6
func UuidFromTextByteMust ¶ added in v0.0.7
func UuidFromTextMust ¶ added in v0.0.7
func (Uuid) MarshalJSON ¶
MarshalJSON() implements json.Marshaler.
func (Uuid) UniquePart ¶
func (*Uuid) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type UuidMap ¶ added in v0.0.5
func (UuidMap[T]) MarshalJSON ¶ added in v0.0.5
func (*UuidMap[T]) UnmarshalJSON ¶ added in v0.0.5
type UuidRealRandomGenerator ¶ added in v0.0.2
type UuidRealRandomGenerator struct { Size int // contains filtered or unexported fields }
UuidRealRandomGenerator - random uuid generator with random values
func (*UuidRealRandomGenerator) GetRandBytes ¶ added in v0.0.2
func (urg *UuidRealRandomGenerator) GetRandBytes() []byte
GetRandBytes returns 16 bytes
func (*UuidRealRandomGenerator) Init ¶ added in v0.0.2
func (urg *UuidRealRandomGenerator) Init() error
func (*UuidRealRandomGenerator) Next ¶ added in v0.0.2
func (urg *UuidRealRandomGenerator) Next() (res Uuid)
Next Random id xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx M 0100 (version 4) N 10 (variant 1) rrrrrrrr-rrrr-Mrrr-Nrrr-rrrrrrrrrrrr M - 0100 (version 4) N - 10rr (variant 1) r - random value
func (*UuidRealRandomGenerator) NextOrDefault ¶ added in v0.0.2
func (usg *UuidRealRandomGenerator) NextOrDefault() (res Uuid)
NextOrDefault gets Next from usg where usg != nil else uses DefaultRandomUuidGenerator.Next()
type UuidSerialGenerator ¶
type UuidSerialGenerator struct { RandomTail UInt128 Mx sync.Mutex // contains filtered or unexported fields }
func (*UuidSerialGenerator) Init ¶
func (usg *UuidSerialGenerator) Init() error
func (*UuidSerialGenerator) Next ¶
func (usg *UuidSerialGenerator) Next() (res Uuid)
Next Serial id xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx M 0100 (version 4) N 10 (variant 1) tttttttt-tttt-Msss-Nrrr-rrrrrrrrrrrr M - 0100 (version 4) N - 10ss (variant 1) t - time (unix milli) s - step r - random value (Generated on Init)
func (*UuidSerialGenerator) NextOrDefault ¶ added in v0.0.1
func (usg *UuidSerialGenerator) NextOrDefault() (res Uuid)
NextOrDefault gets Next from usg where usg != nil else uses DefaultUuidGenerator.Next()
func (*UuidSerialGenerator) NextRaw ¶
func (usg *UuidSerialGenerator) NextRaw() (res Uuid, overflow bool)
NextRaw - Next Serial id (requare to lock befor call) xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx M 0100 (version 4) N 10 (variant 1) tttttttt-tttt-Msss-Nrrr-rrrrrrrrrrrr M - 0100 (version 4) N - 10ss (variant 1) t - time (unix milli) s - step r - random value (Generated on Init) overflow - may be not correct or unique result