references

package
v0.0.0-...-5b112dc Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilKey = errors.New("nil key")

ErrNilKey means a key was nil.

Functions

func Grow

func Grow(m *RHMap, newSize int)

Grow is the default implementation to grow a RHMap.

Types

type Item

type Item struct {
	Key Key
	Val Val

	Distance int // How far item is from its best position.
}

Item represents an entry in the RHMap.

type Key

type Key []byte

Key is the type for a key. A nil key is invalid.

type RHMap

type RHMap struct {
	// Items are the slots of the hashmap for items.
	Items []Item

	// Number of keys in the RHMap.
	Count int

	// Overridable hash func. Defaults to hash/fnv.New32a().
	HashFunc func(Key) uint32

	// When any item's distance gets too large, grow the RHMap.
	// Defaults to 10.
	MaxDistance int

	// Overridable func to calculate a size multiplier when resizing
	// for growth is needed. Default returns a constant 2.0.
	Growth func(*RHMap) float64

	// Overridable func to grow the RHMap.
	Grow func(m *RHMap, newSize int)
}

RHMap is a hashmap that uses the robinhood algorithm. This implementation is not concurrent safe.

func New

func New(size int) *RHMap

New returns a new robinhood hashmap.

func (*RHMap) CopyTo

func (m *RHMap) CopyTo(dest *RHMap)

CopyTo copies key/val's to the dest RHMap.

func (*RHMap) Del

func (m *RHMap) Del(k Key) (prev Val, existed bool)

Del removes a key/val from the RHMap. The previous val, if it existed, is returned.

func (*RHMap) Get

func (m *RHMap) Get(k Key) (v Val, found bool)

Get retrieves the val for a given key.

func (*RHMap) Reset

func (m *RHMap) Reset()

Reset clears RHMap, where already allocated memory will be reused.

func (*RHMap) Set

func (m *RHMap) Set(k Key, v Val) (wasNew bool, err error)

Set inserts or updates a key/val into the RHMap. The returned wasNew will be true if the mutation was on a newly seen, inserted key, and wasNew will be false if the mutation was an update to an existing key.

NOTE: RHMap does not keep its own copy of the key/val's. Especially, applications should take care not to mutate the key. Careful mutations to the val bytes that do not resize the val slice, however, should work.

func (*RHMap) Visit

func (m *RHMap) Visit(callback func(k Key, v Val) (keepGoing bool))

Visit invokes the callback on key/val. The callback can return false to exit the visitation early.

type Val

type Val []byte

Val is the type for a val. A nil val is valid.

Jump to

Keyboard shortcuts

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