All Projects → rmind → Rhashmap

rmind / Rhashmap

Licence: other
Robin Hood hash map library

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Rhashmap

Thmap
Concurrent trie-hash map library
Stars: ✭ 51 (+54.55%)
Mutual labels:  algorithm, hashing, library
Memento
Fairly basic redis-like hashmap implementation on top of a epoll TCP server.
Stars: ✭ 74 (+124.24%)
Mutual labels:  hashing, hashmap, key-value-store
Towel
Throw in the towel.
Stars: ✭ 333 (+909.09%)
Mutual labels:  algorithm, library
Delaunay Triangulation
C++ version the delaunay triangulation
Stars: ✭ 339 (+927.27%)
Mutual labels:  algorithm, library
React Native Blurhash
🖼️ A library to show colorful blurry placeholders while your content loads.
Stars: ✭ 430 (+1203.03%)
Mutual labels:  algorithm, library
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (+8875.76%)
Mutual labels:  key-value-store, library
Gokv
Simple key-value store abstraction and implementations for Go (Redis, Consul, etcd, bbolt, BadgerDB, LevelDB, Memcached, DynamoDB, S3, PostgreSQL, MongoDB, CockroachDB and many more)
Stars: ✭ 314 (+851.52%)
Mutual labels:  key-value-store, library
Tstl
TypeScript-STL (Standard Template Library, migrated from C++)
Stars: ✭ 397 (+1103.03%)
Mutual labels:  algorithm, hashmap
cachegrand
cachegrand is an open-source fast, scalable and secure Key-Value store, also fully compatible with Redis protocol, designed from the ground up to take advantage of modern hardware vertical scalability, able to provide better performance and a larger cache at lower cost, without losing focus on distributed systems.
Stars: ✭ 87 (+163.64%)
Mutual labels:  high-performance, key-value-store
Solid
🎯 A comprehensive gradient-free optimization framework written in Python
Stars: ✭ 546 (+1554.55%)
Mutual labels:  algorithm, library
Faster
Fast persistent recoverable log and key-value store + cache, in C# and C++.
Stars: ✭ 4,846 (+14584.85%)
Mutual labels:  key-value-store, library
Zero Allocation Hashing
Zero-allocation hashing for Java
Stars: ✭ 561 (+1600%)
Mutual labels:  hashing, high-performance
Cuckoofilter
Substitute for bloom filter.
Stars: ✭ 270 (+718.18%)
Mutual labels:  algorithm, hashing
komihash
Very fast, high-quality hash function (non-cryptographic, C) + PRNG
Stars: ✭ 68 (+106.06%)
Mutual labels:  hashing, hashmap
Klib
A standalone and lightweight C library
Stars: ✭ 3,442 (+10330.3%)
Mutual labels:  algorithm, library
hatrack
Fast, multi-reader, multi-writer, lockless data structures for parallel programming
Stars: ✭ 55 (+66.67%)
Mutual labels:  high-performance, hashmap
Sharedhashfile
Share Hash Tables With Stable Key Hints Stored In Memory Mapped Files Between Arbitrary Processes
Stars: ✭ 380 (+1051.52%)
Mutual labels:  key-value-store, high-performance
Polysnap
A work in progress polygon operations library with integer snap-rounding
Stars: ✭ 14 (-57.58%)
Mutual labels:  algorithm, library
Ringbuf
Lock-free ring buffer (MPSC)
Stars: ✭ 227 (+587.88%)
Mutual labels:  algorithm, library
Merkletreejs
🌱 Construct Merkle Trees and verify proofs in JavaScript.
Stars: ✭ 238 (+621.21%)
Mutual labels:  algorithm, hashing

Robin Hood hash map

Build Status

Robin Hood hash map library -- a general purpose hash table, using open addressing with linear probing and Robin Hood hashing for the collision resolution algorithm. Optimal for solving the dictionary problem. The library provides support for the SipHash and Murmurhash3 algorithms. The implementation is written in C99 and distributed under the 2-clause BSD license.

Reference:

Pedro Celis, 1986, Robin Hood Hashing, University of Waterloo
https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf

API

  • rhashmap_t *rhashmap_create(size_t size, unsigned flags)

    • Construct a new hash map. If size is not zero, then the hash map will be pre-allocated with, at least, the given size as a minimum; otherwise, a default size will be used. Certain hash map behaviour can be specified using any of the following optional flags:
      • RHM_NOCOPY: the keys on insert will not be copied and the given pointers to them will be expected to be valid and the values constant until the key is deleted; by default, the put operation will make a copy of the key.
      • RHM_NONCRYPTO: a non-cryptographic hash function will be used to provide higher performance. By default, half SipHash-2-4 is used to defend against the hash-flooding DoS attacks. With this flag set, the hash function will be switched to the MurmurHash3 algorithm.
  • void rhashmap_destroy(rhashmap_t *hmap)

    • Destroy the hash map, freeing the memory it uses.
  • void *rhashmap_get(rhashmap_t *hmap, const void *key, size_t len)

    • Lookup the key (of a given length) and return the value associated with it. Return NULL if the key is not found (see the caveats section).
  • void *rhashmap_put(rhashmap_t *hmap, const void *key, size_t len, void *val)

    • Insert the key with an arbitrary value. If the key is already present, return the already existing associated value without changing it. Otherwise, on a successful insert, return the given value. Just compare the result against val to test whether the insert was successful.
  • void *rhashmap_del(rhashmap_t *hmap, const void *key, size_t len)

    • Remove the given key. If the key was present, return the associated value; otherwise return NULL.

Caveats

  • The hash table will grow when it reaches ~85% fill and will shrink when the fill is below ~40%.

  • The key sizes greater than 64 KB are not supported. The hash map supports up to UINT_MAX elements, which is, on any modern CPU architecture, more than 4 billion elements. These limits are expected to be enough for all practical use cases, while allowing this implementation to use less memory.

  • While the NULL values may be inserted, rhashmap_get and rhashmap_del cannot indicate whether the key was not found or a key with a NULL value was found. If the caller needs to indicate an "empty" value, it can use a special pointer value, such as (void *)(uintptr_t)0x1.

Performance

With small to medium key sizes, Robin Hood hash map scores above Judy array (JudyHS) and Google Sparse hash map on lookup performance benchmarks. With the very small key sizes, it demonstrates similar performance to JudyHS.

Disclaimer: benchmark results, however, depend on many aspects (workload, hardware characteristics, methodology, etc). Ultimately, readers are encouraged to perform their own benchmarks.

Example

An illustrative code fragment:

#include <rhashmap.h>

rhashmap_t *kvmap;
struct obj *obj;

kvmap = rhashmap_create(0, 0);
assert(kvmap != NULL);
...
obj = obj_create();
rhashmap_put(kvmap, "test", sizeof("test") - 1, obj);
...
obj = rhashmap_get(kvmap, "test", sizeof("test") - 1);
...
rhashmap_destroy(kvmap);

Packages

Just build the package, install it and link the library using the -lrhashmap flag.

  • RPM (tested on RHEL/CentOS 7): cd pkg && make rpm
  • DEB (tested on Debian 9): cd pkg && make deb
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].