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

Hashtab #954

Closed
wants to merge 6 commits into from
Closed

Hashtab #954

wants to merge 6 commits into from

Conversation

zuiderkwast
Copy link
Contributor

@zuiderkwast zuiderkwast commented Aug 27, 2024

This is in early stages.

Implementation and documentation is in src/hashtab.c and src/hashtab.h.

To test, look at src/unit/test_hashtab.c

To run test, do

cd src
make valkey-unit-tests
./valkey-unit-tests --single test_hashtab.c

TODO

  • Very few unit tests
  • Basic unit tests of the implemented functionality
  • More tests, large tables, fuzzing
  • Debug crash or hang for large tables (> 3M elements)
  • Type (struct with callbacks)
  • Create and release, seed hash function, etc.
  • Mem usage
  • Global resize policy (allow/avoid/forbid)
  • Incremental rehashing, rehash step, expand-if-needed, etc.
  • RehashMicroseconds
  • RehashingInfo
  • Basic operations: find, add, replace, delete
  • FindEntryByPtrAndHash (needed?)
  • Scan
  • Possibility to defrag (flag to scan to emit pointer to the elements within the table)
  • Iterator
  • Random element
  • Fair random element
  • Two-phase delete (TwoPhaseUnlinkFind/TwoPhaseUnlinkFree)
  • Two-phase insert (FindPositionForInsert/InsertAtPosition)
  • Stats

Comparison with dict

Most of the API is similar. The main difference is that the hashtab contains
elements (where an element can contain a key and other data), rather than keys
and values.

dict hashtab Notes
key-value entry element element contains key
DICT_OK, DICT_ERR 1, 0
dictResizeEnabled hashtabResizePolicy Better name
dictAddRaw hashtabAddOrFind Better name
dictUnlink hashsetPop Delete and return element
dictPauseAutoResize hashtabPauseAutoShrink Affects only shrinking, not expanding.
dictResumeAutoResize hashtabResumeAutoShrink Does a shrink if needed. The dict one doesn't.

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 347 lines in your changes missing coverage. Please review.

Project coverage is 69.88%. Comparing base (6172907) to head (52e8bba).

Files Patch % Lines
src/hashtab.c 0.00% 347 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #954      +/-   ##
============================================
- Coverage     70.30%   69.88%   -0.43%     
============================================
  Files           114      115       +1     
  Lines         61744    62091     +347     
============================================
- Hits          43412    43392      -20     
- Misses        18332    18699     +367     
Files Coverage Δ
src/hashtab.c 0.00% <0.00%> (ø)

... and 11 files with indirect coverage changes

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
@zuiderkwast
Copy link
Contributor Author

Moving this to personal repo and hiding from public PRs, for now. It's not ready for public review.

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

Successfully merging this pull request may close these issues.

1 participant