Commit Graph
75 Commits
Author SHA1 Message Date
Michael Steindorfer b34c8dad97 [Capsule] Implement Equatable protocol 2022-08-09 17:20:28 +02:00
Michael Steindorfer 8e2ec3c49b [Capsule] Make copyAndSetNode generic 2022-08-09 17:20:28 +02:00
Michael Steindorfer d4ecaa0f75 [Capsule] Make spine of trie monomorphic 2022-08-09 17:20:28 +02:00
Michael Steindorfer e09c8db428 [Capsule] Implement preliminary hash-collision resolution 2022-08-09 17:20:28 +02:00
Michael Steindorfer b518d56b65 [Capsule] Implement Hashable extension for HashMap 2022-08-09 17:20:28 +02:00
Michael Steindorfer ce5a6bd71a [Capsule] Update copyright headers
Correctly reflects refining edits as well and not only initial draft date.
2022-08-09 17:20:28 +02:00
Michael Steindorfer b3e1e9d446 [Capsule] Harmonize identation 2022-08-09 17:20:28 +02:00
Michael Steindorfer 1598e22e45 [Capsule] Split nested structs and classes into separate files 2022-08-09 17:20:28 +02:00
Michael Steindorfer 88051725bb [Capsule] Rename Common.swift -> _Common.swift 2022-08-09 17:20:28 +02:00
Michael Steindorfer 3cb6fb3251 [Capsule] Split HashMap extensions into separate files 2022-08-09 17:20:28 +02:00
Michael Steindorfer 097e6b75b7 [Capsule] Update copyright headers 2022-08-09 17:20:28 +02:00
Michael Steindorfer 03913fd745 [Capsule] Increase visibility of count and subscript to public 2022-08-09 17:20:28 +02:00
Michael Steindorfer 488322edff [Capsule] Import sources 2022-08-09 17:20:28 +02:00
Karoy Lorentey 29120ea640 Merge branch 'release/1.0' 2022-02-09 11:56:38 -08:00
Karoy Lorentey 50e6a1ac71 [OrderedDictionary] Fix type inference issue with OrderedDictionary.init(grouping:by:)
This adds a new overload to help the type checker infer `[S.Element]` as the default `Value` type.

Resolves #139.
2022-02-08 14:16:18 -08:00
Karoy Lorentey 286fedb1e8 Merge branch 'release/1.0' 2021-11-15 17:01:49 -08:00
Károly Lőrentey efefae5653 [Deque] append(contentsOf:): Use exponential capacity reservation
Depending on the supplied sequence, `Deque.append(contentsOf:)` currently reserves just enough capacity as it needs to perform the append. This isn't right -- it can result in O(n) reallocs instead of O(log(n)) when items are incrementally appended in constant-sized `append(contents:)` batches.
2021-11-15 16:12:28 -08:00
Károly Lőrentey 074b0ad213 [OrderedSet] Add missing uniqueness check in OrderedSet._insertNew(_:at:in:) 2021-11-11 00:40:01 -08:00
Károly Lőrentey 13b5889757 [OrderedCollections][test] Strengthen withHiddenCopies tests
`withHiddenCopies(if:of:)` is supposed to check for value semantic violations where mutations of one copy affect another -- however, it currently only checks that iteration returns the same items before/after the change, not that the old copy is still in a fully consistent state.

Add an extra parameter that can be set to a closure that performs stricter checks.

Use it to call `_checkInvariants()` in ordered collections tests, uncovering a missing uniqueness check in `OrderedSet._insertNew(_:at:in:)`.
2021-11-11 00:39:29 -08:00
Saleem Abdulrasool 1c1e6206fa Update CMakeLists.txt
Remove `Heap+OrderedViews.swift` from the source list after #119.
2021-10-22 15:08:52 -07:00
Karoy Lorentey aba079126e Merge pull request #119 from lorentey/remove-heap-views
[Heap] Remove Heap's `ascending` and `descending` views
2021-10-20 11:56:00 -07:00
Karoy Lorentey 30e6eb1116 [Heap] Remove Heap's ascending and descending views
These two do *very* non-trivial processing, so they don't at all work like views in the Standard Library.

They also don't carry their weight -- they are simply lightweight wrappers around `popMin` and `popMax`, respectively.

Let's get rid of them before we etch them in stone as public API.
2021-10-11 14:50:08 -07:00
Saleem Abdulrasool 95be379a3a PriorityQueueModule: remove import Foundation
This removes an accidental dependency on Foundation.
2021-10-11 13:04:22 -07:00
Karoy Lorentey 7f57a0ed1c [OrderedSet][doc] Fix thinko 2021-09-14 11:50:31 -07:00
Karoy Lorentey 5f255a887e Merge branch 'release/1.0' 2021-09-10 11:58:12 -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 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 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 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
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:)
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
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 53a870dd0b [OrderedDictionary] modifyValue → updateValue (#91)
* [OrderedDictionary] modifyValue → updateValue

* Update CMakeLists.txt
2021-08-19 15:42:17 -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