On this page
article
peary/utils/string_hash_map.hpp
peary/utils/string_hash_map.hpp
Unordered string map using hashes for fast lookup. More…
Namespaces
| Name |
|---|
| peary |
| peary::utils |
Classes
| Name | |
|---|---|
| struct | peary::utils::string_hash Hash for std::unordered_map. |
Detailed Description
Unordered string map using hashes for fast lookup.
Copyright: Copyright (c) 2025 the Peary authors. This software is distributed under the terms of the LGPL-3.0-only License, copied verbatim in the file “LICENSE.md”. SPDX-License-Identifier: LGPL-3.0-only
Source code
#pragma once
#include <cstdlib>
#include <functional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
namespace peary::utils {
// NOLINTBEGIN(readability-identifier-naming)
struct string_hash {
using hash_type = std::hash<std::string_view>;
using is_transparent = void;
[[nodiscard]] std::size_t operator()(const char* str) const noexcept { return hash_type {}(str); }
[[nodiscard]] std::size_t operator()(std::string_view str) const noexcept { return hash_type {}(str); }
[[nodiscard]] std::size_t operator()(const std::string& str) const noexcept { return hash_type {}(str); }
};
template <typename V> using string_hash_map = std::unordered_map<std::string, V, string_hash, std::equal_to<>>;
using string_hash_set = std::unordered_set<std::string, string_hash, std::equal_to<>>;
// NOLINTEND(readability-identifier-naming)
} // namespace peary::utils
Updated on 2025-11-14 at 11:31:23 +0100