rhh

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: ISC Imports: 1 Imported by: 2

README

rhh

GoDoc

A simple and efficient hashmap package for Go using the xxhash algorithm, open addressing, and robin hood hashing.

This is an alternative to the standard Go map.

Getting Started

Installing

To start using rhh, install Go and run go get:

$ go get github.com/tidwall/rhh

This will retrieve the library.

Usage

The Map type works similar to a standard Go map, and includes four methods: Set, Get, Delete, Len.

var m rhh.Map
m.Set("Hello", "Dolly!")
val, _ := m.Get("Hello")
fmt.Printf("%v\n", val)
val, _ = m.Delete("Hello")
fmt.Printf("%v\n", val)
val, _ = m.Get("Hello")
fmt.Printf("%v\n", val)

// Output:
// Dolly!
// Dolly!
// <nil>

Contact

Josh Baker @tidwall

License

Source code is available under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map is a hashmap. Like map[string]interface{}

func New

func New(cap int) *Map

New returns a new Map. Like map[string]interface{}

func (*Map) Delete

func (m *Map) Delete(key string) (interface{}, bool)

Delete deletes a value for a key. Returns the deleted value, or false when no value was assigned.

func (*Map) Get

func (m *Map) Get(key string) (interface{}, bool)

Get returns a value for a key. Returns false when no value has been assign for key.

func (*Map) GetPos added in v1.1.0

func (m *Map) GetPos(pos uint64) (key string, value interface{}, ok bool)

GetPos gets a single keys/value nearby a position The pos param can be any valid uint64. Useful for grabbing a random item from the map. It's not safe to call or Set or Delete while ranging.

func (*Map) Len

func (m *Map) Len() int

Len returns the number of values in map.

func (*Map) Range

func (m *Map) Range(iter func(key string, value interface{}) bool)

Range iterates over all key/values. It's not safe to call or Set or Delete while ranging.

func (*Map) Set

func (m *Map) Set(key string, value interface{}) (interface{}, bool)

Set assigns a value to a key. Returns the previous value, or false when no value was assigned.

Jump to

Keyboard shortcuts

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