Wildmeshing Toolkit
Hashable.cpp
Go to the documentation of this file.
1 #include "Hashable.hpp"
2 #include <fmt/format.h>
3 #include <fmt/ranges.h>
4 #include <stdexcept>
5 #include <vector>
6 
7 
8 namespace wmtk::utils {
9 Hashable::Hashable() = default;
10 Hashable::Hashable(const Hashable&) = default;
11 Hashable::Hashable(Hashable&&) = default;
12 Hashable& Hashable::operator=(const Hashable&) = default;
13 Hashable& Hashable::operator=(Hashable&&) = default;
14 Hashable::~Hashable() = default;
15 std::size_t Hashable::hash() const
16 {
17  auto ch = child_hashes();
18  // if (ch.size() == 0) {
19  // throw std::runtime_error(
20  // "Hash base implementation was called without any child hashes. Either guarantee there
21  // " "is a child in child_hashes overload or overload this hash() function directly");
22  // }
23  std::vector<std::string> data;
24  for (const auto& [key, value] : ch) {
25  data.emplace_back(fmt::format("({}:{})", key, value));
26  }
27 
28  std::string strdata = fmt::format("{}", fmt::join(data, ","));
29  return std::hash<std::string>{}(strdata);
30 }
31 
32 std::map<std::string, size_t> Hashable::child_hashes() const
33 {
34  return {};
35 }
36 } // namespace wmtk::utils
virtual std::map< std::string, size_t > child_hashes() const
Definition: Hashable.cpp:32
virtual std::size_t hash() const
Definition: Hashable.cpp:15
Hashable & operator=(const Hashable &)