#ifndef Hash
#define ID_HASH
-#define Hash(self,key) ((unsigned)(key))
+#define Hash(self,key) ((unsigned)(((char *)key) - (char *)0))
#endif /* Hash */
#ifdef DO_REHASH
#ifndef hashset_size
#error You have to redefine hashset_size
#endif
+
+#ifndef NO_ITERATOR
#ifndef hashset_iterator_init
#error You have to redefine hashset_iterator_init
#endif
#ifndef hashset_remove_iterator
#error You have to redefine hashset_remove_iterator
#endif
+#endif
/**
* Returns the number of elements in the hashset
HashSetEntry *entry = & self->entries[bucknum];
if(EntryIsEmpty(*entry)) {
- size_t p;
+ size_t p;
HashSetEntry *nentry;
if(insert_pos != ILLEGAL_POS) {
self->consider_shrink = 0;
}
+#ifndef HAVE_OWN_RESIZE
/**
* Resize the hashset
* @internal
/* now we can free the old array */
Free(old_entries);
}
+#else
+
+/* resize must be defined outside */
+static void resize(HashSet *self, size_t new_size);
+
+#endif
/**
* grow the hashset if adding 1 more elements would make it too crowded
return;
self->consider_shrink = 0;
- size = hashset_size(self);
+ size = hashset_size(self);
if(size <= HT_MIN_BUCKETS)
return;
}
/**
- * Insert an element into the hashset. If no element with key key exists yet,
+ * Insert an element into the hashset. If no element with the given key exists yet,
* then a new one is created and initialized with the InitData function.
- * Otherwise the exisiting element is returned (for hashs where key is equal to
+ * Otherwise the existing element is returned (for hashs where key is equal to
* value, nothing is returned.)
*
* @param self the hashset
}
/**
- * Searchs for an element with key @p key.
+ * Searches for an element with key @p key.
*
* @param self the hashset
* @param key the key to search for
#ifndef NDEBUG
self->entries_version = 0;
#endif
+#ifdef ADDITIONAL_INIT
+ ADDITIONAL_INIT
+#endif
reset_thresholds(self);
}
/**
- * Initialializes a hashset with the default size. The memory for the set has to
+ * Initializes a hashset with the default size. The memory for the set has to
* already allocated.
*/
void hashset_init(HashSet *self)
*/
void hashset_destroy(HashSet *self)
{
+#ifdef ADDITIONAL_TERM
+ ADDITIONAL_TERM
+#endif
Free(self->entries);
#ifndef NDEBUG
self->entries = NULL;
}
/**
- * Initializes a hashset expecting expected_element size
+ * Initializes a hashset expecting expected_element size.
*/
void hashset_init_size(HashSet *self, size_t expected_elements)
{
init_size(self, po2size);
}
+#ifndef NO_ITERATOR
/**
* Initializes a hashset iterator. The memory for the allocator has to be
* already allocated.
self->num_deleted++;
self->consider_shrink = 1;
}
+#endif /* NO_ITERATOR */
-#endif
+#endif /* HashSet */