AnalysisTree
Loading...
Searching...
No Matches
BranchHashHelper.hpp
1#ifndef ANALYSISTREE_INFRA_BRANCHHASHHELPER_HPP_
2#define ANALYSISTREE_INFRA_BRANCHHASHHELPER_HPP_
3
4namespace Impl {
5
6inline void hash_combine(std::size_t& /*seed*/) {}
7
8template<typename T, typename... Rest>
9inline void hash_combine(std::size_t& seed, const T& v, Rest... rest) {
10 std::hash<T> hasher;
11 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
12 hash_combine(seed, rest...);
13}
14
15inline std::size_t BranchConfigHasher(const AnalysisTree::BranchConfig& config) {
16 using Type = AnalysisTree::Types;
17
18 std::size_t hash = 0;
19 hash_combine(hash, static_cast<AnalysisTree::ShortInt_t>(config.GetType()));
20
21 auto hash_fields = [&hash](const std::map<std::string, AnalysisTree::ConfigElement>& fields_map, Type field_type) {
22 for (auto& field : fields_map) {
23 hash_combine(hash, field.first, field.second.id_, static_cast<AnalysisTree::ShortInt_t>(field_type));
24 }
25 };
26
27 hash_fields(config.GetMap<float>(), Type::kFloat);
28 hash_fields(config.GetMap<int>(), Type::kInteger);
29 hash_fields(config.GetMap<bool>(), Type::kBool);
30 return hash;
31}
32
33}// namespace Impl
34
35#endif//ANALYSISTREE_INFRA_BRANCHHASHHELPER_HPP_
A class to store configuration of the Container.
Definition BranchConfig.hpp:118