guid

package
v0.0.0-...-38a8f93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(guidBitsSize int, estimatedGUIDs, scaleFactor int64)

Init initializes the GUID package with the size of the GUID.

func SizeBits

func SizeBits() int

SizeBits returns the size of the GUID (in bits).

func SizeBytes

func SizeBytes() int

SizeBytes returns the size of the GUID (in bytes).

Types

type GUID

type GUID struct {
	// contains filtered or unexported fields
}

GUID represents a Global Unique Identifier (GUID) for a system's node

func MaximumGUID

func MaximumGUID() *GUID

MaximumGUID creates the maximum available for the current defined number of bits.

func NewGUIDBigInt

func NewGUIDBigInt(guidBigInt *big.Int) *GUID

NewGUIDBigInt...

func NewGUIDBytes

func NewGUIDBytes(bytesID []byte) *GUID

NewGUIDBytes creates a new GUID based on an array of bytes representation of the identifier. Array of bytes is a representation of the number using the minimum number of bits.

func NewGUIDInteger

func NewGUIDInteger(intId int64) *GUID

NewGUIDInteger creates a new GUID based on an integer64 representation of the identifier.

func NewGUIDRandom

func NewGUIDRandom() *GUID

NewGUIDRandom creates a random GUID in the range [0,MaxGUID).

func NewGUIDString

func NewGUIDString(stringID string) *GUID

NewGUIDString creates a new GUID based on a string representation (in base 10) of the identifier.

func NewZero

func NewZero() *GUID

NewZero creates the 0 GUID.

func (*GUID) AddOffset

func (g *GUID) AddOffset(offset string)

AddOffset adds an offset (as a string in base 10) of ids to the GUID.

func (*GUID) BigInt

func (g *GUID) BigInt() *big.Int

BigInt...

func (*GUID) Bytes

func (g *GUID) Bytes() []byte

Bytes returns an array of bytes (with size of guidSizeBits) with the value of the GUID.

func (*GUID) Cmp

func (g *GUID) Cmp(guid2 GUID) int

Cmp used to check what if the guid is higher, lower or equal than the given guid.

func (*GUID) Copy

func (g *GUID) Copy() *GUID

Copy creates a copy of the GUID object.

func (*GUID) Equals

func (g *GUID) Equals(guid2 GUID) bool

Compare if two GUIDs are equal or not.

func (*GUID) GenerateInnerRandomGUID

func (g *GUID) GenerateInnerRandomGUID(topGUID GUID) (*GUID, error)

GenerateInnerRandomGUID generates a random GUID that belongs to the interval [this, topGUID).

func (*GUID) GenerateInnerRandomGUIDScaled

func (g *GUID) GenerateInnerRandomGUIDScaled(topGUID GUID) (*GUID, error)

GenerateInnerRandomGUIDScaled generates a random GUID that belongs to the interval [this, topGUID). But it returns one of a specific set of GUIDs from the interval. This set is small than the total GUIDs of the interval.

func (*GUID) Higher

func (g *GUID) Higher(guid2 GUID) bool

Higher returns true if guid is higher than the given guid and false otherwise.

func (*GUID) Int64

func (g *GUID) Int64() int64

Int64 returns an int64 that represents the GUID.

func (*GUID) Lower

func (g *GUID) Lower(guid2 GUID) bool

Greater returns true if guid is lower than the given guid and false otherwise.

func (*GUID) PercentageOffset

func (g *GUID) PercentageOffset(offsetPercentage int, nextGuid GUID) string

PercentageOffset returns the number of ids (as a string with an integer in base 10) using % offset to higher GUID.

func (*GUID) Short

func (g *GUID) Short() string

Short returns the first digits of the GUID in a string representation.

func (*GUID) String

func (g *GUID) String() string

String returns the value of the GUID in a string representation (as an integer in base 10).

type Range

type Range struct {
	// contains filtered or unexported fields
}

Range represents a range of GUIDs (Global Unique Identifiers), i.e. [lowerGUID, higherGUID).

func NewGUIDRange

func NewGUIDRange(lowerGUID GUID, higherGUID GUID) *Range

NewGUIDRange creates a new GUID range given a lower GUID and higher GUID.

func (*Range) CreatePartitions

func (r *Range) CreatePartitions(partitionsPercentage []int) []*Range

CreatePartitions returns partitions, set of ranges, of the receiver range.

func (*Range) GenerateRandom

func (r *Range) GenerateRandom() (*GUID, error)

GenerateRandom ...

func (*Range) GenerateRandomSuperPeer

func (r *Range) GenerateRandomSuperPeer() (*GUID, error)

GenerateRandomSuperPeer generate random GUID inside the range.

func (*Range) HigherGUID

func (r *Range) HigherGUID() *GUID

HigherGUID get the higher GUID of the range.

func (*Range) Inside

func (r *Range) Inside(guid GUID) bool

Inside verify if the given GUID is inside the range.

func (*Range) LowerGUID

func (r *Range) LowerGUID() *GUID

LowerGUID get the lower GUID of the range.

func (*Range) String

func (r *Range) String() string

String returns the string representation of the range.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL