40 #ifndef UTIL_GTL_HASHTABLE_COMMON_H_
41 #define UTIL_GTL_HASHTABLE_COMMON_H_
52 # define __attribute__(x)
55 _START_GOOGLE_NAMESPACE_
58 #define SPARSEHASH_COMPILE_ASSERT(expr, msg) \
59 typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] \
60 __attribute__((unused))
62 namespace sparsehash_internal {
92 template<
typename Ignored>
94 void* data,
size_t length) {
95 return fread(data, length, 1, fp) == 1;
98 template<
typename Ignored>
100 const void* data,
size_t length) {
101 return fwrite(data, length, 1, fp) == 1;
110 template<
typename ISTREAM>
112 void* data,
size_t length) {
113 return fp->read(reinterpret_cast<char*>(data), length).good();
115 template<
typename Ignored>
117 void* data,
size_t length) {
121 template<
typename OSTREAM>
123 const void* data,
size_t length) {
124 return fp->write(reinterpret_cast<const char*>(data), length).good();
126 template<
typename Ignored>
128 const void* data,
size_t length) {
136 template <
typename INPUT>
138 void* data,
size_t length) {
139 return static_cast<size_t>(fp->Read(data, length)) == length;
144 template <
typename OUTPUT>
146 const void* data,
size_t length) {
147 return static_cast<size_t>(fp->Write(data, length)) == length;
152 template <
typename INPUT>
153 inline bool read_data(INPUT* fp,
void* data,
size_t length) {
157 template <
typename OUTPUT>
158 inline bool write_data(OUTPUT* fp,
const void* data,
size_t length) {
167 template <
typename INPUT,
typename IntType>
172 SPARSEHASH_COMPILE_ASSERT(static_cast<IntType>(-1) > static_cast<IntType>(0),
173 serializing_int_requires_an_unsigned_type);
174 for (
size_t i = 0; i < length; ++i) {
175 if (!
read_data(fp, &byte,
sizeof(byte)))
return false;
176 *value |=
static_cast<IntType
>(byte) << ((length - 1 - i) * 8);
181 template <
typename OUTPUT,
typename IntType>
185 SPARSEHASH_COMPILE_ASSERT(static_cast<IntType>(-1) > static_cast<IntType>(0),
186 serializing_int_requires_an_unsigned_type);
187 for (
size_t i = 0; i < length; ++i) {
188 byte = (
sizeof(value) <= length-1 - i)
189 ? 0 :
static_cast<unsigned char>((value >> ((length-1 - i) * 8)) & 255);
190 if (!
write_data(fp, &byte,
sizeof(byte)))
return false;
201 template <
typename INPUT>
203 return read_data(fp, value,
sizeof(*value));
206 template <
typename OUTPUT>
225 template<
typename Key,
typename HashFunc,
226 typename SizeType,
int HT_MIN_BUCKETS>
235 const float ht_occupancy_flt,
236 const float ht_empty_flt)
327 if (shrink > grow/2.0f)
328 shrink = grow / 2.0f;
338 while ( sz < min_buckets_wanted ||
339 num_elts >= static_cast<size_type>(sz * enlarge) ) {
342 if (static_cast<size_type>(sz * 2) < sz) {
343 throw std::length_error(
"resize overflow");
366 return hash /
sizeof(
void*);
384 #undef SPARSEHASH_COMPILE_ASSERT
385 _END_GOOGLE_NAMESPACE_
387 #endif // UTIL_GTL_HASHTABLE_COMMON_H_
bool write_data(OUTPUT *fp, const void *data, size_t length)
Definition: hashtable-common.h:158
void set_use_deleted(bool t)
Definition: hashtable-common.h:303
size_type enlarge_size(size_type x) const
Definition: hashtable-common.h:279
float shrink_factor() const
Definition: hashtable-common.h:259
Definition: hashtable-common.h:200
void set_use_empty(bool t)
Definition: hashtable-common.h:296
bool read_data(INPUT *fp, void *data, size_t length)
Definition: hashtable-common.h:153
void set_enlarge_threshold(size_type t)
Definition: hashtable-common.h:269
bool consider_shrink() const
Definition: hashtable-common.h:286
bool write_data_internal_for_ostream(OSTREAM *fp, const void *data, size_t length)
Definition: hashtable-common.h:122
void reset_thresholds(size_type num_buckets)
Definition: hashtable-common.h:315
static size_t MungedHash(size_t hash)
Definition: hashtable-common.h:353
bool use_empty() const
Definition: hashtable-common.h:293
size_type shrink_threshold_
Definition: hashtable-common.h:371
size_type shrink_threshold() const
Definition: hashtable-common.h:272
void set_resizing_parameters(float shrink, float grow)
Definition: hashtable-common.h:324
float shrink_factor_
Definition: hashtable-common.h:373
size_type min_buckets(size_type num_elts, size_type min_buckets_wanted)
Definition: hashtable-common.h:335
bool write_data_internal(Ignored *, FILE *fp, const void *data, size_t length)
Definition: hashtable-common.h:99
bool consider_shrink_
Definition: hashtable-common.h:375
size_type num_ht_copies() const
Definition: hashtable-common.h:307
bool write_bigendian_number(OUTPUT *fp, IntType value, size_t length)
Definition: hashtable-common.h:182
bool use_deleted() const
Definition: hashtable-common.h:300
sh_hashtable_settings(const hasher &hf, const float ht_occupancy_flt, const float ht_empty_flt)
Definition: hashtable-common.h:234
float enlarge_factor_
Definition: hashtable-common.h:372
void set_enlarge_factor(float f)
Definition: hashtable-common.h:256
bool read_data_internal(Ignored *, FILE *fp, void *data, size_t length)
Definition: hashtable-common.h:93
float enlarge_factor() const
Definition: hashtable-common.h:253
bool operator()(OUTPUT *fp, const value_type &value) const
Definition: hashtable-common.h:207
const Name x("x")
current scaling factor of the synaptic weight [0...1] (Tsodyks2_connection)
Definition: nest_names.h:356
size_type hash(const key_type &v) const
Definition: hashtable-common.h:248
static size_t MungedHash(size_t hash)
Definition: hashtable-common.h:360
Key key_type
Definition: hashtable-common.h:229
void set_shrink_factor(float f)
Definition: hashtable-common.h:262
bool read_bigendian_number(INPUT *fp, IntType *value, size_t length)
Definition: hashtable-common.h:168
HashFunc hasher
Definition: hashtable-common.h:230
void set_consider_shrink(bool t)
Definition: hashtable-common.h:289
size_type shrink_size(size_type x) const
Definition: hashtable-common.h:282
bool use_deleted_
Definition: hashtable-common.h:377
bool operator()(INPUT *fp, value_type *value) const
Definition: hashtable-common.h:202
Definition: hashtable-common.h:227
size_type enlarge_threshold_
Definition: hashtable-common.h:370
void set_shrink_threshold(size_type t)
Definition: hashtable-common.h:275
bool read_data_internal_for_istream(ISTREAM *fp, void *data, size_t length)
Definition: hashtable-common.h:111
Definition: hashtable-common.h:57
size_type enlarge_threshold() const
Definition: hashtable-common.h:266
Definition: hashtable-common.h:351
bool use_empty_
Definition: hashtable-common.h:376
unsigned int num_ht_copies_
Definition: hashtable-common.h:379
void inc_num_ht_copies()
Definition: hashtable-common.h:310
SizeType size_type
Definition: hashtable-common.h:231