X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2FHashVector.c;h=7b68c59f9f3e9ded09e8e3a4151bdbf94bb120c4;hb=3cb0a5b799686068172de48232d3dea6ac7caed4;hp=ec0e0b41a38e18aed3b4e7f48de3180a66fc4810;hpb=3d4400773c3361961bcb9f8b6898321f2005a093;p=rrq%2Frrqmisc.git diff --git a/vector/HashVector.c b/vector/HashVector.c index ec0e0b4..7b68c59 100644 --- a/vector/HashVector.c +++ b/vector/HashVector.c @@ -1,8 +1,6 @@ #include #include -#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,7 +57,7 @@ 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; }