• This repository has been archived on 26/Dec/2023
  • Stars
    star
    1,510
  • Rank 31,048 (Top 0.7 %)
  • Language
    C++
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20

➡ robin_hood unordered map & set Release GitHub license


NOTE: Unfortunately I do not have time to continue development for this hashmap. I have a worthy successor though, please head over to: ankerl::unordered_dense::{map, set}

I have spent a lot of time developing and improving it robin_hood, and it works quite well for most use cases. I won't make any updates to this code any more, unless they are PRs for critical bug fixes.


Travis CI Build Status Appveyor Build Status Codacy Badge Total alerts Language grade: C/C++ Coverage Status

robin_hood::unordered_map and robin_hood::unordered_set is a platform independent replacement for std::unordered_map / std::unordered_set which is both faster and more memory efficient for real-world use cases.

Installation & Usage

Direct Inclusion

  1. Add robin_hood.h to your C++ project.
  2. Use robin_hood::unordered_map instead of std::unordered_map
  3. Use robin_hood::unordered_set instead of std::unordered_set

Conan, the C/C++ Package Manager

  1. Setup your CMakeLists.txt (see Conan documentation on how to use MSBuild, Meson and others) like this:
    project(myproject CXX)
    
    add_executable(${PROJECT_NAME} main.cpp)
    
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Include Conan-generated file
    conan_basic_setup(TARGETS) # Introduce Conan-generated targets
    
    target_link_libraries(${PROJECT_NAME} CONAN_PKG::robin-hood-hashing)
  2. Create conanfile.txt in your source dir (don't forget to update the version)
    [requires]
    robin-hood-hashing/3.11.5
    
    [generators]
    cmake
  3. Install and run Conan, then build your project as always:
    pip install conan
    mkdir build
    cd build
    conan install ../ --build=missing
    cmake ../
    cmake --build .
    The robin-hood-hashing package in Conan is kept up to date by Conan contributors. If the version is out of date, please create an issue or pull request on the conan-center-index repository.

Benchmarks

Please see extensive benchmarks at Hashmaps Benchmarks. In short: robin_hood is always among the fastest maps and uses far less memory than std::unordered_map.

Design Choices

  • Two memory layouts. Data is either stored in a flat array, or with node indirection. Access for unordered_flat_map is extremely fast due to no indirection, but references to elements are not stable. It also causes allocation spikes when the map resizes, and will need plenty of memory for large objects. Node based map has stable references & pointers (NOT iterators! Similar to std::unordered_map) and uses const Key in the pair. It is a bit slower due to indirection. The choice is yours; you can either use robin_hood::unordered_flat_map or robin_hood::unordered_node_map directly. If you use robin_hood::unordered_map It tries to choose the layout that seems appropriate for your data.

  • Custom allocator. Node based representation has a custom bulk allocator that tries to make few memory allocations. All allocated memory is reused, so there won't be any allocation spikes. It's very fast as well.

  • Optimized hash. robin_hood::hash has custom implementations for integer types and for std::string that are very fast and falls back to std::hash for everything else.

  • Depends on good Hashing. For a really bad hash the performance will not only degrade like in std::unordered_map, the map will simply fail with an std::overflow_error. In practice, when using the standard robin_hood::hash, I have never seen this happening.

License

Licensed under the MIT License. See the LICENSE file for details.

by martinus

More Repositories

1

nanobench

Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20
C++
1,398
star
2

unordered_dense

A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion
C++
870
star
3

map_benchmark

Comprehensive benchmarks of C++ maps
C++
294
star
4

svector

Compact SVO optimized vector for C++17 or higher
C++
94
star
5

BitcoinUtxoVisualizer

Visualize Bitcoin UTXO set
C++
42
star
6

programming-font-test-pattern

Test pattern for programming fonts
38
star
7

better-faster-stronger-mixer

Testing framework for the quest to find a fast & strong mixer, e. g for hashtables.
C++
35
star
8

differential-evolution-rs

Generic Differential Evolution for Rust
Rust
18
star
9

YaceReloaded

Yet Another Corewar Evolver - It's been 12 years, now I'll try my luck again.
Red
9
star
10

base58

A fast implementation of base58 encoding
C++
7
star
11

keto-calculator

keto calculator on the web
HTML
5
star
12

ninja2wctr

Calculates Wall Clock Time Responsibility for each output from .ninja_log
C++
4
star
13

cpp_rng

C++ implementation of random number generators
C++
4
star
14

java-playground

Lots of small java features
Java
3
star
15

exMARS

exMARS - Exhaust Memory Array Redcode Simulator
C
3
star
16

parallel_hashmap_benchmark

simple benchmark of parallel hash maps in C++
C++
3
star
17

bitcoin-stuff

Helpful script, documentation, etc for my bitcoin development
Ruby
3
star
18

bitcoin-utxo-visualizer-rs

Bitcoin UTXO Visualizer in Rust
Rust
3
star
19

gra

Git Repo Admin
Python
2
star
20

tacho

An experimental python tool to measure process runtimes
Python
2
star
21

Bench

Microbenchmark facility for C++. Very simple to use, single header only, with sound statistics.
C++
2
star
22

wordle

C++
1
star
23

brainwallet.rb

Ruby app for brainwallets
Ruby
1
star
24

bunter

colorizes program output, making it 'bunter'
1
star
25

qmars

QMars stands for Quicker Mars. It is a completely new implementation of a mars simulator
C++
1
star
26

rust-ninja-progressbar

Progressbar for Ninja written in Rust
Rust
1
star