Commit Graph
150 Commits
Author SHA1 Message Date
Karoy Lorentey 45ecd2ebee [BitCollections] Clean up unused test code 2022-08-16 15:55:24 -07:00
Karoy Lorentey da84296b9b [BitSet] Add custom sorted(), returning self 2022-08-16 15:53:06 -07:00
Karoy Lorentey 4cb8ecebee [BitSet] Add new initializers (from words & bit arrays) 2022-08-16 15:44:13 -07:00
Karoy Lorentey 94e2e477db [BitArray] Add truncateOrExtend method
This comes handy to e.g. restore the original count of a bit array
after a BitArray→BitSet→BitArray conversion roundtrip.
2022-08-16 15:43:34 -07:00
Karoy Lorentey cbf933665b [BitSet] Revert to non-generic BitSet
Also, remove members that were generic over FixedWidthInteger.
2022-08-12 19:22:24 -07:00
Karoy Lorentey d8bace07c8 Merge branch 'main' into feature/BitSet
# Conflicts:
#	Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/BitCollections.xcscheme
#	Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/CollectionsTestSupport.xcscheme
#	Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/PriorityQueueModule.xcscheme
2022-08-12 16:38:36 -07:00
Karoy Lorentey f8ac3af99b Merge pull request #156 from apple/fiddle-with-schemes
Reinstate custom schemes under Utils/swift-collections.xcworkspace
2022-08-05 13:47:47 -07:00
Karoy Lorentey 00a99aa77c swift-collections.xcworkspace: Update dependencies 2022-08-03 12:18:57 -07:00
Karoy Lorentey 3fce10a45a Set up shared schemes in the xcworkspace under Utils/ 2022-08-03 12:18:57 -07:00
Karoy Lorentey afac2cf830 Merge pull request #155 from hectormatos2011/patch-1
Remove Swift PM Artifacts to avoid Generated Schemes in Xcode
2022-08-03 12:04:06 -07:00
Hector Matos 7016a13f0e Update .gitignore 2022-08-02 16:46:27 -05:00
Hector Matos 480b0af010 Delete .swiftpm directory 2022-08-02 16:44:59 -05:00
Károly Lőrentey 1d1fbc82d4 [BitSet] Make BitSet generic over its Element
This gets rid of the weird asymmetry between reading the contents of a BitSet (where we used to always get Int values) and mutating it (where we used to be able to give it values fo any fixed-width integer type).
2022-07-30 23:25:53 -07:00
Karoy Lorentey 55f3b58437 [benchmark] Update bit collections module name 2022-06-20 12:55:12 -07:00
Karoy Lorentey c8d81c0a45 Update dependencies in dev workspace 2022-06-20 12:54:53 -07:00
Karoy Lorentey 84e6c006f5 [BitSet][test] withInterestingSets: fix 9% sampling 2022-06-20 12:54:53 -07:00
Karoy Lorentey d890b35cb2 [BitSet] Fix typo in filename 2022-06-20 12:54:53 -07:00
Karoy Lorentey 108ac4fa4e Merge pull request #141 from apple/merge.2021-02-09.release-1.0→main
Merge `release/1.0` to `main`
2022-02-09 14:46:41 -08:00
Karoy Lorentey 29120ea640 Merge branch 'release/1.0' 2022-02-09 11:56:38 -08:00
Karoy Lorentey 20e7fceec8 Merge pull request #140 from apple/fix-OrderedDictionary-grouping-inference
[OrderedDictionary] Fix type inference issue with `OrderedDictionary.init(grouping:by:)`
2022-02-09 11:55:48 -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 565c09e8d5 Review & update BitArray 2022-02-06 22:38:35 -08:00
Károly Lőrentey 8f2e0c79c3 Review & update BitSet
This is a work in progress; in particular, it adds a cached `count` to BitSet, which may turn out to be a bad idea. (It generates extra work for bulk operations even if the count is never needed.) I think replacing this with a cached `startIndex` might be more useful in practice.

The `_UnsafeBitset` type from the OrderedCollections module is brought over as `BitSet._UnsafeHandle`. This implements an (internal-only) fixed-size bitset.

