Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traverse over keys? #8

Open
dzpt opened this issue Apr 20, 2020 · 1 comment
Open

Traverse over keys? #8

dzpt opened this issue Apr 20, 2020 · 1 comment

Comments

@dzpt
Copy link

dzpt commented Apr 20, 2020

I wonder that can you implement loop over existing keys?

@luispedro
Copy link
Owner

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)

thsfs added a commit to thsfs/diskhash that referenced this issue Jun 22, 2023
* Size calculation mismatch on Windows.

* Removes unnecessary POSIX includes

* Adds casting to const char*

* Adding asserts + fixing file overwrite issue on Windows.

* Adding success return to dht_close_file.

* Fixing unittest to work on Windows.

* Removed wrong assertion.

* Fixes an OSX building error.

* Inverting (unsigned long) casts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants