Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
Generator returns an ID number for an operation.
Implementations of Generator are free to return both monotonic and random numbers with varying distribution according to requirements.
Must be concurrency safe.
type GeneratorSource ¶
type GeneratorSource interface {
New() Generator
}
GeneratorSource returns a Generator
type Monotonic ¶
type Monotonic struct {
// contains filtered or unexported fields
}
Monotonic returns an increasing, ordered ID number.
Calls to GetNew increases the internal counter, and GetExisting returns the current counter value.
Monotonic is safe for concurrent access and all Monotonic from the same MonotonicSource share the same internal counter.
func (*Monotonic) GetExisting ¶
GetExisting returns the internal counter value.
type MonotonicSource ¶
type MonotonicSource struct {
Count uint64
}
MonotonicSource is used to create linked instances of Monotonic.
Each Monotonic returned by New operates on the same internal counter.
func (*MonotonicSource) New ¶
func (m *MonotonicSource) New() Generator
New returns an instance of Monotonic using MonotonicSource.Counter as it's internal counter.
type Persistent ¶
type Persistent struct {
// contains filtered or unexported fields
}
Persistent wraps a Generator to provide the same ID number to GetExisting for KeepFor number calls.
Persistent should be used to chain together plan.DoFunc methods operating on the same ID number.
Calling GetNew always returns a new ID number.
func (*Persistent) GetExisting ¶
func (p *Persistent) GetExisting() uint64
GetExisting returns the same ID number for KeepFor number of calls after a call to GetNew.
Once KeepFor number of calls to GetExisting has been made, GetExisting is called on source Generator and it's value returned for KeepFor number of calls.
func (*Persistent) GetNew ¶
func (p *Persistent) GetNew() uint64
GetNew calls GetNew on the underlying Generator and resets the used count.
type PersistentSource ¶
type PersistentSource struct { KeepFor uint Source GeneratorSource }
PersistentSource returns a configured Persistent for each goroutine.
Each Persistent has in individual KeepFor counter.
func (*PersistentSource) New ¶
func (p *PersistentSource) New() Generator
New returns a Persistent Generator using PersistentSource.Source as the underlying Generator.
type Uniform ¶
type Uniform struct {
// contains filtered or unexported fields
}
Uniform returns a random ID number evenly distributed between 0 and the configured maximum ID counter.
Uniform is good for randomly reading records from the entire table, causing a high number of cache misses.
func (*Uniform) GetExisting ¶
GetExisting returns a uniformally distributed random ID number.
type UniformSource ¶
type UniformSource struct {
Max uint64
}
UniformSource returns a Generator using Max as it's internal maximum ID counter.
Each Uniform returned by New operates on the same internal maximum ID counter.
func (*UniformSource) New ¶
func (u *UniformSource) New() Generator
New returns a Uniform Generator using Max as it's internal maximum ID counter.
type Zipfian ¶
type Zipfian struct {
// contains filtered or unexported fields
}
Zipfian is used to return a random ID number heavily skewed towards a record with a high ID numbers.
Example output when Max is 100,000:
99991 99986 99993 99981 99979 99976 99972 99934 99996 99995 99998 99930 99997 99921 99973 99982
Zipfian is good for performing operations on records that are probably still in the cache.
All Zipfian from the same ZipfianSource share an internal maximum ID counter.
func (*Zipfian) GetExisting ¶
GetExisting return an existing ID number heavily skewed towards the internal maximum ID counter.
type ZipfianSource ¶
type ZipfianSource struct {
Max uint64
}
ZipfianSource is used to create linked instances of Zipfian.
All Zipfian from the same source share the same Max ID counter.
func (*ZipfianSource) New ¶
func (z *ZipfianSource) New() Generator
New returns an instance of Zipfian using the same Max.