diff options
author | Maxim Pimenov <m@maps.me> | 2018-12-18 20:14:43 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2018-12-27 14:12:10 +0300 |
commit | 8336cc56cf775c55e00b9a13d81dd1db3478acb6 (patch) | |
tree | cbe73de41aeec99440a5861dfeef00fdb61cec21 /geocoder | |
parent | 9c62284c6aa9d03da471845011c69a9dd31dbcec (diff) |
[base] [geocoder] Moved the Beam class from geocoder to base.
Diffstat (limited to 'geocoder')
-rw-r--r-- | geocoder/CMakeLists.txt | 1 | ||||
-rw-r--r-- | geocoder/beam.hpp | 61 | ||||
-rw-r--r-- | geocoder/geocoder.hpp | 4 |
3 files changed, 2 insertions, 64 deletions
diff --git a/geocoder/CMakeLists.txt b/geocoder/CMakeLists.txt index a90fa2a41a..3e50874841 100644 --- a/geocoder/CMakeLists.txt +++ b/geocoder/CMakeLists.txt @@ -4,7 +4,6 @@ include_directories(${OMIM_ROOT}/3party/jansson/src) set( SRC - beam.hpp geocoder.cpp geocoder.hpp hierarchy.cpp diff --git a/geocoder/beam.hpp b/geocoder/beam.hpp deleted file mode 100644 index 04fbf29cdc..0000000000 --- a/geocoder/beam.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include "base/geo_object_id.hpp" -#include "base/macros.hpp" - -#include <vector> - -namespace geocoder -{ -// A data structure to perform the beam search with. -// Maintains a list of (Key, Value) pairs sorted in the decreasing -// order of Values. -template <typename TKey, typename TValue> -class Beam -{ -public: - using Key = TKey; - using Value = TValue; - - struct Entry - { - Key m_key; - Value m_value; - - Entry(Key const & key, Value const & value) : m_key(key), m_value(value) {} - - bool operator<(Entry const & rhs) const { return m_value > rhs.m_value; } - }; - - explicit Beam(size_t capacity) : m_capacity(capacity) { m_entries.reserve(m_capacity); } - - // O(log(n) + n) for |n| entries. - // O(|m_capacity|) in the worst case. - void Add(Key const & key, Value const & value) - { - if (PREDICT_FALSE(m_capacity == 0)) - return; - - Entry const e(key, value); - auto it = std::lower_bound(m_entries.begin(), m_entries.end(), e); - - if (it == m_entries.end()) - { - if (m_entries.size() < m_capacity) - m_entries.emplace_back(e); - return; - } - - if (m_entries.size() == m_capacity) - m_entries.pop_back(); - - m_entries.insert(it, e); - } - - std::vector<Entry> const & GetEntries() const { return m_entries; } - -private: - size_t m_capacity; - std::vector<Entry> m_entries; -}; -} // namespace geocoder diff --git a/geocoder/geocoder.hpp b/geocoder/geocoder.hpp index ccf8e1be60..08434b113f 100644 --- a/geocoder/geocoder.hpp +++ b/geocoder/geocoder.hpp @@ -1,11 +1,11 @@ #pragma once -#include "geocoder/beam.hpp" #include "geocoder/hierarchy.hpp" #include "geocoder/index.hpp" #include "geocoder/result.hpp" #include "geocoder/types.hpp" +#include "base/beam.hpp" #include "base/geo_object_id.hpp" #include "base/stl_helpers.hpp" #include "base/string_utils.hpp" @@ -113,7 +113,7 @@ public: // The highest value of certainty for a fixed amount of // the most relevant retrieved osm ids. - Beam<BeamKey, double> m_beam; + base::Beam<BeamKey, double> m_beam; std::vector<Layer> m_layers; }; |