-
Notifications
You must be signed in to change notification settings - Fork 76
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
Hashtable documentation #93
Merged
alexfertel
merged 11 commits into
alexfertel:main
from
scriptandcompile:hashtable_documentation
Jun 17, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
52ecb92
Added Debug, PartialEq, and Eq for HashTable<K, V>
scriptandcompile 9e3ff45
added hashable imp for usize to ease testing purposes.
scriptandcompile 64b5ef0
Added is_empty impl for HashTable.
scriptandcompile c4c87e9
Added test doc for HashTable, removed previous test that is no longer…
scriptandcompile 5db932e
Added documentation for HashTable impl's
scriptandcompile 4421985
Removed TestKey testing type since we now have a usize impl we can use.
scriptandcompile b57e447
fixed docs to use fully qualified new
scriptandcompile 51b1e4d
Improved is_empty doc test
scriptandcompile 43175d2
Added 'Notes' section to insert.
scriptandcompile c5139b6
Added capacity impl to HashTable.
scriptandcompile 1b413e3
cargo fmt.
scriptandcompile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so this is valuable, because this way we test that the hash table works with hashable elements.
What's interesting here is that no tests broke, which means that we aren't testing the actual placement of keys in the table (
Testkey(i)
would be placed in the i-th bucket, buti
, would be placed in thehash(i) % length
bucket).I think this is a bit involved, and I'm not sure how educational it is, so I think it's fine to remove this. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. What was actually upsetting about this was that the key educational bit of a hash table, the bit that makes it 'different' than other data structures, is the hash function...which we are just setting it to the item! which means it might as well just be an array.
But wait! There is more!
We are using a vector and a linked list internally! Which is...just. no.
We definitely should have a linked list as a structure as an example, but we shouldn't be using them internally. The cache thrashing they cause is just not worth their use in modern code. The cost vs benefit just fails. Arena's are significantly better choices and that goes doubly so given rust's hate of multi-borrow mechanics.
vec of Option for storage, K is the index into the vec, v is the value in the vec, and we are off and running. The same could be done with the b-tree but I just couldn't be bothered since I've been focusing on the doc's instead of the core implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you'd like to implement that, I'm more than happy to review it!
I still think it's valuable to show suboptimal implementations though: if someone is starting, they should have access to both the dumb, easy implementation and the nicer, optimized, linear-probing implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm merging this, feel free to open a separate PR!