Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
map_hashes.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <functional>
5#include <vector>
6
9
10// Specialization of std::hash for std::vector<T> to be used as a key in unordered_flat_map.
11namespace std {
12
13template <typename T> struct hash<std::reference_wrapper<const T>> {
14 size_t operator()(const std::reference_wrapper<const T>& ref) const { return std::hash<T>{}(ref.get()); }
15};
16
17template <typename T> struct hash<std::vector<T>> {
18 size_t operator()(const std::vector<T>& vec) const
19 {
20 size_t seed = vec.size();
21 for (const auto& item : vec) {
22 seed ^= std::hash<T>{}(item) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
23 }
24 return seed;
25 }
26};
27
28// Define a hash function for std::array so that it can be used as a key in a std::unordered_map.
29template <typename T, size_t SIZE> struct hash<std::array<T, SIZE>> {
30 inline std::size_t operator()(const std::array<T, SIZE>& arr) const noexcept
31 {
32 return [&arr]<size_t... Is>(std::index_sequence<Is...>) {
33 return bb::utils::hash_as_tuple(arr[Is]...);
35 }
36};
37
38// Define a hash function for flat_tuple::tuple so that it can be used as a key in a std::unordered_map.
39template <typename... Ts> struct hash<bb::flat_tuple::tuple<Ts...>> {
40 inline std::size_t operator()(const bb::flat_tuple::tuple<Ts...>& tup) const noexcept
41 {
42 return bb::flat_tuple::apply([](const auto&... args) { return bb::utils::hash_as_tuple(args...); }, tup);
43 }
44};
45
46} // namespace std
void hash(State &state) noexcept
size_t hash_as_tuple(const Ts &... ts)
Definition utils.hpp:22
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::size_t operator()(const bb::flat_tuple::tuple< Ts... > &tup) const noexcept
std::size_t operator()(const std::array< T, SIZE > &arr) const noexcept
size_t operator()(const std::reference_wrapper< const T > &ref) const
size_t operator()(const std::vector< T > &vec) const