All Projects → cornelk → Hashmap

cornelk / Hashmap

Licence: apache-2.0
A Golang lock-free thread-safe HashMap optimized for fastest read access.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Hashmap

Imtools
Fast and memory-efficient immutable collections and helper data structures
Stars: ✭ 85 (-90.55%)
Mutual labels:  lock-free, map
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (-64.29%)
Mutual labels:  hashmap, lock-free
Eternal
A C++14 compile-time/constexpr map and hash map with minimal binary footprint
Stars: ✭ 93 (-89.66%)
Mutual labels:  hashmap, map
Hashmap
HashMap JavaScript class for Node.js and the browser. The keys can be anything and won't be stringified
Stars: ✭ 363 (-59.62%)
Mutual labels:  hashmap, map
hatrack
Fast, multi-reader, multi-writer, lockless data structures for parallel programming
Stars: ✭ 55 (-93.88%)
Mutual labels:  hashmap, lock-free
Lockfreehashmap Rs
A concurrent lock-free hash map for Rust.
Stars: ✭ 16 (-98.22%)
Mutual labels:  hashmap, lock-free
Sharpmap
An easy-to-use mapping library for use in web and desktop applications
Stars: ✭ 613 (-31.81%)
Mutual labels:  map
Wobike
Documentation of Bike Sharing APIs 🚴🛴🛵
Stars: ✭ 705 (-21.58%)
Mutual labels:  map
Webgl Wind
Wind power visualization with WebGL particles
Stars: ✭ 601 (-33.15%)
Mutual labels:  map
Alerts And Pickers
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...
Stars: ✭ 5,267 (+485.87%)
Mutual labels:  map
Maps
A Mapbox GL react native module for creating custom maps
Stars: ✭ 893 (-0.67%)
Mutual labels:  map
Zeps Gui
L'interface d'un outil de calcul d'itinéraires, principalement utilisé pour se repérer dans le Netherrail de Zcraft. Nécessite https://github.com/zDevelopers/ZePS-Core .
Stars: ✭ 5 (-99.44%)
Mutual labels:  map
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (-23.25%)
Mutual labels:  lock-free
City Vein
Urban structure characterized by 🚌 public lines
Stars: ✭ 644 (-28.36%)
Mutual labels:  map
React Map Gl
React friendly API wrapper around MapboxGL JS
Stars: ✭ 6,244 (+594.55%)
Mutual labels:  map
Umap
uMap lets you create maps with OpenStreetMap layers in a minute and embed them in your site.
Stars: ✭ 609 (-32.26%)
Mutual labels:  map
Harp.gl
harp.gl - web map rendering engine
Stars: ✭ 828 (-7.9%)
Mutual labels:  map
Iclient Javascript
Modern GIS Web Client for JavaScript, based on Leaflet\OpenLayers\MapboxGL-JS\Classic(iClient8C), enhanced with ECharts\D3\MapV etc. Contributed by SuperMap & community.
Stars: ✭ 593 (-34.04%)
Mutual labels:  map
Webglobe
基于HTML5原生WebGL实现的轻量级Google Earth三维地图引擎
Stars: ✭ 685 (-23.8%)
Mutual labels:  map
Exchange Core
Ultra-fast matching engine written in Java based on LMAX Disruptor, Eclipse Collections, Real Logic Agrona, OpenHFT, LZ4 Java, and Adaptive Radix Trees.
Stars: ✭ 801 (-10.9%)
Mutual labels:  lock-free

hashmap Build Status GoDoc Go Report Card codecov

Overview

A Golang lock-free thread-safe HashMap optimized for fastest read access.

Usage

Set a value for a key in the map:

m := &HashMap{}
m.Set("amount", 123)

Read a value for a key from the map:

amount, ok := m.Get("amount")

Use the map to count URL requests:

var i int64
actual, _ := m.GetOrInsert("api/123", &i)
counter := (actual).(*int64)
atomic.AddInt64(counter, 1) // increase counter
...
count := atomic.LoadInt64(counter) // read counter

Benchmarks

Reading from the hash map in a thread-safe way is nearly as fast as reading from a standard Golang map in an unsafe way and twice as fast as Go's sync.Map:

BenchmarkReadHashMapUint-8                	  200000	      6830 ns/op
BenchmarkReadGoMapUintUnsafe-8            	  300000	      4280 ns/op
BenchmarkReadGoMapUintMutex-8             	   30000	     51294 ns/op
BenchmarkReadGoSyncMapUint-8              	  200000	     10351 ns/op

If your keys for the map are already hashes, no extra hashing needs to be done by the map:

BenchmarkReadHashMapHashedKey-8           	 1000000	      1692 ns/op

Reading from the map while writes are happening:

BenchmarkReadHashMapWithWritesUint-8      	  200000	      8395 ns/op
BenchmarkReadGoMapWithWritesUintMutex-8   	   10000	    143793 ns/op
BenchmarkReadGoSyncMapWithWritesUint-8    	  100000	     12221 ns/op

Write performance without any concurrent reads:

BenchmarkWriteHashMapUint-8               	   10000	    210383 ns/op
BenchmarkWriteGoMapMutexUint-8            	   30000	     53331 ns/op
BenchmarkWriteGoSyncMapUint-8             	   10000	    176903 ns/op

The benchmarks were run with Golang 1.10.1 on MacOS.

Benefits over Golangs builtin map

  • Faster

  • thread-safe access without need of a(n extra) mutex

  • Compare-and-swap access for values

  • Access functions for keys that are hashes and do not need to be hashed again

Benefits over Golangs sync.Map

  • Faster

  • Access functions for keys that are hashes and do not need to be hashed again

Technical details

  • Technical design decisions have been made based on benchmarks that are stored in an external repository: go-benchmark

  • The library uses a sorted doubly linked list and a slice as an index into that list.

  • The Get() function contains helper functions that have been inlined manually until the Golang compiler will inline them automatically.

  • It optimizes the slice access by circumventing the Golang size check when reading from the slice. Once a slice is allocated, the size of it does not change. The library limits the index into the slice, therefore the Golang size check is obsolete. When the slice reaches a defined fill rate, a bigger slice is allocated and all keys are recalculated and transferred into the new slice.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].