-static unsigned int xbt_lib_hash(const char *str)
-{
-#ifdef DJB2_HASH_FUNCTION
- /* fast implementation of djb2 algorithm */
- int c;
- register unsigned int hash = 5381;
-
- while ((c = *str++)) {
- hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
- }
-
-# elif defined(FNV_HASH_FUNCTION)
- register unsigned int hash = 0x811c9dc5;
-
- while (*str) {
- /* multiply by the 32 bit FNV magic prime mod 2^32 */
- hash +=
- (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) +
- (hash << 24);
-
- /* xor the bottom with the current byte */
- hash ^= (unsigned int) *str++;
- }
-
-# else
- register unsigned int hash = 0;
-
- while (*str) {
- hash += (*str) * (*str);
- str++;
- }
-#endif
- return hash;
-}
-
-static void xbt_lib_rehash(xbt_lib_t lib)
-{
- const int oldsize = lib->table_size + 1;
- register int newsize = oldsize * 2;
- register int i;
- register xbt_libelm_t *currcell;
- register xbt_libelm_t *twincell;
- register xbt_libelm_t bucklet;
- register xbt_libelm_t *pprev;
-
- currcell =
- (xbt_libelm_t *) xbt_realloc((char *) lib->table,
- newsize * (sizeof(xbt_libelm_t) + sizeof(void*)*(lib->levels - 1)));
- memset(&currcell[oldsize], 0, oldsize * (sizeof(xbt_libelm_t) + sizeof(void*)*(lib->levels - 1))); /* zero second half */
- lib->table_size = --newsize;
- lib->table = currcell;
- XBT_DEBUG("REHASH (%d->%d)", oldsize, newsize);
-
- for (i = 0; i < oldsize; i++, currcell++) {
- if (!*currcell) /* empty cell */
- continue;
- twincell = currcell + oldsize;
- for (pprev = currcell, bucklet = *currcell; bucklet; bucklet = *pprev) {
- /* Since we use "& size" instead of "%size" and since the size was doubled,
- each bucklet of this cell must either :
- - stay in cell i (ie, currcell)
- - go to the cell i+oldsize (ie, twincell) */
- if ((bucklet->hash_code & newsize) != i) { /* Move to b */
- *pprev = bucklet->next;
- bucklet->next = *twincell;
- if (!*twincell)
- lib->fill++;
- *twincell = bucklet;
- continue;
- } else {
- pprev = &bucklet->next;
- }
-
- }
-
- if (!*currcell) /* everything moved */
- lib->fill--;
- }
-
-}
-
-void xbt_lib_cursor_first(const xbt_lib_t lib,
- xbt_lib_cursor_t * cursor)
-{
- XBT_DEBUG("xbt_lib_cursor_first");
- if (!*cursor) {
- XBT_DEBUG("Create the cursor on first use");
- *cursor = xbt_lib_cursor_new(lib);