X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2FHashVector.c;h=19269c1a0eaec61137ee12565bcf92905ee83154;hb=d6f70b77023f9682bf2c65428068a6897dd16ce3;hp=dbf1ab2ee3c6cbeaa17cefff205483e4ebaf1059;hpb=58de9483c458a25a691d648ce13b81227c327d03;p=rrq%2Frrqmisc.git diff --git a/vector/HashVector.c b/vector/HashVector.c index dbf1ab2..19269c1 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,36 +57,28 @@ 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; } static int capture_item(Vector *pv,unsigned long ix,void *item,void *data) { + (void)pv; (void)ix; if ( item && item != HV_HOLE ) { HashVector_add( (HashVector *) data, item ); } @@ -96,6 +86,7 @@ static int capture_item(Vector *pv,unsigned long ix,void *item,void *data) { } static int iter_item(unsigned long ix,void *item,void *data) { + (void)ix; if ( item && item != HV_HOLE ) { HashVector_add( (HashVector *) data, item ); } @@ -184,7 +175,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; }