-
Notifications
You must be signed in to change notification settings - Fork 13
/
gen.go
81 lines (62 loc) · 1.56 KB
/
gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"math/rand"
"time"
"github.com/pingcap/go-ycsb/pkg/generator"
)
type NewGeneratorFunc = func(int) Generator
type Generator interface {
Name() string
Next() string
}
//------------------------------------------------------------------------------
type ScrambledZipfian struct {
r *rand.Rand
z *generator.ScrambledZipfian
}
func NewScrambledZipfian(max int) Generator {
return &ScrambledZipfian{
r: rand.New(rand.NewSource(time.Now().UnixNano())),
z: generator.NewScrambledZipfian(0, int64(max), generator.ZipfianConstant),
}
}
func (g *ScrambledZipfian) Name() string {
return "zipfian"
}
func (g *ScrambledZipfian) Next() string {
return stringFromInt64(g.z.Next(g.r))
}
//------------------------------------------------------------------------------
type Hotspot struct {
r *rand.Rand
h *generator.Hotspot
}
func NewHotspot(max int) Generator {
return &Hotspot{
r: rand.New(rand.NewSource(time.Now().UnixNano())),
h: generator.NewHotspot(0, int64(max), 0.1, 0.9),
}
}
func (g *Hotspot) Name() string {
return "hostspot(0.1, 0.9)"
}
func (g *Hotspot) Next() string {
return stringFromInt64(g.h.Next(g.r))
}
//------------------------------------------------------------------------------
type Uniform struct {
r *rand.Rand
h *generator.Uniform
}
func NewUniform(max int) Generator {
return &Uniform{
r: rand.New(rand.NewSource(time.Now().UnixNano())),
h: generator.NewUniform(0, int64(max)),
}
}
func (g *Uniform) Name() string {
return "uniform"
}
func (g *Uniform) Next() string {
return stringFromInt64(g.h.Next(g.r))
}