Table of Contents
Fetching ...

static_maps: consteval std::map and std::unordered_map Implementations in C++23

Isaac D. Myhal, Oliver Serang

TL;DR

Using consteval from C++23, this library implements efficient, new versions of std::map and std::unordered_map for use when the keys are known at compile time, making this library the overall fastest drop-in hashing alternative to std::unordered_map.

Abstract

Using consteval from C++23, we implement efficient, new versions of std::map and std::unordered_map for use when the keys are known at compile time. We demonstrate superior performance of our unordered_map on three demonstration use-cases: Lookup of elemental mass from atomic symbol, lookup of amino acid from codon, and modification of stock prices from S&P 500 ticker symbols all produced runtimes <40%, <35%, <73% of the respective runtimes of the std implementations. Our library runimes were <80%, <45%, <97% of the lookup time of Frozen, an alternative perfect hashing implementation in C++ for problems also using constexpr keys. To our knowledge, this makes our library the overall fastest drop-in (i.e., with a similar API) alternative to std::unordered_map. On one arbitrarily chosen demo, we demonstrate runtimes <35% of PTHash and <89% gperf, state-of-the-art but not drop-in hashing libraries via external tools.

static_maps: consteval std::map and std::unordered_map Implementations in C++23

TL;DR

Using consteval from C++23, this library implements efficient, new versions of std::map and std::unordered_map for use when the keys are known at compile time, making this library the overall fastest drop-in hashing alternative to std::unordered_map.

Abstract

Using consteval from C++23, we implement efficient, new versions of std::map and std::unordered_map for use when the keys are known at compile time. We demonstrate superior performance of our unordered_map on three demonstration use-cases: Lookup of elemental mass from atomic symbol, lookup of amino acid from codon, and modification of stock prices from S&P 500 ticker symbols all produced runtimes <40%, <35%, <73% of the respective runtimes of the std implementations. Our library runimes were <80%, <45%, <97% of the lookup time of Frozen, an alternative perfect hashing implementation in C++ for problems also using constexpr keys. To our knowledge, this makes our library the overall fastest drop-in (i.e., with a similar API) alternative to std::unordered_map. On one arbitrarily chosen demo, we demonstrate runtimes <35% of PTHash and <89% gperf, state-of-the-art but not drop-in hashing libraries via external tools.
Paper Structure (35 sections, 5 equations, 3 figures, 1 table)

This paper contains 35 sections, 5 equations, 3 figures, 1 table.

Figures (3)

  • Figure 1: Runtimes of construction and lookup for static_maps::map against std::map on various demos. Lower is better.
  • Figure 2: Runtimes of construction and lookup for static_maps::map against std::map on various demos. Lower is better.
  • Figure 3: Runtimes compared to alternatives to drop-in replacements of unordered_map. Lower is better.