package hashmap

import "github.com/nats-io/gnatsd/hashmap"

HashMap defines a high performance hashmap based on fast hashing and fast key comparison. Simple chaining is used, relying on the hashing algorithms for good distribution

Index

Variables

var DefaultHash = hash.Jesteress

DefaultHash to be used unless overridden.

Types

type Entry

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

Entry represents what the map is actually storing. Uses simple linked list resolution for collisions.

type HashMap

type HashMap struct {
	Hash func([]byte) uint32
	// contains filtered or unexported fields
}

HashMap stores Entry items using a given Hash function. The Hash function can be overridden.

func New

func New() *HashMap

New creates a new HashMap of default size and using the default Hashing algorithm.

func NewWithBkts

func NewWithBkts(bkts []*Entry) (*HashMap, error)

NewWithBkts creates a new HashMap using the bkts slice argument. len(bkts) must be a power of 2.

func (*HashMap) All

func (h *HashMap) All() []interface{}

All returns all the Entries in the map

func (*HashMap) AllKeys

func (h *HashMap) AllKeys() [][]byte

AllKeys will return all the keys stored in the HashMap

func (*HashMap) Count

func (h *HashMap) Count() uint32

Count returns number of elements in the HashMap

func (*HashMap) Get

func (h *HashMap) Get(key []byte) interface{}

Get will return the item at key.

func (*HashMap) Remove

func (h *HashMap) Remove(key []byte)

Remove will remove what is associated with key.

func (*HashMap) RemoveRandom

func (h *HashMap) RemoveRandom()

RemoveRandom can be used for a random policy eviction. This is stochastic but very fast and does not impede performance like LRU, LFU or even ARC based implementations.

func (*HashMap) Set

func (h *HashMap) Set(key []byte, data interface{})

Set will set the key item to data. This will blindly replace any item that may have been at key previous.

func (*HashMap) Stats

func (h *HashMap) Stats() *Stats

Stats will collect general statistics about the HashMap

type Stats

type Stats struct {
	NumElements uint32
	NumSlots    uint32
	NumBuckets  uint32
	LongChain   uint32
	AvgChain    float32
}

Stats are reported on HashMaps

Source Files

hashmap.go rand_evict.go

Version
v0.5.1
Published
Apr 25, 2014
Platform
js/wasm
Imports
6 packages
Last checked
1 hour ago

Tools for package owners.