X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Fhashvector.c;h=b39ef5ed2851168e78b0db7c4806b7ec0570c1cb;hb=d90019791ac5db4335ff117b765704a7b6167e68;hp=c9c2fb3ea7e360da75553ec3efb156010eefd100;hpb=d9a0011032a13d1477db102be3c1305af3223e72;p=rrq%2Frrqmisc.git diff --git a/vector/hashvector.c b/vector/hashvector.c index c9c2fb3..b39ef5e 100644 --- a/vector/hashvector.c +++ b/vector/hashvector.c @@ -56,16 +56,27 @@ static void **hashvector_find_slot( } } -// Find the keyed element, and assign the x pointer, or assign 0. -// Returns 1 if element is found and 0 otherwise. -int hashvector_find(hashvector *hv,void *key,void **x) { - unsigned long i; - void **p = hashvector_find_slot( hv, key, &i, 0 ); - if ( p && *p && *p != HV_HOLE ) { - if ( x ) { - *x = *p; +// Find the keyed element at or after the index. Update index and +// return item. +void *hashvector_next(hashvector *hv,vector_index *index,void *key) { + unsigned long i = index? *index : 0; + for ( ; i < hv->table.size; i++ ) { + void **p = vector_next_used( &hv->table, &i ); + if ( p == 0 ) { + break; } - return 1; + 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; } return 0; } @@ -176,7 +187,7 @@ unsigned long hashvector_hashcode(unsigned char *key,unsigned long n) { } -hashvector *hashvector_create(int variant,itemkeyfun *type) { +hashvector *hashvector_create(enum vector_variant variant,itemkeyfun *type) { hashvector *hv = (hashvector*) malloc( sizeof( hashvector ) ); (*hv) = (hashvector) { .table = (vector) {