aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/metrics/point_map_collection.h
blob: ee556ea21070ecca3fcc6ea29b9ec74ffa7ab3f7 (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
35
36
37
38
39
40
41
42
// Copyright Yahoo. 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 "point_map.h"

namespace vespalib {
namespace metrics {

// internal
class HashedPointMap {
private:
    const PointMap _map;
    size_t _hash;
public:
    HashedPointMap(PointMap &&from);
    bool operator< (const HashedPointMap &other) const;

    const PointMap &backingMap() const { return _map; }
};

// internal
class PointMapCollection {
private:
    using PointMapMap = std::map<HashedPointMap, size_t>;

    mutable std::mutex _lock;
    PointMapMap _map;
    std::vector<PointMapMap::const_iterator> _vec;
public:
    const PointMap &lookup(size_t id) const;
    size_t resolve(PointMap map);
    size_t size() const;

    PointMapCollection() = default;
    ~PointMapCollection() {}
};

} // namespace vespalib::metrics
} // namespace vespalib