debugging" vector" and added regression test
[rrq/rrqmisc.git] / vector / hashvector.c
index 1afae8086f2985dde4dfbaa0755fbaa4cde55e88..bd6fb97b8697c1594414301a5cf3d28fead0b23e 100644 (file)
@@ -48,7 +48,7 @@ int hashvector_find(hashvector *hv,void *key,void **x) {
 }
 
 static int capture_item(vector *pv,unsigned long ix,void *item,void *data) {
-    if ( item != HV_HOLE ) {
+    if ( item && item != HV_HOLE ) {
        hashvector_add( (hashvector *) data, item );
     }
     return 0;
@@ -70,7 +70,7 @@ static void hashvector_resize(hashvector *hv,unsigned long new_size) {
     if ( new_size < hv->table.size ) {
        vector_resize( &tmp.table, 0, capture_item, hv );
     } else {
-       vector_iterate( &tmp.table, iter_item, hv );
+       vector_iterate( &tmp.table, 0, iter_item, hv );
     }
 }
     
@@ -119,16 +119,14 @@ int hashvector_contents(hashvector *hv,vector *pv) {
     }
     unsigned long from = 0;
     unsigned long to = 0;
-    while ( to < hv->fill ) {
-       void **slot = vector_next_used( &hv->table, &from, 0, 0 );
-       if ( slot ) {
-           if ( *slot != HV_HOLE ) {
-               vector_set( pv, to++, *slot );
-           }
-           from++;
-       } else {
+    for ( ; to < hv->fill; from++ ) {
+       void **slot = vector_next_used( &hv->table, &from );
+       if ( slot == 0 ) {
            break;
        }
+       if ( *slot != HV_HOLE ) {
+           vector_set( pv, to++, *slot );
+       }
     }
     return 0;
 }