summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp
blob: 36cb884290e2149f6d1ef8096fbe0f3661696cf7 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "point_map_collection.h"
#include <assert.h>

namespace vespalib {
namespace metrics {

using Guard = std::lock_guard<std::mutex>;

const HashedPointMap &
PointMapCollection::lookup(size_t id) const
{
    Guard guard(_lock);
    assert(id < _vec.size());
    PointMapMap::const_iterator iter = _vec[id];
    return iter->first;
}

size_t
PointMapCollection::resolve(HashedPointMap map)
{
    Guard guard(_lock);
    size_t nextId = _vec.size();
    auto iter_check = _map.emplace(std::move(map), nextId);
    if (iter_check.second) {
        _vec.push_back(iter_check.first);
    }
    return iter_check.first->second;
}

size_t
PointMapCollection::size() const
{
    Guard guard(_lock);
    return _vec.size();
}

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