-#include "hashvector.h"
+#include <stdlib.h>
+#include <hashvector.h>
#define SELF hv->type
// 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
// overfull hashvector (i.e. 0 shouldn't happen).
-// If itemkey is set, then the itmekey callback function is used for
+// If itemkey is set, then the itemkey callback function is used for
// obtaining a temporary key from the item.
static void **hashvector_find_slot(
hashvector *hv, void *key, unsigned long *i, int itemkey )
}
}
-// 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;
}
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;
+}
+