Skip to content

Do some cleanups for hashmaps #45263

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

Merged
merged 2 commits into from
Oct 15, 2017
Merged

Conversation

Manishearth
Copy link
Member

@mystor noticed some things whilst reading through the hashmap RawTable code.

Firstly, in RawTable we deal with this hash_offset value that is the offset of the list of hashes from the buffer start. This is always zero, and this isn't consistently used (which means that we would have bugs if we set it to something else). We should just remove this since it doesn't help us at all.

Secondly, the probing length tag is not copied when cloning a raw table. This is minor and basically means we do a bit more work than we need on further inserts on a cloned hashmap.

r? @gankro

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2017
@bluss
Copy link
Member

bluss commented Oct 13, 2017

@arthurprs is probably interested in this PR

Copy link
Contributor

@arthurprs arthurprs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -768,7 +767,7 @@ impl<K, V> RawTable<K, V> {
// This is great in theory, but in practice getting the alignment
// right is a little subtle. Therefore, calculating offsets has been
// factored out into a different function.
let (alignment, hash_offset, size, oflo) = calculate_allocation(hashes_size,
let (alignment, size, oflo) = calculate_allocation(hashes_size,
align_of::<HashUint>(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: lines bellow need some formating adjustments.

@@ -1157,6 +1156,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
}

new_ht.size = self.size();
new_ht.set_tag(self.tag());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I overlooked that before.

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 14, 2017
@Manishearth
Copy link
Member Author

Fixed

This offset is always zero, and we don't consistently take it into
account. This is okay, because it's zero, but if it ever changes we're
going to have bugs (e.g. in the `dealloc` call, where we don't take it
into account).

It's better to remove this for now; if we ever have a need for a
nonzero offset we can add it back, and handle it properly when we do so.
This isn't strictly necessary for hashmap cloning to work. The tag is
used to hint for an upcoming resize, so it's good to copy this
information over.

(We can do cleverer things like actually resizing the hashmap when we
see the tag, or even cleaning up the entry order, but this requires
more thought and might not be worth it)
@bluss
Copy link
Member

bluss commented Oct 14, 2017

@bors r+ rollup

Thanks @Manishearth and @arthurprs

@bors
Copy link
Collaborator

bors commented Oct 14, 2017

📌 Commit e8e7715 has been approved by bluss

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 14, 2017
kennytm added a commit to kennytm/rust that referenced this pull request Oct 14, 2017
Do some cleanups for hashmaps

@mystor noticed some things whilst reading through the hashmap RawTable code.

Firstly, in RawTable we deal with this hash_offset value that is the offset of the list of hashes from the buffer start. This is always zero, and this isn't consistently used (which means that we would have bugs if we set it to something else). We should just remove this since it doesn't help us at all.

Secondly, the probing length tag is not copied when cloning a raw table. This is minor and basically means we do a bit more work than we need on further inserts on a cloned hashmap.

r? @gankro
bors added a commit that referenced this pull request Oct 14, 2017
Rollup of 9 pull requests

- Successful merges: #45113, #45250, #45255, #45258, #45263, #45264, #45269, #45280, #45289
- Failed merges:
kennytm added a commit to kennytm/rust that referenced this pull request Oct 15, 2017
Do some cleanups for hashmaps

@mystor noticed some things whilst reading through the hashmap RawTable code.

Firstly, in RawTable we deal with this hash_offset value that is the offset of the list of hashes from the buffer start. This is always zero, and this isn't consistently used (which means that we would have bugs if we set it to something else). We should just remove this since it doesn't help us at all.

Secondly, the probing length tag is not copied when cloning a raw table. This is minor and basically means we do a bit more work than we need on further inserts on a cloned hashmap.

r? @gankro
bors added a commit that referenced this pull request Oct 15, 2017
Rollup of 9 pull requests

- Successful merges: #45113, #45250, #45255, #45258, #45263, #45264, #45269, #45280, #45289
- Failed merges:
@bors bors merged commit e8e7715 into rust-lang:master Oct 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants