sequence

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sequence implements Iceflake sequence generator interface. ```bash Iceflake is the interface for snowflake similar sequence generator.

Iceflake algorithm:

+-------+--------------------+----------+ | sign | delta milliseconds | sequence | +-------+--------------------+----------+ | 1 bit | 63-n bits | n bits |

sequence (n bits) The last custom n bits, represents sequence within the one millisecond.

delta milliseconds (63-n bits) The next 63-n bits, represents delta milliseconds since a custom epoch. ```

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iceflake

type Iceflake interface {
	Sequencer
	// StartTime defines the time since which
	// the Iceflake time is defined as the elapsed time.
	StartTime() time.Time
	// BitLenSequence defines the bit length of sequence number,
	// and the bit length of time is 63 - BitLenSequence().
	BitLenSequence() uint8
}

Iceflake is the interface for snowflake similar sequence generator.

type MemFlake

type MemFlake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MemFlake is an implementation of in-memory Iceflake.

func NewMemFlake

func NewMemFlake(startTime time.Time, bitLenSequence uint8, machineID uint64) *MemFlake

NewMemFlake creates a MemFlake.

func (*MemFlake) BitLenSequence

func (m *MemFlake) BitLenSequence() uint8

BitLenSequence ...

func (*MemFlake) MachineID

func (m *MemFlake) MachineID() uint64

MachineID ...

func (*MemFlake) Next

func (m *MemFlake) Next() (uint64, error)

Next ...

func (*MemFlake) NextN

func (m *MemFlake) NextN(n int) (uint64, error)

NextN ...

func (*MemFlake) StartTime

func (m *MemFlake) StartTime() time.Time

StartTime ...

type MemSeq

type MemSeq struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MemSeq is an implementation of in-memory Sequencer.

func NewMemSeq

func NewMemSeq(machineID uint64) *MemSeq

NewMemSeq creates a MemSeq.

func (*MemSeq) MachineID

func (m *MemSeq) MachineID() uint64

MachineID ...

func (*MemSeq) Next

func (m *MemSeq) Next() (uint64, error)

Next ...

func (*MemSeq) NextN

func (m *MemSeq) NextN(n int) (uint64, error)

NextN ...

type Sequencer

type Sequencer interface {
	// Next returns the next sequence.
	Next() (uint64, error)
	// NextN reserves the next `n` sequences and returns the first one,
	// `n` should not be less than 1.
	NextN(n int) (uint64, error)
	// MachineID returns the unique ID of the instance.
	MachineID() uint64
}

Sequencer is the interface for sequence generator.

Jump to

Keyboard shortcuts

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