Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pre_ranker.hpp « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e7f25f5913c58e30df2131aced448acc90fc748 (plain)
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
50
51
52
53
54
#pragma once

#include "search/intermediate_result.hpp"

#include "base/macros.hpp"

#include "std/algorithm.hpp"
#include "std/cstdint.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"

namespace search
{
// Fast and simple pre-ranker for search results.
class PreRanker
{
public:
  explicit PreRanker(size_t limit);

  void Add(impl::PreResult1 const & result);

  template <typename... TArgs>
  void Emplace(TArgs &&... args)
  {
    m_results.emplace_back(forward<TArgs>(args)...);
  }

  void Filter(bool viewportSearch);

  inline size_t Size() const { return m_results.size(); }
  inline size_t Limit() const { return m_limit; }
  inline bool IsEmpty() const { return Size() == 0; }
  inline void Clear() { m_results.clear(); };

  template <typename TFn>
  void ForEach(TFn && fn)
  {
    for_each(m_results.begin(), m_results.end(), forward<TFn>(fn));
  }

  template <typename TFn>
  void ForEachInfo(TFn && fn)
  {
    for (auto & result : m_results)
      fn(result.GetId(), result.GetInfo());
  }

private:
  vector<impl::PreResult1> m_results;
  size_t const m_limit;

  DISALLOW_COPY_AND_MOVE(PreRanker);
};
}  // namespace search