Commit Graph
167 Commits
Author SHA1 Message Date
Karoy Lorentey 638c62cd7b Merge pull request #674 from wjdtjq6/fix/superset-doc-comments
Fix superset set algebra doc comments
2026-07-07 15:08:52 -07:00
wjdtjq6 646274ed7c docs: fix superset set algebra comments 2026-06-23 13:21:36 +09:00
inju2403 86ddbd9705 [OrderedCollections] OrderedSet.reverse(): update the hash table in place
Reversing an ordered set is a deterministic permutation: the element at offset `i` moves to offset `count - 1 - i`. Hash values are unaffected, so every element stays in its current bucket and only the stored offset needs to be flipped. `reverse()` was instead regenerating the whole hash table from scratch, rehashing every element -- exactly what the existing `// FIXME: Update hash table contents in place.` called out.

Replace `_regenerateHashTable()` with an in-place offset flip (`v -> count - 1 - v`) over the table's buckets, reusing the same bucket-walk idiom as `adjustContents` and `swapBucketValues`. This drops all hash recomputation and the table reallocation.
2026-06-12 08:57:42 +09:00
Karoy Lorentey e31c04143e Update CMake & Xcode build configurations 2026-06-05 18:45:56 -07:00
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
David Nadoba 508f36f48d [OrderedSet] Add move(_:toOffset:)
Adds two overloads for relocating elements within an `OrderedSet`: one
taking a contiguous `Range<Int>`, and one taking a `Sequence<Element>`.
The moved elements occupy consecutive positions starting at the
destination, in the order they appear in the input.

The hot path runs in O(*d* + *k*) time, where *d* is the distance moved
and *k* is the number of elements moved; the implementation falls back
to O(`count`) for large moves.
2026-05-25 23:01:28 -07:00
Karoy Lorentey 215a9ac0a7 Merge pull request #632 from lorentey/assorted-fixes
[BasicContainers, DequeModule]: Assorted fixes
2026-04-30 15:53:21 -07:00
Karoy Lorentey 0fa494d3a8 [OrderedCollections] Minor fixes in _HashTable.UnsafeHandle 2026-04-30 15:29:25 -07:00
Karoy Lorentey 6017342a4d Merge pull request #616 from inju2403/feature/ordered-dictionary-replace-element-at-index
[OrderedCollections] Add OrderedDictionary.replaceElement(at:withKey:…
2026-04-27 18:05:52 -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
Manan 396577ca27 OrderedSet: Don't crash on negative capacity values
Fixes https://github.com/apple/swift-collections/issues/608, and starts behaving similar to Set()
2026-04-16 10:10:02 +05:30
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 ee9808c72f [Dequemodule, OrderedCollections] Avoid using floating point arithmetic 2026-03-06 18:19:16 -08: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
Karoy Lorentey ebaef60379 [OrderedCollections] Fix doc typo 2026-02-03 13:22:00 -08:00
Karoy Lorentey 5f03d1bc24 Adopt availability macros 2025-08-17 13:23:01 -07: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
Alex Azarov 9f68408a70 Update OrderedSet.swift
Make values immutable if they are never mutated in example usage docs.
2025-06-30 11:35:45 +02:00
Alex Azarov d7301b7278 Fix OrderedSet example usage 2025-06-29 16:48:57 +02:00
Karoy Lorentey 4216d2ad1b Merge pull request #478 from ozumin/patch-1
fix comment for OrderedSet.appending(contentsOf:)
2025-05-21 09:24:42 -07:00
Karoy Lorentey 0f73f0ace7 Merge branch 'release/1.2'
# Conflicts:
#	.github/workflows/pull_request.yml
#	.swiftci/5_10_ubuntu2204
#	.swiftci/5_7_ubuntu2204
#	.swiftci/5_8_ubuntu2204
#	.swiftci/5_9_ubuntu2204
#	.swiftci/nightly_6_0_macos
#	.swiftci/nightly_6_0_ubuntu2204
#	.swiftci/nightly_main_macos
#	.swiftci/nightly_main_ubuntu2204
2025-05-20 11:13:32 -07:00
Mizuo Nagayama 1812091001 fix comment for OrderedSet.appending(contentsOf:) 2025-05-20 18:38:06 +09:00
Peter Meyers 3fb4855e0e [OrderedSet] Add OrderedSet.appending(contentsOf:) 2025-05-16 00:16:00 -07:00
Peter Meyers e00243217e [OrderedSet] Add OrderedSet.appending(contentsOf:) 2025-02-20 15:34:04 -05:00
김봉균 1cb3ca50a6 fix typo 2025-02-06 17:54:37 -08:00
김봉균 4450b7c622 fix typo 2025-01-07 11:26:40 +09:00
Karoy Lorentey 2709b96947 Minor code style updates 2024-11-18 13:59:31 -08:00
David Nadoba 13245da5f5 Optimize unspecialized OrderedSet.init and OrderedSet.firstIndex(of:) 2024-11-18 13:59:23 -08:00
Karoy Lorentey 5dd817c33d Merge branch 'release/1.1' 2024-08-05 20:10:26 -07:00
Jeremy Schonfeld 3e120b48bb [CMake] Reduce path lengths in single-module build (#392)
* Eliminate relative paths from the cmake single-module build

* Attempt to reduce length of paths in single module build
2024-06-26 08:39:11 -07:00
Karoy Lorentey ad79ce5b6a Merge branch 'release/1.1'
# Conflicts:
#	.swiftci/5_10_ubuntu2204
#	.swiftci/5_7_ubuntu2204
#	.swiftci/5_8_ubuntu2204
#	.swiftci/5_9_ubuntu2204
#	.swiftci/nightly_6_0_macos
#	.swiftci/nightly_6_0_ubuntu2204
#	.swiftci/nightly_main_macos
#	.swiftci/nightly_main_ubuntu2204
2024-06-05 10:28:47 -07:00
Jeremy Schonfeld ee97538f5b Add Single Module Build Mode to CMake for Foundation (#385)
* Add new single-module and foundation-toolchain-module modes to CMake build

* Fix allowable client flag syntax
2024-06-03 16:15:50 -07: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
Charles Hu 89b3ca0146 Fix the incorrect file name in OrderedCollections cmake file
- Currently OrderedCollections cmake incorrectly list "Utilities/_UnsafeBitSet.swift" instead of "Utilities/_UnsafeBitset.swift", causing build failures
2024-05-21 19:24:08 -07:00
Karoy Lorentey e004cd36fa Merge branch 'release/1.1' into merge.1.1→main
# Conflicts:
#	CMakeLists.txt
#	README.md
2024-02-07 17:35:40 -08:00
Dimitris Apostolou 7539583245 Fix typos
# Conflicts:
#	Sources/SortedCollections/BTree/_BTree+BidirectionalCollection.swift
#	Sources/SortedCollections/BTree/_BTree+UnsafeCursor.swift
#	Sources/SortedCollections/BTree/_BTree.Builder.swift
#	Sources/SortedCollections/BTree/_BTree.swift
#	Sources/SortedCollections/BTree/_Node.Splinter.swift
#	Sources/SortedCollections/BTree/_Node.Storage.swift
#	Sources/SortedCollections/BTree/_Node.UnsafeHandle+Insertion.swift
#	Sources/SortedCollections/BTree/_Node.swift
#	Tests/SortedCollectionsTests/BTree/Node+Join Tests.swift
2024-02-06 15:52:26 -08:00
Dimitris Apostolou ab744afc39 Fix typos 2024-02-04 20:35:42 +02: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 cdcf9e606a Update CMake configuration 2023-12-19 17:45:02 -08:00