Commit Graph
61 Commits
Author SHA1 Message Date
Karoy Lorentey 5c8d97dccb Merge pull request #660 from apple/dn/ordered-set-move
[OrderedCollections] Add move operations
2026-06-05 17:45:16 -07:00
David Nadoba 72f074a23a [OrderedCollections] Use pre-removal destination index for move APIs 2026-06-05 17:05:03 -07:00
David Nadoba 5a6af29d55 [OrderedCollections] Refine move APIs and simplify no-op check 2026-06-05 14:44:22 -07:00
David Nadoba a83773321e [OrderedCollections] Rework move APIs and extend to OrderedDictionary
Reworks the relocation API and extends it to `OrderedDictionary`:

* Renames the index-range move to `moveSubrange(_:to:)` (with a
  `RangeExpression` overload) and the by-value move to `move(contentsOf:to:)`,
  matching the conventions of `removeSubrange`/`insert(_:at:)`. Adds
  `move(fromIndices:to:)`, which takes the source indices directly.
* Factors the element rearrangement into generic
  `UnsafeMutableBufferPointer` operations (rotation / rotation+permutation /
  scatter) so `OrderedDictionary` relocates its keys and values in lockstep
  through the same code, adding only the parallel value move; the hash-table
  maintenance stays entirely in `OrderedSet`.
* The hot path runs in O(*d* + *k*) and falls back to O(`count`) for large
  moves; bucket maintenance chooses targeted updates or a full rebuild by the
  same threshold.
* `move(contentsOf:to:)` ignores elements/keys that aren't present; duplicate
  members are detected and trap.

Adds tests (exhaustive hash-table integrity, value alignment under lifetime
tracking) and move benchmarks for both types.
2026-06-04 22:33:54 -07:00
inju2403 8c5830ee46 [OrderedCollections] OrderedDictionary.replaceElement: allow the new key to equal the key at index
Per review feedback, relax the precondition so that the new key may compare equal to the key currently stored at index. This enables replacing an existing key with an equal-but-not-identical instance — for example, swapping a decomposed Unicode string with its precomposed equivalent — without an inefficient remove/insert workaround.

When the new key matches the one being replaced, the pair is updated in place via OrderedSet.update(_:at:) and the hash table is left untouched, preserving the expected amortized O(1) complexity.

Add a test_replaceElement_sameKey test on both OrderedDictionary and its Elements view that exercises the new path with LifetimeTracked keys carrying equal payloads but distinct instances.
2026-04-23 21:38:11 +09:00
inju2403 9426246879 [OrderedCollections] Add OrderedDictionary.replaceElement(at:withKey:value:) 2026-04-03 16:55:14 +09:00
Karoy Lorentey 80878519f2 [doc] Fix most issues reported by docc
DocC keeps changing its link syntax. The latest iteration appears to have trouble dealing with `Self`-taking or `Self`-returning methods, so change our API to replace `Self` with a direct mention of the concrete type. ¯\\\_(ツ)\_/¯

