-
Notifications
You must be signed in to change notification settings - Fork 285
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 a min-max heap implementation that can be used to back a priority queue #61
Conversation
OK, |
@kylemacomber How do you want to handle this? The code was already mostly reviewed in the other PR; should @timvermeulen take another look? Also, do we want to merge this into |
@lorentey is the final boss 😉 |
@lorentey Any update on when you might be able to look at this? 🙏 |
I'm on it! It's slow going, but I'll submit the review soon! (Things are looking good.) |
Quick update on our plans: I'd like to release version 1.0 of this package relatively soon with the existing three types (to signal that we're committing to source stability), then quickly follow it up with version 1.1 that includes this work as well as anything else that's ready. However, we don't need to wait on the 1.0 tag to merge new work to |
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 think this is ready to land, with a small handful of nits that would be useful to resolve before merging.
I also noted several larger FIXMEs/experiments that we should eventually get around to implementing, but they need not be done before merging this PR.
@property (nonatomic, readonly) NSUInteger count; | ||
|
||
- (void)insert:(NSInteger)value; | ||
- (NSInteger)popMinimum; |
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.
FIXME: I wonder if objc_msg_send
introduces measurable overhead in the benchmarks -- it's fast, but I don't expect it fares well when compared to a direct function call, and these microbenchmarks are tiny enough that even minute overheads have an effect. It would be interesting to compare results to a variant where these are all C functions.
(This doesn't need to be resolved before this lands.)
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.
Yeah. I started writing a C++ benchmark for comparison but haven't been able to finish that yet. I'd be happy for any assistance improving the comparative benchmarks here from anyone; I'm quickly approaching the limits of my understanding of perf.
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 can have a go at it relatively soon.
internal func _minMaxHeapIsMinLevel(_ index: Int) -> Bool { | ||
precondition(index >= 0) | ||
|
||
return (index + 1)._binaryLogarithm() & 0b1 == 0 |
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.
FIXME: IIRC this has a cost of a ~multiplication operation; it may be better to explicitly keep track of the depth of an Index, by switching to a custom struct rather than just a naked Int value.
This would also make the parent/left/right child operations more elegant:
struct _Index: Comparable {
let offset: Int
let level: Int
func parent() -> _Index?
func grandParent() -> Index?
func leftChild() -> _Index
func rightChild() -> _Index
}
Given that this is not going to be exposed as public, it may make sense to use UInts to (trivially) speed up operations like the division by two in parent()
.
This doesn't need to be addressed before landing this.
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.
Issue filed as #71
@inline(__always) | ||
@inlinable | ||
internal mutating func _swapAt(_ i: Int, _ j: Int) { | ||
let tmp = storage[i] |
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.
Nit: why not just call _storage.swapAt(_:_:)
here?
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.
It was determined in the original PR that doing it this way was more performant.
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.
Wow, that's terrible. This is another FIXME for later -- there is no reason Array.swapAt
needs to be any slower than doing this.
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.
Issue filed as #72 (in addition to the existing Swift issue https://bugs.swift.org/browse/SR-14778 -- thanks very much for filing that!)
XCTAssertEqual(90, heap.max()) | ||
} | ||
|
||
func test_popMin() { |
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.
FIXME: Combinatorial tests would work great on these!
This doesn't need to be addressed before this lands.
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.
Issue filed as #73
|
||
import Swift | ||
|
||
/// A [Min-Max Heap](https://en.wikipedia.org/wiki/Min-max_heap) data structure. |
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.
This is useful information to have in an "Implementation Details" section, but it doesn't tell the reader what a heap is and why they would want to use it. We should add an introduction that is useful for a wider audience.
Something like this would be a good start:
A collection of comparable items arranged in a way that allows efficient access to its minimal and maximal elements.
Heaps can be used to efficiently provide sorted access to items that arrive incrementally and out of order. For example, a server application may use a heap to store its queue of incoming client transactions, processing them in order of decreasing priority.
Heaps provide highly optimized implementations for the following operations:
insert(_:)
: Inserts a new element in O(log(count
)) time.min()
/max()
: Retrieve (but does not remove) the minimum/maximum item in O(1) time.removeMin()
/removeMax()
: Remove and return the minimum/maximum item in O(log(count
)) time.<Some toy sample code illustrating these operations>
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.
Issue filed as #74
b0d3c9a
to
97782e3
Compare
OK, updated things. I think the only things left from the "need to fix before merging this" bucket are the documentation changes. |
The doc updates we can also do as followup work. Let's land this! 🚀 Do you need me to help resolve the conflicts? |
Sounds good!
I can do it. |
storage.swapAt exhibits excessive allocations
Co-authored-by: Dante Broggi <34220985+Dante-Broggi@users.noreply.github.com>
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
Adapted from Daryle Walker's (github.com/CTMacUser) suggestions
Heap+Iterator.swift was renamed to Heap+OrderedViews.swift Co-authored-by: Karoy Lorentey <klorentey@apple.com>
Merge conflicts have been resolved. We should be good to go! 🚀 Do you want me to create GitHub issues for the follow-up changes? |
@swift-ci test |
Oh, that's a good idea -- let me do that though; it seems unfair to ask you to file issues for my loosely explained FIXMEs. 🙈 |
Ah, this makes sense -- I think we'll need to add (Which is super annoying, as it makes the benchmark library json platform dependent. Argh -- this is another FIXME for later.) |
OK, I filed issues for all my FIXMEs: https://github.com/apple/swift-collections/issues?q=is%3Aissue+is%3Aopen+label%3AHeap As usual with these, some of them are suggestions for optimizations that may turn out to be unnecessary or even harmful. The benchmarks will be the judge. 😝 |
@swift-ci test |
…v1.1.0 (#906) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [com_github_apple_swift_collections](https://togithub.com/apple/swift-collections) | http_archive | minor | `1.0.6` -> `1.1.0` | --- ### Release Notes <details> <summary>apple/swift-collections (com_github_apple_swift_collections)</summary> ### [`v1.1.0`](https://togithub.com/apple/swift-collections/releases/tag/1.1.0): Swift Collections 1.1.0 [Compare Source](https://togithub.com/apple/swift-collections/compare/1.0.6...1.1.0) This feature release adds a number of new data structure implementations, along with minor changes to existing constructs. ##### New Data Structures - `Heap` implements a min-max heap, backed by a native array. (Contributed by [@​AquaGeek](https://togithub.com/AquaGeek)) - `BitSet` and `BitArray` are two alternate representations of a bitmap type, backed by dynamically allocated storage. (Contributed by [@​MahanazAtiqullah](https://togithub.com/MahanazAtiqullah)) - `TreeSet` and `TreeDictionary` are hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). They provide similar API as `Set`/`Dictionary` in the Standard Library, but as persistent data structures, supporting incremental mutations of shared instances and efficient structural diffing. (Contributed by [@​msteindorfer](https://togithub.com/msteindorfer)) ##### Other Changes - This version of the package can only be built using Swift 5.7 or later. - New methods: the `OrderedSet.isEqualSet` family of functions provide a way to test that two containers contain the same members, ignoring the order of elements. ([apple/swift-collections#183, [apple/swift-collections#234) - New method: `OrderedSet.filter` implements a version of the standard filter operation that returns an `OrderedSet` instead of an `Array`. ([apple/swift-collections#159) - `debugDescription` implementations have been updated to follow Swift best practice. (These are called by container types like `Array` to print their elements, so they work best when they're succinct variants of `description` that are suitable for embedding in structured output: specifically, they must not produce unpaired delimiter characters (`[`/`]`, `(`/`)`, `{`/`}`, `<`/`>` etc), raw top level commas, semicolons, colons, unquoted strings etc. `debugDescription` should not needlessly print type names etc.) ##### New Contributors - [@​AquaGeek](https://togithub.com/AquaGeek) made their first contribution in [apple/swift-collections#61 - [@​ejmarchant](https://togithub.com/ejmarchant) made their first contribution in [apple/swift-collections#82 - [@​just-gull](https://togithub.com/just-gull) made their first contribution in [apple/swift-collections#115 - [@​jPaolantonio](https://togithub.com/jPaolantonio) made their first contribution in [apple/swift-collections#121 - [@​MahanazAtiqullah](https://togithub.com/MahanazAtiqullah) made their first contribution in [apple/swift-collections#83 - [@​hectormatos2011](https://togithub.com/hectormatos2011) made their first contribution in [apple/swift-collections#155 - [@​ktoso](https://togithub.com/ktoso) made their first contribution in [apple/swift-collections#159 - [@​CTMacUser](https://togithub.com/CTMacUser) made their first contribution in [apple/swift-collections#116 - [@​hassila](https://togithub.com/hassila) made their first contribution in [apple/swift-collections#297 Many thanks to our contributors for their great work (and patience)! ##### List of Pull Requests **Full Changelog**: apple/swift-collections@1.0.6...1.1.0 - Add a min-max heap implementation that can be used to back a priority queue by [@​AquaGeek](https://togithub.com/AquaGeek) in [apple/swift-collections#61 - \[benchmark] Review and extend Heap benchmarks by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#76 - Add reference benchmarks for bit vector implementations by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#79 - Fix Markdown link in README by [@​AquaGeek](https://togithub.com/AquaGeek) in [apple/swift-collections#77 - Fix documentation for types conforming to ExpressibleByArrayLiteral o… by [@​ejmarchant](https://togithub.com/ejmarchant) in [apple/swift-collections#82 - \[Heap] Performance tweaks by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#78 - Fix typos: missing subscript parameters by [@​ejmarchant](https://togithub.com/ejmarchant) in [apple/swift-collections#81 - \[Heap] Update implementation details section in docs by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#84 - Update CMakeLists.txt by [@​compnerd](https://togithub.com/compnerd) in [apple/swift-collections#85 - Stop depending on swift-collections-benchmark by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#86 - \[OrderedDictionary] modifyValue → updateValue by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#91 - Add Benchmarks package to workspace by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#93 - \[OrderedDictionary] Deprecate `subscript(offset:)` for now by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#92 - Documentation: Remove in-place mutation comments by [@​ejmarchant](https://togithub.com/ejmarchant) in [apple/swift-collections#96 - \[main] Freeze some types for consistency with their inlinable initializers by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#98 - Follow stdlib's leading underscore rule by [@​ejmarchant](https://togithub.com/ejmarchant) in [apple/swift-collections#95 - \[Heap] Disable heap tests in release builds by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#100 - \[NFC] Merge release/1.0 to main by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#105 - Merge `release/1.0` into `main` by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#108 - \[README] Note that `Heap` hasn't been tagged yet & list other enhancements in progress by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#109 - PriorityQueueModule: remove `import Foundation` by [@​compnerd](https://togithub.com/compnerd) in [apple/swift-collections#118 - \[Heap] Remove Heap's `ascending` and `descending` views by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#119 - \[Heap] Enable heap tests in optimized builds ([#​101](https://togithub.com/apple/swift-collections/issues/101)) by [@​just-gull](https://togithub.com/just-gull) in [apple/swift-collections#115 - Update CMakeLists.txt by [@​compnerd](https://togithub.com/compnerd) in [apple/swift-collections#122 - Fix link to package internal documentation by [@​jPaolantonio](https://togithub.com/jPaolantonio) in [apple/swift-collections#121 - Merge release/1.0 to main by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#130 - BitArray and BitSet data structures by [@​MahanazAtiqullah](https://togithub.com/MahanazAtiqullah) in [apple/swift-collections#83 - Sorted collections by [@​vihanb](https://togithub.com/vihanb) in [apple/swift-collections#65 - Merge `release/1.0` to `main` by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#141 - Remove Swift PM Artifacts to avoid Generated Schemes in Xcode by [@​hectormatos2011](https://togithub.com/hectormatos2011) in [apple/swift-collections#155 - Reinstate custom schemes under Utils/swift-collections.xcworkspace by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#156 - \+OrderedSet add filter [#​158](https://togithub.com/apple/swift-collections/issues/158) by [@​ktoso](https://togithub.com/ktoso) in [apple/swift-collections#159 - \[Xcode] Update schemes & file template by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#161 - \[OrderedCollection] Use standard temp allocation facility, if available by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#160 - \[OrderedSet] Work around weird name lookup issue in compiler by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#162 - \=OrderedSet.filter Attempt to optimize filter impl by [@​ktoso](https://togithub.com/ktoso) in [apple/swift-collections#163 - Force-inline \_modify accessors to work around a performance issue by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#165 - Merge release/1.0 branch to main by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#172 - Incubate persistent data structures by [@​msteindorfer](https://togithub.com/msteindorfer) in [apple/swift-collections#31 - Persistent collections updates by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#174 - Persistent collections updates by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#175 - Persistent collections updates (part 3) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#176 - Persistent collections updates (part 4) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#177 - \[OrderedDictionary] Tiny documentation fix by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#178 - Persistent collections updates (part 5) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#179 - Integrate PriorityQueueModule, BitCollections, PersistentCollections, SortedCollections into release/1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#181 - Persistent collections updates (part 6) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#180 - Persistent collections updates (part 7) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#182 - \[BitSet] Fix decoding format on 32 bit architectures by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#185 - Persistent collections updates (part 8) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#184 - Persistent collections updates (part 9) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#188 - Add Sendable conformances to all public types by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#191 - \[test] Check baseline API expectations for set-like types by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#192 - Fleshing out `PersistentSet` by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#193 - Rename `PriorityQueueModule` to `HeapModule` by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#194 - \[BitSet] Fix invariant violation in member subscript by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#195 - \[1.1.0] Bump minimum required Swift toolchain to 5.5 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#196 - Restore support for building with Swift 5.5 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#198 - Merge release/1.0 to release/1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#199 - Update CMake configuration in preparation for 1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#200 - Update CMakeLists.txt by [@​compnerd](https://togithub.com/compnerd) in [apple/swift-collections#202 - \[1.1]\[SortedCollections] Remove for now by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#205 - \[Heap] Change value of minimum or maximum element by [@​CTMacUser](https://togithub.com/CTMacUser) in [apple/swift-collections#116 - \[Heap] Prerelease preparations by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#210 - Update README files by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#212 - \[manifest] Exclude CMakeLists.txt; remove unnecessary path settings; reindent file by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#213 - Review and finalize (?) set relation predicates for 1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#216 - Merge.1.0→1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#217 - Update CMake configuration by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#218 - Cherry pick changes from main to release/1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#219 - Fix unusual build problems by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#221 - Review & update descriptions throughout the package by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#222 - Review and finalize (?) binary set operations for 1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#223 - \[Xcode] Disable implicit dependencies by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#227 - \[OrderedSet] Improve sequence-taking initializer by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#226 - \[OrderedSet, BitSet] Fix custom mirror display style by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#225 - Finalize persistent collections API by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#224 - Start working on DocC support by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#228 - Update CMake build configuration by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#230 - \[PersistentSet] Iterator.next(): Make inlinable by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#233 - \[SetAlgebra types] isEqual(to:) → isEqualSet(to:) by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#234 - \[PersistentCollections] Doc & benchmark updates in preparation of API review by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#235 - Apply changes from in-progress review thread by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#237 - \[ShareableHashedCollections] API Review: add missing `mutating` keywords by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#238 - \[Benchmarks] Split default huge library up into individual files, one per type by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#240 - \[ShareableHashedCollections] Add missing import by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#243 - Unify unsafe bit set implementations by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#244 - Fix warnings in development versions of Swift by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#245 - \[HashTreeCollections] Change prefix `Shareable` to `Tree` by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#242 - \[TreeDictionary] Fix in-place merge operation to properly update the count by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#247 - \[cmake] Update CMake configuration by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#249 - Add not so experimental rope implementation by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#264 - Fix off by one error in BitSet by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#267 - Monomodule support by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#266 - Expose a handful of BigString.Index methods by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#269 - BitArray API refinements & additions by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#263 - Make most of Rope inlinable by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#270 - BigString: Fix String.Index.\_knownScalarAligned by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#272 - Rope: Fix `Sendable` conformance by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#271 - Require Swift 5.6 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#273 - \[OrderedDictionary] Explicitly mention in documentation that keys/values are ordered by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#275 - \[HashCollections] Ensure `self` doesn’t get destroyed before we’re done working with it by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#276 - Remove obsolete swift(>=5.5)/swift(>=5.6) checks by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#277 - \[Xcode] Update Xcode project by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#278 - Minor rope updates by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#279 - \[Rope] remove(at:): Fix assertion when removing the last item creates a deficiency by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#280 - Merge changes from release 1.0 to release 1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#283 - \[CollectionUtilities] Silence a warning on 32 bit platforms by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#286 - \[BitSet] Fix a thinko in BitSet.isEqualSet by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#287 - Grab bag of fixes for small test issues by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#288 - \[Xcode] Set a code sign identity in the Xcode project by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#285 - Rope: Fix trap when replaceSubrange is called on an empty rope by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#290 - `Rope.find` returns a bogus remainder for the end position by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#291 - Update TreeSet.md by [@​hassila](https://togithub.com/hassila) in [apple/swift-collections#297 - Fix CustomStringConvertible/CustomDebugStringConvertible conformances by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#302 - \[RopeModule] Fix issues in Swift's ABI stable dialect by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#318 - \[CMake, Xcode] Update configurations for alternate build systems by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#319 - \[RopeModule] Remove unnecessary typealiases by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#320 - \[Heap] Improve type-level doc comment by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#326 - \[Heap] insert(contentsOf:) Switch to Floyd’s if we’re inserting too many items by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#327 - \[1.1] build: support building in Debug mode on Windows by [@​compnerd](https://togithub.com/compnerd) in [apple/swift-collections#336 - Merge release/1.0 to release/1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#348 - \[Heap] Convert min() and max() to properties by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#328 - \[BitArray] Disable bitwise operators for now by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#353 - \[Heap] Final(?) Heap API adjustments for 1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#354 - \[Benchmarks] Add Collection Equality Benchmarks by [@​vanvoorden](https://togithub.com/vanvoorden) in [apple/swift-collections#351 - Release preparations for 1.1 by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#355 - \[1.1] Fix typos by [@​lorentey](https://togithub.com/lorentey) in [apple/swift-collections#357 - \[TreeDictionary]\[Keys] Add Equatable and Hashable Conformance to TreeDictionary.Keys by [@​vanvoorden](https://togithub.com/vanvoorden) in [apple/swift-collections#352 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
Description
This is an extraction of the heap implementation hammered out in #51.
Detailed Design
One of the big advantages of using a min-max heap is that we don't need to bifurcate into a min heap or max heap and keep track of which kind is used — you can pop min or max, as needed. This makes it very useful as the backing storage for a double-ended priority queue.
Future Directions
replaceMin
andreplaceMax
(@timvermeulen has a branch of this already)Heap
#51)Documentation
The public APIs have largely been documented. An overview document has been added to the Documentation directory that is adapted from the API review and code comments.
Testing
There are unit tests for the added
Heap
type.Performance
Performance tests have been added (including comparable tests against a
CFBinaryHeap
). We may want to revisit the library JSON to ensure we have the desired comparisons defined. (Can somebody with a better understanding of how all of that works/is structured take a look? Maybe @lorentey?)Source Impact
This is purely additive. No existing APIs were changed, deprecated, or removed.
Checklist