d_ary_addressable_int_heap: Add push_without_update, make clear linear in size #34
Open
michitux wants to merge 2 commits into
Open
d_ary_addressable_int_heap: Add push_without_update, make clear linear in size #34michitux wants to merge 2 commits into
michitux wants to merge 2 commits into
Conversation
This allows adding elements without building the heap. This allows adding elements individually while still retaining linear time for building the heap.
Previously, the performance of clear() was linear in the maximum key. When re-using a heap data structure several times whose items have much larger keys than the size of the heap, this made clear() more expensive than necessary.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This makes the clear method linear in the size of the heap and adds a new method for adding elements without updating the heap. The use case is that I want to re-use a single heap several times as the keys are significantly larger than the size of the heap. Between the uses, I clear the heap and this should be linear in the number of remaining elements. I recognize that a simple linear fill is faster than random writes. Therefore, this only uses the random writes if we do not touch all cache lines with the random writes even if every write is on a separate cache line. I have not compared the performance and I'm also open to other suggestions. For adding new elements after the clear, I added the
push_without_updatemethod. It is very similar to thebuild_heapmethods, just that it allows adding elements one-by-one and one has to callupdate_all(orclear) at the end. I have kept the update of the handles even though it is not strictly necessary as this ensures thatcontainscan be used in betweenpush_without_updatecalls. I have not added apush_without_updatemethod that moves the key as the documentation states thatkey_type"has to be an unsigned integer type" and I cannot imagine that moving unsigned integers has any advantage over a pass by value or pass by reference.