X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Fhashvector.c;h=4d89890e172b0874deafd6329c29d4625f18d936;hb=d9858ce46cb09b9127c7246f628e65982aa43a15;hp=0f5b31f6e640f9281bf982a9ca8fea422bd073d7;hpb=a464c26b7c4513b124d5927d5ed8dd6812380aea;p=rrq%2Frrqmisc.git diff --git a/vector/hashvector.c b/vector/hashvector.c index 0f5b31f..4d89890 100644 --- a/vector/hashvector.c +++ b/vector/hashvector.c @@ -1,4 +1,5 @@ -#include "hashvector.h" +#include +#include #define SELF hv->type @@ -55,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 = hashvector_find_slot( hv, key, &i, 0 ); + if ( p == 0 ) { + break; + } + if ( *p && *p != HV_HOLE ) { + if ( key && hv->type->haskey( hv->type, key, *p ) == 0 ) { + continue; + } + if ( index ) { + (*index) = i; + } + return *p; } - return 1; + } + if ( index ) { + (*index) = hv->table.size; } return 0; } @@ -174,3 +186,19 @@ unsigned long hashvector_hashcode(unsigned char *key,unsigned long n) { return value; } + +hashvector *hashvector_create(enum vector_variant variant,itemkeyfun *type) { + hashvector *hv = (hashvector*) malloc( sizeof( hashvector ) ); + (*hv) = (hashvector) { + .table = (vector) { + .variant = variant, + .size = 16, + .entries = 0 + }, + .fill = 0, + .holes = 0, + .type = type + }; + return hv; +} +