aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/metrics/name_collection.h
blob: 7c9e1b1c652ad751585fc21850dc9057362cd745 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <mutex>
#include <map>
#include <vector>
#include <vespa/vespalib/stllike/string.h>

namespace vespalib::metrics {

// internal
class NameCollection {
private:
    using Map = std::map<vespalib::string, size_t>;
    mutable std::mutex _lock;
    Map _names;
    std::vector<Map::const_iterator> _names_by_id;
public:
    const vespalib::string &lookup(size_t id) const;
    size_t resolve(const vespalib::string& name);
    size_t size() const;

    NameCollection();
    NameCollection(const NameCollection &) = delete;
    NameCollection & operator = (const NameCollection &) = delete;
    ~NameCollection();

    static constexpr size_t empty_id = 0;
};

}