flother

package
v0.0.0-...-4437b4c Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package flother is an implementation of Twitter's Snowflake 64-bit ID generation.

See: https://blog.twitter.com/2010/announcing-snowflake or: http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram

Index

Constants

View Source
const DEFAULT_NODE_BITS = 13

DEFAULT_NODE_BITS is set to 13 bits to allow for 8192 nodes.

View Source
const DEFAULT_TIME_BITS = 41

DEFAULT_TIME_BITS is set to 41 bits to allow for almost 70 years of ids with an epoch.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flother

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

func NewFlother

func NewFlother(epoch time.Time, node uint64, timeBits uint64, nodeBits uint64) *Flother

NewFlother returns a *Flother can be used to generate unique ids.

epoch is the offset to use for the id generation.

node is the unique node id for this server / application.

timeBits are the number of bits to use to represent the time; recommended DEFAULT_TIME_BITS.

nodeBits are the number of bits to use to represent the unique node; recommended DEFAULT_NODE_BITS.

func (*Flother) NewID

func (f *Flother) NewID() uint64

NewID returns a new unique identifier.

func (*Flother) NodeID

func (f *Flother) NodeID() uint64

NodeID returns the node identifier given when creating this Flother.

Jump to

Keyboard shortcuts

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