Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add not so experimental rope implementation #264

Merged
merged 60 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
150a165
Add experimental rope implementation
lorentey Feb 1, 2023
eabd941
Add some operations taking subsequences
lorentey Feb 1, 2023
18aa309
Generalize some _BString iterators
lorentey Feb 4, 2023
96aebb9
Fix initializing a String from a _BString slice
lorentey Feb 4, 2023
283d407
Assorted bug fixes and refinements
lorentey Feb 9, 2023
8c8cb56
Restrict BIgString and _BString to Swift 5.8 and macOS 13.3 /iOS 16.…
lorentey Feb 9, 2023
67a149d
_BString: Set better max node size in Release builds
lorentey Feb 13, 2023
8c1740a
_Rope.Index: Merge height into UInt64 storage.
lorentey Feb 13, 2023
8f48c3a
More assorted bug fixes and refinements
lorentey Feb 16, 2023
3cc5a38
_Rope: Add a leaf node reference to indices. Implement explicit index…
lorentey Feb 20, 2023
b6f9d83
Replace Rope iterator with indices in most index-like use cases
lorentey Feb 21, 2023
575937f
Remove _Rope._leaf(at:)
lorentey Feb 21, 2023
79bdcb6
Implement path caching in indices
lorentey Feb 22, 2023
9bbdfdc
Cosmetic updates to _BString.CharacterIterator
lorentey Feb 22, 2023
605e45b
_BString: Additional fixes and new functionality
lorentey Feb 28, 2023
fe54fda
More fixes.
lorentey Feb 28, 2023
85a43d9
_BString: Add a substring types and actual collection views
lorentey Mar 3, 2023
4f2024c
_BString: Elaborate on the swift 5.8 dependency a bit
lorentey Mar 3, 2023
7444bb2
_CharacterRecognizer don’t use conformances that aren’t in the Xcode …
lorentey Mar 6, 2023
b5e3bee
_BString.Index: Add alignment bits
lorentey Mar 7, 2023
28727f7
_BString: Implement views
lorentey Mar 7, 2023
e0f8305
_BString.hashUTF8(into:from:end:): Fix typo
lorentey Mar 8, 2023
eda72e3
_BString: Fix character index rounding; use it when accessing charact…
lorentey Mar 9, 2023
a10439b
_BString, _BSubstring: Merge character views into top-level types. Ad…
lorentey Mar 11, 2023
59b5c63
_Rope.UnsafeHandle._removeChild(at:): Fix buffer overflow uncovered b…
lorentey Mar 11, 2023
1182398
_BString: Give each view a custom iterator by hooking up the existing…
lorentey Mar 11, 2023
abf5dfd
_BSubstring: Conform to Comparable
lorentey Mar 11, 2023
258d229
_BString: Review Equatable implementations
lorentey Mar 11, 2023
03d7c43
_BString: Add index rounding methods to all views
lorentey Mar 11, 2023
05f8f9b
_BString: Modernize tests
lorentey Mar 11, 2023
6a7f53c
_BString: Add conversion initializers from all views
lorentey Mar 11, 2023
cffcd51
BigString: Start modernizing
lorentey Mar 11, 2023
2211329
_BString: Adjust substring mutation test to actually exercise Unicode…
lorentey Mar 11, 2023
033bf17
_BString: Add UTF-8 and UTF-16 index rounding tests
lorentey Mar 13, 2023
d79a752
_BString: Review views & add missing functionality/shortcuts
lorentey Mar 14, 2023
b8927d8
BigString: Flesh out views, make them consistent with _BString
lorentey Mar 14, 2023
b355480
_BString: Make unicodeScalars properties mutable
lorentey Mar 14, 2023
64a8098
_BSubstring.UnicodeScalarView: Fix range-replacing mutations that don…
lorentey Mar 14, 2023
b50fb5a
_BString.resolve: Don’t crash when resolving indices in the empty string
lorentey Mar 14, 2023
da78365
_BString: Add isIdentical(to:) to all string views
lorentey Mar 16, 2023
4849d54
Add a compile-time conditional for enabling randomized testing, enabl…
lorentey Mar 16, 2023
ddcd178
Unconditionally enable use of _CharacterRecognizer’s Equatable confor…
lorentey Mar 16, 2023
535b8b8
Fix compatbility with Swift toolchains below 5.8
lorentey Mar 20, 2023
975a890
Disable modules that haven’t gone through API review yet
lorentey Mar 20, 2023
79f1e16
Don’t skip building/testing BitCollections and HeapModule
lorentey Mar 20, 2023
09577a3
RopeModule→_RopeModule. Stop reexporting it from Collections.
lorentey Mar 20, 2023
73de433
Restore workaround for SR-14663
lorentey Mar 20, 2023
b022b7f
Make _BString and _Rope public
lorentey Mar 21, 2023
44cff40
Work around SPM limitations around test case availability 💗
lorentey Mar 21, 2023
24e58e8
Don’t override `XCTestCase.invokeTest` on non-Darwin systems
lorentey Mar 21, 2023
706be4d
Also, don’t forget to call super.setUp
lorentey Mar 21, 2023
0ad7f0c
_BString → BigString
lorentey Mar 21, 2023
51ef861
Underscore more internals
lorentey Mar 21, 2023
6f3f19d
_Rope → Rope
lorentey Mar 21, 2023
88286b6
BigString: Fix Issue in utf16.distance when endpoint is on the traili…
lorentey Mar 21, 2023
dc23b4d
Rope: Fix splitting logic after insertions
lorentey Mar 21, 2023
ad82bc3
Naming review
lorentey Mar 21, 2023
28010b2
Use COLLECTIONS_INTERNAL_CHECKS
lorentey Mar 21, 2023
8394ea7
Clean up test definitions
lorentey Mar 21, 2023
fcd6800
BigString: Slightly speed up a slow test
lorentey Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
250 changes: 147 additions & 103 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -17,7 +17,7 @@ import PackageDescription
// from the package manager command line:
//
// swift build -Xswiftc -DCOLLECTIONS_INTERNAL_CHECKS
var settings: [SwiftSetting] = [
var defines: [String] = [

// Enables internal consistency checks at the end of initializers and
// mutating operations. This can have very significant overhead, so enabling
Expand All @@ -26,7 +26,7 @@ var settings: [SwiftSetting] = [
// This is mostly useful while debugging an issue with the implementation of
// the hash table itself. This setting should never be enabled in production
// code.
// .define("COLLECTIONS_INTERNAL_CHECKS"),
// "COLLECTIONS_INTERNAL_CHECKS",

// Hashing collections provided by this package usually seed their hash
// function with the address of the memory location of their storage,
Expand All @@ -40,109 +40,153 @@ var settings: [SwiftSetting] = [
// This is mostly useful while debugging an issue with the implementation of
// the hash table itself. This setting should never be enabled in production
// code.
// .define("COLLECTIONS_DETERMINISTIC_HASHING"),
// "COLLECTIONS_DETERMINISTIC_HASHING",

// Enables randomized testing of some data structure implementations.
"COLLECTIONS_RANDOMIZED_TESTING",

// Enable modules that aren't source stable yet, and aren't ready for general use.
// "COLLECTIONS_ENABLE_UNSTABLE_MODULES",
]

var _modules: [String] = []
var _products: [Product] = []
var _targets: [Target] = []
var _settings: [SwiftSetting] = defines.map { .define($0) }

func registerTargets(_ targets: [Target]) {
_targets.append(contentsOf: targets)
}
func registerTargets(_ targets: Target...) { registerTargets(targets) }

func registerLibrary(_ module: String, _ targets: [Target]) {
_modules.append(module)
_products.append(.library(name: module, targets: [module]))
registerTargets(targets)
}
func registerLibrary(_ module: String, _ targets: Target...) {
registerLibrary(module, targets)
}

func registerUnstableLibrary(_ module: String, _ targets: Target...) {
if defines.contains("COLLECTIONS_ENABLE_UNSTABLE_MODULES") {
registerLibrary(module, targets)
}
}

registerTargets(
.target(
name: "_CollectionsTestSupport",
dependencies: ["_CollectionsUtilities"],
swiftSettings: _settings,
linkerSettings: [
.linkedFramework(
"XCTest",
.when(platforms: [.macOS, .iOS, .watchOS, .tvOS])),
]
),
.testTarget(
name: "CollectionsTestSupportTests",
dependencies: ["_CollectionsTestSupport"],
swiftSettings: _settings),

.target(
name: "_CollectionsUtilities",
exclude: ["CMakeLists.txt"],
swiftSettings: _settings)
)

registerLibrary(
"BitCollections",
.target(
name: "BitCollections",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: _settings),
.testTarget(
name: "BitCollectionsTests",
dependencies: [
"BitCollections", "_CollectionsTestSupport", "OrderedCollections"
],
swiftSettings: _settings)
)

registerLibrary(
"DequeModule",
.target(
name: "DequeModule",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: _settings),
.testTarget(
name: "DequeTests",
dependencies: ["DequeModule", "_CollectionsTestSupport"],
swiftSettings: _settings)
)

registerLibrary(
"HashTreeCollections",
.target(
name: "HashTreeCollections",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: _settings),
.testTarget(
name: "HashTreeCollectionsTests",
dependencies: ["HashTreeCollections", "_CollectionsTestSupport"],
swiftSettings: _settings)
)

registerLibrary(
"HeapModule",
.target(
name: "HeapModule",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: _settings),
.testTarget(
name: "HeapTests",
dependencies: ["HeapModule", "_CollectionsTestSupport"],
swiftSettings: _settings)
)

registerLibrary(
"OrderedCollections",
.target(
name: "OrderedCollections",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: _settings),
.testTarget(
name: "OrderedCollectionsTests",
dependencies: ["OrderedCollections", "_CollectionsTestSupport"],
swiftSettings: _settings)
)

registerLibrary(
"_RopeModule",
.target(
name: "_RopeModule",
dependencies: ["_CollectionsUtilities"],
path: "Sources/RopeModule",
swiftSettings: _settings),
.testTarget(
name: "RopeModuleTests",
dependencies: ["_RopeModule", "_CollectionsTestSupport"],
swiftSettings: _settings)
)

registerLibrary(
"Collections",
.target(
name: "Collections",
dependencies: _modules.map { .target(name: $0) },
exclude: ["CMakeLists.txt"],
swiftSettings: _settings)
)

let package = Package(
name: "swift-collections",
products: [
.library(name: "Collections", targets: ["Collections"]),
.library(name: "BitCollections", targets: ["BitCollections"]),
.library(name: "DequeModule", targets: ["DequeModule"]),
.library(name: "HeapModule", targets: ["HeapModule"]),
.library(name: "OrderedCollections", targets: ["OrderedCollections"]),
.library(name: "HashTreeCollections", targets: ["HashTreeCollections"]),
],
targets: [
.target(
name: "Collections",
dependencies: [
"BitCollections",
"DequeModule",
"HeapModule",
"OrderedCollections",
"HashTreeCollections",
],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),

// Testing support module
.target(
name: "_CollectionsTestSupport",
dependencies: ["_CollectionsUtilities"],
swiftSettings: settings,
linkerSettings: [
.linkedFramework(
"XCTest",
.when(platforms: [.macOS, .iOS, .watchOS, .tvOS])),
]
),
.testTarget(
name: "CollectionsTestSupportTests",
dependencies: ["_CollectionsTestSupport"],
swiftSettings: settings),

.target(
name: "_CollectionsUtilities",
exclude: ["CMakeLists.txt"],
swiftSettings: settings),

// BitSet, BitArray
.target(
name: "BitCollections",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),
.testTarget(
name: "BitCollectionsTests",
dependencies: [
"BitCollections", "_CollectionsTestSupport", "OrderedCollections"
],
swiftSettings: settings),

// Deque<Element>
.target(
name: "DequeModule",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),
.testTarget(
name: "DequeTests",
dependencies: ["DequeModule", "_CollectionsTestSupport"],
swiftSettings: settings),

// Heap<Value>
.target(
name: "HeapModule",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),
.testTarget(
name: "HeapTests",
dependencies: ["HeapModule", "_CollectionsTestSupport"],
swiftSettings: settings),

// OrderedSet<Element>, OrderedDictionary<Key, Value>
.target(
name: "OrderedCollections",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),
.testTarget(
name: "OrderedCollectionsTests",
dependencies: ["OrderedCollections", "_CollectionsTestSupport"],
swiftSettings: settings),

// TreeSet<Element>, TreeDictionary<Key, Value>
.target(
name: "HashTreeCollections",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),
.testTarget(
name: "HashTreeCollectionsTests",
dependencies: ["HashTreeCollections", "_CollectionsTestSupport"],
swiftSettings: settings),
]
products: _products,
targets: _targets
)
6 changes: 4 additions & 2 deletions Sources/Collections/Collections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -11,6 +11,8 @@

@_exported import BitCollections
@_exported import DequeModule
@_exported import HashTreeCollections
@_exported import HeapModule
@_exported import OrderedCollections
@_exported import HashTreeCollections

//@_exported import _RopeModule