All Projects → mapbox → Eternal

mapbox / Eternal

Licence: isc
A C++14 compile-time/constexpr map and hash map with minimal binary footprint

Projects that are alternatives of or similar to Eternal

komihash
Very fast, high-quality hash function (non-cryptographic, C) + PRNG
Stars: ✭ 68 (-26.88%)
Mutual labels:  hashing, hash, hashmap
Semimap
A semi compile-/run-time associative map container with compile-time lookup and run-time storage
Stars: ✭ 335 (+260.22%)
Mutual labels:  compile-time, hashmap
Ahash
aHash is a non-cryptographic hashing algorithm that uses the AES hardware instruction
Stars: ✭ 251 (+169.89%)
Mutual labels:  hash, hashing
Collection
A PHP library for representing and manipulating collections.
Stars: ✭ 488 (+424.73%)
Mutual labels:  hash, map
pthash
Fast and compact minimal perfect hash functions in C++.
Stars: ✭ 62 (-33.33%)
Mutual labels:  hashing, hash
agent-python
Official python agent for using the distributed hashcracker Hashtopolis
Stars: ✭ 39 (-58.06%)
Mutual labels:  hashing, hash
Wyhash
The FASTEST QUALITY hash function, random number generators (PRNG) and hash map.
Stars: ✭ 410 (+340.86%)
Mutual labels:  hash, hashmap
metrohash-rs
Rust MetroHash
Stars: ✭ 45 (-51.61%)
Mutual labels:  hashing, hash
Lazy importer
library for importing functions from dlls in a hidden, reverse engineer unfriendly way
Stars: ✭ 544 (+484.95%)
Mutual labels:  compile-time, hashing
Hashmap
A Golang lock-free thread-safe HashMap optimized for fastest read access.
Stars: ✭ 899 (+866.67%)
Mutual labels:  hashmap, map
Rhashmap
Robin Hood hash map library
Stars: ✭ 33 (-64.52%)
Mutual labels:  hashing, hashmap
laravel-hashid
HashId Implementation on Laravel Eloquent ORM
Stars: ✭ 23 (-75.27%)
Mutual labels:  hashing, hash
bromberg sl2
Cayley hashing as in "Navigating in the Cayley Graph of SL₂(𝔽ₚ)"
Stars: ✭ 32 (-65.59%)
Mutual labels:  hashing, hash
agent
hashtopolis.org
Stars: ✭ 19 (-79.57%)
Mutual labels:  hashing, hash
Wyhash Rs
wyhash fast portable non-cryptographic hashing algorithm and random number generator in Rust
Stars: ✭ 44 (-52.69%)
Mutual labels:  hash, hashing
Hashmap
HashMap JavaScript class for Node.js and the browser. The keys can be anything and won't be stringified
Stars: ✭ 363 (+290.32%)
Mutual labels:  hashmap, map
hash-checker
Fast and simple application that allows you to generate and compare hashes from files and text
Stars: ✭ 72 (-22.58%)
Mutual labels:  hashing, hash
haiti
🔑 Hash type identifier (CLI & lib)
Stars: ✭ 287 (+208.6%)
Mutual labels:  hashing, hash
Name That Hash
🔗 Don't know what type of hash it is? Name That Hash will name that hash type! 🤖 Identify MD5, SHA256 and 3000+ other hashes ☄ Comes with a neat web app 🔥
Stars: ✭ 540 (+480.65%)
Mutual labels:  hash, hashing
Sparsepp
A fast, memory efficient hash map for C++
Stars: ✭ 1,021 (+997.85%)
Mutual labels:  hash, hashmap

eternal.hpp is a header-only C++ implementation of constexpr/compile-time maps and hash maps. It provides an API that is somewhat compatible with std::map/std::unordered_map, but doesn't support insertion, or other modifications. It's main focus is in binary size: it generates minimal code and doesn't incur any static initialization overhead.

Why is this useful?

  • Lookup tables

Tested with these compilers/platforms:

  • Linux GCC 4.9.4 (runtime only, since constexpr support is broken in this version)
  • Linux GCC 5.5
  • Linux GCC 6.5
  • Linux GCC 7.3
  • Linux GCC 8.1
  • Linux Clang 3.9.1
  • Linux Clang 4
  • Linux Clang 5
  • Linux Clang 6
  • Linux Clang 7
  • macOS Xcode 10.1
  • Android NDK r17+

Usage

MAPBOX_ETERNAL_CONSTEXPR const auto colors = mapbox::eternal::map<mapbox::eternal::string, Color>({
    { "red", { 255, 0, 0, 1 } },
    { "green", { 0, 128, 0, 1 } },
    { "yellow", { 255, 255, 0, 1 } },
    { "white", { 255, 255, 255, 1 } },
    { "black", { 0, 0, 0, 1 } }
});
  • mapbox::eternal::map<key, value>() is a factory function that produces a constexpr map from the std::pair<key, value>s passed to it.
  • Alternatively, use mapbox::eternal::hash_map<key, value>() to construct a hash map. The key needs a specialization of std::hash.
  • Use mapbox::eternal::string for constexpr strings.
  • If you need to support GCC 4.9, use MAPBOX_ETERNAL_CONSTEXPR instead of constexpr in the variable definition.
  • You can pass the elements in arbitrary order; they will be sorted at compile time (except for GCC 4.9). To speed up compilation, list the elements in sorted order. To determine the sort order for hash_map, iterate over the map and print the result. Note that hashes may be architecture-specific.
  • Both map() and hash_map() support multiple values for the same key. To ensure that keys are unique, run static_assert(map.unique()); (or equivalent for GCC 4.9)
  • The preprocessor variable MAPBOX_ETERNAL_IS_CONSTEXPR is set to 1 if constexpr construction and lookups are supported.

Performance

Uses a list of 148 unique CSS color names

Run on (8 X 2600 MHz CPU s)
CPU Caches:
  L1 Data 32K (x4)
  L1 Instruction 32K (x4)
  L2 Unified 262K (x4)
  L3 Unified 6291K (x1)
-----------------------------------------------------------------------------
Benchmark                                      Time           CPU Iterations
-----------------------------------------------------------------------------
EternalMap_ConstexprLookup                     2 ns          2 ns  424582090
EternalMap_Lookup                             48 ns         48 ns   14494194
EternalMap_LookupMissing                      35 ns         35 ns   20442492
EternalMap_LookupEqualRange                   78 ns         78 ns    8862891

EternalHashMap_ConstexprLookup                 2 ns          2 ns  429076688
EternalHashMap_Lookup                         30 ns         30 ns   22685952
EternalHashMap_LookupMissing                  17 ns         17 ns   39521898
EternalHashMap_LookupEqualRange               43 ns         43 ns   16696442

StdMap_Lookup                                 51 ns         50 ns   13580630
StdMap_LookupMissing                          58 ns         58 ns   11868028
StdMap_LookupEqualRange                       89 ns         89 ns    7766129

StdMultimap_Lookup                            50 ns         50 ns   14262312
StdMultimap_LookupMissing                     60 ns         59 ns   11555922
StdMultimap_LookupEqualRange                 103 ns        103 ns    6783077

StdUnorderedMap_Lookup                        43 ns         43 ns   16175696
StdUnorderedMap_LookupMissing                 50 ns         50 ns   10000000
StdUnorderedMap_LookupEqualRange              57 ns         57 ns   12256189

StdUnorderedMultimap_Lookup                   43 ns         43 ns   16011528
StdUnorderedMultimap_LookupMissing            52 ns         51 ns   10000000
StdUnorderedMultimap_LookupEqualRange         61 ns         60 ns   11519221
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].