diskhash icon indicating copy to clipboard operation
diskhash copied to clipboard

Traverse over keys?

Open dzpt opened this issue 5 years ago • 1 comments

I wonder that can you implement loop over existing keys?

dzpt avatar Apr 20 '20 09:04 dzpt

It's not so hard to implement. If you want to give it a shot, it's basically having an integer loop over 0..dt->cur_size_ and checking each entry for dht_empty

Here's some pseudocode, which may help:

typedef struct {
   HashEntry et;
   size_t dht_internal_ix_;
} HashIterator;

bool  dht_begin(HashTable * ht, HashIterator* init) {
   init->dht_internal_ix_ = 0;
   return dht_next_iter(ht, init);
}

bool dht_advance_iter(HashTable ht*, HashIterator* it) {
   while (it->dht_internal_ix < ht->cursize_) {
       ++it->dht_internal_ix;
        it->et = dht_entry_at(ht, it->dht_internal_ix);
        if (!et_empty(it->et)) { return true; }
   }
   return false;
}

(Also because covid, I do not have a lot of time, but I am happy to review pull requests)

luispedro avatar Apr 20 '20 09:04 luispedro