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

Implement automatic shrinking on key_put() #121

Open
capr opened this issue Jan 18, 2019 · 3 comments
Open

Implement automatic shrinking on key_put() #121

capr opened this issue Jan 18, 2019 · 3 comments

Comments

@capr
Copy link

capr commented Jan 18, 2019

Hi!

I noticed this TODO on kh_put():

TODO: implement automatic shrinking; resize() already supports shrinking

... and above I see there's a resize call with h.n_buckets - 1 and the comment clear "deleted" elements so it seems like it does shrink on certain situations but not in others? Can you give more details on this please?

Thanks!

@attractivechaos
Copy link
Owner

No, the table never shrinks automatically. You have to manually shrink the table by calling kh_resize().

khash may automatically rehash to the same size in order to clear "tomestones" when there are too many.

@attractivechaos
Copy link
Owner

Khash doesn't automatically shrink because it can't expect what users will do with the hash table. Automatic shrink may have big unexpected performance hits. It's better to let users decide.

@capr
Copy link
Author

capr commented Jan 18, 2019

Hi @attractivechaos thanks for the explanation. Can you recommend a good strategy / formula for when to call resize periodically in order to implement auto-shrinking?

Btw, AFAIU, n_buckets is the total number of key/value pairs that there's memory allocated for, and size is the number of live pairs. Is that right? If so, what does n_occupied measure?

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