00001 #ifndef LM_BUILDER_COMBINE_COUNTS_H 00002 #define LM_BUILDER_COMBINE_COUNTS_H 00003 00004 #include "lm/builder/payload.hh" 00005 #include "lm/common/ngram.hh" 00006 #include "lm/common/compare.hh" 00007 #include "lm/word_index.hh" 00008 #include "util/stream/sort.hh" 00009 00010 #include <functional> 00011 #include <string> 00012 00013 namespace lm { 00014 namespace builder { 00015 00016 // Sum counts for the same n-gram. 00017 struct CombineCounts { 00018 bool operator()(void *first_void, const void *second_void, const SuffixOrder &compare) const { 00019 NGram<BuildingPayload> first(first_void, compare.Order()); 00020 // There isn't a const version of NGram. 00021 NGram<BuildingPayload> second(const_cast<void*>(second_void), compare.Order()); 00022 if (memcmp(first.begin(), second.begin(), sizeof(WordIndex) * compare.Order())) return false; 00023 first.Value().count += second.Value().count; 00024 return true; 00025 } 00026 }; 00027 00028 } // namespace builder 00029 } // namespace lm 00030 00031 #endif // LM_BUILDER_COMBINE_COUNTS_H