hashmap

package module
v0.0.0-...-b2c4df5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hashmap

GoDoc

A high performance concurrent map for Go, all functions are thread safe, support for generics.

Getting Started

// create a new hashmap with key type int and value type int
m := New[int, int](0)

// set the value for key
m.Set(1, 1)
m.Set(1, 2)
m.Set(2, 1)

// get count of key-value for the hashmap
n = m.Len()

// get value by key
v, ok = m.Get(1)
v, ok = m.Get(2)

// delete the value for a key.
m.Del(1)

Benchmark

goos: linux
goarch: amd64
pkg: github.com/nnsgmsone/hashmap
cpu: Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz
BenchmarkHashMap/hashmap-set-parallel100-20         	       1	1586248494 ns/op	  116872 B/op	     	561 allocs/op
BenchmarkHashMap/hashmap-set-parallel1000-20        	       1	11420826547 ns/op	  836576 B/op	    	4695 allocs/op
BenchmarkHashMap/hashmap-set-get-parallel100-20     	       1	3255109261 ns/op	   47776 B/op	     	243 allocs/op
BenchmarkHashMap/hashmap-set-get-parallel1000-20    	       1	17511975838 ns/op	  620832 B/op	    	2966 allocs/op
BenchmarkHashMap/syncmap-set-parallel100-20         	       1	19082770010 ns/op	2400015608 B/op		199976074 allocs/op
BenchmarkHashMap/syncmap-set-parallel1000-20        	       1	204721266296 ns/op	29956965176 B/op	2743807276 allocs/op
BenchmarkHashMap/syncmap-set-get-parallel100-20     	       1	1636063296 ns/op	2400001528 B/op		199975746 allocs/op
BenchmarkHashMap/syncmap-set-get-parallel1000-20    	       1	19790039965 ns/op	32929943928 B/op	3115775177 allocs/op
BenchmarkHashMap/mutexmap-set-parallel100-20        	       1	15495332887 ns/op	799877384 B/op		99974948 allocs/op
BenchmarkHashMap/mutexmap-set-parallel1000-20       	       1	178083314115 ns/op	13960544056 B/op	1743848208 allocs/op
BenchmarkHashMap/mutexmap-set-get-parallel100-20    	       1	9547300918 ns/op	799986024 B/op		99976220 allocs/op
BenchmarkHashMap/mutexmap-set-get-parallel1000-20   	       1	143467062246 ns/op	16978766920 B/op	2116287321 allocs/op

License

hashmap 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[K comparable, V any] struct {
	// contains filtered or unexported fields
}

high performace concurrent hashmap

func New

func New[K comparable, V any](cap int) *Map[K, V]

Map is a concurrent hash map with generics.

func (*Map[K, V]) Del

func (mp *Map[K, V]) Del(k K)

delete the value for a key.

func (*Map[K, V]) Get

func (mp *Map[K, V]) Get(k K) (V, bool)

return the value for a key. the ok result indicates whether k is in the map.

func (*Map[K, V]) Len

func (mp *Map[K, V]) Len() int

return the count of key-value in the map.

func (*Map[K, V]) Set

func (mp *Map[K, V]) Set(k K, v V)

set the value for a key.

Jump to

Keyboard shortcuts

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