-
Notifications
You must be signed in to change notification settings - Fork 48
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 "reserve" and improve "Extend" impl #28
Conversation
Implemented reserve and improved used it to improve extend wrote a `capacity` function, to allow for testsing resizes wrote some tests
reserve
and capacity
and improve Extend
impl
Awesome! I'll take a look through and leave comments. |
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.
@jonhoo Thank you for the review!
I'll work on this some more tomorrow, but I should probably call it quits for today.
PS: The pipeline seems to fail (partially) due to not being able to install rust.
It might make sense to take a look at that.
I am a bit confused about why the java version multiplies the requested capacity tableSizeFor(size + (size >>> 1) + 1) and why it set's the size control to 3/4 of the current capacity if the table was not yet initialized: sc = n - (n >>> 2); It obviously is the right thing to do since the java version does it this way, but it seems really weird to me... |
I'm not sure. It may have to do with the way that their
|
Ah, I was confused about the exact meaning of size_ctl, guess I'll look at the rest of my code, to make sure I didn't make any wrong comments because of that. |
since if n = (sc > c) ? sc : c; take that into account? |
I'm thinking of something like this: let initial_capacity = if size_ctl == 0 {
DEFAULT_CAPACITY as isize
} else {
size_ctl
};
// the new capacity is either the requested capacity or the initial capacity, if it is larger
// since all maps should be at least as big as their initial capacity specifies
let new_capacity = requested_capacity.max(initial_capacity) as usize; |
Well, the initial capacity for a table is determined here: Lines 313 to 317 in 051ca79
Or maybe I'm missing something about your question? |
We'll if I used a map and initialized it with an initial capacity I would assume that it has at least that capacity... Nevermind if |
following code audit feedback and documented `try_presize` better
Ohhh, I see what you're getting at: let map = flurry::HashMap::with_capacity(1024);
map.reserve(512); The call to |
b83cbe2 looks great |
I think calling |
The question is how we handle the guard for |
Is there a reason you were dividing by the load factor: let size = (1.0 + (n as f64) / LOAD_FACTOR) as usize; instead of multiplying by it: let size = (1.0 + (n as f64) * LOAD_FACTOR) as usize; or was that just a typo? |
reworked how the load factor is applied
make some tests unit tests make `capacity` private
I initially wanted to make a new branch for this but impulsively committed this here, should I revert the last commit and make a new branch, or can I just leave it? |
Well, It should be fine to use I divide because that's what the Java code does. I'm fine with you folding the fix for the resize stamp in here :) |
This is looking really good. Are there any other changes you want to make before merging? |
But we don't need it in
That's really weird, especially since it adds a global constant just for that...
Great, thank you |
Not really, I initially wanted to look into maybe relaxing some |
Right, hence my comment above:
Yes, I think that belongs in a new PR! Okay, let's merge this 🎉 |
Whoops, guess I missed that, sorry.
Great, Thank you! |
No, thank you! |
This Draft somewhat naively follows the suggestions made at #10 to implement
reserve
and improve theExtend
implementation.I'll continue to work on this and update this PR when I have made more progress
I have so far:
tryPresize
functionreserve
wrapper around it (which, like most of the public API, takes aGuard
for now)Extend
implementation to usereserve
and thehashbrown::HashMap::extend
heuristic on how much to reservecapacity
to make sure a resize actually happened`What still needs to be done:
- possibly relax some(Should probably get it's own PR)Ordering
s (everything isSeqConst
for now)