Documentation
¶
Overview ¶
Package chd implements the compress, hash, and displace (CHD) minimal perfect hash algorithm. It provides a map builder that manages adding of items and map creation.
See http://cmph.sourceforge.net/papers/esa09.pdf for more details.
Index ¶
- func SetCompactArray(a CompactArray)
- type BuildOptions
- type Builder
- type CompactArray
- type Map
- func (m *Map) Get(key []byte) []byte
- func (m *Map) GetRandomKey() []byte
- func (m *Map) GetRandomValue() []byte
- func (m *Map) Len() int
- func (m *Map) Read(p []byte) (n int, err error)
- func (m *Map) Size() int
- func (m *Map) Values(yield func([]byte) bool) bool
- func (m *Map) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetCompactArray ¶
func SetCompactArray(a CompactArray)
SetCompactArray sets the compressed array used to store hash indices. It is important that the compact array used when building and reading a map is exactly the same.
Types ¶
type BuildOptions ¶
type BuildOptions struct {
// LoadFactor sets the load
// factor. Lower values results
// in faster build times. Default
// value is 1.0
//
// If ForceBuild is enabled the
// actual load factor may differ
// significantly from the set value.
LoadFactor float64
// BucketSize sets the average
// number of keys per bucket.
// Default value is 5.
BucketSize int
// ForceBuild indicates that the
// Builder.Build method will always
// succeed. This is done by decreasing
// the load factor every time it fails.
// Default value is true.
ForceBuild bool
Trials int
}
BuildOptions specifies the options for building a map.
func NewBuildOptions ¶
func NewBuildOptions() *BuildOptions
NewBuildOptions creates build options with default values.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder manages adding of items and map creation.
func NewBuilder ¶
func NewBuilder(opts *BuildOptions) *Builder
NewBuilder returns a new map builder given the build options. If opts is nil, the default values are used.
type CompactArray ¶
CompactArray represents a compressed integer array.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map represents a map that uses CHD minimal perfect hash algorithm.
func (*Map) GetRandomKey ¶
Get a random entry from the hash table
func (*Map) GetRandomValue ¶
Get a random entry from the hash table