summaryrefslogtreecommitdiff
path: root/klm/search/source.hh
blob: 11839f7bc41111e10ee5e17922bf020210f78275 (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
#ifndef SEARCH_SOURCE__
#define SEARCH_SOURCE__

#include "search/types.hh"

#include <assert.h>
#include <vector>

namespace search {

template <class Final> class Source {
  public:
    Source() : bound_(kScoreInf) {}

    Index Size() const {
      return final_.size();
    }

    Score Bound() const {
      return bound_;
    }

    const Final &operator[](Index index) const {
      return *final_[index];
    }

    Score ScoreOrBound(Index index) const {
      return Size() > index ? final_[index]->Total() : Bound();
    }

  protected:
    void AddFinal(const Final &store) {
      final_.push_back(&store);
    }

    void SetBound(Score to) {
      assert(to <= bound_ + 0.001);
      bound_ = to;
    }

  private:
    std::vector<const Final *> final_;

    Score bound_;
};

} // namespace search
#endif // SEARCH_SOURCE__