hashmap

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2014 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

View Source
var DefaultHash = hash.Jesteress

DefaultHash to be used unless overridden.

Functions

This section is empty.

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

Jump to

Keyboard shortcuts

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