changed ABI
[rrq/rrqmisc.git] / vector / HashVector.c
index dbf1ab2ee3c6cbeaa17cefff205483e4ebaf1059..7b68c59f9f3e9ded09e8e3a4151bdbf94bb120c4 100644 (file)
@@ -1,8 +1,6 @@
 #include <stdlib.h>
 #include <HashVector.h>
 
-#define SELF hv->type
-
 // Find the slot for the keyed element, and return pointer to it, or
 // to the first of holes encountered while considering collisions.
 // Returns a pointer to the place for the item, or 0 in case of OOM or
@@ -14,9 +12,9 @@ static void **HashVector_find_slot(
 {
     if ( itemkey ) {
         // Get actual key from keying item
-       key = hv->type->itemkey( SELF, key );
+       key = ItemKeyFun_itemkey( hv->type, key );
     }
-    unsigned long index = hv->type->hashcode( SELF, key ) % hv->table.size;
+    unsigned long index = ItemKeyFun_hashcode( hv->type, key ) % hv->table.size;
     *i = index;
     void **hole = 0;
     void **p = 0;
@@ -24,13 +22,13 @@ static void **HashVector_find_slot(
        p = Vector_entry( &hv->table, (*i) );
        if ( p == 0 ) {
            if ( itemkey ) {
-               hv->type->releasekey( SELF, key );
+               ItemKeyFun_releasekey( hv->type, key );
            }
            return 0; // This basically means OOM, and is a failure condition.
        }
        if ( (*p) == 0 ) {
            if ( itemkey ) {
-               hv->type->releasekey( SELF, key );
+               ItemKeyFun_releasekey( hv->type, key );
            }
            return ( hole )? hole : p; // Not found; it's place is here.
        }
@@ -38,9 +36,9 @@ static void **HashVector_find_slot(
            if ( hole == 0 ) {
                hole = p; // Remember the first hole
            }
-       } else if ( hv->type->haskey( SELF, (*p), key ) ) {
+       } else if ( ItemKeyFun_haskey( hv->type, (*p), key ) ) {
            if ( itemkey ) {
-               hv->type->releasekey( SELF, key );
+               ItemKeyFun_releasekey( hv->type, key );
            }
            return p; // Found
        }
@@ -49,7 +47,7 @@ static void **HashVector_find_slot(
        }
        if ( (*i) == index ) {
            if ( itemkey ) {
-               hv->type->releasekey( SELF, key );
+               ItemKeyFun_releasekey( hv->type, key );
            }
            return 0; // Overfull HashVector!
        }
@@ -59,32 +57,23 @@ static void **HashVector_find_slot(
 // Find the keyed item
 void *HashVector_find(HashVector *hv,void *key) {
     VectorIndex index = 0;
-    void **slot = HashVector_find_slot( hv, &index, key, 0 );
+    void **slot = HashVector_find_slot( hv, key, &index, 0 );
     return ( slot && *slot && *slot != HV_HOLE )? *slot : 0;
 }
 
 // Find any element at or after the index that admits to the key.
 // Update index and return item.
-void *HashVector_next(HashVector *hv,VectorIndex *index,void *key) {
-    unsigned long i = index? *index : 0;
-    for ( ; i < hv->table.size; i++ ) {
-       void **p = Vector_next_used( &hv->table, &i );
+void *HashVector_next(HashVector *hv,VectorIndex *index) {
+    for ( ; (*index) < hv->table.size; (*index)++ ) {
+       void **p = Vector_next_used( &hv->table, index );
        if ( p == 0 ) {
            break;
        }
        if ( *p && *p != HV_HOLE ) {
-           if ( key && hv->type->haskey( hv->type, *p, key ) == 0 ) {
-               continue;
-           }
-           if ( index ) {
-               (*index) = i;
-           }
            return *p;
        }
     }
-    if ( index ) {
-       (*index) = hv->table.size;
-    }
+    (*index) = hv->table.size;
     return 0;
 }
 
@@ -184,7 +173,7 @@ Vector *HashVector_contents(
     VectorIndex i;
     VectorIndex j = 0;
     for ( i = 0; i < v->size; i++, j++ ) {
-       Vector_set( v, i, HashVector_next( hv, &j, 0 ) );
+       Vector_set( v, i, HashVector_next( hv, &j ) );
     }
     return v;
 }