#ifndef HT_OCCUPANCY_FLT
/** how full before we double size */
-#define HT_OCCUPANCY_FLT 0.5f
+#define HT_OCCUPANCY_FLT(x) ((x)/2)
#endif /* HT_OCCUPANCY_FLT */
+#ifndef HT_1_DIV_OCCUPANCY_FLT
+#define HT_1_DIV_OCCUPANCY_FLT 2
+#endif
#ifndef HT_EMPTY_FLT
/** how empty before we half size */
-#define HT_EMPTY_FLT (0.4f * (HT_OCCUPANCY_FLT))
+#define HT_EMPTY_FLT(x) ((x)/5)
#endif /* HT_EMPTY_FLT */
#ifndef HT_MIN_BUCKETS
static INLINE
void reset_thresholds(HashSet *self)
{
- self->enlarge_threshold = (size_t) (self->num_buckets * HT_OCCUPANCY_FLT);
- self->shrink_threshold = (size_t) (self->num_buckets * HT_EMPTY_FLT);
+ self->enlarge_threshold = (size_t) HT_OCCUPANCY_FLT(self->num_buckets);
+ self->shrink_threshold = (size_t) HT_EMPTY_FLT(self->num_buckets);
self->consider_shrink = 0;
}
self->consider_shrink = 0;
size = hashset_size(self);
+ if(size <= HT_MIN_BUCKETS)
+ return;
+
if(LIKELY(size > self->shrink_threshold))
return;
abort();
}
- needed_size = expected_elements * (int)(1.0 / HT_OCCUPANCY_FLT);
+ needed_size = expected_elements * HT_1_DIV_OCCUPANCY_FLT;
po2size = ceil_po2(needed_size);
init_size(self, po2size);
}