arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2602.22506cs.DScs.SE
收藏

static_maps: C++23 中 consteval 实现的 std::map 和 std::unordered_map

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

Hillsdale College(霍利斯戴尔学院);Dept. of Math and Computer Science(数学与计算机科学系)

Isaac D. Myhal, Oliver Serang

AI总结:

本文提出了一种基于 C++23 consteval 的高效 std::map 和 std::unordered_map 实现,展示了在编译时已知键场景下的高性能表现。

摘要:

利用 C++23 中的 consteval,我们实现了高效的、新的 std::map 和 std::unordered_map 版本,用于在编译时已知键的情况下使用。我们展示了我们的 unordered_map 在三个演示用例中的优越性能:从原子符号查找元素质量、从密码子查找氨基酸以及从 S&P 500 股票代码修改股票价格,其运行时间分别低于标准实现的 40%、35% 和 73%。我们的库运行时间分别低于 Frozen,一个用于使用 constexpr 键问题的 C++ 替代完美哈希实现的 80%、45% 和 97%。据我们所知,这使我们的库成为整体最快的、与 std::unordered_map 兼容(即具有相似 API)的替代品。在其中一个任意选择的演示中,我们展示了运行时间低于 PTHash 的 35% 和 gperf 的 89%,尽管 gperf 是状态最先进的但非 drop-in 哈希库。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