fastinteger

package
v1.0.48 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2018 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package fastinteger is designed to provide a very primitive implementation of a hash map for unsigned integer keys and values. It is designed to have existence checks and insertions that are faster than Go's native implementation. Like Go's native implementation, FastIntegerHashMap will dynamically grow in size.

Current benchmarks on identical machine against native Go implementation:

BenchmarkInsert-8	   10000	    131258 ns/op
BenchmarkGoMapInsert-8	   10000	    208787 ns/op
BenchmarkExists-8	  100000	     15820 ns/op
BenchmarkGoMapExists-8	  100000	     16394 ns/op
BenchmarkDelete-8	  100000	     17909 ns/op
BenchmarkGoDelete-8	   30000	     49376 ns/op
BenchmarkInsertWithExpand-8	   20000	     90301 ns/op
BenchmarkGoInsertWithExpand-8	   10000	    142088 ns/op

This performance could be further enhanced by using a better probing technique.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FastIntegerHashMap

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

FastIntegerHashMap is a simple hashmap to be used with integer only keys. It supports few operations, and is designed primarily for cases where the consumer needs a very simple datastructure to set and check for existence of integer keys over a sparse range.

func New

func New(hint uint64) *FastIntegerHashMap

New returns a new FastIntegerHashMap with a bucket size specified by hint.

func (*FastIntegerHashMap) Cap

func (fi *FastIntegerHashMap) Cap() uint64

Cap returns the capacity of the hashmap.

func (*FastIntegerHashMap) Delete

func (fi *FastIntegerHashMap) Delete(key uint64)

Delete will remove the provided key from the hashmap. If the key cannot be found, this is a no-op.

func (*FastIntegerHashMap) Exists

func (fi *FastIntegerHashMap) Exists(key uint64) bool

Exists will return a bool indicating if the provided key exists in the map.

func (*FastIntegerHashMap) Get

func (fi *FastIntegerHashMap) Get(key uint64) (uint64, bool)

Get returns an item from the map if it exists. Otherwise, returns false for the second argument.

func (*FastIntegerHashMap) Len

func (fi *FastIntegerHashMap) Len() uint64

Len returns the number of items in the hashmap.

func (*FastIntegerHashMap) Set

func (fi *FastIntegerHashMap) Set(key, value uint64)

Set will set the provided key with the provided value.

Jump to

Keyboard shortcuts

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