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

Add ordered_remove with O(n) perf. #15

Closed
wants to merge 1 commit into from

Conversation

cristicbz
Copy link

I might be understanding the implementation wrong, but I think that order-preserving remove can be implemented by shifting both the indices and entry Vec-s, then decrementing all indices after the removed one, then correcting the robin hood property. But maybe I'm wrong, please review carefully @bluss :)

Because this operation is O(n) compared to the std O(1), I named it ordered_remove so that you're forced to make a conscious decision to preserve order at the expense of performance.

If this implementation makes sense, I'm happy to add a couple more commits to update the README and add this operation to Entry too.

@bluss bluss self-assigned this Feb 20, 2017
@bluss
Copy link
Member

bluss commented Apr 24, 2017

This does look good to me, just not sure if we need it. I think it is ultimately needed, the OrderMap has a lot of Vec like functionality going already.

@bluss bluss mentioned this pull request Sep 2, 2017
8 tasks
@cuviper cuviper mentioned this pull request Dec 1, 2017
@bluss
Copy link
Member

bluss commented Dec 31, 2017

Since some time has passed, you can disregard review comments here. But I'll put down my thoughts so that I don't forget them, for when I come back to this.

self.index = updater(self.index as usize) as u64;
} else {
let (index, hash) = split_lo_hi(self.index);
self.index = updater(index as usize) as u64 | ((hash as u64) << 32);
Copy link
Member

Choose a reason for hiding this comment

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

thought: does this truncate index correctly

if entry_index >= found {
entry_index - 1
} else {
entry_index
}
Copy link
Member

Choose a reason for hiding this comment

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

If found == 0; entry_index - 1 wraps around

@bluss
Copy link
Member

bluss commented Jan 2, 2018

Ok, to not bother you further, I've copied this branch for later reuse to this repo and I'll close the PR. :-)

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.

2 participants