aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/common/config_hash.hpp
blob: ceedc48d22ffb11e68f9d579d5bca596c8038e12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "config_hash.h"
#include <vespa/vespalib/stllike/hash_map.hpp>
#include <cassert>

namespace proton {

template <class Elem>
ConfigHash<Elem>::ConfigHash(const std::vector<Elem> &config)
    : _hash()
{
    for (const auto &elem : config) {
        auto insres = _hash.insert(std::make_pair(elem.name, &elem));
        assert(insres.second);
    }
}

template <class Elem>
ConfigHash<Elem>::~ConfigHash()
{
}

template <class Elem>
const Elem *
ConfigHash<Elem>::lookup(const vespalib::string &name) const
{
    auto itr = _hash.find(name);
    return ((itr == _hash.end()) ? nullptr : itr->second);
}

} // namespace proton