42 Commits
Author SHA1 Message Date
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
Karoy Lorentey 7f57a0ed1c [OrderedSet][doc] Fix thinko 2021-09-14 11:50:31 -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
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
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 3426dba9ee [test] checkCollection: Don’t pass decreasing indices to distance(from:to:) (#63)
Also, try running the conformance checkers on the minimal collection types to catch similar issues.
2021-07-08 18:48:48 -07:00
Karoy Lorentey fa45de1018 Work around another MergeModules crash (#62)
* [utils] Add utility for shuffling sources to help reproduce MergeModules issues

* [Deque] Collapse Sequence/Collection conformances into a single file

The MergeModules phase in the compiler is broken: it isn’t always able to correctly handle circular dependencies across source files, like the ones that keep organically popping up with Sequence/Collection conformances that are defined in separate files.

Such dependencies sometimes triggers a compiler crash, depending on some (unknown) environmental parameters.

Trying to manually find and eliminate these circular dependencies has not proved productive. Instead, roll all Collection conformances into a single, huge source file.

* [Deque] Update CMakeLists
2021-07-08 17:02:00 -07:00
Rodrigo Kreutz c0549b6284 Fixing a small typo on quick help documentation. (#55) 2021-06-12 12:06:19 -07:00
Vihan 2aeaac76ae Update invalid OrderedDictionary invariant check. (#53) 2021-06-10 10:54:34 -07:00
3405691582 57bbf14270 Changes to support OpenBSD. (#52)
* [cmake] Support amd64 architecture name.

On OpenBSD, "x86_64" is called "amd64", and therefore recognition of this
name is required for the cmake build.

* [cmake] Add missing file.

This is required since, for example, `Deque+Extras` requires
`_withContiguousStorageIfAvailable_SR14663`.

* ManagedBuffer.capacity is unavailable on OpenBSD.

ManagedBuffer requires nonstandard API to implement `capacity` and
subsequently is unavailable on OpenBSD. For portability, just use
`minimumCapacity` on this platform.
2021-06-01 13:15:07 -07:00
Karoy Lorentey d45e63421d [Deque][NFC] Remove unused code (#49) 2021-05-27 20:08:42 -07:00
Karoy Lorentey de5f1e6061 [Deque] Work around stdlib issue with Array.withContiguousStorageIfAvailable (#44)
Resolves #27.
2021-05-27 18:59:45 -07:00
Saleem Abdulrasool 689c485dfe build: add a CMake based build system (#42)
Add a CMake based build system to enable bootstrapping the toolchain
with the ability to use Swift Collections in SPM.
2021-05-21 19:54:59 -07:00
François Lamboley f6d8f82627 Replace Index with Int where possible (#32) 2021-05-10 16:36:10 -07:00
Karoy Lorentey 65a38419d0 [OrderedDictionary] Document encoding format (#26)
Unlike the regular unordered `Dictionary`, `OrderedDictionary` always encodes/decodes itself as alternating key/value pairs in an unkeyed container. Document this fact (and the reason behind it) in the `Decodable` implementation.
2021-04-16 15:59:00 -07:00
Abin Tom 14299b8d79 Fix CollectionTestCase calling super setup on tearDown (#23)
Fixes issue https://github.com/apple/swift-collections/issues/17
2021-04-13 19:32:10 -07:00
Kiel Gillard 0096c5b39d Add the @discardableResult attribute to OrderedSet.insert(_:at:) (#21)
* Add the @discardableResult attribute to OrderedSet.insert(_:at:). Fixes #19

* Add the @discardableResult attribute to OrderedSet.updateOrAppend(_).

* Add the @discardableResult attribute to OrderedSet.updateOrInsert(_:at:).
2021-04-13 19:03:56 -07:00
Karoy Lorentey 2d719d75a2 Fix nondeterministic compiler crash in debug builds (#18)
So as it turns out, the Swift compiler’s MergeModules phase (which SwiftPM uses in Debug builds) has a known issue with dependency cycles between separate source files — it rarely triggers, but when it does, swiftc hits an assertion complaining about a deserialization failure.

The v0.0.1 of Swift Collections happens to include such a cycle, but it only triggers the assertion on a small fraction of machines. I don’t yet know what exactly makes it nondeterministic, but it is reproducible by randomly reshuffling the source filenames of the OrderedSet implementation — a couple dozen randomizations will eventually lead to a state where it happens in every build.

The workaround is to put OrderedSet’s Sequence and RandomAccessCollection conformances in the same file. (OrderedSet uses the standard IndexingIterator, which requires a Collection conformance, while Collection itself refines Sequence — I believe this is the dependency cycle that is causing all this problem.)

Unfortunately, until we figure out what triggers the nondeterminism (or until the MergeModules action is replaced with something that actually, you know, works, this issue may keep randomly reoccurring. None of this makes much sense, but here we are. 😝
2021-04-10 00:17:50 -07:00
Karoy Lorentey 9492a283e7 Merge pull request #6 from numist/numist/ordered-set-diffing
Efficient diffing for OrderedSet
2021-04-08 23:10:10 -07:00
Karoy Lorentey 5a2a6841fd Update OrderedSet+ReserveCapacity.swift 2021-04-08 15:40:08 -07:00
Franklin Byaruhanga b68a025e23 Minor Fix in documentation for function OrderedDictionary.updateValue
Signed-off-by: Franklin Byaruhanga <byaruhaf@appbantu.com>
2021-04-06 16:46:04 -07:00
Scott Perry 956ea437df Update complexity in headerdoc to match implementation (and simplify per big-O rules) 2021-04-06 09:49:06 -07:00
Scott PerryandKaroy Lorentey 9ffceb3878 Use elements to manifest an Array from an OrderedSet
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2021-04-06 07:44:35 -07:00
Scott Perry 7b37f7892b Add benchmarks and clean up headerdoc 2021-04-05 20:57:32 -07:00
Scott Perry 7401c23c18 Basic implementation of OrderedSet.applying() balancing performance with code complexity 2021-04-05 19:19:28 -07:00
Scott Perry c71b73954e Match style 2021-04-05 19:07:03 -07:00
Scott Perry ed375766aa Initial implementation of diffing (and tests!) for OrderedSet 2021-04-05 18:35:23 -07:00
Karoy Lorentey 68609682e0 Remove Uniqued<Base>
This type was one of the prototypes for `OrderedSet` — it allowed us to customize the collection type used for element storage. (E.g., using `Deque` instead of `Array` to get efficient insertions at the front.) The original idea was that `OrderedSet` would simply be a typealias:

```swift
typealias OrderedSet<Element> = Uniqued<Array<Element>>
```

Unfortunately, while this concept is intellectually pleasing, in practice it just made the interface more complicated (and, in some cases, slower). Worse, it cannot be directly translated to an `OrderedDictionary`-style key-value mapping without major usability problems.

# Conflicts:
#	Package.swift
2021-04-05 09:41:00 -07:00
Karoy Lorentey a2bcac435f Initial import.
Introduce OrderedCollections module
2021-04-05 09:41:00 -07:00