From 2cb224de7db49b761ac06b031090fe7f846744fe Mon Sep 17 00:00:00 2001 From: graehl Date: Sat, 24 Jul 2010 21:18:01 +0000 Subject: FSA: simpler Scan1 ScanT1 methods, otherewise also expose edge to full Scan git-svn-id: https://ws10smt.googlecode.com/svn/trunk@399 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/hash.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'decoder/hash.h') diff --git a/decoder/hash.h b/decoder/hash.h index 3e4ad1ff..3a60a429 100755 --- a/decoder/hash.h +++ b/decoder/hash.h @@ -1,6 +1,8 @@ #ifndef CDEC_HASH_H #define CDEC_HASH_H +#include "murmur_hash.h" + #include "config.h" #ifdef HAVE_SPARSEHASH # include @@ -13,7 +15,40 @@ # define HASH_MAP_RESERVED(h,empty,deleted) # define HASH_MAP_EMPTY(h,empty) #endif + #include +// assumes C is POD +template +struct murmur_hash +{ + typedef MurmurInt return_type; + typedef C /*const&*/ argument_type; + return_type operator()(argument_type const& c) const { + return MurmurHash((void*)&c,sizeof(c)); + } +}; + +// murmur_hash_array isn't std guaranteed safe (you need to use string::data()) +template <> +struct murmur_hash +{ + typedef MurmurInt return_type; + typedef std::string /*const&*/ argument_type; + return_type operator()(argument_type const& c) const { + return MurmurHash(c.data(),c.size()); + } +}; + +// uses begin(),size() assuming contiguous layout and POD +template +struct murmur_hash_array +{ + typedef MurmurInt return_type; + typedef C /*const&*/ argument_type; + return_type operator()(argument_type const& c) const { + return MurmurHash(&*c.begin(),c.size()*sizeof(*c.begin())); + } +}; #endif -- cgit v1.2.3