From 2c4453984060dd039b8a99e5a8d98dbc107588b9 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sun, 12 Aug 2012 21:56:58 -0400 Subject: possible errors with google hashes --- utils/fast_sparse_vector.h | 8 +++++++- utils/hash.h | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'utils') diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h index 5647a2a9..9fe00459 100644 --- a/utils/fast_sparse_vector.h +++ b/utils/fast_sparse_vector.h @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include "config.h" @@ -192,6 +193,7 @@ class FastSparseVector { } else { is_remote_ = true; data_.rbmap = new SPARSE_HASH_MAP(first, last); + HASH_MAP_DELETED(*data_.rbmap, std::numeric_limits::max()); } } void erase(unsigned k) { @@ -213,8 +215,11 @@ class FastSparseVector { if (&other == this) return *this; clear(); std::memcpy(this, &other, sizeof(FastSparseVector)); - if (is_remote_) + if (is_remote_) { data_.rbmap = new SPARSE_HASH_MAP(*data_.rbmap); + // TODO: do i need to set_deleted on a copy? + HASH_MAP_DELETED(*data_.rbmap, std::numeric_limits::max()); + } return *this; } T const& get_singleton() const { @@ -445,6 +450,7 @@ class FastSparseVector { SPARSE_HASH_MAP* m = new SPARSE_HASH_MAP( reinterpret_cast*>(&data_.local[0]), reinterpret_cast*>(&data_.local[local_size_]), local_size_ * 1.5 + 1); + HASH_MAP_DELETED(*m, std::numeric_limits::max()); data_.rbmap = m; is_remote_ = true; } diff --git a/utils/hash.h b/utils/hash.h index 6d992086..189ed1ae 100644 --- a/utils/hash.h +++ b/utils/hash.h @@ -16,14 +16,16 @@ # define SPARSE_HASH_MAP google::sparse_hash_map # define HASH_MAP google::dense_hash_map # define HASH_SET google::dense_hash_set -# 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) +# define HASH_MAP_DELETED(h,deleted) do { (h).set_deleted_key(deleted); } while(0) +# 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 # include # define SPARSE_HASH_MAP std::tr1::unordered_map # define HASH_MAP std::tr1::unordered_map # define HASH_SET std::tr1::unordered_set +# define HASH_MAP_DELETED(h,deleted) # define HASH_MAP_RESERVED(h,empty,deleted) # define HASH_MAP_EMPTY(h,empty) #endif -- cgit v1.2.3