From f1d366381033c0caae18f8d15305ded38734bdbf Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Thu, 25 Apr 2013 19:42:30 +0100 Subject: Back FactorCollection with a memory pool. Less memory for large vocabularies. --- moses/FactorCollection.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'moses/FactorCollection.h') diff --git a/moses/FactorCollection.h b/moses/FactorCollection.h index 9a01766f4..e7749244f 100644 --- a/moses/FactorCollection.h +++ b/moses/FactorCollection.h @@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include "util/string_piece.hh" +#include "util/pool.hh" #include "Factor.h" namespace Moses @@ -62,27 +63,20 @@ class FactorCollection friend std::ostream& operator<<(std::ostream&, const FactorCollection&); struct HashFactor : public std::unary_function { - std::size_t operator()(const StringPiece &str) const { - return util::MurmurHashNative(str.data(), str.size()); - } std::size_t operator()(const FactorFriend &factor) const { - return (*this)(factor.in.GetString()); + return util::MurmurHashNative(factor.in.m_string.data(), factor.in.m_string.size()); } }; struct EqualsFactor : public std::binary_function { bool operator()(const FactorFriend &left, const FactorFriend &right) const { return left.in.GetString() == right.in.GetString(); } - bool operator()(const FactorFriend &left, const StringPiece &right) const { - return left.in.GetString() == right; - } - bool operator()(const StringPiece &left, const FactorFriend &right) const { - return left == right.in.GetString(); - } }; typedef boost::unordered_set Set; Set m_set; + util::Pool m_string_backing; + static FactorCollection s_instance; #ifdef WITH_THREADS //reader-writer lock @@ -117,6 +111,5 @@ public: }; - } #endif -- cgit v1.2.3