summaryrefslogtreecommitdiff
path: root/klm/lm/model.hh
diff options
context:
space:
mode:
authorKenneth Heafield <kenlm@kheafield.com>2011-09-24 07:58:58 -0400
committerKenneth Heafield <kenlm@kheafield.com>2011-09-24 07:58:58 -0400
commit2e5720a8e7141a75ae549c6be74f50bd18068ef1 (patch)
tree4cb3c144d5958143523f74300f184a039c67336a /klm/lm/model.hh
parentd71c74f3924e6c207f3ebfab470b9a30e2551dde (diff)
Belated documentation
Diffstat (limited to 'klm/lm/model.hh')
-rw-r--r--klm/lm/model.hh25
1 files changed, 13 insertions, 12 deletions
diff --git a/klm/lm/model.hh b/klm/lm/model.hh
index fe91af2e..c278acd6 100644
--- a/klm/lm/model.hh
+++ b/klm/lm/model.hh
@@ -12,6 +12,8 @@
#include "lm/vocab.hh"
#include "lm/weights.hh"
+#include "util/murmur_hash.hh"
+
#include <algorithm>
#include <vector>
@@ -28,21 +30,18 @@ class State {
public:
bool operator==(const State &other) const {
if (length != other.length) return false;
- const WordIndex *end = words + length;
- for (const WordIndex *first = words, *second = other.words;
- first != end; ++first, ++second) {
- if (*first != *second) return false;
- }
- // If the histories are equal, so are the backoffs.
- return true;
+ return !memcmp(words, other.words, length * sizeof(WordIndex));
}
// Three way comparison function.
int Compare(const State &other) const {
- if (length == other.length) {
- return memcmp(words, other.words, length * sizeof(WordIndex));
- }
- return (length < other.length) ? -1 : 1;
+ if (length != other.length) return length < other.length ? -1 : 1;
+ return memcmp(words, other.words, length * sizeof(WordIndex));
+ }
+
+ bool operator<(const State &other) const {
+ if (length != other.length) return length < other.length;
+ return memcmp(words, other.words, length * sizeof(WordIndex)) < 0;
}
// Call this before using raw memcmp.
@@ -62,7 +61,9 @@ class State {
unsigned char length;
};
-size_t hash_value(const State &state);
+inline size_t hash_value(const State &state) {
+ return util::MurmurHashNative(state.words, sizeof(WordIndex) * state.length);
+}
namespace detail {