Commit Graph
96 Commits
Author SHA1 Message Date
Daryle Walker e55e516f11 Add methods that change the heap minimum or maximum element 2021-10-10 20:15:40 -04:00
Daryle Walker c8e24c399c Add heap initializer that takes pre-arranged data 2021-10-10 00:33:54 -04:00
Daryle Walker 35e4873c5c Segregate the heap consistency testing code from the precondition code
AFAIK, the previous code had no tests for itself, so the revised code doesn't either.
2021-10-07 22:47:48 -04:00
Karoy Lorentey 52d426a116 Merge pull request #109 from apple/readme-update
[README] Note that `Heap` hasn't been tagged yet & list other enhancements in progress
2021-09-10 13:13:25 -07:00
Karoy Lorentey c46c77f7f8 Note that Heap hasn't been tagged yet & list other enhancements in progress 2021-09-10 12:59:43 -07:00
Karoy Lorentey 2ce28a9eaa Merge pull request #108 from lorentey/main
Merge `release/1.0` into `main`
2021-09-10 12:46:15 -07:00
Karoy Lorentey 5f255a887e Merge branch 'release/1.0' 2021-09-10 11:58:12 -07:00
Karoy Lorentey 37e15aed66 Merge pull request #107 from lorentey/let’s-table-that
[OrderedSet] Don't let the unchecked init create large sets with no hash table
2021-09-10 11:15:36 -07:00
Karoy Lorentey 1c54f35b45 Merge pull request #105 from lorentey/main
[NFC] Merge release/1.0 to main
2021-09-09 17:03:21 -07:00
Karoy Lorentey f69104b507 [OrderedSet] Don't set a default value for the primary initializer's second argument
This will hopefully prevent issues like the one fixed in the previous commit from reoccurring in the future.
2021-09-09 16:44:06 -07:00
Karoy Lorentey e4f62c1520 [OrderedSet] Don't let the unchecked init create large sets with no hash table
In debug builds, the `OrderedSet.init(uncheckedUniqueElements:)` initializer always created a set with no hash table, even if it had an element count >15. This is technically an invariant violation (caught by `_checkInvariants()`), although it generally only triggers (very) slow performance. (The set reverts to linear searching.)
2021-09-09 16:44:06 -07:00
Karoy Lorentey 95fa069858 Merge pull request #106 from lorentey/check-please
[1.0][OrderedSet] Make _checkInvariants public and call it in more operations
2021-09-09 11:46:12 -07:00
Karoy Lorentey 96100d4b6a [NFC] Cosmetic/doc updates 2021-09-08 21:12:52 -07:00
Karoy Lorentey e959a64528 [OrderedDictionary] Add some more _checkInvariants() calls 2021-09-08 21:12:52 -07:00
Karoy Lorentey 1ae008a410 [OrderedSet] Make _checkInvariants public and call it in more operations
It seems useful to be able to manually call `_checkInvariants` while debugging a package issue. This is public as in `public`, not public as in Public API -- it's underscored.
2021-09-08 21:12:52 -07:00
Karoy Lorentey 4e4bad9c30 Merge pull request #102 from lorentey/release-prep
1.0 release preparations
2021-09-08 11:50:55 -07:00
Karoy Lorentey ead0916a2f [Heap] Disable heap tests in release builds (#100)
These tests rely on @testable imports, which sadly won't work in optimized builds.
2021-09-08 11:47:47 -07:00
Karoy Lorentey 6cd0392237 Merge branch 'release/1.0'
# Conflicts:
#	.swiftpm/xcode/xcshareddata/xcschemes/PriorityQueueModule.xcscheme
#	Package.swift
2021-09-07 14:58:25 -07:00
Karoy Lorentey 8303a77bc2 [Utils] run-full-tests.sh: Add disclaimer about needing to tweak the script sometimes 2021-09-07 14:51:02 -07:00
Karoy Lorentey 227710b76f Update xcodebuild schemes 2021-09-03 19:40:09 -07:00
Karoy Lorentey 4520853f49 Update README for 1.0 2021-09-03 19:11:29 -07:00
Karoy Lorentey 9adbe3e87b [docs] Add a release checklist 2021-09-03 19:11:29 -07:00
Karoy Lorentey 9d4bb8cdf8 [OrderedDictionary] Remove deprecated API
Mark the deprecated `subscript(offset:)` and `modifyValue(...)` APIs unavailable and replace their bodies with fatalError().
2021-09-03 19:11:29 -07:00
Karoy Lorentey 6fbf995006 [Utils] Add run-full-tests.sh script
This script builds and tests the package a tiny fraction of the full support matrix. It's useful for prerelease testing.
2021-09-03 15:58:19 -07:00
Karoy Lorentey f1f48d569a [test] CollectionsTestSupport → _CollectionsTestSupport
The underscored module name makes it clear that this isn't public API.
2021-09-03 15:57:09 -07:00
Karoy Lorentey 01f1104841 Move development .xcworkspace under Utils/
This (undocumented) workspace allows benchmark developers to work on the collection benchmarks and the benchmarking infrastructure within Xcode, with minimal pain. Moving it under Utils/ makes it easier to build the package with the xcodebuild utility; it also makes it (hopefully) clear that the workspace isn't source stable.
2021-09-03 14:20:20 -07:00
ejmarchant 4c22d00065 Follow stdlib's leading underscore rule (#95) 2021-08-30 15:44:27 -07:00
Edward Marchant 751ae1b08b Documentation: Remove in-place mutation comments 2021-08-30 15:44:27 -07:00
ejmarchant 5762a3a50c Follow stdlib's leading underscore rule (#95) 2021-08-30 15:32:50 -07:00
Karoy Lorentey 837a273bef Also freeze Heap types 2021-08-30 15:31:25 -07:00
Karoy Lorentey 0e9e7f13e4 Freeze some types for consistency with their inlinable initializers
Note: @frozen does *not* mean that we actually consider these struct types frozen. Their layout may arbitrarily change between even minor releases.
2021-08-30 15:31:25 -07:00
Karoy Lorentey 56b82b1b7f Freeze some types for consistency with their inlinable initializers
Note: @frozen does *not* mean that we actually consider these struct types frozen. Their layout may arbitrarily change between even minor releases.
2021-08-30 15:31:12 -07:00
Edward Marchant 215ed90386 Documentation: Remove in-place mutation comments 2021-08-30 15:27:14 -07:00
Karoy Lorentey 9d8719c8be [OrderedDictionary] Deprecate subscript(offset:) for now (#92)
* [OrderedDictionary] Deprecate index(forKey:), subscript(offset:) and friends for now

* [OrderedDictionary] Update tests

* Update benchmarks

* Un-deprecate index(forKey:)
0.0.7
2021-08-19 19:26:41 -07:00
Karoy Lorentey 0bf9755eb6 Add Benchmarks package to workspace (#93) 2021-08-19 19:26:41 -07:00
Karoy Lorentey 1e68069c98 [OrderedDictionary] modifyValue → updateValue (#91)
* [OrderedDictionary] modifyValue → updateValue

* Update CMakeLists.txt
2021-08-19 19:26:41 -07:00
Karoy Lorentey 6b86e2cf4a Stop depending on swift-collections-benchmark (#86)
* Stop depending on swift-collections-benchmark

Instead, move the benchmark suite into its own private nested package, under `Benchmarks/`.

The recommended way to build & run benchmarks is via the `Utils/run-benchmarks.sh` script, which continues to work as before with this change.

* Delete top-level Package.resolved file
# Conflicts:
#	.swiftpm/xcode/xcshareddata/xcschemes/swift-collections-benchmark.xcscheme
#	Package.swift
2021-08-19 19:26:41 -07:00
ejmarchant 5ff8c003b0 Fix documentation for types conforming to ExpressibleByArrayLiteral or ExpressibleByDictionaryLiteral (#82)
# Conflicts:
#	Sources/PriorityQueueModule/Heap+ExpressibleByArrayLiteral.swift
2021-08-19 19:26:41 -07:00
ejmarchant 85a207063b Fix typos: missing subscript parameters (#81)
* Fix typos: missing subscript parameters

* Fix typos: more missing subscript parameters

* Improve symbol documentation
2021-08-19 19:26:41 -07:00
Karoy Lorentey 4d695b9ccf [OrderedDictionary] Deprecate subscript(offset:) for now (#92)
* [OrderedDictionary] Deprecate index(forKey:), subscript(offset:) and friends for now

* [OrderedDictionary] Update tests

* Update benchmarks

* Un-deprecate index(forKey:)
2021-08-19 18:56:31 -07:00
Karoy Lorentey 1de0da5579 Add Benchmarks package to workspace (#93) 2021-08-19 18:54:00 -07:00
Karoy Lorentey 53a870dd0b [OrderedDictionary] modifyValue → updateValue (#91)
* [OrderedDictionary] modifyValue → updateValue

* Update CMakeLists.txt
2021-08-19 15:42:17 -07:00
Karoy Lorentey 0d1ca3240c Stop depending on swift-collections-benchmark (#86)
* Stop depending on swift-collections-benchmark

Instead, move the benchmark suite into its own private nested package, under `Benchmarks/`.

The recommended way to build & run benchmarks is via the `Utils/run-benchmarks.sh` script, which continues to work as before with this change.

* Delete top-level Package.resolved file
2021-08-19 11:42:14 -07:00
Saleem Abdulrasool 413ff5596c Update CMakeLists.txt
Update source list of priority queue implementation after #78
2021-08-18 08:37:21 -07:00
Karoy Lorentey 1eea663318 [Heap] Update implementation details section in docs (#84)
- Use a persistent DOI-based link rather than linking to ephemeral course material.
- Replace the example heap (borrowed from Wikipedia) with a better one.
2021-08-17 13:46:10 -07:00
ejmarchant c04384acac Fix typos: missing subscript parameters (#81)
* Fix typos: missing subscript parameters

* Fix typos: more missing subscript parameters

* Improve symbol documentation
2021-08-17 11:54:30 -07:00
Karoy Lorentey cd33954168 [Heap] Performance tweaks (#78)
* [Heap] Don't always inline large functions

* [docs] Use a stable link to the Atkinson article

(The original link was pointing to course materials at a random university.)

* Remove stray import

* Revert "[Heap] Don't always inline large functions"

This reverts commit 07ffd6591f.

* [Heap] Enable code coverage collection in Xcode scheme

* [Heap] Speed up invariant checking

* [Heap] Precalculate levels for each offset

`_Node` is a new struct that consists of a storage offset (the old index) along with its level in the tree. The level can be incrementally calculated, saving some time vs counting bits whenever it's needed.

* [Heap] Switch to using unsafe buffer pointers

Introduce `Heap._UnsafeHandle` (a thin wrapper around an unsafe buffer pointer) and rebase most heap algorithms on top of that instead of array operations.

This simplifies things by reducing (hopefully) unnecessary index validation, resulting in some measurable performance improvements.

* [Heap] Stop force-inlining bubbleUp; mark it releasenone

Not inlining such a large function speeds things up by leaving some headroom for the optimizer to make better inlining decisions elsewhere. (Force inlining this resulted in the compiler not inlining the closure passed to `_update` instead, which isn't a great tradeoff.

To speed things up, mark `bubbleUp` with `@_effects(releasenone)`. This may be questionable (because it calls `Element.<`), but it results in better codegen, making `insert` match the performance of `std::priority_queue`.

* [Heap] Rework removals

* [Heap] Remove dead code

* [Heap] Switch to using _ContiguousArray as storage

* [Heap] insert<S>(contentsOf:): add fast path for count == 0 case

* [Heap] Perf pass on trickleDown code paths

This improves popMin/popMax (and the sequence initializer) by reviewing trickleDown and optimizing things:

- Replace swapAt with a scheme where we keep a hold in the storage buffer
- Slightly shorten min/max dependency chain in primary sink loop

In exchange, we get even less readable code.

* [Heap] bubbleUp: remove @_effects attribute

This reintroduces retain/release operations for the empty array until https://github.com/apple/swift/pull/38898 lands.

Mitigate the performance costs of this by refactoring code to reduce the size of the inlined bubbleUpMin/Max invocations.

* [Heap] Finetune Heap.insert
2021-08-16 22:28:55 -07:00
ejmarchant 69d4867984 Fix documentation for types conforming to ExpressibleByArrayLiteral or ExpressibleByDictionaryLiteral (#82) 2021-08-16 13:37:05 -07:00
Tyler Stromberg 0d73c74c9f Fix Markdown link in README (#77) 2021-08-13 18:31:33 -07:00
Karoy Lorentey f73d5e95a8 Add reference benchmarks for bit vector implementations (#79)
* [benchmark] Reorganize C++/Foundation benchmarks into separate files

* [benchmark] Add reference benchmarks for std::vector<bool> and CFBitVector

* Fix thinko breaking non-Darwin builds
2021-08-13 14:14:26 -07:00