generator

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WindowSize is the size of window of pending acks.
	WindowSize int64 = 1 << 20

	// WindowMask is used to turn an ID into a slot in the window.
	WindowMask int64 = WindowSize - 1
)
View Source
const (
	// ZipfianConstant is the default constant for the zipfian.
	ZipfianConstant = float64(0.99)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AcknowledgedCounter

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

AcknowledgedCounter reports generated integers via Last only after they have been acknoledged.

func NewAcknowledgedCounter

func NewAcknowledgedCounter(start int64) *AcknowledgedCounter

NewAcknowledgedCounter creates the counter which starts at start.

func (*AcknowledgedCounter) Acknowledge

func (a *AcknowledgedCounter) Acknowledge(value int64)

Acknowledge makes a generated counter vaailable via Last.

func (*AcknowledgedCounter) Last

func (a *AcknowledgedCounter) Last() int64

Last implements the Generator Last interface.

func (*AcknowledgedCounter) Next

func (a *AcknowledgedCounter) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Constant

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

Constant is a trivial generator that always returns the same value.

func NewConstant

func NewConstant(value int64) *Constant

NewConstant creates a constant generator

func (*Constant) Last

func (c *Constant) Last() int64

Last implements the Generator Last interface.

func (*Constant) Next

func (c *Constant) Next(_ *rand.Rand) int64

Next implements the Generator Next interface.

type Counter

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

Counter generates a sequence of integers. [0, 1, ...]

func NewCounter

func NewCounter(start int64) *Counter

NewCounter creates the Counter generator.

func (*Counter) Last

func (c *Counter) Last() int64

Last implements Generator Last interface.

func (*Counter) Next

func (c *Counter) Next(_ *rand.Rand) int64

Next implements Generator Next interface.

type Discrete

type Discrete struct {
	Number
	// contains filtered or unexported fields
}

Discrete generates a distribution by choosing from a discrete set of values.

func NewDiscrete

func NewDiscrete() *Discrete

NewDiscrete creates the generator.

func (*Discrete) Add

func (d *Discrete) Add(weight float64, value int64)

Add adds a value with weight.

func (*Discrete) Next

func (d *Discrete) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Exponential

type Exponential struct {
	Number
	// contains filtered or unexported fields
}

Exponential generates an exponential distribution. It produces a sequence of time intervals according to an expontential distribution.

func NewExponential

func NewExponential(percentile float64, rng float64) *Exponential

NewExponential creats an exponential generator with percential and range.

func NewExponentialWithMean

func NewExponentialWithMean(mean float64) *Exponential

NewExponentialWithMean creates an exponential generator with a mean arrival rate of gamma.

func (*Exponential) Next

func (e *Exponential) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Histogram

type Histogram struct {
	Number
	// contains filtered or unexported fields
}

Histogram generates integers according to a histogram distribution.

func NewHistogram

func NewHistogram(buckets []int64, blockSize int64) *Histogram

NewHistogram creates a Histogram generator.

func NewHistogramFromFile

func NewHistogramFromFile(name string) *Histogram

NewHistogramFromFile creates a Histogram generator from file.

func (*Histogram) Next

func (h *Histogram) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Hotspot

type Hotspot struct {
	Number
	// contains filtered or unexported fields
}

Hotspot generates integers resembling a hotspot distribution where %x of operations access y% of data items.

func NewHotspot

func NewHotspot(lowerBound int64, upperBound int64, hotsetFraction float64, hotOpnFraction float64) *Hotspot

NewHotspot creates a Hotspot generator. lowerBound: the lower bound of the distribution. upperBound: the upper bound of the distribution. hotsetFraction: percentage of data itme. hotOpnFraction: percentage of operations accessing the hot set.

func (*Hotspot) Next

func (h *Hotspot) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Number

type Number struct {
	LastValue int64
}

Number is a common generator.

func (*Number) Last

func (n *Number) Last() int64

Last implements the Generator Last interface.

func (*Number) SetLastValue

func (n *Number) SetLastValue(value int64)

SetLastValue sets the last value generated.

type ScrambledZipfian

type ScrambledZipfian struct {
	Number
	// contains filtered or unexported fields
}

ScrambledZipfian produces a sequence of items, such that some items are more popular than others, according to a zipfian distribution

func NewScrambledZipfian

func NewScrambledZipfian(min int64, max int64, zipfianConstant float64) *ScrambledZipfian

NewScrambledZipfian creates a ScrambledZipfian generator.

func (*ScrambledZipfian) Next

func (s *ScrambledZipfian) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Sequential

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

Sequential generates a sequence of integers 0, 1, ...

func NewSequential

func NewSequential(countStart int64, countEnd int64) *Sequential

NewSequential creates a counter that starts at countStart.

func (*Sequential) Last

func (s *Sequential) Last() int64

Last implements the Generator Last interface.

func (*Sequential) Next

func (s *Sequential) Next(_ *rand.Rand) int64

Next implements the Generator Next interface.

type SkewedLatest

type SkewedLatest struct {
	Number
	// contains filtered or unexported fields
}

SkewedLatest generates a popularity distribution of items, skewed to favor recent items significantly more than older items.

func NewSkewedLatest

func NewSkewedLatest(basis ycsb.Generator) *SkewedLatest

NewSkewedLatest creates the SkewedLatest generator. basis is Counter or AcknowledgedCounter

func (*SkewedLatest) Next

func (s *SkewedLatest) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Uniform

type Uniform struct {
	Number
	// contains filtered or unexported fields
}

Uniform generates integers randomly.

func NewUniform

func NewUniform(lb int64, ub int64) *Uniform

NewUniform creates the Uniform generator.

func (*Uniform) Next

func (u *Uniform) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

type Zipfian

type Zipfian struct {
	Number
	// contains filtered or unexported fields
}

Zipfian generates the zipfian distribution. It produces a sequence of items, such that some items are more popular than others, according to a zipfian distribution. When you construct an instance of this class, you specify the number of items in the set to draw from, either by specifying an itemcount (so that the sequence is of items from 0 to itemcount-1) or by specifying a min and a max (so that the sequence is of items from min to max inclusive). After you construct the instance, you can change the number of items by calling Next(*rand.Rand).

Note that the popular items will be clustered together, e.g. item 0 is the most popular, item 1 the second most popular, and so on (or min is the most popular, min+1 the next most popular, etc.) If you don't want this clustering, and instead want the popular items scattered throughout the item space, then use ScrambledZipfian(located in scrambled_zipfian.go) instead.

Be aware: initializing this generator may take a long time if there are lots of items to choose from (e.g. over a minute for 100 million objects). This is because certain mathematical values need to be computed to properly generate a zipfian skew, and one of those values (zeta) is a sum sequence from 1 to n, where n is the itemcount. Note that if you increase the number of items in the set, we can compute a new zeta incrementally, so it should be fast unless you have added millions of items. However, if you decrease the number of items, we recompute zeta from scratch, so this can take a long time.

The algorithm used here is from "Quickly Generating Billion-Record Synthetic Databases", Jim Gray et al, SIGMOD 1994.

func NewZipfian

func NewZipfian(min int64, max int64, zipfianConstant float64, zetan float64) *Zipfian

NewZipfian creates the Zipfian generator.

func NewZipfianWithItems

func NewZipfianWithItems(items int64, zipfianConstant float64) *Zipfian

NewZipfianWithItems creates the Zipfian generator.

func NewZipfianWithRange

func NewZipfianWithRange(min int64, max int64, zipfianConstant float64) *Zipfian

NewZipfianWithRange creates the Zipfian generator.

func (*Zipfian) Next

func (z *Zipfian) Next(r *rand.Rand) int64

Next implements the Generator Next interface.

Jump to

Keyboard shortcuts

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