All Projects → rigtorp → Hashmap

rigtorp / Hashmap

Licence: mit
An open addressing linear probing hash table, tuned for delete heavy workloads

Labels

Projects that are alternatives of or similar to Hashmap

komihash
Very fast, high-quality hash function (non-cryptographic, C) + PRNG
Stars: ✭ 68 (-40.35%)
Mutual labels:  hashmap
Wyhash
The FASTEST QUALITY hash function, random number generators (PRNG) and hash map.
Stars: ✭ 410 (+259.65%)
Mutual labels:  hashmap
Sparsepp
A fast, memory efficient hash map for C++
Stars: ✭ 1,021 (+795.61%)
Mutual labels:  hashmap
Rustbreak
A simple, fast and easy to use self-contained single file storage for Rust
Stars: ✭ 315 (+176.32%)
Mutual labels:  hashmap
Hashmap
HashMap JavaScript class for Node.js and the browser. The keys can be anything and won't be stringified
Stars: ✭ 363 (+218.42%)
Mutual labels:  hashmap
Lockfreehashmap Rs
A concurrent lock-free hash map for Rust.
Stars: ✭ 16 (-85.96%)
Mutual labels:  hashmap
HashMapC
A tiny library for using easily HashMap, arraylist in the C.
Stars: ✭ 21 (-81.58%)
Mutual labels:  hashmap
Eternal
A C++14 compile-time/constexpr map and hash map with minimal binary footprint
Stars: ✭ 93 (-18.42%)
Mutual labels:  hashmap
Tstl
TypeScript-STL (Standard Template Library, migrated from C++)
Stars: ✭ 397 (+248.25%)
Mutual labels:  hashmap
Rhashmap
Robin Hood hash map library
Stars: ✭ 33 (-71.05%)
Mutual labels:  hashmap
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 (+181.58%)
Mutual labels:  hashmap
Capsule
The Capsule Hash Trie Collections Library
Stars: ✭ 350 (+207.02%)
Mutual labels:  hashmap
Hashmap
A Golang lock-free thread-safe HashMap optimized for fastest read access.
Stars: ✭ 899 (+688.6%)
Mutual labels:  hashmap
Smoothiemap
A gulp of low latency Java
Stars: ✭ 255 (+123.68%)
Mutual labels:  hashmap
Dashmap
Blazing fast concurrent HashMap for Rust.
Stars: ✭ 1,128 (+889.47%)
Mutual labels:  hashmap
hatrack
Fast, multi-reader, multi-writer, lockless data structures for parallel programming
Stars: ✭ 55 (-51.75%)
Mutual labels:  hashmap
Algorithms
CLRS study. Codes are written with golang.
Stars: ✭ 482 (+322.81%)
Mutual labels:  hashmap
Containers
Containers backed by std.experimental.allocator
Stars: ✭ 111 (-2.63%)
Mutual labels:  hashmap
Memento
Fairly basic redis-like hashmap implementation on top of a epoll TCP server.
Stars: ✭ 74 (-35.09%)
Mutual labels:  hashmap
Koloboke
Java Collections till the last breadcrumb of memory and performance
Stars: ✭ 909 (+697.37%)
Mutual labels:  hashmap

HashMap.h

C/C++ CI Build Status License

A hash table mostly compatible with the C++11 std::unordered_map interface, but with much higher performance for many workloads.

Implementation

This hash table uses open addressing with linear probing and backshift deletion. Open addressing and linear probing minimizes memory allocations and achieves high cache efficiency. Backshift deletion keeps performance high for delete heavy workloads by not clobbering the hash table with tombestones.

Usage

HashMap is mostly compatible with the C++11 container interface. The main differences are:

  • A key value to represent the empty key is required.
  • Key and T needs to be default constructible.
  • Iterators are invalidated on all modifying operations.
  • It's invalid to perform any operations with the empty key.
  • Destructors are not called on erase.
  • Extensions for lookups using related key types.

Member functions:

  • HashMap(size_type bucket_count, key_type empty_key);

    Construct a HashMap with bucket_count buckets and empty_key as the empty key.

The rest of the member functions are implemented as for std::unordered_map.

Example

  using namespace rigtorp;

  // Hash for using std::string as lookup key
  struct Hash {
    size_t operator()(int v) { return v * 7; }
    size_t operator()(const std::string &v) { return std::stoi(v) * 7; }
  };

  // Equal comparison for using std::string as lookup key
  struct Equal {
    bool operator()(int lhs, int rhs) { return lhs == rhs; }
    bool operator()(int lhs, const std::string &rhs) {
      return lhs == std::stoi(rhs);
    }
  };

  // Create a HashMap with 16 buckets and 0 as the empty key
  HashMap<int, int, Hash, Equal> hm(16, 0);
  hm.emplace(1, 1);
  hm[2] = 2;

  // Iterate and print key-value pairs
  for (const auto &e : hm) {
    std::cout << e.first << " = " << e.second << "\n";
  }

  // Lookup using std::string
  std::cout << hm.at("1") << "\n";

  // Erase entry
  hm.erase(1);

Benchmark

A benchmark src/HashMapBenchmark.cpp is included with the sources. The benchmark simulates a delete heavy workload where items are repeatedly inserted and deleted.

I ran this benchmark on the following configuration:

  • AMD Ryzen 9 3900X
  • Linux 5.8.4-200.fc32.x86_64
  • gcc (GCC) 10.2.1 20200723 (Red Hat 10.2.1-1)
  • Isolated a core complex (CCX) using isolcpus for running the benchmark

When working set fits in L3 cache (HashMapBenchmark -c 100000 -i 100000000):

Implementation mean ns/iter max ns/iter
HashMap 24 1082
absl::flat_hash_map 24 2074
google::dense_hash_map 49 689846
std::unordered_map 67 10299

When working set is larger than L3 cache (HashMapBenchmark -c 10000000 -i 1000000000):

Implementation mean ns/iter max ns/iter
HashMap 75 19026
absl::flat_hash_map 101 19848
google::dense_hash_map 111 226083255
std::unordered_map 408 22422

Cited by

HashMap has been cited by the following papers:

About

This project was created by Erik Rigtorp <[email protected]>.

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].