From cd5d8e0ab902a0c87e108b863aca2888248a4516 Mon Sep 17 00:00:00 2001 From: graehl Date: Tue, 20 Jul 2010 21:38:29 +0000 Subject: hash.h git-svn-id: https://ws10smt.googlecode.com/svn/trunk@342 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/dict.h | 22 +++------------------- decoder/ff_factory.h | 2 ++ decoder/hash.h | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 19 deletions(-) create mode 100755 decoder/hash.h diff --git a/decoder/dict.h b/decoder/dict.h index dd433c3e..348a97e3 100644 --- a/decoder/dict.h +++ b/decoder/dict.h @@ -1,37 +1,21 @@ #ifndef DICT_H_ #define DICT_H_ -#include "config.h" #include #include -#ifdef HAVE_SPARSEHASH -# include -#else -# include -#endif #include #include -#include - +#include "hash.h" #include "wordid.h" class Dict { typedef -#ifdef HAVE_SPARSEHASH - google::dense_hash_map -#else - std::tr1::unordered_map -#endif - > Map; - + HASH_MAP > Map; public: Dict() : b0_("") { -#ifdef HAVE_SPARSEHASH - d_.set_empty_key(""); - d_.set_deleted_key(""); -#endif + HASH_MAP_EMPTY(d_,""); words_.reserve(1000); } diff --git a/decoder/ff_factory.h b/decoder/ff_factory.h index 6f86f2f9..12e768aa 100644 --- a/decoder/ff_factory.h +++ b/decoder/ff_factory.h @@ -1,6 +1,8 @@ #ifndef _FF_FACTORY_H_ #define _FF_FACTORY_H_ +//TODO: use http://www.boost.org/doc/libs/1_43_0/libs/functional/factory/doc/html/index.html? + #include #include #include diff --git a/decoder/hash.h b/decoder/hash.h new file mode 100755 index 00000000..3e4ad1ff --- /dev/null +++ b/decoder/hash.h @@ -0,0 +1,19 @@ +#ifndef CDEC_HASH_H +#define CDEC_HASH_H + +#include "config.h" +#ifdef HAVE_SPARSEHASH +# include +# define HASH_MAP google::dense_hash_map +# define HASH_MAP_RESERVED(h,empty,deleted) do { h.set_empty_key(empty); h.set_deleted_key(deleted); } while(0) +# define HASH_MAP_EMPTY(h,empty) do { h.set_empty_key(empty); } while(0) +#else +# include +# define HASH_MAP std::tr1::unordered_map +# define HASH_MAP_RESERVED(h,empty,deleted) +# define HASH_MAP_EMPTY(h,empty) +#endif +#include + + +#endif -- cgit v1.2.3