That said, the new compiler also found a large number of mismatching parameter names, and that was really helpful.
2026-03-09 14:14:51 -07:00
Karoy Lorentey 1c69635852 Add SPDX-License-Identifier tags 2026-03-05 19:39:24 -08:00
Karoy Lorentey d9b09ecde8 Update copyright dates 2026-03-05 19:39:20 -08:00
Nate Cook 54ca53612f Include notes about index mutation in span(after/before:)
The indexes passed to span(after:) and friends on UniqueArray
and RigidArray are modified before return. This adds notes
about the updated values to the method documentation, along
with a few other minor formatting changes (dropping smart
quotes, single-sentence abstracts).
2026-03-02 16:38:48 -08:00
Karoy Lorentey ecafd9e947 Merge pull request #578 from ordo-one/isempty 2026-02-24 19:15:00 -08:00
Diana Ma b52dcf61e8 give constant folding an opportunity to select a much faster code path 2026-02-23 04:15:07 +00:00
Karoy Lorentey 9503f8fe57 Improve consistency of precondition failure messages
More uniform message strings should feel better, and they should ever so slightly reduce code size.
2026-02-04 10:27:17 -08:00
Tony Parker c883a1729a Add support for embedded Swift mode
Remove calls to `debugPrint` (which does not exist), and ifdef out support for `Codable` and `Reflection`.
2025-07-17 16:36:56 -07:00
김봉균 4450b7c622 fix typo 2025-01-07 11:26:40 +09:00
Karoy Lorentey 35d5746117 Rename _CollectionsUtilities to InternalCollectionsUtilities
We are forced to do this due to an Xcode issue (#364) with underscored module names.

This module remains unstable, despite the removal of the underscore. Directly importing it from outside the package remains unsupported. This module and/or its entire contents may go away or change in incompatible ways in any future swift-collections release.
2024-05-29 14:00:13 -07:00
Karoy Lorentey 64b286d63d [OrderedCollections] Update copyright notices 2024-02-02 16:20:21 -08:00
Karoy Lorentey f59aeeb56a [OrderedCollections] Adopt modern generic declaration syntax and _specialize 2024-02-02 16:20:21 -08:00
Karoy Lorentey 1a0ac8c06c Merge branch 'release/1.0' into release/1.1
# Conflicts:
#	Sources/DequeModule/CMakeLists.txt
#	Sources/DequeModule/Deque+Collection.swift
#	Sources/DequeModule/Deque+Sendable.swift
#	Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Elements.SubSequence.swift
#	Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Elements.swift
#	Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Sendable.swift
#	Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Sequence.swift
#	Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Values.swift
#	Sources/OrderedCollections/OrderedSet/OrderedSet+Sendable.swift
#	Sources/OrderedCollections/OrderedSet/OrderedSet+SubSequence.swift
#	Sources/OrderedCollections/OrderedSet/OrderedSet+UnorderedView.swift
#	Sources/OrderedCollections/OrderedSet/OrderedSet+UnstableInternals.swift
2023-12-21 15:17:15 -08:00
Karoy Lorentey 03d60bed63 Merge pull request #343 from lorentey/sendable-1.0
[1.0] Backport Sendable conformances on all public types
2023-12-18 18:43:30 -05:00
Karoy Lorentey 8bfcaddd5f [1.0] Update copyright dates 2023-12-18 15:35:56 -08:00
Karoy Lorentey 7d43c07a71 Backport Sendable conformances on all public types
Resolves #317
2023-12-18 15:25:38 -08:00
Karoy Lorentey 40e737cdaf [OrderedDictionary] Fix usage of deprecated API in index(forKey:) docs
Resolves #289.
2023-12-18 15:00:55 -08:00
Rick van Voorden e42fb868b7 forward ordered dictionary values equality to values property 2023-12-08 17:39:25 -08:00
Karoy Lorentey 09c09f0f73 Fix CustomStringConvertible/CustomDebugStringConvertible conformances
- For CustomStringConvertible, `description` should print elements using `String(reflecting:)` rather than `String(describing:)`, to avoid element output from interfering with syntactically relevant punctuation within structured list displays.
- To make this work without making displays overly verbose, make `debugDescription` mostly the same as `description`, except for escaping raw string displays when and if needed.
- Avoid printing type names in `debugDescription` — it is generally not helpful, as the type is already easily accessible elsewhere. Including it makes for overly verbose displays when the type serves as an Element of a collection.
- Avoid having `debugDescription` return the empty string — it can be confusing when such a description appears in list displays.

Resolves #301.
2023-07-06 17:25:11 -07:00
Karoy Lorentey 3e4a8b4dff Merge branch 'release/1.0' into release/1.1
# Conflicts:
#	.gitignore
#	Package.swift
#	Sources/Collections/Collections.docc/Collections.md
#	Sources/Collections/Collections.docc/Extensions/Deque.md
#	Sources/Collections/Collections.docc/Extensions/OrderedSet.UnorderedView.md
#	Sources/Collections/Collections.docc/Extensions/OrderedSet.md
#	Sources/DequeModule/DequeModule.docc/DequeModule.md
#	Sources/DequeModule/DequeModule.docc/Extensions/Deque.md
#	Sources/OrderedCollections/HashTable/_HashTable+UnsafeHandle.swift
#	Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.UnorderedView.md
#	Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.md
#	Sources/OrderedCollections/OrderedCollections.docc/OrderedCollections.md
#	Sources/OrderedCollections/OrderedDictionary/OrderedDictionary.swift
#	Sources/OrderedCollections/OrderedSet/OrderedSet.swift
#	Sources/OrderedCollections/Utilities/_UnsafeBitset.swift
#	Utils/generate-docs.sh
2023-04-24 13:45:55 -07:00
Karoy Lorentey a8dad62bc9 Remove obsolete swift(>=5.5)/swift(>=5.6) checks 2023-04-10 18:33:52 -07:00
Ryan McLeod 7f63914a71 [OrderedDictionary] Explicitly mention in documentation that keys/values are ordered
(cherry picked from commit fef3839500)
2023-04-10 17:36:49 -07:00
Karoy Lorentey cbab9e3737 Introduce COLLECTIONS_SINGLE_MODULE condition 2023-03-21 18:42:33 -07:00
Karoy Lorentey a874de5f7f [OrderedCollections] Refresh some docs with DocC links 2022-12-06 19:00:59 -08:00
Karoy Lorentey aaeeb9e440 [OrderedCollections] Doc updates 2022-10-28 12:34:14 -07:00
Karoy Lorentey de22bed429 [OrderedCollections] Update top-level docs 2022-10-28 12:34:14 -07:00
Karoy Lorentey 7143421800 [OrderedCollections] Add missing Custom[Debug]StringConvertable conformances, review existing ones
Add `Custom[Debug]StringConvertible` conformance on:

- `OrderedDictionary.Values`
- `OrderedDictionary.Elements.Subsequence`
- `OrderedSet.SubSequence`
2022-10-20 17:14:52 -07:00
Karoy Lorentey 381cf5d17e Merge branch 'release/1.0' into release/1.1 2022-10-19 15:50:34 -07:00
Karoy Lorentey f76630db8e [Internals] Add missing internal checking predicates & docs for all 2022-10-18 22:13:19 -07:00
Karoy Lorentey 51604cd196 [OrderedCollections] Oops, restore custom wording for areInIncreasingOrder variants 2022-10-12 15:11:57 -07:00
Karoy Lorentey a624614717 [OrderedCollections] Document that sort is stable (as of SE-0372) 2022-10-11 13:38:10 -07:00
Karoy Lorentey 17b6c8f5c7 [OrderedDictionary] OrderedDictionary, .Iterator, .Values, .Elements, .Elements.SubSequence, .Elements.SubSequence.Iterator: Explicitly conform to Sendable when Element is Sendable 2022-10-05 11:44:06 -07:00
Karoy Lorentey de31437ee5 Merge branch 'feature/PersistentCollections' into release/1.1 2022-09-19 16:02:51 -07:00
Karoy Lorentey 9f38e7424b [OrderedDictionary] Doc fix 2022-09-16 16:07:33 -07:00
Karoy Lorentey c9ca59fbb9 [PersistentCollections] Improved storage representation
- Switch to using `ManagedBuffer` to represent node storage. This has
  useful performance benefits, but it significantly complicates access
  to node data. We no longer have direct access to the underlying raw
  storage: everything needs to go through closures passed to
  `ManagedBuffer.withUnsafeMutablePointers`.

- Introduce `struct _Node` and `struct _Node.UnsafeHandle` to
  represent a (strong) reference to a hash tree node, and a
  convenient handle for node storage, respectively. Use these instead
  of directly accessing the ManagedBuffer object, whenever feasible.

- Implement separate paths for in-place mutations vs copy-on-write
  operation, optimizing both flavors.

- Go to great lengths to eliminate unnecessary retain-release traffic,
  whenever possible.

- Push subtree counts into parent nodes by moving the corresponding
  field from the node header into the `_Node` struct. (This results in
  a cool ~20x speedup for jumping around in the tree by integer
  offsets.)

- Implement a type-punned empty root singleton, to allow creating
  empty trees without allocating anything.
2022-09-13 23:48:54 -07:00
Karoy Lorentey 77edbef16d [_CollectionsUtilities] Restore original debug descriptions 2022-09-13 23:45:22 -07:00
Karoy Lorentey dd76591970 [_CollectionsUtilities] New module. Use it to unify description/debugDescription implementations 2022-09-12 12:47:04 -07:00
Karoy Lorentey a9e2276472 Merge pull request #168 from lorentey/cherry-pick-1.0.3
Cherry pick recent fixes to release/1.0 in preparation of tagging 1.0.3
2022-09-01 17:21:25 -07:00
Karoy Lorentey 71aa4a39ae [OrderedDictionary] Resolve spurious(?) call-site ambiguities 2022-08-31 17:57:24 -07:00
Karoy Lorentey b379fa7aee [OrderedCollections] Force-inline all _modify accessors
(cherry picked from commit ee1b2de06e)
2022-08-31 17:13:53 -07:00
Karoy Lorentey 6cb037037d [OrderedDictionary][doc] Update docs for merge/filter operations
Resolves #145
2022-05-23 16:17:35 -07: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 e959a64528 [OrderedDictionary] Add some more _checkInvariants() calls 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