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

Stack.h « CubePruningBitmapStack « defer « moses2 - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f052fab4285e9a4e4d3b28b25610a80db612ebb7 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Stack.h
 *
 *  Created on: 24 Oct 2015
 *      Author: hieu
 */
#pragma once
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <deque>
#include "../Hypothesis.h"
#include "../../TypeDef.h"
#include "../../Vector.h"
#include "../../MemPool.h"
#include "../../Recycler.h"
#include "../../legacy/Util2.h"

namespace Moses2
{

class Manager;

namespace NSCubePruningBitmapStack
{
typedef Vector<const Hypothesis*>  Hypotheses;

class MiniStack
{
public:
  typedef boost::unordered_set<const Hypothesis*,
          UnorderedComparer<Hypothesis>,
          UnorderedComparer<Hypothesis>
          > _HCType;

  MiniStack(const Manager &mgr);

  StackAdd Add(const Hypothesis *hypo);

  _HCType &GetColl() {
    return m_coll;
  }

  const _HCType &GetColl() const {
    return m_coll;
  }

  void Clear();

  Hypotheses &GetSortedAndPruneHypos(const Manager &mgr) const;

protected:
  _HCType m_coll;
  mutable Hypotheses *m_sortedHypos;

  void SortAndPruneHypos(const Manager &mgr) const;

};

/////////////////////////////////////////////
class Stack
{
protected:


public:
  typedef std::pair<const Bitmap*, size_t> HypoCoverage;
  // bitmap and current endPos of hypos
  typedef boost::unordered_map<HypoCoverage, Hypotheses*> SortedHypos;

  typedef const Bitmap* HypoCoverageInternal;
  typedef boost::unordered_map<HypoCoverageInternal, MiniStack*
  ,boost::hash<HypoCoverageInternal>
  ,std::equal_to<HypoCoverageInternal>
  > Coll;


  Stack(const Manager &mgr);
  virtual ~Stack();

  size_t GetHypoSize() const;

  Coll &GetColl() {
    return m_coll;
  }
  const Coll &GetColl() const {
    return m_coll;
  }

  void Add(const Hypothesis *hypo, Recycler<Hypothesis*> &hypoRecycle);

  MiniStack &GetMiniStack(const HypoCoverageInternal &key);

  std::vector<const Hypothesis*> GetBestHypos(size_t num) const;
  void Clear();

  SortedHypos GetSortedAndPruneHypos(const Manager &mgr) const;
  void SortAndPruneHypos(const Manager &mgr, Hypotheses &hypos) const;

  void DebugCounts();

protected:
  const Manager &m_mgr;
  Coll m_coll;

  std::deque<MiniStack*> m_miniStackRecycler;


};

}

}