diff options
author | Chris Dyer <redpony@gmail.com> | 2014-04-07 22:56:34 -0400 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-04-07 22:56:34 -0400 |
commit | 5a8b0aa3245f14a3c049f6f8d34c3a6f37cf070c (patch) | |
tree | 2117a9eca8065e9eed33251a4ac12ebc875fae9f /decoder/node_state_hash.h | |
parent | 8c77c634836e56c7b9b3400afeac21277f168238 (diff) |
track node state for smarter union
Diffstat (limited to 'decoder/node_state_hash.h')
-rw-r--r-- | decoder/node_state_hash.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/decoder/node_state_hash.h b/decoder/node_state_hash.h new file mode 100644 index 00000000..cdc05877 --- /dev/null +++ b/decoder/node_state_hash.h @@ -0,0 +1,36 @@ +#ifndef _NODE_STATE_HASH_ +#define _NODE_STATE_HASH_ + +#include <cassert> +#include <cstring> +#include "murmur_hash3.h" +#include "ffset.h" + +namespace cdec { + + struct FirstPassNode { + FirstPassNode(int cat, int i, int j, int pi, int pj) : lhs(cat), s(i), t(j), u(pi), v(pj) {} + int32_t lhs; + short s; + short t; + short u; + short v; + }; + + inline uint64_t HashNode(int cat, int i, int j, int pi, int pj) { + FirstPassNode fpn(cat, i, j, pi, pj); + return MurmurHash3_64(&fpn, sizeof(FirstPassNode), 2654435769U); + } + + inline uint64_t HashNode(uint64_t old_hash, const FFState& state) { + uint8_t buf[1024]; + std::memcpy(buf, &old_hash, sizeof(uint64_t)); + assert(state.size() < (1024u - sizeof(uint64_t))); + std::memcpy(&buf[sizeof(uint64_t)], state.begin(), state.size()); + return MurmurHash3_64(buf, sizeof(uint64_t) + state.size(), 2654435769U); + } + +} + +#endif + |