diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-26 12:50:27 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-26 12:50:27 +0300 |
commit | 73d8dff5fe9636e76181270410e933167d3de3ea (patch) | |
tree | 018217085eedc1aebd6f6b69a68d158fdb663062 /moses/Bitmap.h | |
parent | 52f4086dbc5b5621600d07c3edf9dbca2e8cd38e (diff) |
precalculate number of words covered
Diffstat (limited to 'moses/Bitmap.h')
-rw-r--r-- | moses/Bitmap.h | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/moses/Bitmap.h b/moses/Bitmap.h index 904024e62..c06120abb 100644 --- a/moses/Bitmap.h +++ b/moses/Bitmap.h @@ -53,6 +53,7 @@ class Bitmap private: std::vector<char> m_bitmap; //! Ticks of words in sentence that have been done. size_t m_firstGap; //! Cached position of first gap, or NOT_FOUND. + size_t m_numWordsCovered; Bitmap(); // not implemented Bitmap& operator= (const Bitmap& other); @@ -81,48 +82,33 @@ private: //! set value between 2 positions, inclusive void - SetValue(Range const& range, bool value) { + SetValueNonOverlap(Range const& range) { size_t startPos = range.GetStartPos(); size_t endPos = range.GetEndPos(); for(size_t pos = startPos ; pos <= endPos ; pos++) { - m_bitmap[pos] = value; + m_bitmap[pos] = true; } - UpdateFirstGap(startPos, endPos, value); + + m_numWordsCovered += range.GetNumWordsCovered(); + UpdateFirstGap(startPos, endPos, true); } public: //! Create Bitmap of length size, and initialise with vector. - Bitmap(size_t size, const std::vector<bool>& initializer) - :m_bitmap(initializer.begin(), initializer.end()), m_firstGap(0) { - - // The initializer may not be of the same length. Change to the desired - // length. If we need to add any elements, initialize them to false. - m_bitmap.resize(size, false); - - // Find the first gap, and cache it. - std::vector<char>::const_iterator first_gap = std::find( - m_bitmap.begin(), m_bitmap.end(), false); - m_firstGap = ( - (first_gap == m_bitmap.end()) ? - NOT_FOUND : first_gap - m_bitmap.begin()); - } + Bitmap(size_t size, const std::vector<bool>& initializer); //! Create Bitmap of length size and initialise. - Bitmap(size_t size) - :m_bitmap(size, false), m_firstGap(0) { - } + Bitmap(size_t size); //! Deep copy. - Bitmap(const Bitmap ©) - :m_bitmap(copy.m_bitmap), m_firstGap(copy.m_firstGap) { - } + Bitmap(const Bitmap ©); Bitmap(const Bitmap ©, const Range &range); //! Count of words translated. size_t GetNumWordsCovered() const { - return std::count(m_bitmap.begin(), m_bitmap.end(), true); + return m_numWordsCovered; } //! position of 1st word not yet translated, or NOT_FOUND if everything already translated @@ -160,8 +146,20 @@ public: } //! set value at a particular position void SetValue( size_t pos, bool value ) { - m_bitmap[pos] = value; - UpdateFirstGap(pos, pos, value); + bool origValue = m_bitmap[pos]; + if (origValue == value) { + // do nothing + } + else { + m_bitmap[pos] = value; + UpdateFirstGap(pos, pos, value); + if (value) { + ++m_numWordsCovered; + } + else { + --m_numWordsCovered; + } + } } //! whether every word has been translated |