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.cpp | |
parent | 52f4086dbc5b5621600d07c3edf9dbca2e8cd38e (diff) |
precalculate number of words covered
Diffstat (limited to 'moses/Bitmap.cpp')
-rw-r--r-- | moses/Bitmap.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/moses/Bitmap.cpp b/moses/Bitmap.cpp index 2fe4c2987..87219479c 100644 --- a/moses/Bitmap.cpp +++ b/moses/Bitmap.cpp @@ -27,11 +27,47 @@ namespace Moses TO_STRING_BODY(Bitmap); +Bitmap::Bitmap(size_t size, const std::vector<bool>& initializer) + :m_bitmap(initializer.begin(), initializer.end()) +{ + + // 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); + + m_numWordsCovered = std::count(m_bitmap.begin(), m_bitmap.end(), true); + + // 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()); +} + +//! Create Bitmap of length size and initialise. +Bitmap::Bitmap(size_t size) + :m_bitmap(size, false) + ,m_firstGap(0) + ,m_numWordsCovered(0) + +{ +} + +//! Deep copy. +Bitmap::Bitmap(const Bitmap ©) + :m_bitmap(copy.m_bitmap) + ,m_firstGap(copy.m_firstGap) + ,m_numWordsCovered(copy.m_numWordsCovered) +{ +} + Bitmap::Bitmap(const Bitmap ©, const Range &range) :m_bitmap(copy.m_bitmap) ,m_firstGap(copy.m_firstGap) +,m_numWordsCovered(copy.m_numWordsCovered) { - SetValue(range, true); + SetValueNonOverlap(range); } // for unordered_set in stack |