Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <tuple>
6#include <vector>
7
8namespace bb::utils {
9
16std::vector<uint8_t> hex_to_bytes(const std::string& hex);
17
22template <typename... Ts> size_t hash_as_tuple(const Ts&... ts)
23{
24 // See https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set.
25 size_t seed = 0;
26 ((seed ^= std::hash<Ts>()(ts) + 0x9e3779b9 + (seed << 6) + (seed >> 2)), ...);
27 return seed;
28}
29
30} // namespace bb::utils
31
32// Define std::hash for any type that has a hash() method.
33template <typename T>
34concept Hashable = requires(const T& t) {
35 { t.hash() } -> std::same_as<std::size_t>;
36};
37
38template <Hashable T> struct std::hash<T> {
39 std::size_t operator()(const T& t) const noexcept { return t.hash(); }
40};
std::vector< uint8_t > hex_to_bytes(const std::string &hex)
Routine to transform hexstring to vector of bytes.
Definition utils.cpp:5
size_t hash_as_tuple(const Ts &... ts)
Definition utils.hpp:22
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::size_t operator()(const T &t) const noexcept
Definition utils.hpp:39