`BitSet` now conforms to `SetAlgebra`. We decided against this in the initial implementation, but on reflection, it seems like the right move. (The somewhat nonsensical `insert` and `update` methods are unfortunate, but consistency is valuable.)
2022-01-10 23:35:33 -08:00
Károly Lőrentey 8463f381fc Set up scheme for BitCollections 2022-01-10 17:12:21 -08:00
Károly Lőrentey b33bd007d6 Remove benchmark results from source root 2022-01-10 17:10:23 -08:00
Károly Lőrentey 537382f2a6 BitArrayModule ⟹ BitCollections 2021-12-28 15:45:38 -08:00
Károly Lőrentey 49a82fe6e1 Merge branch 'main' into feature/BitSet
# Conflicts:
#	.gitignore
#	.swiftpm/xcode/xcshareddata/xcschemes/swift-collections-Package.xcscheme
#	Benchmarks/Package.resolved
#	Benchmarks/benchmark-tool/main.swift
#	Package.swift
#	Sources/CMakeLists.txt
#	Sources/Collections/CMakeLists.txt
#	Sources/Collections/Collections.swift
#	Sources/DequeModule/Deque+Collection.swift
#	Sources/OrderedCollections/CMakeLists.txt
#	Tests/CollectionsTestSupportTests/MinimalTypeConformances.swift
#	cmake/modules/SwiftSupport.cmake
2021-11-22 14:57:40 -08:00
173d2acc24 BitArray and BitSet data structures (#83)
* Create Screen Shot 2021-05-17 at 7.15.09 PM.png

* Delete Screen Shot 2021-05-17 at 7.15.09 PM.png

* Create BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* Added BitArray as a product to the package

* Update Package.swift

* Update Package.swift

* Update Package.swift

* Update BitArray.swift

* Update Package.swift

* Update Collections.swift

* Update Collections.swift

* Update Package.swift

* Create BitArray.xcscheme

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* 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.

* Update BitArray.swift

* Update BitArray.swift

* git: ignore vim swap files (#41)

* Initial conformation to Collection. Lots of faulty code right now

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* Update BitArray.swift

* [Deque] Work around stdlib issue with Array.withContiguousStorageIfAvailable (#44)

Resolves #27.

* [manifest] Ignore CMake files (#47)

The package manager doesn’t like it when it finds unexpected non-source files in source directories.

* [meta] Update dependencies (#48)

(This only affects local development.)

* [Deque][NFC] Remove unused code (#49)

* 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.

* Fixed subscript to have bit manipulations

* Update BitArray.swift

* Update BitArray.swift

* Moved Collection Conformance into appropriate file

* Implements some bit manip

* Fixed issue with endIndex resetting when storage element is full

When an element of the storage array in the BitArray filled, the endIndex would reset to 0, but then would be the correct value at any other time. This was due to a calculation error in endIndex

* Update invalid OrderedDictionary invariant check. (#53)

* Added XCTests, MutableCollection Conformance, Fixed endIndex bug

MutableCollection conformance still has bugs to be fixed
Additionally, the code is still very rough
endIndex had an issue where it was 0 when the array was empty. Fixed this by switching the code for count and endIndex, and making endIndex = 1 when count is 0

* Update BitArrayTests.swift

* Fixed subscript bug

Wouldn't work sometimes when current value was true because the return for `storage[index] & mask` could be anything >= 1, and not == 1, hence resulting in a unwanted toggle of the value. Fixed by comparing a boolean value of the current value to the boolean value of the newValue instead of the integers

* Code clean up ish

* Fixing a small typo on quick help documentation. (#55)

* Modifying Existing Code From Feedback

- `endIndex` corrected
- changed `remaining` in `count` to use ternary operator instead of being a computed local variable
- added `_split` as a helper function to `subscript`
- modified `set{...}` portion of `subscript` and included comments of the different options
- removed `clear()` as `removeAll()` seems to already exist somewhere
- modified unit tests to have a new BitArray for every test instead of a shared one
- Improved `testSubscriptSetOnly()` to hopefully be more thorough

* Added Bitwise Operations (No Tests)

Both mutable and immutable OR, AND, XOR operations

* Mark OrderedSetDiffingTests with availability (#54)

* Added Rough Bitwise Operation UnitTests

* Added BitSet Files

Did not add methods as I know a lot will go in BitStorage, which Im still figuring out

* Beginning implementations for BitSet

* Mutating Bitwise Operations

Performance-UNfriendly starter implementations

* Fixed subscript set mask for the &= operation and changed fatalErrors to preconditions

changed mask on &= operation from 0 to ~mask

* Also corrected subscript set test to fail if mask of 0 was used (instead of ~mask)

* Implemented BitSet with BitArray storage type and some tests

Tests are not yet passing. Pushing early so mentor can see progress
So sorry for waiting to push so late!

* Fixed error in first BitSet test ( which is testAppend() ) so it passes!

* BitSet formUnion initial implementation

* formUnion() test added and implementation modified to pass test

formUnion() is still incomplete and needs more tests atm

* Finished formUnion() for BitSet

* Modified formUnion() to use bit shifts instead

* Initial formIntersection function for BitSet

Untested

* Added an array view for BitSet, fixed BitSet.count bug, added and modified tests

* Initial Cartesian Product implementation and unfinished test

* Update BitArrayConformances.swift

* [CMake] swift-collections → SwiftCollections (#60)

* [CMake] swift-collections → SwiftCollections

This is an integration FIXME for SwiftPM: https://github.com/apple/swift-package-manager/pull/3595#issuecomment-875201764

* [CMake] Generate exports under cmake/modules/SwiftCollectionsConfig.cmake

* 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

* [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.

* Attempting to make an Index

* First steps in implementing Index struct for BitSet

* Fixed up endIndex

* Last tweaks of tonight

Tomorrow: fix up Index implementations, SetAlgebra, Unit Testing

* Adding index function preconditions

* Altered index(_ index: Index, offsetBy distance: Int) -> Index

* Update BitSetConformances.swift

* Update BitSetBitwiseOperations.swift

* Time for SetAlgebra!

* Transitioning to using CollectionsTestSupport

* Conformance to Set Algebra (without bringing in bitarray methods)

* Overloaded Bitwise Operators on BitArray

* Tilday (bitwiseNOT operations)

* Fixed coding style - 2 space indents

* Initial implementation od initializers

Bug found

* Fixed count bug

* Completed and XCTested BitArray initializers

By"XCTested" I mean using my own XCTests without the thorough CollectionsTestSupport

* Update BitArray.swift

* BitSet Initializers -- XCTested

By "XCTested" I mean not thoroughly tested with the CollectionsTestSupport methods

* BitSet's "custom" SetAlgebra

* contains(Int) and dropExcessFalses() methods for BitSet

* Consistently use UNIT.bitWidth instead of the number 8

This will be useful for benchmarking purposes

* Modified BitArray.swift according to feedback

Also added more typealias consistencies (using `UNIT.max` instead of hardcoded 255)

* Modified BitArray bitwise operations according to feedback

Added overloaded mutating operators

* Modified BitArrayConformances.swift according to feedback

* Modified BitArrayOperations.swift according to feedbacl

* Adjust Bitwise Operations' naming to be consistent with that of the atomics package

* .

* Modified According to Feedback

* testing

* First working test using CollectionsTestSupport

Testing sequence initializer

* All initializer tests for BitArray (except using BitSet)

* Update BitArrayTests.swift

* BitArray Append test

* Improved BitArray append() test to test multiple appends

* Untested remove functions

Also updated any UInt8 usages to use the UNIT typealias instead

* BitArray removeLast() Test

* Update BitArrayTests.swift

* BitArray removeAll() test

* BitArray removeLast(_ rangeSize: Int) function test and bug fix

* BitArray removet(at: Int) tests

Also added test for discardable results for current and existing remove tests

* BitArray removeFirst(_ rangeSize: Int) test implemented and passing

Current method has terrible run time for now as I can't get the optimized version to work yet

* BitArray first and last true index functions TEST and BUG FIX

firstTrueIndex()
lastTrueIndex()

* Failing OR and AND bitwise operations test on BitArray

* Update BitArrayTests.swift

* Update BitArrayTests.swift

* Update BitArrayTests.swift

* PUSHHHHH

* removeFirst(_ rangeSize: Int) optimization/bugFix

* BitArray bitwise operations tests and bug fixes

* BitSet tests, bug fixes, and name changes

sequence init test and bug fix
change "UNIT" to "WORD"

* Update BitArrayTests.swift

* add BitSet layout to test support

* BitSet testExpressibleByArrayLiteralAndArrayLiteralInit()

* testExpressibleByArrayLiteralAndArrayLiteralInit()

* BitSet insert and contains functions test + bug fixes

* forceInsert test for BitSet

* BitSet remove function test and improvements

* Update BitSetSetAlgebra.swift

* BitSet intersection tests and bug fixes

* BitSet symmetricDifference test and bug fix

* starting index test and found interesting bug...

* BitArray init(BitSet) test

* Update BitSetTests.swift

* patch

* bug fix in BitSet index after

* BitSet index before test

* Clean up unneeded code

* Delete BitArrayBenchmarks.swift

* My added, not-working benchmark

* BitSet init from BitArray benchmark

* BiSet insert benchmark

* BitSet forceInsert benchmark

* Passing BitSet index offset by test

I plan to add more to the test to test offsets from indices in the middle and not just start and end

* BitArray testing modification to accommodate varying WORD sizes

* Minor comment clean-up

* Correcting bitset tests for varying WORD sizes

* Headers with License info

* simple set operation comparison

incomplete

* .

* adjustments

* Update BitSetOperations.swift

* Benchmarks and preconditions

* Update BitArrayOperations.swift

* Update BitSetTests.swift

* quick edits

* .

* Documentation for bitwise operations and some initializers

* Testing `==` operator to ensure bug fix

* BitSet SetAlgebra and Operations Documentation

* Update BitSetOperations.swift

Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
Co-authored-by: 3405691582 <dsk@google.com>
Co-authored-by: Vihan <vihan_bhargava@apple.com>
Co-authored-by: Rodrigo Kreutz <8869678+rkreutz@users.noreply.github.com>
Co-authored-by: Andrew Monshizadeh <1282845+amonshiz@users.noreply.github.com>
2021-11-22 14:43:26 -08:00
Karoy Lorentey 22dc81b89f Merge pull request #130 from lorentey/main
Merge release/1.0 to main
2021-11-15 17:22:35 -08:00
Karoy Lorentey 286fedb1e8 Merge branch 'release/1.0' 2021-11-15 17:01:49 -08:00
Karoy Lorentey 48254824bb Merge pull request #113 from lorentey/deque-scaling
[Deque] `append(contentsOf:):` Use exponential capacity reservation
1.0.2
2021-11-15 16:15:59 -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
Karoy Lorentey 1337897dc6 Merge pull request #128 from lorentey/full-test-improvements
[Utils] run-full-tests.sh: Add support for testing on Swift 5.3 without manual editing
2021-11-15 16:05:40 -08:00
Karoy Lorentey 9dde4b5603 [Utils] run-full-tests.sh: Add support for testing on Swift 5.3 without manual editing 2021-11-15 15:46:12 -08:00
Karoy Lorentey da3a73ed90 Merge pull request #126 from lorentey/full-test-improvements
[Utils] run-full-tests.sh: Keep going after a failure
2021-11-15 14:50:57 -08:00
Károly Lőrentey ddc8b9c66d [Utils] run-full-tests.sh: Keep going after a failure 2021-11-15 14:08:09 -08:00
Karoy Lorentey c86bf6adf0 Merge pull request #123 from lorentey/fix-OrderedSet
[OrderedSet] Add missing uniqueness check
2021-11-12 17:09:27 -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 6eeae8088b Merge pull request #121 from jPaolantonio/jp/readme-link-fix
Fix link to package internal documentation
2021-10-27 18:00:41 -07:00
Karoy Lorentey 1904ebb97d Merge pull request #122 from compnerd/patch-1 2021-10-25 13:36:34 -07:00
Karoy Lorentey 776410b72d Merge pull request #115 from just-gull/heap-tests-release
[Heap] Enable heap tests in optimized builds (#101)
2021-10-22 17:04:38 -07: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
James Paolantonio 276ddee5df Fix link to package internal documentation 2021-10-22 15:47:11 -04: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
Sergey PetrenkoandKaroy Lorentey 8b3af12ece @_spi attributes are removed because they weren't necessary
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2021-10-12 13:08:38 +03:00
Karoy Lorentey fc876e18c1 Merge pull request #118 from compnerd/no-foundations
PriorityQueueModule: remove `import Foundation`
2021-10-11 15:03:48 -07:00
Karoy Lorentey f41f2cae69 [Heap] Update docs 2021-10-11 14:54:59 -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