Skip to content

Commit

Permalink
Merge pull request #264 from lorentey/ropes
Browse files Browse the repository at this point in the history
Add not so experimental rope implementation
  • Loading branch information
lorentey committed Mar 21, 2023
2 parents 8c7b853 + fcd6800 commit 9151af9
Show file tree
Hide file tree
Showing 87 changed files with 12,422 additions and 111 deletions.
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

0 comments on commit 9151af9

Please sign in to comment.