blob: 6818050233fa675feb4a4f3a5c745c40ebfd4e8f (
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
43
44
45
46
47
48
49
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "point.h"
#include "metrics_manager.h"
namespace vespalib {
namespace metrics {
PointMap::PointMap(BackingMap &&from)
: _map(std::move(from)),
_hash(0)
{
for (const BackingMap::value_type &entry : _map) {
_hash = (_hash << 7) + (_hash >> 31) + entry.first.id();
_hash = (_hash << 7) + (_hash >> 31) + entry.second.id();
}
}
bool
PointMap::operator< (const PointMap &other) const
{
// cheap comparison first
if (_hash != other._hash) {
return _hash < other._hash;
}
if (_map.size() != other._map.size()) {
return _map.size() < other._map.size();
}
// sizes equal, iterate in parallel
for (auto m = _map.begin(), o = other._map.begin();
m != _map.end();
++m, ++o)
{
const Dimension& d1 = m->first;
const Dimension& d2 = o->first;
if (d1 != d2) {
return d1 < d2;
}
const Label &l1 = m->second;
const Label &l2 = o->second;
if (l1 != l2) {
return l1 < l2;
}
}
// equal
return false;
}
} // namespace vespalib::metrics
} // namespace vespalib
|