X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=map%2Fhashtable.c;h=bff782f84afdf46867dcbc27275402f1e3ac18dd;hp=34d04d5a0ede98273b730242cc92ed911929888c;hb=5aa9223647fbb52fa8941d92c8896ebaf148b41c;hpb=973c2b13fe82d6ebd030cd58869fa237b1fe5370 diff --git a/map/hashtable.c b/map/hashtable.c index 34d04d5..bff782f 100644 --- a/map/hashtable.c +++ b/map/hashtable.c @@ -10,6 +10,8 @@ * Every atomic operation is also an implicit full memory barrier. The upshot is that it simplifies * the code a bit, but it won't be as fast as it could be on platforms that provide weaker * operations like and unfenced CAS which would still do the job. + * + * 11FebO9 - Bug fix in ht_iter_next() from Rui Ueyama */ #include @@ -677,9 +679,6 @@ map_val_t ht_iter_next (ht_iter_t *iter, map_key_t *key_ptr) { } while (key == DOES_NOT_EXIST || val == DOES_NOT_EXIST || val == TOMBSTONE); - if (key_ptr) { - *key_ptr = key; - } if (val == COPIED_VALUE) { const datatype_t *key_type = iter->hti->ht->key_type; #ifdef NBD32 @@ -688,8 +687,15 @@ map_val_t ht_iter_next (ht_iter_t *iter, map_key_t *key_ptr) { uint32_t hash = (key_type == NULL) ? murmur32_8b((uint64_t)key) : key_type->hash((void *)key); #endif val = hti_get(iter->hti->next, (map_key_t)ent->key, hash); + + // Go to the next entry if key is already deleted. + if (val == DOES_NOT_EXIST) + return ht_iter_next(iter, key_ptr); // recursive tail-call } + if (key_ptr) { + *key_ptr = key; + } return val; }