summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2018-10-05 20:20:44 +0000
committerArne Juul <arnej@yahoo-inc.com>2018-10-05 20:20:44 +0000
commitc22ca093e702812e992c148e0a5016813e5cd3e8 (patch)
tree11d2dbfcabddc2175ad46f9385888cdcf398f6b6 /staging_vespalib
parent90a024290d5db17d4484a04530f1bffe2532cf4d (diff)
HashedPointMap is only needed PointMapCollection
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp5
-rw-r--r--staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp49
-rw-r--r--staging_vespalib/src/vespa/vespalib/metrics/point_map.h13
-rw-r--r--staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp46
-rw-r--r--staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h17
5 files changed, 61 insertions, 69 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp
index 7db14f3af52..9e3683d465f 100644
--- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp
+++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp
@@ -53,14 +53,13 @@ NameRepo::labelValue(Label l) const
const PointMap&
NameRepo::pointMap(Point from) const
{
- const HashedPointMap &map = _pointMaps.lookup(from.id());
- return map.backingMap();
+ return _pointMaps.lookup(from.id());
}
Point
NameRepo::pointFrom(PointMap map)
{
- size_t id = _pointMaps.resolve(HashedPointMap(std::move(map)));
+ size_t id = _pointMaps.resolve(std::move(map));
return Point(id);
}
diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp
index 134123b2685..6e9ab4d1801 100644
--- a/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp
+++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp
@@ -1,49 +1,2 @@
// 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 {
-
-HashedPointMap::HashedPointMap(PointMap &&from)
- : _map(std::move(from)),
- _hash(0)
-{
- for (const PointMap::value_type &entry : _map) {
- _hash = (_hash << 7) + (_hash >> 31) + entry.first.id();
- _hash = (_hash << 7) + (_hash >> 31) + entry.second.id();
- }
-}
-
-bool
-HashedPointMap::operator< (const HashedPointMap &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
+#include "point_map.h"
diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map.h
index 91c28b292c8..a1063ce944a 100644
--- a/staging_vespalib/src/vespa/vespalib/metrics/point_map.h
+++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map.h
@@ -10,18 +10,5 @@ namespace metrics {
using PointMap = std::map<Dimension, Label>;
-// internal
-class HashedPointMap {
-private:
- const PointMap _map;
- size_t _hash;
-public:
- HashedPointMap() : _map(), _hash(0) {}
- HashedPointMap(PointMap &&from);
- bool operator< (const HashedPointMap &other) const;
-
- const PointMap &backingMap() const { return _map; }
-};
-
} // namespace vespalib::metrics
} // namespace vespalib
diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp
index 36cb884290e..9909eb04cdc 100644
--- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp
+++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp
@@ -5,19 +5,59 @@
namespace vespalib {
namespace metrics {
+HashedPointMap::HashedPointMap(PointMap &&from)
+ : _map(std::move(from)),
+ _hash(0)
+{
+ for (const PointMap::value_type &entry : _map) {
+ _hash = (_hash << 7) + (_hash >> 31) + entry.first.id();
+ _hash = (_hash << 7) + (_hash >> 31) + entry.second.id();
+ }
+}
+
+bool
+HashedPointMap::operator< (const HashedPointMap &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;
+}
+
using Guard = std::lock_guard<std::mutex>;
-const HashedPointMap &
+const PointMap &
PointMapCollection::lookup(size_t id) const
{
Guard guard(_lock);
assert(id < _vec.size());
PointMapMap::const_iterator iter = _vec[id];
- return iter->first;
+ return iter->first.backingMap();
}
size_t
-PointMapCollection::resolve(HashedPointMap map)
+PointMapCollection::resolve(PointMap map)
{
Guard guard(_lock);
size_t nextId = _vec.size();
diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h
index 91eb907ee74..3474bff6188 100644
--- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h
+++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h
@@ -10,6 +10,19 @@ namespace vespalib {
namespace metrics {
// internal
+class HashedPointMap {
+private:
+ const PointMap _map;
+ size_t _hash;
+public:
+ HashedPointMap() : _map(), _hash(0) {}
+ 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>;
@@ -18,8 +31,8 @@ private:
PointMapMap _map;
std::vector<PointMapMap::const_iterator> _vec;
public:
- const HashedPointMap &lookup(size_t id) const;
- size_t resolve(HashedPointMap map);
+ const PointMap &lookup(size_t id) const;
+ size_t resolve(PointMap map);
size_t size() const;
PointMapCollection() = default;