From de68a98a82cb29b5339e3a3667e7f16cab9c261d Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 16 Oct 2025 14:45:22 -0700 Subject: [PATCH 01/75] wip --- .../DequeModule/RigidDeque/RigidDeque.swift | 39 +++++++++++++++++++ .../DequeModule/UniqueDeque/UniqueDeque.swift | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque.swift diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift new file mode 100644 index 00000000..ec321103 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(<6.2) + +@frozen +@available(*, unavailable, message: "RigidDeque requires a Swift 6.2 toolchain") +public struct RigidDeque: ~Copyable { + public init() { + fatalError() + } +} + +#else + +@available(SwiftStdlib 5.0, *) +@safe +@frozen +public struct RigidDeque: ~Copyable { + +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} + +#endif // compiler(<6.2) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift new file mode 100644 index 00000000..31cd6e61 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(<6.2) + +@frozen +@available(*, unavailable, message: "RigidDeque requires a Swift 6.2 toolchain") +public struct RigidDeque: ~Copyable { + public init() { + fatalError() + } +} + +#else + +@available(SwiftStdlib 5.0, *) +@safe +@frozen +public struct UniqueDeque: ~Copyable { + +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} + +#endif // compiler(<6.2) From 397577439323936ecf8553c56605329b479b22fa Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 23 Oct 2025 15:05:12 -0700 Subject: [PATCH 02/75] wip --- Benchmarks/Libraries/Deque.json | 39 +- Benchmarks/Package.resolved | 6 +- Benchmarks/Package.swift | 39 +- Benchmarks/Plugins/RustBuild/RustBuild.swift | 54 + .../Benchmarks/BigStringBenchmarks.swift | 5 +- .../Sources/Benchmarks/DequeBenchmarks.swift | 2 - .../Benchmarks/RigidDequeBenchmarks.swift | 63 + .../Benchmarks/Rust/RustBenchmarks.swift | 18 + .../Rust/RustVecDequeBenchmarks.swift | 141 + .../Benchmarks/UniqueDequeBenchmarks.swift | 132 + .../RustBenchmarks/VecDequeBenchmarks.rs | 138 + Benchmarks/Sources/RustBenchmarks/dummy.swift | 0 Benchmarks/Sources/benchmark-tool/main.swift | 3 + Benchmarks/results | 1 + Benchmarks/results.html | 3247 +++++++++++++++++ Package.swift | 2 +- Sources/ContainersPreview/Mut.swift | 4 +- Sources/ContainersPreview/Ref.swift | 2 +- Sources/DequeModule/Deque._UnsafeHandle.swift | 18 +- .../RigidDeque/RigidDeque+Append.swift | 150 + .../RigidDeque/RigidDeque+Initializers.swift | 63 + .../RigidDeque/RigidDeque+Insertions.swift | 31 + .../RigidDeque/RigidDeque+Prepend.swift | 35 + .../RigidDeque/RigidDeque+Removals.swift | 91 + .../DequeModule/RigidDeque/RigidDeque.swift | 154 +- .../UniqueDeque/UniqueDeque+Append.swift | 127 + .../UniqueDeque+Initializers.swift | 54 + .../UniqueDeque/UniqueDeque+Insertions.swift | 29 + .../UniqueDeque/UniqueDeque+Prepend.swift | 29 + .../UniqueDeque/UniqueDeque+Removals.swift | 79 + .../DequeModule/UniqueDeque/UniqueDeque.swift | 112 +- Sources/DequeModule/_DequeSlot.swift | 34 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 980 +++++ ...uffer.swift => _UnsafeDequeSegments.swift} | 128 +- ...ixedWidthInteger+roundUpToPowerOfTwo.swift | 2 +- .../UnsafeBufferPointer+Extras.swift | 7 +- .../UnsafeMutableBufferPointer+Extras.swift | 18 + 37 files changed, 5934 insertions(+), 103 deletions(-) create mode 100644 Benchmarks/Plugins/RustBuild/RustBuild.swift create mode 100644 Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift create mode 100644 Benchmarks/Sources/Benchmarks/Rust/RustBenchmarks.swift create mode 100644 Benchmarks/Sources/Benchmarks/Rust/RustVecDequeBenchmarks.swift create mode 100644 Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift create mode 100644 Benchmarks/Sources/RustBenchmarks/VecDequeBenchmarks.rs create mode 100644 Benchmarks/Sources/RustBenchmarks/dummy.swift create mode 100644 Benchmarks/results create mode 100644 Benchmarks/results.html create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Append.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift create mode 100644 Sources/DequeModule/_UnsafeDequeHandle.swift rename Sources/DequeModule/{_UnsafeWrappedBuffer.swift => _UnsafeDequeSegments.swift} (74%) diff --git a/Benchmarks/Libraries/Deque.json b/Benchmarks/Libraries/Deque.json index 1d1adb1e..d1628eff 100644 --- a/Benchmarks/Libraries/Deque.json +++ b/Benchmarks/Libraries/Deque.json @@ -209,14 +209,15 @@ }, { "kind": "group", - "title": "Deque vs std::deque", - "directory": "versus STL deque", + "title": "Deque vs std::deque vs VecDeque vs RigidDeque vs UniqueDeque", + "directory": "versus other deques", "contents": [ { "kind": "chart", "title": "init from buffer of integers", "tasks": [ "std::deque constructor from buffer", + "VecDeque constructor from buffer", "Deque init from unsafe buffer" ] }, @@ -225,10 +226,12 @@ "title": "sequential iteration", "tasks": [ "std::deque sequential iteration", + "VecDeque sequential iteration", "Deque sequential iteration (contiguous, iterator)", "Deque sequential iteration (contiguous, indices)", "Deque sequential iteration (discontiguous, iterator)", - "Deque sequential iteration (discontiguous, indices)" + "Deque sequential iteration (discontiguous, indices)", + "UniqueDeque sequential iteration" ] }, { @@ -246,8 +249,19 @@ "title": "append individual integers", "tasks": [ "std::deque push_back", + "VecDeque push_back", "Deque append", - "Deque append, reserving capacity" + "UniqueDeque append" + ] + }, + { + "kind": "chart", + "title": "append individual integers, reserving capacity", + "tasks": [ + "VecDeque push_back, reserving capacity", + "Deque append, reserving capacity", + "RigidDeque append, reserving capacity", + "UniqueDeque append, reserving capacity" ] }, { @@ -255,8 +269,19 @@ "title": "prepend individual integers", "tasks": [ "std::deque push_front", + "VecDeque push_front", "Deque prepend", - "Deque prepend, reserving capacity" + "UniqueDeque prepend" + ] + }, + { + "kind": "chart", + "title": "prepend individual integers, reserving capacity", + "tasks": [ + "VecDeque push_front, reserving capacity", + "Deque prepend, reserving capacity", + "RigidDeque prepend, reserving capacity", + "UniqueDeque prepend, reserving capacity" ] }, { @@ -264,7 +289,9 @@ "title": "random insertions", "tasks": [ "std::deque random insertions", - "Deque random insertions" + "VecDeque random insertions", + "Deque random insertions", + "UniqueDeque random insertions" ] }, { diff --git a/Benchmarks/Package.resolved b/Benchmarks/Package.resolved index 1936b386..72b9ccc3 100644 --- a/Benchmarks/Package.resolved +++ b/Benchmarks/Package.resolved @@ -1,13 +1,13 @@ { - "originHash" : "77540dbea8c5b0878a1a745326146f44af61e58620d5484d3d37c7454bf8b088", + "originHash" : "4f32ed9368a26ffe852c02e155d3f9304019975ede688f715b0601ca2185ea48", "pins" : [ { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-argument-parser", "state" : { - "revision" : "41982a3656a71c768319979febd796c6fd111d5c", - "version" : "1.5.0" + "revision" : "cdd0ef3755280949551dc26dee5de9ddeda89f54", + "version" : "1.6.2" } }, { diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift index 96727d25..c95c1c58 100644 --- a/Benchmarks/Package.swift +++ b/Benchmarks/Package.swift @@ -12,6 +12,27 @@ import PackageDescription +let availabilityMacros: KeyValuePairs = [ + "SwiftStdlib 5.0": "macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2", + "SwiftStdlib 5.1": "macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0", + "SwiftStdlib 5.6": "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4", + "SwiftStdlib 5.8": "macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4", + "SwiftStdlib 5.9": "macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0", + "SwiftStdlib 5.10": "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1", + "SwiftStdlib 6.0": "macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0", + "SwiftStdlib 6.1": "macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4", + "SwiftStdlib 6.2": "macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0", + // Note: if you touch these, please make sure to also update the similar lists in + // CMakeLists.txt and Xcode/Shared.xcconfig. +] + +let _sharedSettings: [SwiftSetting] = ( + availabilityMacros.map { name, value in + .enableExperimentalFeature("AvailabilityMacro=\(name): \(value)") + } + + [.enableExperimentalFeature("Extern")] +) + let package = Package( name: "swift-collections.Benchmarks", platforms: [.macOS(.v15), .iOS(.v18), .watchOS(.v11), .tvOS(.v18), .visionOS(.v2)], @@ -30,17 +51,31 @@ let package = Package( .product(name: "Collections", package: "swift-collections"), .product(name: "CollectionsBenchmark", package: "swift-collections-benchmark"), "CppBenchmarks", - ] + ], + swiftSettings: _sharedSettings ), .target( name: "CppBenchmarks" ), + .plugin( + name: "RustBuild", + capability: .buildTool() + ), + .target( + name: "RustBenchmarks", + plugins: [ + .plugin(name: "RustBuild") + ] + ), .executableTarget( name: "benchmark", dependencies: [ "Benchmarks", ], - path: "Sources/benchmark-tool" + path: "Sources/benchmark-tool", + linkerSettings: [ + .unsafeFlags(["-L\(Context.packageDirectory)/.build/plugins/outputs/benchmarks/RustBenchmarks/destination/RustBuild", "-lRustBenchmarks"]) + ] ), .executableTarget( name: "memory-benchmark", diff --git a/Benchmarks/Plugins/RustBuild/RustBuild.swift b/Benchmarks/Plugins/RustBuild/RustBuild.swift new file mode 100644 index 00000000..e02f8356 --- /dev/null +++ b/Benchmarks/Plugins/RustBuild/RustBuild.swift @@ -0,0 +1,54 @@ +import Foundation +import PackagePlugin + +@main +struct RustBuild: BuildToolPlugin { + func findRustCompiler() throws -> URL { + let which = Process() + which.executableURL = URL(filePath: "/usr/bin/which") + which.arguments = ["rustc"] + + let whichOutput = Pipe() + which.standardOutput = whichOutput + + try which.run() + which.waitUntilExit() + + let output = whichOutput.fileHandleForReading.readDataToEndOfFile() + var pathString = String(decoding: output, as: UTF8.self) + pathString.removeLast() + return URL(filePath: pathString) + } + + func createBuildCommands( + context: PluginContext, + target: Target + ) throws -> [Command] { + guard let sourceFiles = target.sourceModule?.sourceFiles else { return [] } + + // Filter the dummy Swift source file out. + let rustSources = sourceFiles.filter { + $0.url.pathExtension == "rs" + } + + let rustCompiler = try findRustCompiler() + + let inputs = rustSources.map { + $0.url + } + let inputPaths = inputs.map { + $0.path + } + let lib = "lib\(target.name).a" + let output = context.pluginWorkDirectoryURL.appendingPathComponent(lib) + let args = inputPaths + ["-o", output.path, "-O", "--crate-type", "staticlib"] + + return [.buildCommand( + displayName: "Compiling Rust Sources in Target \(target.name)", + executable: rustCompiler, + arguments: args, + inputFiles: inputs, + outputFiles: [output] + )] + } +} diff --git a/Benchmarks/Sources/Benchmarks/BigStringBenchmarks.swift b/Benchmarks/Sources/Benchmarks/BigStringBenchmarks.swift index 657d945e..30799913 100644 --- a/Benchmarks/Sources/Benchmarks/BigStringBenchmarks.swift +++ b/Benchmarks/Sources/Benchmarks/BigStringBenchmarks.swift @@ -74,7 +74,7 @@ struct BridgedStringInput { } } -@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) +@available(SwiftStdlib 6.2, *) struct BigStringInput { let flat: String let big: BigString @@ -85,10 +85,9 @@ struct BigStringInput { } } - extension Benchmark { public mutating func addBigStringBenchmarks() { - guard #available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) else { + guard #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) else { return } diff --git a/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift index 83e51af4..e3a29b9f 100644 --- a/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift +++ b/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift @@ -335,7 +335,6 @@ extension Benchmark { for i in input { deque.append(i) } - precondition(deque.count == input.count) blackHole(deque) } @@ -536,6 +535,5 @@ extension Benchmark { } } } - } } diff --git a/Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift new file mode 100644 index 00000000..884e7059 --- /dev/null +++ b/Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2021 - 2024 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 +// +//===----------------------------------------------------------------------===// + +import CollectionsBenchmark +@_spi(Testing) import DequeModule + +/// Do nothing and immediately return. +/// +/// Some compiler optimizations can eliminate operations whose results don't +/// get used, and this could potentially interfere with the accuracy of a +/// benchmark. To defeat these optimizations, pass such unused results to +/// this function so that the compiler considers them used. +@inline(never) +@_optimize(none) +fileprivate func blackHole(_ value: borrowing RigidDeque) {} + +@inline(never) +fileprivate func appendReserveCapacity(_ input: UnsafeBufferPointer) { + var deque = RigidDeque(capacity: input.count) + for i in input { + deque.append(i) + } + blackHole(deque) +} + +@inline(never) +fileprivate func prependReserveCapacity(_ input: UnsafeBufferPointer) { + var deque = RigidDeque(capacity: input.count) + for i in input { + deque.prepend(i) + } + blackHole(deque) +} + +extension Benchmark { + public mutating func addRigidDequeBenchmarks() { + self.addSimple( + title: "RigidDeque append, reserving capacity", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { + appendReserveCapacity($0) + } + } + + self.addSimple( + title: "RigidDeque prepend, reserving capacity", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { + prependReserveCapacity($0) + } + } + } +} diff --git a/Benchmarks/Sources/Benchmarks/Rust/RustBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Rust/RustBenchmarks.swift new file mode 100644 index 00000000..cfd5bae6 --- /dev/null +++ b/Benchmarks/Sources/Benchmarks/Rust/RustBenchmarks.swift @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +import CollectionsBenchmark + +extension Benchmark { + public mutating func addRustBenchmarks() { + _addRustVecDequeBenchmarks() + } +} diff --git a/Benchmarks/Sources/Benchmarks/Rust/RustVecDequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Rust/RustVecDequeBenchmarks.swift new file mode 100644 index 00000000..324dfe57 --- /dev/null +++ b/Benchmarks/Sources/Benchmarks/Rust/RustVecDequeBenchmarks.swift @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +import CollectionsBenchmark + +@_extern(c, "rust_vecdeque_create") +func rust_vecdeque_create( + _: UnsafeRawPointer?, + _: Int +) -> UnsafeMutableRawPointer? + +@_extern(c, "rust_vecdeque_destroy") +func rust_vecdeque_destroy(_: UnsafeMutableRawPointer?) + +@_extern(c, "rust_vecdeque_from_int_range") +func rust_vecdeque_from_int_range(_: Int) + +@_extern(c, "rust_vecdeque_from_int_buffer") +func rust_vecdeque_from_int_buffer(_: UnsafePointer?, _: Int) + +@_extern(c, "rust_vecdeque_append_integers") +func rust_vecdeque_append_integers(_: UnsafePointer?, _: Int) + +@_extern(c, "rust_vecdeque_append_integers_with_capacity") +func rust_vecdeque_append_integers_with_capacity(_: UnsafePointer?, _: Int) + +@_extern(c, "rust_vecdeque_prepend_integers") +func rust_vecdeque_prepend_integers(_: UnsafePointer?, _: Int) + +@_extern(c, "rust_vecdeque_prepend_integers_with_capacity") +func rust_vecdeque_prepend_integers_with_capacity(_: UnsafePointer?, _: Int) + +@_extern(c, "rust_vecdeque_random_insertions") +func rust_vecdeque_random_insertions(_: UnsafePointer?, _: Int) + +@_extern(c, "rust_vecdeque_iterate") +func rust_vecdeque_iterate(_: UnsafeMutableRawPointer?) + +internal class RustDeque { + var ptr: UnsafeMutableRawPointer? + + init(_ input: [Int]) { + self.ptr = input.withUnsafeBufferPointer { buffer in + rust_vecdeque_create(buffer.baseAddress, buffer.count) + } + } + + deinit { + destroy() + } + + func destroy() { + if let ptr = ptr { + rust_vecdeque_destroy(ptr) + } + ptr = nil + } +} + +extension Benchmark { + internal mutating func _addRustVecDequeBenchmarks() { + self.addSimple( + title: "VecDeque push_back from integer range", + input: Int.self + ) { count in + rust_vecdeque_from_int_range(count) + } + + self.addSimple( + title: "VecDeque constructor from buffer", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { buffer in + rust_vecdeque_from_int_buffer(buffer.baseAddress, buffer.count) + } + } + + self.addSimple( + title: "VecDeque push_back", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { buffer in + rust_vecdeque_append_integers(buffer.baseAddress, buffer.count) + } + } + + self.addSimple( + title: "VecDeque push_back, reserving capacity", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { buffer in + rust_vecdeque_append_integers_with_capacity(buffer.baseAddress, buffer.count) + } + } + + self.addSimple( + title: "VecDeque push_front", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { buffer in + rust_vecdeque_prepend_integers(buffer.baseAddress, buffer.count) + } + } + + self.addSimple( + title: "VecDeque push_front, reserving capacity", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { buffer in + rust_vecdeque_prepend_integers_with_capacity(buffer.baseAddress, buffer.count) + } + } + + self.addSimple( + title: "VecDeque random insertions", + input: Insertions.self + ) { insertions in + insertions.values.withUnsafeBufferPointer { buffer in + rust_vecdeque_random_insertions(buffer.baseAddress, buffer.count) + } + } + + self.add( + title: "VecDeque sequential iteration", + input: [Int].self + ) { input in + let deque = RustDeque(input) + return { timer in + rust_vecdeque_iterate(deque.ptr) + } + } + } +} diff --git a/Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift new file mode 100644 index 00000000..9ea9b199 --- /dev/null +++ b/Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2021 - 2024 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 +// +//===----------------------------------------------------------------------===// + +import CollectionsBenchmark +@_spi(Testing) import DequeModule + +@inline(never) +@_optimize(none) +fileprivate func blackHole(_ value: Int) {} + +@inline(never) +@_optimize(none) +fileprivate func blackHole(_ value: borrowing UniqueDeque) {} + +@inline(never) +fileprivate func append(_ input: UnsafeBufferPointer) { + var deque = UniqueDeque() + for i in input { + deque.append(i) + } + blackHole(deque) +} + +@inline(never) +fileprivate func appendReserveCapacity(_ input: UnsafeBufferPointer) { + var deque = UniqueDeque(capacity: input.count) + for i in input { + deque.append(i) + } + blackHole(deque) +} + +@inline(never) +fileprivate func prepend(_ input: UnsafeBufferPointer) { + var deque = UniqueDeque() + for i in input { + deque.prepend(i) + } + blackHole(deque) +} + +@inline(never) +fileprivate func prependReserveCapacity(_ input: UnsafeBufferPointer) { + var deque = UniqueDeque(capacity: input.count) + for i in input { + deque.prepend(i) + } + blackHole(deque) +} + +@inline(never) +fileprivate func randomInsertions(_ insertions: UnsafeBufferPointer) { + var deque = UniqueDeque() + for i in insertions.indices { + deque.insert(i, at: insertions[i]) + } + blackHole(deque) +} + +@inline(never) +fileprivate func sequentialIteration(_ deque: borrowing UniqueDeque) { + for i in deque.indices { + blackHole(deque[i]) + } +} + +extension Benchmark { + public mutating func addUniqueDequeBenchmarks() { + self.addSimple( + title: "UniqueDeque append", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { + append($0) + } + } + + self.addSimple( + title: "UniqueDeque append, reserving capacity", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { + appendReserveCapacity($0) + } + } + + self.addSimple( + title: "UniqueDeque prepend", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { + prepend($0) + } + } + + self.addSimple( + title: "UniqueDeque prepend, reserving capacity", + input: [Int].self + ) { input in + input.withUnsafeBufferPointer { + prependReserveCapacity($0) + } + } + + self.addSimple( + title: "UniqueDeque random insertions", + input: Insertions.self + ) { insertions in + insertions.values.withUnsafeBufferPointer { + randomInsertions($0) + } + } + + self.add( + title: "UniqueDeque sequential iteration", + input: [Int].self + ) { input in + let deque = UniqueDeque(copying: input) + return { timer in + sequentialIteration(deque) + } + } + } +} diff --git a/Benchmarks/Sources/RustBenchmarks/VecDequeBenchmarks.rs b/Benchmarks/Sources/RustBenchmarks/VecDequeBenchmarks.rs new file mode 100644 index 00000000..bfe4ee24 --- /dev/null +++ b/Benchmarks/Sources/RustBenchmarks/VecDequeBenchmarks.rs @@ -0,0 +1,138 @@ +use std::alloc::{alloc, dealloc, Layout}; +use std::collections::VecDeque; +use std::hint::black_box; + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_create( + mut start: *const isize, + count: isize +) -> *mut VecDeque { + let layout = Layout::new::>(); + let allocated = alloc(layout) as *mut VecDeque; + + let mut vec_deque = VecDeque::with_capacity(count as usize); + + for _ in 0..count { + vec_deque.push_back(start.read()); + start = start.add(1); + } + + allocated.write(vec_deque); + + allocated +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_destroy(ptr: *mut VecDeque) { + ptr.drop_in_place(); + dealloc(ptr as *mut u8, Layout::new::>()); +} + +#[no_mangle] +extern "C" fn rust_vecdeque_from_int_range(count: isize) { + let mut vd = VecDeque::default(); + + for i in 0..count { + vd.push_back(black_box(i)); + } + + black_box(&vd); +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_from_int_buffer( + mut start: *const isize, + count: isize +) { + let mut vd = VecDeque::with_capacity(count as usize); + + for _ in 0..count { + vd.push_back(start.read()); + start = start.add(1); + } + + black_box(&vd); +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_append_integers( + mut start: *const isize, + count: isize +) { + let mut vd = VecDeque::default(); + + for _ in 0..count { + vd.push_back(start.read()); + start = start.add(1); + } + + black_box(&vd); +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_append_integers_with_capacity( + mut start: *const isize, + count: isize +) { + let mut vd = VecDeque::with_capacity(count as usize); + + for _ in 0..count { + vd.push_back(start.read()); + start = start.add(1); + } + + black_box(&vd); +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_prepend_integers( + mut start: *const isize, + count: isize +) { + let mut vd = VecDeque::default(); + + for _ in 0..count { + vd.push_front(start.read()); + start = start.add(1); + } + + black_box(&vd); +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_prepend_integers_with_capacity( + mut start: *const isize, + count: isize +) { + let mut vd = VecDeque::with_capacity(count as usize); + + for _ in 0..count { + vd.push_front(start.read()); + start = start.add(1); + } + + black_box(&vd); +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_random_insertions( + start: *const isize, + count: isize +) { + let mut deque = VecDeque::new(); + + for i in 0..count { + deque.insert(i as usize, start.wrapping_add(i as usize).read()); + } + + black_box(&deque); +} + +#[no_mangle] +unsafe extern "C" fn rust_vecdeque_iterate(ptr: *mut u8) { + let deque_ptr = ptr as *mut VecDeque; + + for e in &*deque_ptr { + black_box(e); + } +} diff --git a/Benchmarks/Sources/RustBenchmarks/dummy.swift b/Benchmarks/Sources/RustBenchmarks/dummy.swift new file mode 100644 index 00000000..e69de29b diff --git a/Benchmarks/Sources/benchmark-tool/main.swift b/Benchmarks/Sources/benchmark-tool/main.swift index 1a9f7ab2..49cf1d3e 100644 --- a/Benchmarks/Sources/benchmark-tool/main.swift +++ b/Benchmarks/Sources/benchmark-tool/main.swift @@ -31,6 +31,8 @@ benchmark.addSetBenchmarks() benchmark.addDictionaryBenchmarks() benchmark.addTreeDictionaryBenchmarks() benchmark.addDequeBenchmarks() +benchmark.addRigidDequeBenchmarks() +benchmark.addUniqueDequeBenchmarks() benchmark.addOrderedSetBenchmarks() benchmark.addOrderedDictionaryBenchmarks() #if false @@ -41,6 +43,7 @@ benchmark.addHeapBenchmarks() benchmark.addBitSetBenchmarks() benchmark.addTreeSetBenchmarks() benchmark.addCppBenchmarks() +benchmark.addRustBenchmarks() benchmark.addBigStringBenchmarks() #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) benchmark.addFoundationBenchmarks() diff --git a/Benchmarks/results b/Benchmarks/results new file mode 100644 index 00000000..91590537 --- /dev/null +++ b/Benchmarks/results @@ -0,0 +1 @@ +{"tasks":[{"title":"Deque init from unsafe buffer","results":{"2048":[[0,255410000000],[0,255830000000],[0,316660000000],[0,353750000000]],"1048576":[[0,131833000000000],[0,134804644444444]],"96":[[0,76660000000],[0,77080000000],[0,77920000000],[0,78340000000]],"327680":[[0,41674242424242],[0,42412500000000]],"384":[[0,93750000000],[0,93750000000],[0,94170000000],[0,95830000000]],"12288":[[0,1657920000000],[0,1658750000000],[0,1660830000000],[0,1693330000000]],"81920":[[0,8840840000000],[0,8842666666666],[0,10231660000000],[0,10901250000000]],"8":[[0,61250000000],[0,62500000000],[0,64580000000],[0,65410000000]],"1280":[[0,179590000000],[0,180830000000],[0,181670000000],[0,205410000000]],"3584":[[0,344170000000],[0,359160000000],[0,372500000000],[0,372500000000]],"7":[[0,63750000000],[0,64160000000],[0,65000000000],[0,65830000000]],"524288":[[0,66208000000000],[0,67600574712643]],"112":[[0,79170000000],[0,79580000000],[0,80000000000],[0,80000000000]],"896":[[0,147080000000],[0,147080000000],[0,147500000000],[0,149170000000]],"192":[[0,80410000000],[0,80830000000],[0,80840000000],[0,81660000000]],"80":[[0,75420000000],[0,75830000000],[0,75830000000],[0,77500000000]],"24":[[0,62080000000],[0,63330000000],[0,64170000000],[0,65000000000]],"40960":[[0,4825000000000],[0,4828750000000],[0,4856660000000],[0,5880420000000]],"16":[[0,61670000000],[0,62080000000],[0,63330000000],[0,65410000000]],"3072":[[0,476250000000],[0,477920000000],[0,478330000000],[0,580420000000]],"20":[[0,62080000000],[0,63330000000],[0,63750000000],[0,65420000000]],"224":[[0,82080000000],[0,82910000000],[0,83330000000],[0,83750000000]],"2560":[[0,408750000000],[0,415420000000],[0,417500000000],[0,425000000000]],"1792":[[0,214590000000],[0,220000000000],[0,226250000000],[0,235840000000]],"1024":[[0,158330000000],[0,158750000000],[0,171250000000],[0,189170000000]],"6144":[[0,1146660000000],[0,1160132530120],[0,1192500000000],[0,1371250000000]],"56":[[0,73330000000],[0,73330000000],[0,73750000000],[0,74580000000]],"786432":[[0,103973958333333],[0,105625000000000]],"163840":[[0,17048304347826],[0,21208000000000],[0,22106250000000]],"6":[[0,62500000000],[0,62920000000],[0,63717647058],[0,63750000000]],"48":[[0,72080000000],[0,72500000000],[0,72910000000],[0,73340000000]],"32":[[0,70830000000],[0,71660000000],[0,72080000000],[0,72500000000]],"14":[[0,61250000000],[0,61670000000],[0,62500000000],[0,62500000000]],"28672":[[0,3626660000000],[0,3628340000000],[0,3633330000000],[0,3654170000000]],"512":[[0,111166666666],[0,117080000000],[0,118750000000],[0,127910000000]],"196608":[[0,22008687500000],[0,25305666666666],[0,27252920000000]],"458752":[[0,58467202127659],[0,60358200000000]],"24576":[[0,3214580000000],[0,3219580000000],[0,3224160000000],[0,3248750000000]],"2":[[0,61670000000],[0,62500000000],[0,62920000000],[0,64170000000]],"256":[[0,83340000000],[0,83750000000],[0,84580000000],[0,86250000000]],"1536":[[0,197080000000],[0,198750000000],[0,211250000000],[0,247500000000]],"64":[[0,73750000000],[0,75000000000],[0,75000000000],[0,75000000000]],"320":[[0,90000000000],[0,90000000000],[0,90000000000],[0,90830000000]],"114688":[[0,12068330000000],[0,15093530612244],[0,15125000000000]],"131072":[[0,14504282051282],[0,17159590000000],[0,17440410000000]],"16384":[[0,2318750000000],[0,2351250000000],[0,2352500000000],[0,2424170000000]],"5120":[[0,1067080000000],[0,1104170000000],[0,1105000000000],[0,1109170000000]],"229376":[[0,25226250000000],[0,29459170000000],[0,30474170000000]],"5":[[0,62500000000],[0,63330000000],[0,63330000000],[0,63340000000]],"10":[[0,61660000000],[0,62080000000],[0,62500000000],[0,73330000000]],"28":[[0,70830000000],[0,71250000000],[0,72080000000],[0,72080000000]],"655360":[[0,82875000000000],[0,92386000000000]],"7168":[[0,1238750000000],[0,1247910000000],[0,1260420000000],[0,1332080000000]],"20480":[[0,2815420000000],[0,2840830000000],[0,2841250000000],[0,2980000000000]],"65536":[[0,7230000000000],[0,7258330000000],[0,7274590000000],[0,7278330000000]],"917504":[[0,101833320000000],[0,115831081081081]],"160":[[0,77500000000],[0,78330000000],[0,78330000000],[0,83330000000]],"640":[[0,123750000000],[0,124580000000],[0,124580000000],[0,125840000000]],"40":[[0,71670000000],[0,72080000000],[0,72500000000],[0,72920000000]],"393216":[[0,49916000000000],[0,50606924528301]],"57344":[[0,6434906250000],[0,6437500000000],[0,6447090000000],[0,7167000000000]],"4":[[0,62500000000],[0,62500000000],[0,62910000000],[0,64160000000]],"1":[[0,63750000000],[0,64160000000],[0,66250000000],[0,110000000000]],"768":[[0,136250000000],[0,137500000000],[0,137920000000],[0,152080000000]],"448":[[0,105830000000],[0,106670000000],[0,107080000000],[0,120410000000]],"8192":[[0,1308750000000],[0,1313750000000],[0,1319580000000],[0,1512080000000]],"12":[[0,62500000000],[0,63750000000],[0,63750000000],[0,64160000000]],"10240":[[0,1476250000000],[0,1479580000000],[0,1568750000000],[0,1607910000000]],"14336":[[0,1930000000000],[0,1936250000000],[0,1969170000000],[0,2506670000000]],"32768":[[0,4027080000000],[0,4029580000000],[0,4030533333333],[0,4032500000000]],"128":[[0,73750000000],[0,74160000000],[0,75000000000],[0,75830000000]],"4096":[[0,1219160000000],[0,1219160000000],[0,1220840000000],[0,1231250000000]],"49152":[[0,5631660000000],[0,5633720930232],[0,5636660000000],[0,5642920000000]],"262144":[[0,33500000000000],[0,34251844444444],[0,37196909090909]],"3":[[0,61670000000],[0,62500000000],[0,62500000000],[0,63340000000]],"98304":[[0,10474170000000],[0,10515000000000],[0,13021250000000],[0,13060420000000]]}},{"title":"Deque sequential iteration (contiguous, iterator)","results":{"2048":[[0,1670830000000],[0,1670830000000],[0,1670830000000],[0,1670830000000]],"1048576":[[0,862750000000000],[0,869583000000000]],"96":[[0,85830000000],[0,85830000000],[0,86250000000],[0,86250000000]],"327680":[[0,266542000000000],[0,274041000000000]],"384":[[0,319580000000],[0,319590000000],[0,320000000000],[0,320000000000]],"12288":[[0,9982920000000],[0,9982920000000],[0,9983750000000],[0,10000000000000]],"81920":[[0,66542000000000],[0,66560000000000],[0,66562500000000],[0,66616510204081]],"8":[[0,11660000000],[0,11660000000],[0,11660000000],[0,11660000000]],"1280":[[0,1047080000000],[0,1047090000000],[0,1047090000000],[0,1047500000000]],"3584":[[0,2916750000000],[0,2917500000000],[0,2917500000000],[0,2917920000000]],"7":[[0,10250000000],[0,10830000000],[0,11250000000],[0,11250000000]],"524288":[[0,429375000000000],[0,434000000000000]],"112":[[0,98750000000],[0,98750000000],[0,99160000000],[0,99160000000]],"896":[[0,735410000000],[0,735410000000],[0,735420000000],[0,735830000000]],"192":[[0,163461538461],[0,163750000000],[0,164160000000],[0,164160000000]],"80":[[0,72910000000],[0,72920000000],[0,72920000000],[0,72920000000]],"24":[[0,24580000000],[0,24580000000],[0,24580000000],[0,24580000000]],"40960":[[0,33270500000000],[0,33277784946236],[0,33292000000000],[0,33417000000000]],"16":[[0,17920000000],[0,17920000000],[0,18330000000],[0,18330000000]],"3072":[[0,2500000000000],[0,2500000000000],[0,2502080000000],[0,2502500000000]],"20":[[0,21250000000],[0,21250000000],[0,21250000000],[0,21250000000]],"224":[[0,190000000000],[0,190000000000],[0,190000000000],[0,190000000000]],"2560":[[0,2086250000000],[0,2086250000000],[0,2086660000000],[0,2086660000000]],"1792":[[0,1462910000000],[0,1462920000000],[0,1462920000000],[0,1463330000000]],"1024":[[0,839170000000],[0,839580000000],[0,839580000000],[0,840000000000]],"6144":[[0,4995830000000],[0,4995830000000],[0,4996250000000],[0,4996311111111]],"56":[[0,42000000000],[0,53330000000],[0,53330000000],[0,53750000000]],"786432":[[0,650750000000000],[0,655959000000000]],"163840":[[0,133084000000000],[0,133375567567567],[0,133458000000000]],"6":[[0,9590000000],[0,9590000000],[0,10000000000],[0,10000000000]],"48":[[0,47500000000],[0,47500000000],[0,47500000000],[0,47500000000]],"32":[[0,31250000000],[0,31250000000],[0,31250000000],[0,31250000000]],"14":[[0,16250000000],[0,16250000000],[0,16660000000],[0,16660000000]],"28672":[[0,23284160000000],[0,23288330000000],[0,23315420000000],[0,23322920000000]],"512":[[0,423330000000],[0,423701298701],[0,423750000000],[0,423750000000]],"196608":[[0,160417000000000],[0,161875000000000],[0,165454545454545]],"458752":[[0,372833000000000],[0,388625000000000]],"24576":[[0,19979000000000],[0,19991250000000],[0,19995840000000],[0,20000000000000]],"2":[[0,6660000000],[0,6660000000],[0,6670000000],[0,7080000000]],"256":[[0,215830000000],[0,215830000000],[0,215830000000],[0,215830000000]],"1536":[[0,1255000000000],[0,1255000000000],[0,1255000000000],[0,1255410000000]],"64":[[0,60000000000],[0,60000000000],[0,60000000000],[0,60000000000]],"320":[[0,267500000000],[0,267500000000],[0,267910000000],[0,267920000000]],"114688":[[0,93291000000000],[0,93334000000000],[0,93458000000000]],"131072":[[0,106564075268817],[0,106709000000000],[0,107305666666666]],"16384":[[0,13306680000000],[0,13308340000000],[0,13314580000000],[0,13411670000000]],"5120":[[0,4164160000000],[0,4164160000000],[0,4164170000000],[0,4164580000000]],"229376":[[0,187936111111111],[0,190166000000000],[0,192084000000000]],"5":[[0,9170000000],[0,9580000000],[0,9580000000],[0,9580000000]],"10":[[0,12920000000],[0,12920000000],[0,13330000000],[0,15000000000]],"28":[[0,27500000000],[0,27500000000],[0,27910000000],[0,27910000000]],"655360":[[0,548697875000000],[0,550667000000000]],"7168":[[0,5826660000000],[0,5826670000000],[0,5827080000000],[0,5827920000000]],"20480":[[0,16646000000000],[0,16649333333333],[0,16666250000000],[0,16701660000000]],"65536":[[0,53250000000000],[0,53250000000000],[0,54100420000000],[0,54163650602409]],"917504":[[0,746042000000000],[0,782156250000000]],"160":[[0,137500000000],[0,137910000000],[0,137910000000],[0,137920000000]],"640":[[0,527500000000],[0,527761904761],[0,527910000000],[0,527910000000]],"40":[[0,40830000000],[0,40840000000],[0,41250000000],[0,41250000000]],"393216":[[0,319500000000000],[0,326083333333333]],"57344":[[0,46557250000000],[0,46626670000000],[0,46667000000000],[0,47000000000000]],"4":[[0,8330000000],[0,8330000000],[0,8330000000],[0,8330000000]],"1":[[0,5830000000],[0,6250000000],[0,6660000000],[0,9580000000]],"768":[[0,625000000000],[0,631660000000],[0,631660000000],[0,631660000000]],"448":[[0,371660000000],[0,371670000000],[0,372080000000],[0,421409090909]],"8192":[[0,6657920000000],[0,6658750000000],[0,6659170000000],[0,6692080000000]],"12":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"10240":[[0,8320830000000],[0,8320830000000],[0,8320830000000],[0,8321660000000]],"14336":[[0,11645420000000],[0,11645840000000],[0,11657910000000],[0,11762920000000]],"32768":[[0,26625000000000],[0,26625000000000],[0,26709000000000],[0,26802500000000]],"128":[[0,111670000000],[0,112080000000],[0,112080000000],[0,112080000000]],"4096":[[0,3332500000000],[0,3332920000000],[0,3333330000000],[0,3333942028985]],"49152":[[0,39916000000000],[0,39917000000000],[0,39932500000000],[0,40123330000000]],"262144":[[0,212916000000000],[0,216625000000000],[0,236310975609756]],"3":[[0,7910000000],[0,7910000000],[0,7910000000],[0,7910000000]],"98304":[[0,79806818181818],[0,79871541666666],[0,79959000000000],[0,80118750000000]]}},{"title":"Deque subscript get, random offsets (contiguous)","results":{"2048":[[0,2220830000000],[0,2220924528301],[0,2221250000000],[0,2222080000000]],"1048576":[[0,1147667000000000],[0,1216555666666666]],"96":[[0,83000000000],[0,107920000000],[0,108330000000],[0,108750000000]],"327680":[[0,365383200000000],[0,369483400000000]],"384":[[0,420000000000],[0,420000000000],[0,420410000000],[0,420410000000]],"12288":[[0,13307080000000],[0,13337080000000],[0,13497500000000],[0,13506670000000]],"81920":[[0,88666684210526],[0,88677800000000],[0,88740666666666],[0,90091125000000]],"8":[[0,10000000000],[0,10000000000],[0,10375000000],[0,10410000000]],"1280":[[0,1389590000000],[0,1390000000000],[0,1390000000000],[0,1390410000000]],"3584":[[0,3883750000000],[0,3884160000000],[0,3884170000000],[0,3884590000000]],"7":[[0,5857142857],[0,9160000000],[0,9160000000],[0,9160000000]],"524288":[[0,572937500000000],[0,584147727272727]],"112":[[0,125000000000],[0,125410000000],[0,125420000000],[0,125830000000]],"896":[[0,958000000000],[0,959000000000],[0,974160000000],[0,974170000000]],"192":[[0,212080000000],[0,212090000000],[0,212500000000],[0,212500000000]],"80":[[0,83000000000],[0,83000000000],[0,90830000000],[0,91250000000]],"24":[[0,27080000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,44548263157894],[0,44958000000000],[0,45009823529411],[0,46702910000000]],"16":[[0,18750000000],[0,18750000000],[0,18750000000],[0,21660000000]],"3072":[[0,3329160000000],[0,3329580000000],[0,3329590000000],[0,3330830000000]],"20":[[0,20500000000],[0,22910000000],[0,22920000000],[0,22920000000]],"224":[[0,246250000000],[0,246660000000],[0,246670000000],[0,247080000000]],"2560":[[0,2775000000000],[0,2775000000000],[0,2775410000000],[0,2842500000000]],"1792":[[0,1917000000000],[0,1944160000000],[0,1944170000000],[0,1944580000000]],"1024":[[0,1112500000000],[0,1112500000000],[0,1113330000000],[0,1113750000000]],"6144":[[0,6654590000000],[0,6654590000000],[0,6655840000000],[0,6687920000000]],"56":[[0,64580000000],[0,65000000000],[0,65000000000],[0,65000000000]],"786432":[[0,855152666666666],[0,873760500000000]],"163840":[[0,179635177777777],[0,180713235294117],[0,188530200000000]],"6":[[0,7920000000],[0,8330000000],[0,8330000000],[0,8330000000]],"48":[[0,41000000000],[0,55830000000],[0,55840000000],[0,56250000000]],"32":[[0,31250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"14":[[0,16660000000],[0,16660000000],[0,16660000000],[0,16660000000]],"28672":[[0,31039580000000],[0,31040830000000],[0,31048076923076],[0,31156660000000]],"512":[[0,558330000000],[0,558340000000],[0,558750000000],[0,558750000000]],"196608":[[0,212870333333333],[0,220226142857142],[0,222004555555555]],"458752":[[0,499562500000000],[0,538446428571428]],"24576":[[0,26705000000000],[0,26709580000000],[0,26854590000000],[0,27116250000000]],"2":[[0,3750000000],[0,3750000000],[0,3750000000],[0,4160000000]],"256":[[0,281250000000],[0,281250000000],[0,281660000000],[0,281660000000]],"1536":[[0,1666670000000],[0,1666670000000],[0,1667080000000],[0,1667500000000]],"64":[[0,73330000000],[0,73750000000],[0,73750000000],[0,74160000000]],"320":[[0,350000000000],[0,350420000000],[0,351250000000],[0,351250000000]],"114688":[[0,124602615384615],[0,126128818181818],[0,126327898550724]],"131072":[[0,142991666666666],[0,144269779661016],[0,147034090909090]],"16384":[[0,17741250000000],[0,17748330000000],[0,17754170000000],[0,18002717391304]],"5120":[[0,5545830000000],[0,5546250000000],[0,5546670000000],[0,5550830000000]],"229376":[[0,249601777777777],[0,253843454545454],[0,266223096774193]],"5":[[0,6660000000],[0,6670000000],[0,7080000000],[0,7080000000]],"10":[[0,12080000000],[0,12090000000],[0,12500000000],[0,14160000000]],"28":[[0,32080000000],[0,32080000000],[0,32080000000],[0,32080000000]],"655360":[[0,709666000000000],[0,729615777777777]],"7168":[[0,7763330000000],[0,7763340000000],[0,7764170000000],[0,7764170000000]],"20480":[[0,22175830000000],[0,22250000000000],[0,22262500000000],[0,22445830000000]],"65536":[[0,70958000000000],[0,71333324324324],[0,71750000000000],[0,72000000000000]],"917504":[[0,1004750000000000],[0,1011062500000000]],"160":[[0,177080000000],[0,177500000000],[0,177500000000],[0,177910000000]],"640":[[0,667000000000],[0,687500000000],[0,696670000000],[0,697080000000]],"40":[[0,47080000000],[0,47080000000],[0,47090000000],[0,47090000000]],"393216":[[0,428693647058823],[0,434479000000000]],"57344":[[0,62757920000000],[0,63512920000000],[0,63534160000000],[0,65166000000000]],"4":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5830000000]],"1":[[0,1250000000],[0,1660000000],[0,1660000000],[0,2080000000]],"768":[[0,833000000000],[0,835000000000],[0,835410000000],[0,836250000000]],"448":[[0,489160000000],[0,489580000000],[0,489580000000],[0,542000000000]],"8192":[[0,8871250000000],[0,8871250000000],[0,8875000000000],[0,8875840000000]],"12":[[0,14170000000],[0,14580000000],[0,14580000000],[0,14580000000]],"10240":[[0,11084000000000],[0,11090420000000],[0,11091934782608],[0,11098893333333]],"14336":[[0,15523330000000],[0,15523750000000],[0,15527500000000],[0,15574590000000]],"32768":[[0,35472080000000],[0,35583000000000],[0,35835000000000],[0,36125000000000]],"128":[[0,142910000000],[0,143330000000],[0,143330000000],[0,150000000000]],"4096":[[0,4437920000000],[0,4437920000000],[0,4438330000000],[0,4438340000000]],"49152":[[0,53292000000000],[0,53333000000000],[0,53615410000000],[0,54123330000000]],"262144":[[0,289891962962962],[0,291613142857142],[0,294140625000000]],"3":[[0,3727272727],[0,4580000000],[0,4590000000],[0,4590000000]],"98304":[[0,106406250000000],[0,106520812500000],[0,107579113924050],[0,108232142857142]]}},{"title":"Deque append","results":{"2048":[[0,5227941176470],[0,5235830000000],[0,5267080000000],[0,5288330000000]],"1048576":[[0,2270000000000000],[0,2473750000000000]],"96":[[0,980420000000],[0,987500000000],[0,997920000000],[0,1011250000000]],"327680":[[0,739601888888888],[0,742722333333333]],"384":[[0,1824170000000],[0,1828750000000],[0,1838750000000],[0,1860000000000]],"12288":[[0,27556670000000],[0,27708500000000],[0,27738330000000],[0,28384744680851]],"81920":[[0,160812500000000],[0,160884222222222],[0,163354200000000],[0,163673625000000]],"8":[[0,315830000000],[0,318330000000],[0,323330000000],[0,327500000000]],"1280":[[0,3674160000000],[0,3677500000000],[0,3691666666666],[0,3727500000000]],"3584":[[0,8219590000000],[0,8246660000000],[0,8247500000000],[0,8285410000000]],"7":[[0,312920000000],[0,317080000000],[0,317920000000],[0,325830000000]],"524288":[[0,1120396000000000],[0,1122333500000000]],"112":[[0,1013750000000],[0,1017080000000],[0,1025410000000],[0,1044580000000]],"896":[[0,2816250000000],[0,2820420000000],[0,2833330000000],[0,2870420000000]],"192":[[0,1258330000000],[0,1273330000000],[0,1277910000000],[0,1284170000000]],"80":[[0,859590000000],[0,869047619047],[0,869580000000],[0,900000000000]],"24":[[0,570420000000],[0,570830000000],[0,583333333333],[0,602080000000]],"40960":[[0,86708000000000],[0,87250000000000],[0,87875830000000],[0,88990384615384]],"16":[[0,477920000000],[0,480000000000],[0,507500000000],[0,537500000000]],"3072":[[0,7282090000000],[0,7306250000000],[0,7318340000000],[0,7403340000000]],"20":[[0,485000000000],[0,485420000000],[0,486660000000],[0,499580000000]],"224":[[0,1303330000000],[0,1320830000000],[0,1322080000000],[0,1352080000000]],"2560":[[0,6505000000000],[0,6549160000000],[0,6588768115942],[0,8246500000000]],"1792":[[0,4795830000000],[0,4802000000000],[0,4830410000000],[0,4860830000000]],"1024":[[0,3237080000000],[0,3285420000000],[0,3299160000000],[0,3325000000000]],"6144":[[0,16000000000000],[0,16000000000000],[0,16083500000000],[0,16362546391752]],"56":[[0,726660000000],[0,729170000000],[0,735000000000],[0,750420000000]],"786432":[[0,1612708400000000],[0,1637167000000000]],"163840":[[0,325958333333333],[0,331654000000000],[0,355680666666666]],"6":[[0,307500000000],[0,309160000000],[0,318750000000],[0,331670000000]],"48":[[0,704160000000],[0,710410000000],[0,715000000000],[0,737910000000]],"32":[[0,583500000000],[0,592080000000],[0,598330000000],[0,618340000000]],"14":[[0,396660000000],[0,397500000000],[0,402500000000],[0,412090000000]],"28672":[[0,61750000000000],[0,61764344262295],[0,61867220338983],[0,62317080000000]],"512":[[0,2031660000000],[0,2031660000000],[0,2035000000000],[0,2062500000000]],"196608":[[0,410892857142857],[0,413908333333333],[0,438222166666666]],"458752":[[0,960345285714285],[0,1012819333333333]],"24576":[[0,55166000000000],[0,55396000000000],[0,55825420000000],[0,55960410000000]],"2":[[0,156660000000],[0,157910000000],[0,159160000000],[0,162080000000]],"256":[[0,1476250000000],[0,1478750000000],[0,1486250000000],[0,1513750000000]],"1536":[[0,4330410000000],[0,4406250000000],[0,4431250000000],[0,4437080000000]],"64":[[0,833750000000],[0,835000000000],[0,835000000000],[0,860000000000]],"320":[[0,1582500000000],[0,1595000000000],[0,1605830000000],[0,1626660000000]],"114688":[[0,227257275000000],[0,227508400000000],[0,232295948717948]],"131072":[[0,271625000000000],[0,277600000000000],[0,289309428571428]],"16384":[[0,37050000000000],[0,37571721311475],[0,38322080000000],[0,43763330000000]],"5120":[[0,12208000000000],[0,12285830000000],[0,12371660000000],[0,12497500000000]],"229376":[[0,483270833333333],[0,483433400000000],[0,505610294117647]],"5":[[0,235000000000],[0,242090000000],[0,245000000000],[0,245420000000]],"10":[[0,394590000000],[0,395000000000],[0,401250000000],[0,420000000000]],"28":[[0,578330000000],[0,585420000000],[0,587500000000],[0,605000000000]],"655360":[[0,1362979000000000],[0,1420483400000000]],"7168":[[0,17708000000000],[0,17771739130434],[0,17792000000000],[0,17803750000000]],"20480":[[0,43584000000000],[0,43666000000000],[0,45079580000000],[0,47906670000000]],"65536":[[0,133395500000000],[0,134458333333333],[0,137548472727272],[0,138022887323943]],"917504":[[0,1791875000000000],[0,1919834000000000]],"160":[[0,1190000000000],[0,1204170000000],[0,1224170000000],[0,1224170000000]],"640":[[0,2387080000000],[0,2397500000000],[0,2401250000000],[0,2435830000000]],"40":[[0,690830000000],[0,692920000000],[0,697090000000],[0,724580000000]],"393216":[[0,842333285714285],[0,847180666666666]],"57344":[[0,119417000000000],[0,121979500000000],[0,123030533333333],[0,123458333333333]],"4":[[0,231250000000],[0,231660000000],[0,236660000000],[0,242080000000]],"1":[[0,83750000000],[0,85000000000],[0,90830000000],[0,108750000000]],"768":[[0,2611250000000],[0,2614590000000],[0,2658750000000],[0,2668340000000]],"448":[[0,1924580000000],[0,1927250000000],[0,1966670000000],[0,2185243243243]],"8192":[[0,18906250000000],[0,19157080000000],[0,19197500000000],[0,19354000000000]],"12":[[0,391660000000],[0,393750000000],[0,398750000000],[0,415830000000]],"10240":[[0,23868166666666],[0,24060111111111],[0,24236000000000],[0,24340830000000]],"14336":[[0,30696250000000],[0,30859818181818],[0,31275000000000],[0,31295000000000]],"32768":[[0,68167000000000],[0,69059580000000],[0,69140159090909],[0,70278252873563]],"128":[[0,1045420000000],[0,1049580000000],[0,1055420000000],[0,1073750000000]],"4096":[[0,10548750000000],[0,10560166666666],[0,10625000000000],[0,10671670000000]],"49152":[[0,100667000000000],[0,101000000000000],[0,101250000000000],[0,101567043478260]],"262144":[[0,544698000000000],[0,560513916666666],[0,569927000000000]],"3":[[0,159160000000],[0,159160000000],[0,163330000000],[0,163750000000]],"98304":[[0,199875000000000],[0,200000000000000],[0,201514344827586],[0,205135416666666]]}},{"title":"Deque append, reserving capacity","results":{"2048":[[0,3855000000000],[0,3866670000000],[0,3872080000000],[0,3878750000000]],"1048576":[[0,2048375000000000],[0,2051333500000000]],"96":[[0,269170000000],[0,269170000000],[0,270410000000],[0,270830000000]],"327680":[[0,644584000000000],[0,672604142857142]],"384":[[0,790000000000],[0,794170000000],[0,799580000000],[0,889580000000]],"12288":[[0,22542000000000],[0,23166000000000],[0,23417000000000],[0,24076660000000]],"81920":[[0,159625000000000],[0,159729250000000],[0,161034666666666],[0,162393066666666]],"8":[[0,96660000000],[0,97080000000],[0,97500000000],[0,97920000000]],"1280":[[0,2467500000000],[0,2482500000000],[0,2484170000000],[0,2580000000000]],"3584":[[0,6375000000000],[0,6664170000000],[0,6667000000000],[0,6755420000000]],"7":[[0,95410000000],[0,95420000000],[0,97080000000],[0,97090000000]],"524288":[[0,1023083000000000],[0,1041606555555555]],"112":[[0,298750000000],[0,299580000000],[0,300000000000],[0,301250000000]],"896":[[0,1667000000000],[0,1735410000000],[0,1736670000000],[0,1751660000000]],"192":[[0,440420000000],[0,442500000000],[0,442920000000],[0,443750000000]],"80":[[0,238750000000],[0,240830000000],[0,241250000000],[0,245830000000]],"24":[[0,129580000000],[0,130000000000],[0,130830000000],[0,130840000000]],"40960":[[0,78792000000000],[0,80543478260869],[0,80933750000000],[0,82455000000000]],"16":[[0,110410000000],[0,110840000000],[0,111660000000],[0,117500000000]],"3072":[[0,5625000000000],[0,5745000000000],[0,5794170000000],[0,5801670000000]],"20":[[0,122080000000],[0,122500000000],[0,123750000000],[0,125420000000]],"224":[[0,499580000000],[0,501250000000],[0,503330000000],[0,505000000000]],"2560":[[0,4583000000000],[0,4850420000000],[0,4907576923076],[0,5049580000000]],"1792":[[0,3208500000000],[0,3384170000000],[0,3388750000000],[0,3417920000000]],"1024":[[0,1977500000000],[0,1985000000000],[0,1987500000000],[0,1991250000000]],"6144":[[0,11875000000000],[0,12368750000000],[0,12430000000000],[0,12585420000000]],"56":[[0,194580000000],[0,195830000000],[0,196670000000],[0,196670000000]],"786432":[[0,1528514000000000],[0,1586194500000000]],"163840":[[0,321250000000000],[0,323150000000000],[0,333510777777777]],"6":[[0,93750000000],[0,94170000000],[0,95830000000],[0,95830000000]],"48":[[0,179580000000],[0,181250000000],[0,181660000000],[0,185000000000]],"32":[[0,150410000000],[0,151660000000],[0,152500000000],[0,152920000000]],"14":[[0,106670000000],[0,107080000000],[0,107500000000],[0,109580000000]],"28672":[[0,52750000000000],[0,56446815789473],[0,57426633802816],[0,58049295774647]],"512":[[0,1000000000000],[0,1032500000000],[0,1035000000000],[0,1039160000000]],"196608":[[0,375875000000000],[0,385918320000000],[0,386500000000000]],"458752":[[0,924279200000000],[0,928750000000000]],"24576":[[0,45297571428571],[0,45334000000000],[0,45792000000000],[0,48755840000000]],"2":[[0,87920000000],[0,88750000000],[0,89160000000],[0,100410000000]],"256":[[0,555410000000],[0,558750000000],[0,559580000000],[0,561250000000]],"1536":[[0,2878330000000],[0,2889000000000],[0,2923750000000],[0,2945420000000]],"64":[[0,210410000000],[0,211250000000],[0,211670000000],[0,212080000000]],"320":[[0,675000000000],[0,680000000000],[0,681670000000],[0,687080000000]],"114688":[[0,215958000000000],[0,220084000000000],[0,226500000000000]],"131072":[[0,239084000000000],[0,252264000000000],[0,261769694444444]],"16384":[[0,31291666666666],[0,32000830000000],[0,32319333333333],[0,33553750000000]],"5120":[[0,10083000000000],[0,10125000000000],[0,10331896551724],[0,10497500000000]],"229376":[[0,419042000000000],[0,444792000000000],[0,450263666666666]],"5":[[0,92080000000],[0,92090000000],[0,93750000000],[0,95420000000]],"10":[[0,100000000000],[0,100830000000],[0,102500000000],[0,107910000000]],"28":[[0,142920000000],[0,144160000000],[0,144580000000],[0,146250000000]],"655360":[[0,1342125000000000],[0,1356791666666666]],"7168":[[0,13875000000000],[0,14120830000000],[0,14257500000000],[0,14453330000000]],"20480":[[0,39596288888888],[0,41142910000000],[0,41619580000000],[0,41625000000000]],"65536":[[0,123808400000000],[0,127385250000000],[0,129917000000000],[0,130165540540540]],"917504":[[0,1821066600000000],[0,1857275000000000]],"160":[[0,382080000000],[0,382500000000],[0,386660000000],[0,388750000000]],"640":[[0,1266250000000],[0,1267080000000],[0,1273330000000],[0,1275840000000]],"40":[[0,165420000000],[0,166660000000],[0,167080000000],[0,167500000000]],"393216":[[0,732708000000000],[0,792086833333333]],"57344":[[0,105708000000000],[0,110601142857142],[0,111166000000000],[0,112458400000000]],"4":[[0,90410000000],[0,90830000000],[0,91670000000],[0,92920000000]],"1":[[0,87910000000],[0,87920000000],[0,92910000000],[0,110410000000]],"768":[[0,1479160000000],[0,1502080000000],[0,1508750000000],[0,1513750000000]],"448":[[0,883200000000],[0,913340000000],[0,916660000000],[0,920420000000]],"8192":[[0,15792000000000],[0,16375420000000],[0,16497920000000],[0,16534423913043]],"12":[[0,103750000000],[0,104160000000],[0,105000000000],[0,105420000000]],"10240":[[0,20098340000000],[0,20125000000000],[0,20536670000000],[0,21073750000000]],"14336":[[0,26208000000000],[0,27000000000000],[0,27042000000000],[0,27125000000000]],"32768":[[0,58459000000000],[0,60542000000000],[0,60917000000000],[0,64745921568627]],"128":[[0,319416666666],[0,323750000000],[0,325830000000],[0,327500000000]],"4096":[[0,8333500000000],[0,8366660000000],[0,8367920000000],[0,8455000000000]],"49152":[[0,93584000000000],[0,94395833333333],[0,96930666666666],[0,99642176470588]],"262144":[[0,501479000000000],[0,513583000000000],[0,519037055555555]],"3":[[0,88750000000],[0,89160000000],[0,90830000000],[0,90830000000]],"98304":[[0,183667000000000],[0,185959000000000],[0,191099180000000],[0,192532306122448]]}},{"title":"Deque prepend","results":{"2048":[[0,5199170000000],[0,5207500000000],[0,5208750000000],[0,5248330000000]],"1048576":[[0,2202989500000000],[0,2272541750000000]],"96":[[0,988750000000],[0,993750000000],[0,999160000000],[0,1029170000000]],"327680":[[0,737259615384615],[0,738385416666666]],"384":[[0,1825420000000],[0,1828330000000],[0,1830000000000],[0,1867090000000]],"12288":[[0,27061882352941],[0,27167000000000],[0,27417000000000],[0,30575420000000]],"81920":[[0,159333000000000],[0,159791000000000],[0,160500000000000],[0,163310786885245]],"8":[[0,321250000000],[0,321250000000],[0,324170000000],[0,332080000000]],"1280":[[0,3628750000000],[0,3677500000000],[0,3686660000000],[0,3887080000000]],"3584":[[0,8112080000000],[0,8133200000000],[0,8140840000000],[0,8183750000000]],"7":[[0,317500000000],[0,318750000000],[0,323330000000],[0,330410000000]],"524288":[[0,1088916000000000],[0,1122255250000000]],"112":[[0,1026670000000],[0,1027080000000],[0,1031250000000],[0,1057920000000]],"896":[[0,2808330000000],[0,2810000000000],[0,2810420000000],[0,2870410000000]],"192":[[0,1260830000000],[0,1270830000000],[0,1276250000000],[0,1295420000000]],"80":[[0,876660000000],[0,877090000000],[0,878340000000],[0,913750000000]],"24":[[0,579580000000],[0,589170000000],[0,589170000000],[0,613330000000]],"40960":[[0,85750000000000],[0,86258928571428],[0,86292000000000],[0,86917000000000]],"16":[[0,490420000000],[0,493330000000],[0,510420000000],[0,557080000000]],"3072":[[0,7267090000000],[0,7269170000000],[0,7291250000000],[0,7332080000000]],"20":[[0,489160000000],[0,492080000000],[0,500000000000],[0,511660000000]],"224":[[0,1326670000000],[0,1327500000000],[0,1330830000000],[0,1355420000000]],"2560":[[0,6447920000000],[0,6464170000000],[0,6497080000000],[0,14750000000000]],"1792":[[0,4775830000000],[0,4791250000000],[0,4798330000000],[0,4840410000000]],"1024":[[0,3217500000000],[0,3265830000000],[0,3271250000000],[0,3277920000000]],"6144":[[0,15910714285714],[0,15923330000000],[0,15993750000000],[0,16175830000000]],"56":[[0,737910000000],[0,741670000000],[0,742500000000],[0,761670000000]],"786432":[[0,1591958000000000],[0,1693125000000000]],"163840":[[0,321646000000000],[0,325958344827586],[0,347406250000000]],"6":[[0,315000000000],[0,316250000000],[0,320830000000],[0,326250000000]],"48":[[0,712080000000],[0,720420000000],[0,721250000000],[0,747080000000]],"32":[[0,597500000000],[0,597920000000],[0,602500000000],[0,628330000000]],"14":[[0,405420000000],[0,405830000000],[0,407500000000],[0,423330000000]],"28672":[[0,60166500000000],[0,60750000000000],[0,61098539682539],[0,61329590000000]],"512":[[0,2025000000000],[0,2032090000000],[0,2033330000000],[0,2067500000000]],"196608":[[0,395542000000000],[0,405229500000000],[0,410541000000000]],"458752":[[0,952070900000000],[0,978250000000000]],"24576":[[0,53583000000000],[0,54334580000000],[0,55619580000000],[0,55666670000000]],"2":[[0,155840000000],[0,157500000000],[0,162500000000],[0,178330000000]],"256":[[0,1478330000000],[0,1485830000000],[0,1488750000000],[0,1535420000000]],"1536":[[0,4353340000000],[0,4363330000000],[0,4367080000000],[0,4401250000000]],"64":[[0,844590000000],[0,845000000000],[0,853750000000],[0,881670000000]],"320":[[0,1586250000000],[0,1602500000000],[0,1605830000000],[0,1631250000000]],"114688":[[0,222209000000000],[0,230954357142857],[0,260302250000000]],"131072":[[0,267812500000000],[0,273140151515151],[0,286633588235294]],"16384":[[0,36711660000000],[0,36740000000000],[0,36928340000000],[0,37472500000000]],"5120":[[0,12232910000000],[0,12240420000000],[0,12332500000000],[0,12333000000000]],"229376":[[0,468895500000000],[0,478018750000000],[0,493456000000000]],"5":[[0,236670000000],[0,239590000000],[0,242920000000],[0,248330000000]],"10":[[0,405410000000],[0,405420000000],[0,405830000000],[0,422920000000]],"28":[[0,594170000000],[0,596250000000],[0,597080000000],[0,614580000000]],"655360":[[0,1291292000000000],[0,1319714285714285]],"7168":[[0,17118045454545],[0,17164580000000],[0,17232500000000],[0,17428330000000]],"20480":[[0,43125000000000],[0,43125000000000],[0,43696680000000],[0,48811974358974]],"65536":[[0,131966600000000],[0,133542000000000],[0,134788652173913],[0,134881043478260]],"917504":[[0,1801510500000000],[0,1813650000000000]],"160":[[0,1210830000000],[0,1216600000000],[0,1222500000000],[0,1239160000000]],"640":[[0,2384170000000],[0,2388750000000],[0,2399590000000],[0,2425410000000]],"40":[[0,701333333333],[0,704170000000],[0,712500000000],[0,737080000000]],"393216":[[0,818696909090909],[0,835387500000000]],"57344":[[0,119542000000000],[0,120084000000000],[0,120111000000000],[0,120291666666666]],"4":[[0,233750000000],[0,234160000000],[0,234580000000],[0,244590000000]],"1":[[0,83750000000],[0,85000000000],[0,85410000000],[0,101660000000]],"768":[[0,2594580000000],[0,2607500000000],[0,2612068965517],[0,2655410000000]],"448":[[0,1927125000000],[0,1928340000000],[0,1928750000000],[0,1967090000000]],"8192":[[0,18655420000000],[0,18784590000000],[0,19073750000000],[0,19649890243902]],"12":[[0,402080000000],[0,409580000000],[0,410000000000],[0,426660000000]],"10240":[[0,23920454545454],[0,23958333333333],[0,24166666666666],[0,24308400000000]],"14336":[[0,30370370370370],[0,30540410000000],[0,30562500000000],[0,30642857142857]],"32768":[[0,67042000000000],[0,67708000000000],[0,67920304347826],[0,68458000000000]],"128":[[0,1055410000000],[0,1060000000000],[0,1061250000000],[0,1087500000000]],"4096":[[0,10363750000000],[0,10373800000000],[0,10457500000000],[0,10522500000000]],"49152":[[0,98625000000000],[0,101057112359550],[0,101440571428571],[0,102798684210526]],"262144":[[0,529259277777777],[0,537544117647058],[0,558125000000000]],"3":[[0,163330000000],[0,163340000000],[0,166660000000],[0,168330000000]],"98304":[[0,197500000000000],[0,198958500000000],[0,199192750000000],[0,207265625000000]]}},{"title":"Deque prepend, reserving capacity","results":{"2048":[[0,4120000000000],[0,4120410000000],[0,4120830000000],[0,4124160000000]],"1048576":[[0,2131250000000000],[0,2161792000000000]],"96":[[0,271250000000],[0,271660000000],[0,271660000000],[0,272080000000]],"327680":[[0,676500000000000],[0,677542000000000]],"384":[[0,835420000000],[0,835830000000],[0,836670000000],[0,840830000000]],"12288":[[0,25250000000000],[0,25375000000000],[0,25727090000000],[0,26206250000000]],"81920":[[0,165062500000000],[0,165666000000000],[0,165997169491525],[0,166083000000000]],"8":[[0,95830000000],[0,95830000000],[0,95830000000],[0,97500000000]],"1280":[[0,2604170000000],[0,2605420000000],[0,2609170000000],[0,2754170000000]],"3584":[[0,7132500000000],[0,7145410000000],[0,7147500000000],[0,7162920000000]],"7":[[0,94170000000],[0,94580000000],[0,95000000000],[0,96250000000]],"524288":[[0,1074875000000000],[0,1106542000000000]],"112":[[0,303330000000],[0,303750000000],[0,304160000000],[0,304580000000]],"896":[[0,1846660000000],[0,1847080000000],[0,1848750000000],[0,1848750000000]],"192":[[0,455830000000],[0,456250000000],[0,457080000000],[0,457080000000]],"80":[[0,240000000000],[0,240410000000],[0,240410000000],[0,240840000000]],"24":[[0,127920000000],[0,128330000000],[0,129580000000],[0,130000000000]],"40960":[[0,82942166666666],[0,83250000000000],[0,84745000000000],[0,84757080000000]],"16":[[0,107920000000],[0,108330000000],[0,109170000000],[0,109580000000]],"3072":[[0,6136670000000],[0,6137920000000],[0,6140410000000],[0,6140840000000]],"20":[[0,113750000000],[0,113750000000],[0,115410000000],[0,115830000000]],"224":[[0,520000000000],[0,521660000000],[0,521670000000],[0,522080000000]],"2560":[[0,5125000000000],[0,5137080000000],[0,5138330000000],[0,5140420000000]],"1792":[[0,3607500000000],[0,3612500000000],[0,3615420000000],[0,5166000000000]],"1024":[[0,2099580000000],[0,2100410000000],[0,2100420000000],[0,2103330000000]],"6144":[[0,12862090000000],[0,12870420000000],[0,12875000000000],[0,12900830000000]],"56":[[0,192910000000],[0,193340000000],[0,194160000000],[0,195000000000]],"786432":[[0,1646542000000000],[0,1997073000000000]],"163840":[[0,331166000000000],[0,333625000000000],[0,340488517241379]],"6":[[0,92910000000],[0,92910000000],[0,92920000000],[0,93750000000]],"48":[[0,177920000000],[0,178330000000],[0,179580000000],[0,179580000000]],"32":[[0,149170000000],[0,149590000000],[0,150000000000],[0,151250000000]],"14":[[0,104170000000],[0,104580000000],[0,105000000000],[0,106660000000]],"28672":[[0,57916000000000],[0,58083000000000],[0,58125000000000],[0,58250000000000]],"512":[[0,1092500000000],[0,1092910000000],[0,1093330000000],[0,1097910000000]],"196608":[[0,397625000000000],[0,401042000000000],[0,417000000000000]],"458752":[[0,943541000000000],[0,975375000000000]],"24576":[[0,49875000000000],[0,49917000000000],[0,50000000000000],[0,50670830000000]],"2":[[0,83000000000],[0,87910000000],[0,89160000000],[0,99590000000]],"256":[[0,581670000000],[0,582500000000],[0,583330000000],[0,584170000000]],"1536":[[0,3109170000000],[0,3110410000000],[0,3110830000000],[0,3110840000000]],"64":[[0,207500000000],[0,208750000000],[0,209590000000],[0,210830000000]],"320":[[0,707920000000],[0,709160000000],[0,710420000000],[0,715420000000]],"114688":[[0,231270500000000],[0,231583000000000],[0,242542000000000]],"131072":[[0,269084000000000],[0,269134000000000],[0,278209000000000]],"16384":[[0,33547222222222],[0,33554559523809],[0,33584000000000],[0,33667000000000]],"5120":[[0,10811250000000],[0,10825757575757],[0,10827285714285],[0,10858330000000]],"229376":[[0,462542000000000],[0,468375000000000],[0,469047619047619]],"5":[[0,91660000000],[0,91660000000],[0,92080000000],[0,93750000000]],"10":[[0,98750000000],[0,99580000000],[0,100000000000],[0,100830000000]],"28":[[0,142080000000],[0,142920000000],[0,143330000000],[0,144580000000]],"655360":[[0,1402833000000000],[0,1430673500000000]],"7168":[[0,14893750000000],[0,14915830000000],[0,14955410000000],[0,15042000000000]],"20480":[[0,41685606060606],[0,41750000000000],[0,41875000000000],[0,43127090000000]],"65536":[[0,131791666666666],[0,131991800000000],[0,132000000000000],[0,132667000000000]],"917504":[[0,1855042000000000],[0,1877750000000000]],"160":[[0,393330000000],[0,394170000000],[0,394580000000],[0,395000000000]],"640":[[0,1338750000000],[0,1341250000000],[0,1344580000000],[0,1346250000000]],"40":[[0,162920000000],[0,163330000000],[0,163750000000],[0,165000000000]],"393216":[[0,792916000000000],[0,813750000000000]],"57344":[[0,115417000000000],[0,116167000000000],[0,116209000000000],[0,116334000000000]],"4":[[0,90000000000],[0,90000000000],[0,90830000000],[0,92080000000]],"1":[[0,87080000000],[0,87910000000],[0,88330000000],[0,95830000000]],"768":[[0,1595410000000],[0,1597500000000],[0,1597910000000],[0,1599590000000]],"448":[[0,960410000000],[0,961250000000],[0,962500000000],[0,964160000000]],"8192":[[0,17084000000000],[0,17125830000000],[0,17183340000000],[0,17250000000000]],"12":[[0,101250000000],[0,101670000000],[0,102080000000],[0,103340000000]],"10240":[[0,21244160000000],[0,21250000000000],[0,21333000000000],[0,21458000000000]],"14336":[[0,29542000000000],[0,29583000000000],[0,29625000000000],[0,29750000000000]],"32768":[[0,66315979166666],[0,66334000000000],[0,66625000000000],[0,69829771428571]],"128":[[0,330000000000],[0,330000000000],[0,330000000000],[0,331670000000]],"4096":[[0,8785420000000],[0,8791660000000],[0,8802733333333],[0,8812500000000]],"49152":[[0,99708000000000],[0,99958000000000],[0,100999562500000],[0,101796437500000]],"262144":[[0,529917000000000],[0,535750000000000],[0,542500000000000]],"3":[[0,87920000000],[0,89160000000],[0,90410000000],[0,92080000000]],"98304":[[0,199167000000000],[0,199333000000000],[0,201250000000000],[0,202180541666666]]}},{"title":"Deque removeFirst (contiguous)","results":{"2048":[[0,4584000000000],[0,4666000000000],[0,4666000000000],[0,4667000000000]],"1048576":[[0,2394000000000000],[0,2447833000000000]],"96":[[0,208000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"327680":[[0,777041000000000],[0,782500000000000]],"384":[[0,875000000000],[0,875000000000],[0,875000000000],[0,916000000000]],"12288":[[0,27833000000000],[0,27834000000000],[0,27875000000000],[0,29167000000000]],"81920":[[0,185834000000000],[0,185875000000000],[0,185958000000000],[0,189458000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1280":[[0,2875000000000],[0,2916000000000],[0,2916000000000],[0,3292000000000]],"3584":[[0,8125000000000],[0,8125000000000],[0,8125000000000],[0,9208000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,1189458000000000],[0,1200042000000000]],"112":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"896":[[0,2041000000000],[0,2041000000000],[0,2041000000000],[0,2041000000000]],"192":[[0,416000000000],[0,458000000000],[0,458000000000],[0,459000000000]],"80":[[0,166000000000],[0,167000000000],[0,208000000000],[0,250000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,92875000000000],[0,92916000000000],[0,92917000000000],[0,93000000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,6916000000000],[0,6958000000000],[0,6958000000000],[0,7000000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"224":[[0,500000000000],[0,541000000000],[0,541000000000],[0,709000000000]],"2560":[[0,5791000000000],[0,5792000000000],[0,5833000000000],[0,5833000000000]],"1792":[[0,4042000000000],[0,4083000000000],[0,4083000000000],[0,4625000000000]],"1024":[[0,2333000000000],[0,2333000000000],[0,2333000000000],[0,2333000000000]],"6144":[[0,13917000000000],[0,13917000000000],[0,13958000000000],[0,13958000000000]],"56":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1809917000000000],[0,1915708000000000]],"163840":[[0,371500000000000],[0,371709000000000],[0,375792000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"32":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"28672":[[0,65000000000000],[0,65000000000000],[0,65041000000000],[0,65167000000000]],"512":[[0,1166000000000],[0,1167000000000],[0,1292000000000],[0,1583000000000]],"196608":[[0,446250000000000],[0,449250000000000],[0,466167000000000]],"458752":[[0,1064959000000000],[0,1069334000000000]],"24576":[[0,55708000000000],[0,55750000000000],[0,55750000000000],[0,55791000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,583000000000],[0,583000000000],[0,584000000000],[0,625000000000]],"1536":[[0,3458000000000],[0,3458000000000],[0,3500000000000],[0,3500000000000]],"64":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"320":[[0,708000000000],[0,708000000000],[0,750000000000],[0,750000000000]],"114688":[[0,260125000000000],[0,260209000000000],[0,260250000000000]],"131072":[[0,297292000000000],[0,297292000000000],[0,297417000000000]],"16384":[[0,37125000000000],[0,37125000000000],[0,37166000000000],[0,37167000000000]],"5120":[[0,11625000000000],[0,11625000000000],[0,11625000000000],[0,12541000000000]],"229376":[[0,520334000000000],[0,523750000000000],[0,524000000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"28":[[0,41000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"655360":[[0,1497834000000000],[0,1548500000000000]],"7168":[[0,16250000000000],[0,16250000000000],[0,16292000000000],[0,17625000000000]],"20480":[[0,46458000000000],[0,46459000000000],[0,46542000000000],[0,48791000000000]],"65536":[[0,148583000000000],[0,148666000000000],[0,148667000000000],[0,148875000000000]],"917504":[[0,2082084000000000],[0,2130750000000000]],"160":[[0,375000000000],[0,375000000000],[0,375000000000],[0,500000000000]],"640":[[0,1458000000000],[0,1458000000000],[0,1458000000000],[0,1500000000000]],"40":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"393216":[[0,891666000000000],[0,916541000000000]],"57344":[[0,130083000000000],[0,130083000000000],[0,130084000000000],[0,130125000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1750000000000],[0,1750000000000],[0,1750000000000],[0,1833000000000]],"448":[[0,1000000000000],[0,1000000000000],[0,1042000000000],[0,1042000000000]],"8192":[[0,18583000000000],[0,18583000000000],[0,18584000000000],[0,20166000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,23208000000000],[0,23208000000000],[0,23209000000000],[0,23292000000000]],"14336":[[0,32500000000000],[0,32500000000000],[0,32541000000000],[0,32542000000000]],"32768":[[0,74291000000000],[0,74292000000000],[0,74333000000000],[0,74334000000000]],"128":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"4096":[[0,9291000000000],[0,9291000000000],[0,9292000000000],[0,9333000000000]],"49152":[[0,111500000000000],[0,111500000000000],[0,111541000000000],[0,111583000000000]],"262144":[[0,594750000000000],[0,598042000000000],[0,607166000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,223000000000000],[0,223125000000000],[0,223250000000000],[0,226584000000000]]}},{"title":"Deque removeLast (contiguous)","results":{"2048":[[0,3833000000000],[0,3833000000000],[0,3833000000000],[0,3833000000000]],"1048576":[[0,1969083000000000],[0,2008708000000000]],"96":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"327680":[[0,629834000000000],[0,630833000000000]],"384":[[0,708000000000],[0,708000000000],[0,750000000000],[0,750000000000]],"12288":[[0,23000000000000],[0,23042000000000],[0,23083000000000],[0,24125000000000]],"81920":[[0,153541000000000],[0,153583000000000],[0,153625000000000],[0,153667000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2375000000000],[0,2416000000000],[0,2417000000000],[0,2709000000000]],"3584":[[0,6709000000000],[0,6709000000000],[0,6709000000000],[0,7042000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,984458000000000],[0,986500000000000]],"112":[[0,167000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"896":[[0,1666000000000],[0,1667000000000],[0,1667000000000],[0,1708000000000]],"192":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"80":[[0,166000000000],[0,166000000000],[0,166000000000],[0,209000000000]],"24":[[0,41000000000],[0,41000000000],[0,83000000000],[0,83000000000]],"40960":[[0,76708000000000],[0,76750000000000],[0,76791000000000],[0,76792000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,5750000000000],[0,5750000000000],[0,5750000000000],[0,5750000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,417000000000],[0,417000000000],[0,458000000000],[0,583000000000]],"2560":[[0,4791000000000],[0,4792000000000],[0,4792000000000],[0,4792000000000]],"1792":[[0,3333000000000],[0,3334000000000],[0,3334000000000],[0,3750000000000]],"1024":[[0,1916000000000],[0,1916000000000],[0,1917000000000],[0,1917000000000]],"6144":[[0,11500000000000],[0,11500000000000],[0,11541000000000],[0,11541000000000]],"56":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1486333000000000],[0,1489917000000000]],"163840":[[0,307208000000000],[0,310459000000000],[0,310875000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"32":[[0,42000000000],[0,42000000000],[0,83000000000],[0,84000000000]],"14":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28672":[[0,53750000000000],[0,53750000000000],[0,53750000000000],[0,53791000000000]],"512":[[0,958000000000],[0,958000000000],[0,1083000000000],[0,1291000000000]],"196608":[[0,368666000000000],[0,368875000000000],[0,386292000000000]],"458752":[[0,864958000000000],[0,867792000000000]],"24576":[[0,46000000000000],[0,46041000000000],[0,46083000000000],[0,46083000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,500000000000],[0,500000000000]],"1536":[[0,2875000000000],[0,2875000000000],[0,2875000000000],[0,2875000000000]],"64":[[0,125000000000],[0,125000000000],[0,167000000000],[0,167000000000]],"320":[[0,625000000000],[0,625000000000],[0,625000000000],[0,750000000000]],"114688":[[0,215000000000000],[0,215000000000000],[0,234250000000000]],"131072":[[0,245708000000000],[0,245791000000000],[0,251417000000000]],"16384":[[0,30667000000000],[0,30708000000000],[0,30708000000000],[0,30750000000000]],"5120":[[0,9583000000000],[0,9583000000000],[0,9625000000000],[0,10417000000000]],"229376":[[0,429958000000000],[0,443500000000000],[0,444458000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"655360":[[0,1228666000000000],[0,1228916000000000]],"7168":[[0,13416000000000],[0,13417000000000],[0,13458000000000],[0,14542000000000]],"20480":[[0,38333000000000],[0,38375000000000],[0,38458000000000],[0,40250000000000]],"65536":[[0,122833000000000],[0,122875000000000],[0,122875000000000],[0,122875000000000]],"917504":[[0,1727583000000000],[0,1732916000000000]],"160":[[0,291000000000],[0,291000000000],[0,333000000000],[0,416000000000]],"640":[[0,1208000000000],[0,1208000000000],[0,1208000000000],[0,1250000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"393216":[[0,737375000000000],[0,742667000000000]],"57344":[[0,107417000000000],[0,107500000000000],[0,107500000000000],[0,107500000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1416000000000],[0,1417000000000],[0,1458000000000],[0,1500000000000]],"448":[[0,833000000000],[0,833000000000],[0,834000000000],[0,875000000000]],"8192":[[0,15375000000000],[0,15375000000000],[0,15375000000000],[0,16625000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,19166000000000],[0,19167000000000],[0,19250000000000],[0,19250000000000]],"14336":[[0,26792000000000],[0,26875000000000],[0,26875000000000],[0,26875000000000]],"32768":[[0,61375000000000],[0,61417000000000],[0,61458000000000],[0,61459000000000]],"128":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"4096":[[0,7666000000000],[0,7666000000000],[0,7667000000000],[0,7667000000000]],"49152":[[0,92041000000000],[0,92125000000000],[0,92125000000000],[0,92166000000000]],"262144":[[0,491625000000000],[0,494792000000000],[0,518875000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,184208000000000],[0,184291000000000],[0,184333000000000],[0,184334000000000]]}},{"title":"Deque sort (contiguous)","results":{"2048":[[0,86416000000000],[0,87459000000000],[0,91375000000000],[0,91875000000000]],"1048576":[[0,91693500000000000],[0,93381209000000000]],"96":[[0,2333000000000],[0,2375000000000],[0,2500000000000],[0,2542000000000]],"327680":[[0,26559291000000000],[0,27556250000000000]],"384":[[0,11250000000000],[0,11625000000000],[0,12500000000000],[0,12916000000000]],"12288":[[0,734542000000000],[0,735166000000000],[0,754417000000000],[0,829459000000000]],"81920":[[0,5784667000000000],[0,5785959000000000],[0,5813042000000000],[0,5818500000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,51042000000000],[0,51875000000000],[0,52625000000000],[0,57792000000000]],"3584":[[0,190167000000000],[0,190667000000000],[0,192334000000000],[0,202459000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,43314458000000000],[0,43774083000000000]],"112":[[0,3000000000000],[0,3125000000000],[0,3250000000000],[0,3709000000000]],"896":[[0,35709000000000],[0,35792000000000],[0,36084000000000],[0,36375000000000]],"192":[[0,4667000000000],[0,4750000000000],[0,4834000000000],[0,5208000000000]],"80":[[0,1208000000000],[0,1500000000000],[0,1834000000000],[0,2125000000000]],"24":[[0,208000000000],[0,209000000000],[0,250000000000],[0,291000000000]],"40960":[[0,2703875000000000],[0,2709709000000000],[0,2720166000000000],[0,2722666000000000]],"16":[[0,84000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"3072":[[0,152667000000000],[0,153583000000000],[0,153791000000000],[0,153792000000000]],"20":[[0,125000000000],[0,125000000000],[0,166000000000],[0,209000000000]],"224":[[0,6625000000000],[0,6875000000000],[0,7709000000000],[0,9250000000000]],"2560":[[0,118833000000000],[0,119250000000000],[0,120250000000000],[0,123875000000000]],"1792":[[0,83916000000000],[0,84292000000000],[0,86125000000000],[0,104417000000000]],"1024":[[0,35417000000000],[0,35583000000000],[0,35750000000000],[0,38834000000000]],"6144":[[0,337292000000000],[0,337833000000000],[0,338250000000000],[0,345125000000000]],"56":[[0,1292000000000],[0,1333000000000],[0,1500000000000],[0,1500000000000]],"786432":[[0,70588334000000000],[0,71116542000000000]],"163840":[[0,12285916000000000],[0,12390958000000000],[0,12898208000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,791000000000],[0,791000000000],[0,1000000000000],[0,1000000000000]],"32":[[0,333000000000],[0,333000000000],[0,375000000000],[0,375000000000]],"14":[[0,42000000000],[0,83000000000],[0,125000000000],[0,167000000000]],"28672":[[0,1954208000000000],[0,1956042000000000],[0,1960833000000000],[0,1978958000000000]],"512":[[0,13375000000000],[0,14083000000000],[0,17167000000000],[0,18417000000000]],"196608":[[0,15681750000000000],[0,15742042000000000],[0,16222125000000000]],"458752":[[0,40236334000000000],[0,41881458000000000]],"24576":[[0,1597291000000000],[0,1600750000000000],[0,1604708000000000],[0,1631625000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,5084000000000],[0,5333000000000],[0,5541000000000],[0,5666000000000]],"1536":[[0,66208000000000],[0,66958000000000],[0,67291000000000],[0,67875000000000]],"64":[[0,1000000000000],[0,1125000000000],[0,1250000000000],[0,1666000000000]],"320":[[0,7667000000000],[0,7792000000000],[0,8291000000000],[0,9167000000000]],"114688":[[0,8879583000000000],[0,9062792000000000],[0,10231625000000000]],"131072":[[0,9468833000000000],[0,9504666000000000],[0,9763916000000000]],"16384":[[0,952875000000000],[0,955333000000000],[0,959500000000000],[0,979042000000000]],"5120":[[0,263209000000000],[0,263458000000000],[0,265292000000000],[0,267333000000000]],"229376":[[0,18906000000000000],[0,19117667000000000],[0,20034125000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"28":[[0,250000000000],[0,292000000000],[0,292000000000],[0,333000000000]],"655360":[[0,56738208000000000],[0,58459208000000000]],"7168":[[0,415417000000000],[0,415834000000000],[0,419500000000000],[0,424500000000000]],"20480":[[0,1264750000000000],[0,1265166000000000],[0,1268417000000000],[0,1270291000000000]],"65536":[[0,4410834000000000],[0,4430500000000000],[0,4434042000000000],[0,4448292000000000]],"917504":[[0,84694041000000000],[0,88006834000000000]],"160":[[0,3542000000000],[0,3625000000000],[0,3875000000000],[0,5208000000000]],"640":[[0,19917000000000],[0,20000000000000],[0,21417000000000],[0,24500000000000]],"40":[[0,500000000000],[0,625000000000],[0,667000000000],[0,708000000000]],"393216":[[0,32924458000000000],[0,33645541000000000]],"57344":[[0,4177375000000000],[0,4181625000000000],[0,4189084000000000],[0,4376541000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,27500000000000],[0,27792000000000],[0,28916000000000],[0,29000000000000]],"448":[[0,14750000000000],[0,15083000000000],[0,15375000000000],[0,16000000000000]],"8192":[[0,434291000000000],[0,435375000000000],[0,436625000000000],[0,445667000000000]],"12":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10240":[[0,576375000000000],[0,578167000000000],[0,579416000000000],[0,579875000000000]],"14336":[[0,900334000000000],[0,902000000000000],[0,908167000000000],[0,910625000000000]],"32768":[[0,2065416000000000],[0,2068708000000000],[0,2070292000000000],[0,2076625000000000]],"128":[[0,2250000000000],[0,2333000000000],[0,2334000000000],[0,2500000000000]],"4096":[[0,196333000000000],[0,196917000000000],[0,198333000000000],[0,201958000000000]],"49152":[[0,3411875000000000],[0,3426625000000000],[0,3429375000000000],[0,3472917000000000]],"262144":[[0,20410417000000000],[0,20605250000000000],[0,21132167000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,7259291000000000],[0,7288959000000000],[0,7315167000000000],[0,7381583000000000]]}},{"title":"Deque sort (discontiguous)","results":{"2048":[[0,51334000000000],[0,51791000000000],[0,52125000000000],[0,54125000000000]],"1048576":[[0,59648750000000000],[0,60372875000000000]],"96":[[0,1208000000000],[0,1250000000000],[0,1292000000000],[0,1334000000000]],"327680":[[0,17292417000000000],[0,17777959000000000]],"384":[[0,5292000000000],[0,5292000000000],[0,5375000000000],[0,5500000000000]],"12288":[[0,440417000000000],[0,458083000000000],[0,461750000000000],[0,472500000000000]],"81920":[[0,3688416000000000],[0,3694167000000000],[0,3706250000000000],[0,3713875000000000]],"8":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"1280":[[0,26792000000000],[0,27042000000000],[0,27167000000000],[0,30458000000000]],"3584":[[0,103500000000000],[0,103500000000000],[0,104292000000000],[0,109833000000000]],"7":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"524288":[[0,28410042000000000],[0,28748958000000000]],"112":[[0,1458000000000],[0,1542000000000],[0,1583000000000],[0,1666000000000]],"896":[[0,15792000000000],[0,15958000000000],[0,16167000000000],[0,16334000000000]],"192":[[0,2292000000000],[0,2416000000000],[0,2416000000000],[0,2542000000000]],"80":[[0,833000000000],[0,1000000000000],[0,1000000000000],[0,1042000000000]],"24":[[0,208000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"40960":[[0,1716750000000000],[0,1717500000000000],[0,1728208000000000],[0,1740875000000000]],"16":[[0,167000000000],[0,208000000000],[0,208000000000],[0,291000000000]],"3072":[[0,86000000000000],[0,86000000000000],[0,86208000000000],[0,87791000000000]],"20":[[0,209000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"224":[[0,3083000000000],[0,3166000000000],[0,3375000000000],[0,4416000000000]],"2560":[[0,68458000000000],[0,68875000000000],[0,69792000000000],[0,71375000000000]],"1792":[[0,43000000000000],[0,43250000000000],[0,45041000000000],[0,48958000000000]],"1024":[[0,19292000000000],[0,19625000000000],[0,19625000000000],[0,22250000000000]],"6144":[[0,197625000000000],[0,197791000000000],[0,198000000000000],[0,198083000000000]],"56":[[0,542000000000],[0,583000000000],[0,583000000000],[0,625000000000]],"786432":[[0,43589583000000000],[0,43892292000000000]],"163840":[[0,7899541000000000],[0,7988417000000000],[0,8187291000000000]],"6":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"48":[[0,458000000000],[0,458000000000],[0,542000000000],[0,625000000000]],"32":[[0,291000000000],[0,292000000000],[0,292000000000],[0,375000000000]],"14":[[0,166000000000],[0,167000000000],[0,208000000000],[0,209000000000]],"28672":[[0,1155542000000000],[0,1158333000000000],[0,1172125000000000],[0,1188958000000000]],"512":[[0,6459000000000],[0,6542000000000],[0,6708000000000],[0,7459000000000]],"196608":[[0,9740667000000000],[0,9856708000000000],[0,10085583000000000]],"458752":[[0,24698584000000000],[0,25086292000000000]],"24576":[[0,963541000000000],[0,965125000000000],[0,974916000000000],[0,985667000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,2625000000000],[0,2875000000000],[0,2875000000000],[0,3000000000000]],"1536":[[0,34750000000000],[0,35542000000000],[0,35625000000000],[0,35750000000000]],"64":[[0,708000000000],[0,834000000000],[0,875000000000],[0,959000000000]],"320":[[0,3666000000000],[0,3875000000000],[0,4125000000000],[0,4417000000000]],"114688":[[0,5359250000000000],[0,5412042000000000],[0,5839625000000000]],"131072":[[0,6226541000000000],[0,6261375000000000],[0,6490708000000000]],"16384":[[0,614916000000000],[0,616834000000000],[0,619541000000000],[0,622291000000000]],"5120":[[0,160041000000000],[0,160959000000000],[0,161334000000000],[0,161584000000000]],"229376":[[0,11530792000000000],[0,11556833000000000],[0,11743375000000000]],"5":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"10":[[0,125000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"28":[[0,291000000000],[0,291000000000],[0,292000000000],[0,292000000000]],"655360":[[0,36022500000000000],[0,36369917000000000]],"7168":[[0,236292000000000],[0,236958000000000],[0,240250000000000],[0,243000000000000]],"20480":[[0,785375000000000],[0,795917000000000],[0,799625000000000],[0,850292000000000]],"65536":[[0,2908792000000000],[0,2909333000000000],[0,2919916000000000],[0,2925208000000000]],"917504":[[0,52213458000000000],[0,52319875000000000]],"160":[[0,1833000000000],[0,1959000000000],[0,2000000000000],[0,2041000000000]],"640":[[0,9000000000000],[0,9167000000000],[0,9334000000000],[0,9792000000000]],"40":[[0,333000000000],[0,375000000000],[0,375000000000],[0,416000000000]],"393216":[[0,20451875000000000],[0,20947167000000000]],"57344":[[0,2494834000000000],[0,2495250000000000],[0,2498209000000000],[0,2559666000000000]],"4":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,12083000000000],[0,12292000000000],[0,13833000000000],[0,14375000000000]],"448":[[0,6542000000000],[0,6583000000000],[0,6625000000000],[0,6834000000000]],"8192":[[0,281666000000000],[0,284125000000000],[0,284292000000000],[0,284417000000000]],"12":[[0,166000000000],[0,166000000000],[0,167000000000],[0,167000000000]],"10240":[[0,358166000000000],[0,358375000000000],[0,363291000000000],[0,366250000000000]],"14336":[[0,526833000000000],[0,528417000000000],[0,536875000000000],[0,538250000000000]],"32768":[[0,1340625000000000],[0,1342417000000000],[0,1360417000000000],[0,1479709000000000]],"128":[[0,1333000000000],[0,1416000000000],[0,1417000000000],[0,1500000000000]],"4096":[[0,124083000000000],[0,124541000000000],[0,124709000000000],[0,125334000000000]],"49152":[[0,2098917000000000],[0,2099625000000000],[0,2101667000000000],[0,2131333000000000]],"262144":[[0,13476541000000000],[0,13477667000000000],[0,13581583000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,4520333000000000],[0,4524208000000000],[0,4535458000000000],[0,4600875000000000]]}},{"title":"Deque sequential iteration (discontiguous, iterator)","results":{"2048":[[0,1682080000000],[0,1682080000000],[0,1682080000000],[0,1682080000000]],"1048576":[[0,852458000000000],[0,864799272727272]],"96":[[0,89170000000],[0,89170000000],[0,89580000000],[0,89580000000]],"327680":[[0,266708000000000],[0,273500000000000]],"384":[[0,330410000000],[0,330830000000],[0,331250000000],[0,332500000000]],"12288":[[0,9994565217391],[0,9995830000000],[0,10006660000000],[0,10584000000000]],"81920":[[0,66541000000000],[0,66583000000000],[0,66625000000000],[0,66750000000000]],"8":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"1280":[[0,1057910000000],[0,1057920000000],[0,1058750000000],[0,1109289855072]],"3584":[[0,2928750000000],[0,2929160000000],[0,2929170000000],[0,2929521276595]],"7":[[0,14160000000],[0,14170000000],[0,14580000000],[0,14590000000]],"524288":[[0,426750000000000],[0,436729181818181]],"112":[[0,102080000000],[0,102090000000],[0,102090000000],[0,102500000000]],"896":[[0,746181818181],[0,746660000000],[0,746670000000],[0,747080000000]],"192":[[0,175410000000],[0,175410000000],[0,175420000000],[0,175830000000]],"80":[[0,76250000000],[0,76250000000],[0,76250000000],[0,76660000000]],"24":[[0,27500000000],[0,27910000000],[0,28330000000],[0,28330000000]],"40960":[[0,33292000000000],[0,33292000000000],[0,33304580000000],[0,33333000000000]],"16":[[0,21250000000],[0,21250000000],[0,21250000000],[0,21660000000]],"3072":[[0,2512910000000],[0,2512920000000],[0,2512920000000],[0,2513330000000]],"20":[[0,24580000000],[0,24580000000],[0,24580000000],[0,24590000000]],"224":[[0,200000000000],[0,200830000000],[0,201250000000],[0,201660000000]],"2560":[[0,2084000000000],[0,2097578947368],[0,2097920000000],[0,2098750000000]],"1792":[[0,1459000000000],[0,1474160000000],[0,1474580000000],[0,1670000000000]],"1024":[[0,850000000000],[0,850410000000],[0,850420000000],[0,851250000000]],"6144":[[0,5000000000000],[0,5006670000000],[0,5007500000000],[0,5007928571428]],"56":[[0,57500000000],[0,57500000000],[0,57500000000],[0,57910000000]],"786432":[[0,649852800000000],[0,653500000000000]],"163840":[[0,133125000000000],[0,133166000000000],[0,135684931506849]],"6":[[0,13330000000],[0,13330000000],[0,13330000000],[0,13750000000]],"48":[[0,50410000000],[0,50410000000],[0,50420000000],[0,50830000000]],"32":[[0,34160000000],[0,34580000000],[0,34580000000],[0,34580000000]],"14":[[0,19580000000],[0,20000000000],[0,20000000000],[0,20000000000]],"28672":[[0,23334000000000],[0,23375000000000],[0,23375000000000],[0,23417000000000]],"512":[[0,435000000000],[0,435000000000],[0,435410000000],[0,435830000000]],"196608":[[0,159792000000000],[0,159834000000000],[0,159917000000000]],"458752":[[0,372916000000000],[0,381709000000000]],"24576":[[0,19958000000000],[0,20000000000000],[0,20042000000000],[0,20042000000000]],"2":[[0,7090000000],[0,7090000000],[0,7500000000],[0,8750000000]],"256":[[0,226670000000],[0,227080000000],[0,227080000000],[0,227090000000]],"1536":[[0,1266250000000],[0,1266250000000],[0,1267080000000],[0,1267080000000]],"64":[[0,63750000000],[0,63750000000],[0,63750000000],[0,63750000000]],"320":[[0,279160000000],[0,279580000000],[0,281250000000],[0,292500000000]],"114688":[[0,93145833333333],[0,93208000000000],[0,93708000000000]],"131072":[[0,106542000000000],[0,106582430107526],[0,106791000000000]],"16384":[[0,13291000000000],[0,13320410000000],[0,13321250000000],[0,13375000000000]],"5120":[[0,4176136363636],[0,4176250000000],[0,4176250000000],[0,4176250000000]],"229376":[[0,186375000000000],[0,186375000000000],[0,186792000000000]],"5":[[0,12500000000],[0,12500000000],[0,12500000000],[0,12500000000]],"10":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"28":[[0,31250000000],[0,31250000000],[0,31250000000],[0,31250000000]],"655360":[[0,533048611111111],[0,535125000000000]],"7168":[[0,5833000000000],[0,5838340000000],[0,5838340000000],[0,5873330000000]],"20480":[[0,16646250000000],[0,16666500000000],[0,16709000000000],[0,16709000000000]],"65536":[[0,53250000000000],[0,53292000000000],[0,53333000000000],[0,53417000000000]],"917504":[[0,755322916666666],[0,770614583333333]],"160":[[0,149160000000],[0,149160000000],[0,149170000000],[0,149580000000]],"640":[[0,538330000000],[0,538750000000],[0,538750000000],[0,539580000000]],"40":[[0,40420000000],[0,40830000000],[0,41250000000],[0,41250000000]],"393216":[[0,319750000000000],[0,324041000000000]],"57344":[[0,46568428571428],[0,46583000000000],[0,46583000000000],[0,46875000000000]],"4":[[0,11660000000],[0,11670000000],[0,11670000000],[0,12080000000]],"1":[[0,6250000000],[0,6660000000],[0,6660000000],[0,6670000000]],"768":[[0,643330000000],[0,643330000000],[0,643340000000],[0,643750000000]],"448":[[0,382500000000],[0,382910000000],[0,382910000000],[0,383330000000]],"8192":[[0,6666000000000],[0,6669580000000],[0,6670420000000],[0,6672910000000]],"12":[[0,18330000000],[0,18330000000],[0,18330000000],[0,18330000000]],"10240":[[0,8331250000000],[0,8333330000000],[0,8335000000000],[0,8335410000000]],"14336":[[0,11657500000000],[0,11658330000000],[0,11687500000000],[0,11708000000000]],"32768":[[0,26625000000000],[0,26655000000000],[0,26659580000000],[0,26830000000000]],"128":[[0,115410000000],[0,115410000000],[0,115410000000],[0,115420000000]],"4096":[[0,3345000000000],[0,3345000000000],[0,3345000000000],[0,3345000000000]],"49152":[[0,39925000000000],[0,39953330000000],[0,40000000000000],[0,40042000000000]],"262144":[[0,213000000000000],[0,213000000000000],[0,213250000000000]],"3":[[0,7910000000],[0,8330000000],[0,8330000000],[0,8330000000]],"98304":[[0,79875000000000],[0,79958000000000],[0,80000000000000],[0,80042000000000]]}},{"title":"Deque sequential iteration (contiguous, indices)","results":{"2048":[[0,2208000000000],[0,2220250000000],[0,2220830000000],[0,2221670000000]],"1048576":[[0,1135250000000000],[0,1136000000000000]],"96":[[0,107583333333],[0,108330000000],[0,108330000000],[0,108330000000]],"327680":[[0,354917000000000],[0,371339730769230]],"384":[[0,416500000000],[0,419590000000],[0,419590000000],[0,453340000000]],"12288":[[0,13291500000000],[0,13292000000000],[0,13309170000000],[0,13319333333333]],"81920":[[0,88663250000000],[0,88666727272727],[0,88792000000000],[0,89074590000000]],"8":[[0,10000000000],[0,10420000000],[0,10420000000],[0,10830000000]],"1280":[[0,1388666666666],[0,1389580000000],[0,1390000000000],[0,1390830000000]],"3584":[[0,3883330000000],[0,3883330000000],[0,3883588235294],[0,3883750000000]],"7":[[0,9160000000],[0,9160000000],[0,9580000000],[0,9580000000]],"524288":[[0,568875000000000],[0,570667000000000]],"112":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125410000000]],"896":[[0,974137931034],[0,974160000000],[0,974160000000],[0,974170000000]],"192":[[0,211975000000],[0,212080000000],[0,212080000000],[0,212080000000]],"80":[[0,83000000000],[0,90410000000],[0,90830000000],[0,90830000000]],"24":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27910000000]],"40960":[[0,44333000000000],[0,44375000000000],[0,44458000000000],[0,45405420000000]],"16":[[0,18750000000],[0,19160000000],[0,19160000000],[0,19580000000]],"3072":[[0,3323000000000],[0,3329170000000],[0,3329170000000],[0,3329170000000]],"20":[[0,23330000000],[0,23340000000],[0,23750000000],[0,23750000000]],"224":[[0,246250000000],[0,246660000000],[0,246660000000],[0,246660000000]],"2560":[[0,2770500000000],[0,2775000000000],[0,2775420000000],[0,2775830000000]],"1792":[[0,1937500000000],[0,1943647058823],[0,1943750000000],[0,2202800000000]],"1024":[[0,1104000000000],[0,1112500000000],[0,1112910000000],[0,1112920000000]],"6144":[[0,6625000000000],[0,6654160000000],[0,6654580000000],[0,6655000000000]],"56":[[0,64580000000],[0,65000000000],[0,65000000000],[0,65000000000]],"786432":[[0,855375000000000],[0,859890090909090]],"163840":[[0,177375000000000],[0,177458000000000],[0,177500000000000]],"6":[[0,7910000000],[0,8330000000],[0,8330000000],[0,8340000000]],"48":[[0,52250000000],[0,56250000000],[0,56250000000],[0,56250000000]],"32":[[0,36250000000],[0,36250000000],[0,36660000000],[0,36660000000]],"14":[[0,16660000000],[0,16670000000],[0,17080000000],[0,17080000000]],"28672":[[0,31041647058823],[0,31060000000000],[0,31084000000000],[0,31084000000000]],"512":[[0,542000000000],[0,558330000000],[0,558330000000],[0,558330000000]],"196608":[[0,212812500000000],[0,212854250000000],[0,228121023809523]],"458752":[[0,504379368421052],[0,507791000000000]],"24576":[[0,26584000000000],[0,26625000000000],[0,26667000000000],[0,27433330000000]],"2":[[0,4160000000],[0,4580000000],[0,4580000000],[0,6250000000]],"256":[[0,281250000000],[0,281250000000],[0,281250000000],[0,281250000000]],"1536":[[0,1666670000000],[0,1666670000000],[0,1667000000000],[0,1667080000000]],"64":[[0,73330000000],[0,73340000000],[0,73750000000],[0,73750000000]],"320":[[0,350420000000],[0,350420000000],[0,367500000000],[0,397910000000]],"114688":[[0,124150000000000],[0,124250000000000],[0,124291000000000]],"131072":[[0,142250000000000],[0,142986000000000],[0,149191262295081]],"16384":[[0,17737920000000],[0,17750000000000],[0,17757920000000],[0,17792000000000]],"5120":[[0,5545840000000],[0,5545840000000],[0,5546250000000],[0,5546670000000]],"229376":[[0,248541000000000],[0,253944810810810],[0,261959000000000]],"5":[[0,7080000000],[0,7500000000],[0,7500000000],[0,7500000000]],"10":[[0,12500000000],[0,12500000000],[0,12910000000],[0,12910000000]],"28":[[0,31670000000],[0,32080000000],[0,32080000000],[0,32080000000]],"655360":[[0,710208000000000],[0,714167000000000]],"7168":[[0,7750000000000],[0,7763330000000],[0,7772090000000],[0,7792000000000]],"20480":[[0,22167000000000],[0,22205000000000],[0,22208000000000],[0,22250000000000]],"65536":[[0,70939102564102],[0,71000000000000],[0,71041000000000],[0,71611660000000]],"917504":[[0,1000384222222222],[0,1014000000000000]],"160":[[0,177080000000],[0,177090000000],[0,177090000000],[0,177500000000]],"640":[[0,697080000000],[0,697080000000],[0,697080000000],[0,697080000000]],"40":[[0,47500000000],[0,47910000000],[0,47910000000],[0,47910000000]],"393216":[[0,429208000000000],[0,432214000000000]],"57344":[[0,62125000000000],[0,62167000000000],[0,62622080000000],[0,65709000000000]],"4":[[0,5830000000],[0,6250000000],[0,6250000000],[0,6250000000]],"1":[[0,1670000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,822750000000],[0,835410000000],[0,835420000000],[0,835420000000]],"448":[[0,488750000000],[0,489160000000],[0,489160000000],[0,498750000000]],"8192":[[0,8870840000000],[0,8871250000000],[0,8871660000000],[0,8917000000000]],"12":[[0,13916666666],[0,14580000000],[0,15000000000],[0,15000000000]],"10240":[[0,11084000000000],[0,11087500000000],[0,11087500000000],[0,11096250000000]],"14336":[[0,15500000000000],[0,15519580000000],[0,15635410000000],[0,15667000000000]],"32768":[[0,35458000000000],[0,35489750000000],[0,35500000000000],[0,35502500000000]],"128":[[0,142500000000],[0,142910000000],[0,142910000000],[0,142910000000]],"4096":[[0,4437500000000],[0,4437500000000],[0,4437500000000],[0,4437500000000]],"49152":[[0,53250000000000],[0,53271000000000],[0,53292000000000],[0,53650840000000]],"262144":[[0,283750000000000],[0,287854000000000],[0,288250000000000]],"3":[[0,4580000000],[0,5000000000],[0,5000000000],[0,5410000000]],"98304":[[0,106458000000000],[0,106500000000000],[0,106541000000000],[0,106541000000000]]}},{"title":"Deque sequential iteration (discontiguous, indices)","results":{"2048":[[0,2230000000000],[0,2230410000000],[0,2230410000000],[0,2231660000000]],"1048576":[[0,1135083000000000],[0,1159916625000000]],"96":[[0,108642857142],[0,108750000000],[0,108750000000],[0,109160000000]],"327680":[[0,354958000000000],[0,369130208333333]],"384":[[0,429160000000],[0,429160000000],[0,429170000000],[0,429580000000]],"12288":[[0,13292000000000],[0,13333500000000],[0,13334000000000],[0,13375000000000]],"81920":[[0,88673583333333],[0,88674272727272],[0,89208000000000],[0,89317500000000]],"8":[[0,10420000000],[0,10830000000],[0,10830000000],[0,10830000000]],"1280":[[0,1399160000000],[0,1399160000000],[0,1399170000000],[0,1400420000000]],"3584":[[0,3875000000000],[0,3892500000000],[0,3892910000000],[0,3892920000000]],"7":[[0,9580000000],[0,9580000000],[0,10000000000],[0,10000000000]],"524288":[[0,569497588235294],[0,585334000000000]],"112":[[0,125840000000],[0,126250000000],[0,126250000000],[0,126660000000]],"896":[[0,958000000000],[0,983330000000],[0,983330000000],[0,983750000000]],"192":[[0,208000000000],[0,212910000000],[0,212920000000],[0,213330000000]],"80":[[0,84000000000],[0,91660000000],[0,91660000000],[0,91660000000]],"24":[[0,28330000000],[0,30410000000],[0,30410000000],[0,30420000000]],"40960":[[0,44375000000000],[0,44375000000000],[0,44376250000000],[0,44458000000000]],"16":[[0,19160000000],[0,19170000000],[0,19580000000],[0,20000000000]],"3072":[[0,3334000000000],[0,3338750000000],[0,3338750000000],[0,3339160000000]],"20":[[0,23330000000],[0,23330000000],[0,23750000000],[0,23750000000]],"224":[[0,247500000000],[0,247500000000],[0,247500000000],[0,247910000000]],"2560":[[0,2784580000000],[0,2784580000000],[0,2784580000000],[0,2785000000000]],"1792":[[0,1952920000000],[0,1952920000000],[0,1953330000000],[0,2375000000000]],"1024":[[0,1121250000000],[0,1121846153846],[0,1122080000000],[0,1122080000000]],"6144":[[0,6663750000000],[0,6663750000000],[0,6664170000000],[0,6664580000000]],"56":[[0,65410000000],[0,65410000000],[0,65410000000],[0,65410000000]],"786432":[[0,851584000000000],[0,851875000000000]],"163840":[[0,177334000000000],[0,177417000000000],[0,181500000000000]],"6":[[0,8330000000],[0,8330000000],[0,8750000000],[0,8750000000]],"48":[[0,56250000000],[0,56660000000],[0,56660000000],[0,56670000000]],"32":[[0,36660000000],[0,36660000000],[0,36660000000],[0,36670000000]],"14":[[0,17080000000],[0,17080000000],[0,17090000000],[0,17500000000]],"28672":[[0,31042000000000],[0,31047266666666],[0,31051470588235],[0,31054687500000]],"512":[[0,567418181818],[0,567500000000],[0,567622950819],[0,567910000000]],"196608":[[0,212875000000000],[0,212917000000000],[0,229267441860465]],"458752":[[0,496667000000000],[0,497125000000000]],"24576":[[0,26583000000000],[0,26612847222222],[0,26666000000000],[0,26667000000000]],"2":[[0,4580000000],[0,4580000000],[0,4580000000],[0,4580000000]],"256":[[0,282090000000],[0,282090000000],[0,282500000000],[0,282500000000]],"1536":[[0,1625000000000],[0,1671529411764],[0,1676250000000],[0,1676250000000]],"64":[[0,73750000000],[0,73750000000],[0,74160000000],[0,74160000000]],"320":[[0,333000000000],[0,352080000000],[0,352080000000],[0,369580000000]],"114688":[[0,124250000000000],[0,124913961038961],[0,127164000000000]],"131072":[[0,141875000000000],[0,141917000000000],[0,146459000000000]],"16384":[[0,17750000000000],[0,17750000000000],[0,17768330000000],[0,17929170000000]],"5120":[[0,5542000000000],[0,5555000000000],[0,5555410000000],[0,5555750000000]],"229376":[[0,248458000000000],[0,249000000000000],[0,251090820512820]],"5":[[0,7500000000],[0,7500000000],[0,7500000000],[0,7500000000]],"10":[[0,12910000000],[0,12910000000],[0,12910000000],[0,12910000000]],"28":[[0,32080000000],[0,32090000000],[0,32500000000],[0,32500000000]],"655360":[[0,709584000000000],[0,723227538461538]],"7168":[[0,7750000000000],[0,7772500000000],[0,7791000000000],[0,7792000000000]],"20480":[[0,22166000000000],[0,22196146341463],[0,22209000000000],[0,22250000000000]],"65536":[[0,70956250000000],[0,70959000000000],[0,71000000000000],[0,71000000000000]],"917504":[[0,994417000000000],[0,1021667000000000]],"160":[[0,177000000000],[0,177125000000],[0,178330000000],[0,178330000000]],"640":[[0,706250000000],[0,706660000000],[0,706660000000],[0,706670000000]],"40":[[0,47500000000],[0,47500000000],[0,47910000000],[0,47910000000]],"393216":[[0,425958000000000],[0,436437500000000]],"57344":[[0,62083000000000],[0,62167000000000],[0,62208000000000],[0,62771250000000]],"4":[[0,6250000000],[0,6250000000],[0,6250000000],[0,7080000000]],"1":[[0,1670000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,833000000000],[0,834000000000],[0,845000000000],[0,845000000000]],"448":[[0,498330000000],[0,498330000000],[0,498330000000],[0,498330000000]],"8192":[[0,8880410000000],[0,8880830000000],[0,8916000000000],[0,8916000000000]],"12":[[0,13888888888],[0,15000000000],[0,15000000000],[0,15000000000]],"10240":[[0,11096670000000],[0,11100410000000],[0,11100830000000],[0,11125000000000]],"14336":[[0,15530830000000],[0,15542000000000],[0,15554166666666],[0,15560000000000]],"32768":[[0,35500000000000],[0,35517080000000],[0,35541000000000],[0,35583000000000]],"128":[[0,125000000000],[0,143330000000],[0,143330000000],[0,143750000000]],"4096":[[0,4437500000000],[0,4446660000000],[0,4447080000000],[0,4450000000000]],"49152":[[0,53208000000000],[0,53208000000000],[0,53208000000000],[0,53250000000000]],"262144":[[0,283834000000000],[0,283875000000000],[0,292292000000000]],"3":[[0,5410000000],[0,5410000000],[0,5410000000],[0,5410000000]],"98304":[[0,106417000000000],[0,106417000000000],[0,106542000000000],[0,107082814814814]]}},{"title":"Deque subscript get, random offsets (discontiguous)","results":{"2048":[[0,2208000000000],[0,2221250000000],[0,2221250000000],[0,2221660000000]],"1048576":[[0,1150854500000000],[0,1174270875000000]],"96":[[0,108330000000],[0,108400000000],[0,108750000000],[0,109375000000]],"327680":[[0,354729000000000],[0,366459000000000]],"384":[[0,419444444444],[0,420410000000],[0,420830000000],[0,451333333333]],"12288":[[0,13307920000000],[0,13314590000000],[0,13373750000000],[0,13565410000000]],"81920":[[0,89005830000000],[0,89106670000000],[0,89115420000000],[0,89875000000000]],"8":[[0,10420000000],[0,10420000000],[0,10420000000],[0,10830000000]],"1280":[[0,1390000000000],[0,1390000000000],[0,1390000000000],[0,1391250000000]],"3584":[[0,3875000000000],[0,3884170000000],[0,3884580000000],[0,3884580000000]],"7":[[0,9160000000],[0,9170000000],[0,9580000000],[0,9580000000]],"524288":[[0,568857823529411],[0,580480533333333]],"112":[[0,125000000000],[0,125000000000],[0,125000000000],[0,126250000000]],"896":[[0,958000000000],[0,974170000000],[0,974580000000],[0,974580000000]],"192":[[0,209000000000],[0,212500000000],[0,212500000000],[0,212500000000]],"80":[[0,90840000000],[0,91250000000],[0,92080000000],[0,92080000000]],"24":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27910000000]],"40960":[[0,44345500000000],[0,44370830000000],[0,44541000000000],[0,44542000000000]],"16":[[0,19160000000],[0,19160000000],[0,19160000000],[0,20410000000]],"3072":[[0,3329580000000],[0,3329580000000],[0,3329590000000],[0,3330420000000]],"20":[[0,23340000000],[0,23750000000],[0,23750000000],[0,23750000000]],"224":[[0,246670000000],[0,246670000000],[0,247080000000],[0,247080000000]],"2560":[[0,2775410000000],[0,2775420000000],[0,2775840000000],[0,2776250000000]],"1792":[[0,1943750000000],[0,1944160000000],[0,1944580000000],[0,1944580000000]],"1024":[[0,1112910000000],[0,1112910000000],[0,1113330000000],[0,1113330000000]],"6144":[[0,6655000000000],[0,6655410000000],[0,6655420000000],[0,6655830000000]],"56":[[0,64580000000],[0,65000000000],[0,65000000000],[0,65000000000]],"786432":[[0,853000000000000],[0,884375000000000]],"163840":[[0,177375000000000],[0,180125000000000],[0,191588428571428]],"6":[[0,7920000000],[0,8330000000],[0,8330000000],[0,8330000000]],"48":[[0,41000000000],[0,55830000000],[0,56250000000],[0,56660000000]],"32":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"14":[[0,15625000000],[0,16660000000],[0,17080000000],[0,17080000000]],"28672":[[0,31041642857142],[0,31057090000000],[0,31060166666666],[0,31083000000000]],"512":[[0,558330000000],[0,558750000000],[0,559160000000],[0,559160000000]],"196608":[[0,213104173913043],[0,217667000000000],[0,229504837209302]],"458752":[[0,501486333333333],[0,509750000000000]],"24576":[[0,26606250000000],[0,26750000000000],[0,26750000000000],[0,26904017857142]],"2":[[0,5830000000],[0,5830000000],[0,5830000000],[0,6250000000]],"256":[[0,281250000000],[0,281660000000],[0,281670000000],[0,282080000000]],"1536":[[0,1666000000000],[0,1666670000000],[0,1667000000000],[0,1667080000000]],"64":[[0,73340000000],[0,74160000000],[0,74160000000],[0,74580000000]],"320":[[0,350830000000],[0,351250000000],[0,351250000000],[0,352500000000]],"114688":[[0,124875000000000],[0,125167000000000],[0,134628250000000]],"131072":[[0,141917000000000],[0,144375000000000],[0,145416000000000]],"16384":[[0,17740384615384],[0,17746520833333],[0,17833000000000],[0,17834000000000]],"5120":[[0,5541000000000],[0,5541000000000],[0,5542000000000],[0,6280830000000]],"229376":[[0,250803571428571],[0,251886583333333],[0,257083000000000]],"5":[[0,7080000000],[0,7080000000],[0,7500000000],[0,7500000000]],"10":[[0,12500000000],[0,12500000000],[0,12500000000],[0,12910000000]],"28":[[0,32080000000],[0,32080000000],[0,32080000000],[0,32080000000]],"655360":[[0,714167000000000],[0,741368083333333]],"7168":[[0,7763637931034],[0,7764160000000],[0,7764160000000],[0,7765420000000]],"20480":[[0,22174066666666],[0,22176670000000],[0,22185770833333],[0,22209000000000]],"65536":[[0,70941230769230],[0,70958000000000],[0,71047920000000],[0,71166000000000]],"917504":[[0,1009552000000000],[0,1043209000000000]],"160":[[0,177500000000],[0,177500000000],[0,177910000000],[0,177910000000]],"640":[[0,694333333333],[0,696660000000],[0,697080000000],[0,697500000000]],"40":[[0,47910000000],[0,47910000000],[0,47910000000],[0,47920000000]],"393216":[[0,425708500000000],[0,437406250000000]],"57344":[[0,62042000000000],[0,62208000000000],[0,62375000000000],[0,62583000000000]],"4":[[0,5830000000],[0,6250000000],[0,6250000000],[0,6660000000]],"1":[[0,1670000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,833000000000],[0,835410000000],[0,835830000000],[0,835840000000]],"448":[[0,489160000000],[0,489580000000],[0,489580000000],[0,490000000000]],"8192":[[0,8872080000000],[0,8872500000000],[0,8872920000000],[0,8917000000000]],"12":[[0,14580000000],[0,14580000000],[0,15000000000],[0,15000000000]],"10240":[[0,11089580000000],[0,11089580000000],[0,11091670000000],[0,11105000000000]],"14336":[[0,15522925000000],[0,15524590000000],[0,15530000000000],[0,15533962962962]],"32768":[[0,35458000000000],[0,35473340000000],[0,35500000000000],[0,35500000000000]],"128":[[0,142857142857],[0,142920000000],[0,142920000000],[0,143330000000]],"4096":[[0,4436523809523],[0,4437920000000],[0,4439516129032],[0,4440000000000]],"49152":[[0,53208000000000],[0,53292000000000],[0,53530840000000],[0,53792000000000]],"262144":[[0,285922086956521],[0,286218424242424],[0,298842961538461]],"3":[[0,5000000000],[0,5000000000],[0,5000000000],[0,5000000000]],"98304":[[0,106459000000000],[0,106515625000000],[0,106785397849462],[0,109767325842696]]}},{"title":"Deque mutate through subscript (contiguous)","results":{"2048":[[0,2791000000000],[0,2791000000000],[0,2791000000000],[0,2792000000000]],"1048576":[[0,1436042000000000],[0,1444292000000000]],"96":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"327680":[[0,449459000000000],[0,449583000000000]],"384":[[0,541000000000],[0,541000000000],[0,541000000000],[0,583000000000]],"12288":[[0,16666000000000],[0,16708000000000],[0,17458000000000],[0,17542000000000]],"81920":[[0,110875000000000],[0,110875000000000],[0,110958000000000],[0,111000000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,1750000000000],[0,1750000000000],[0,1959000000000],[0,2208000000000]],"3584":[[0,4833000000000],[0,4833000000000],[0,4875000000000],[0,4875000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,716125000000000],[0,721625000000000]],"112":[[0,166000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"896":[[0,1209000000000],[0,1250000000000],[0,1250000000000],[0,1250000000000]],"192":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,55417000000000],[0,55458000000000],[0,55458000000000],[0,55542000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,4167000000000],[0,4167000000000],[0,4167000000000],[0,4167000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"224":[[0,292000000000],[0,292000000000],[0,333000000000],[0,333000000000]],"2560":[[0,3458000000000],[0,3458000000000],[0,3500000000000],[0,3500000000000]],"1792":[[0,2416000000000],[0,2416000000000],[0,2416000000000],[0,2750000000000]],"1024":[[0,1375000000000],[0,1375000000000],[0,1416000000000],[0,1792000000000]],"6144":[[0,8333000000000],[0,8333000000000],[0,8333000000000],[0,8334000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"786432":[[0,1075625000000000],[0,1080792000000000]],"163840":[[0,221834000000000],[0,222000000000000],[0,233125000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,38833000000000],[0,38833000000000],[0,38834000000000],[0,38916000000000]],"512":[[0,708000000000],[0,708000000000],[0,708000000000],[0,709000000000]],"196608":[[0,266334000000000],[0,268291000000000],[0,270291000000000]],"458752":[[0,630000000000000],[0,635834000000000]],"24576":[[0,33250000000000],[0,33291000000000],[0,33291000000000],[0,33292000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,334000000000],[0,375000000000],[0,416000000000]],"1536":[[0,2083000000000],[0,2083000000000],[0,2084000000000],[0,2166000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,458000000000],[0,458000000000],[0,458000000000],[0,500000000000]],"114688":[[0,155208000000000],[0,155250000000000],[0,155958000000000]],"131072":[[0,177375000000000],[0,177417000000000],[0,191625000000000]],"16384":[[0,22125000000000],[0,22167000000000],[0,22167000000000],[0,27041000000000]],"5120":[[0,6917000000000],[0,6958000000000],[0,6958000000000],[0,6958000000000]],"229376":[[0,312000000000000],[0,312500000000000],[0,316291000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,914083000000000],[0,924917000000000]],"7168":[[0,9708000000000],[0,9708000000000],[0,9709000000000],[0,9709000000000]],"20480":[[0,27708000000000],[0,27708000000000],[0,27750000000000],[0,27792000000000]],"65536":[[0,88667000000000],[0,88708000000000],[0,88750000000000],[0,88791000000000]],"917504":[[0,1257709000000000],[0,1264833000000000]],"160":[[0,208000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"640":[[0,875000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"40":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,535667000000000],[0,543333000000000]],"57344":[[0,77583000000000],[0,77583000000000],[0,77625000000000],[0,77708000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1041000000000],[0,1042000000000],[0,1042000000000],[0,1083000000000]],"448":[[0,625000000000],[0,625000000000],[0,625000000000],[0,667000000000]],"8192":[[0,11000000000000],[0,11083000000000],[0,11083000000000],[0,11084000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,13833000000000],[0,13833000000000],[0,13875000000000],[0,13875000000000]],"14336":[[0,19375000000000],[0,19375000000000],[0,19416000000000],[0,19417000000000]],"32768":[[0,44375000000000],[0,44375000000000],[0,44375000000000],[0,44375000000000]],"128":[[0,166000000000],[0,167000000000],[0,209000000000],[0,209000000000]],"4096":[[0,5541000000000],[0,5541000000000],[0,5542000000000],[0,5583000000000]],"49152":[[0,66541000000000],[0,66542000000000],[0,66542000000000],[0,66625000000000]],"262144":[[0,355917000000000],[0,356500000000000],[0,360791000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,133042000000000],[0,133125000000000],[0,133208000000000],[0,133291000000000]]}},{"title":"Deque mutate through subscript (discontiguous)","results":{"2048":[[0,2791000000000],[0,2791000000000],[0,2791000000000],[0,2791000000000]],"1048576":[[0,1438750000000000],[0,1458042000000000]],"96":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"327680":[[0,446584000000000],[0,465292000000000]],"384":[[0,541000000000],[0,541000000000],[0,542000000000],[0,750000000000]],"12288":[[0,16584000000000],[0,16666000000000],[0,16666000000000],[0,17375000000000]],"81920":[[0,110833000000000],[0,110834000000000],[0,110875000000000],[0,110916000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1750000000000],[0,1750000000000],[0,1833000000000],[0,2000000000000]],"3584":[[0,4833000000000],[0,4833000000000],[0,4875000000000],[0,4875000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,714167000000000],[0,729875000000000]],"112":[[0,166000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"896":[[0,1208000000000],[0,1250000000000],[0,1250000000000],[0,1250000000000]],"192":[[0,250000000000],[0,250000000000],[0,291000000000],[0,291000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"24":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"40960":[[0,55416000000000],[0,55417000000000],[0,55458000000000],[0,55459000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"3072":[[0,4166000000000],[0,4166000000000],[0,4166000000000],[0,4167000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"224":[[0,291000000000],[0,292000000000],[0,333000000000],[0,333000000000]],"2560":[[0,3458000000000],[0,3458000000000],[0,3459000000000],[0,3500000000000]],"1792":[[0,2416000000000],[0,2417000000000],[0,2417000000000],[0,2709000000000]],"1024":[[0,1375000000000],[0,1416000000000],[0,1417000000000],[0,1458000000000]],"6144":[[0,8333000000000],[0,8333000000000],[0,8333000000000],[0,8375000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"786432":[[0,1081292000000000],[0,1103875000000000]],"163840":[[0,221833000000000],[0,221875000000000],[0,233000000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,38750000000000],[0,38792000000000],[0,38875000000000],[0,38875000000000]],"512":[[0,708000000000],[0,708000000000],[0,708000000000],[0,708000000000]],"196608":[[0,266500000000000],[0,267334000000000],[0,273042000000000]],"458752":[[0,628875000000000],[0,629250000000000]],"24576":[[0,33250000000000],[0,33292000000000],[0,33333000000000],[0,33333000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,333000000000],[0,333000000000],[0,375000000000]],"1536":[[0,2083000000000],[0,2084000000000],[0,2084000000000],[0,2208000000000]],"64":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"320":[[0,458000000000],[0,458000000000],[0,458000000000],[0,500000000000]],"114688":[[0,155250000000000],[0,155292000000000],[0,159625000000000]],"131072":[[0,177458000000000],[0,177667000000000],[0,186583000000000]],"16384":[[0,22125000000000],[0,22125000000000],[0,22167000000000],[0,28708000000000]],"5120":[[0,6958000000000],[0,6958000000000],[0,6958000000000],[0,6958000000000]],"229376":[[0,311750000000000],[0,312125000000000],[0,322375000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"655360":[[0,910750000000000],[0,923250000000000]],"7168":[[0,9666000000000],[0,9666000000000],[0,9667000000000],[0,9708000000000]],"20480":[[0,27708000000000],[0,27750000000000],[0,27750000000000],[0,27791000000000]],"65536":[[0,88666000000000],[0,88709000000000],[0,88709000000000],[0,88750000000000]],"917504":[[0,1267333000000000],[0,1277375000000000]],"160":[[0,208000000000],[0,208000000000],[0,250000000000],[0,250000000000]],"640":[[0,875000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"40":[[0,41000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,535167000000000],[0,538291000000000]],"57344":[[0,77583000000000],[0,77584000000000],[0,77625000000000],[0,77625000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1041000000000],[0,1041000000000],[0,1042000000000],[0,1042000000000]],"448":[[0,625000000000],[0,625000000000],[0,625000000000],[0,666000000000]],"8192":[[0,11041000000000],[0,11083000000000],[0,11083000000000],[0,11125000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,13833000000000],[0,13875000000000],[0,13875000000000],[0,13875000000000]],"14336":[[0,19375000000000],[0,19416000000000],[0,19417000000000],[0,19417000000000]],"32768":[[0,44333000000000],[0,44334000000000],[0,44416000000000],[0,44458000000000]],"128":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"4096":[[0,5541000000000],[0,5542000000000],[0,5542000000000],[0,5542000000000]],"49152":[[0,66500000000000],[0,66500000000000],[0,66500000000000],[0,66583000000000]],"262144":[[0,356333000000000],[0,356500000000000],[0,357167000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,133042000000000],[0,133042000000000],[0,133125000000000],[0,133209000000000]]}},{"title":"Deque random swaps (contiguous)","results":{"2048":[[0,3375000000000],[0,3375000000000],[0,3375000000000],[0,3375000000000]],"1048576":[[0,1894291000000000],[0,1907375000000000]],"96":[[0,167000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"327680":[[0,572125000000000],[0,583917000000000]],"384":[[0,625000000000],[0,666000000000],[0,667000000000],[0,917000000000]],"12288":[[0,20000000000000],[0,20042000000000],[0,20125000000000],[0,21042000000000]],"81920":[[0,137709000000000],[0,138041000000000],[0,138542000000000],[0,139333000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2125000000000],[0,2125000000000],[0,2416000000000],[0,2917000000000]],"3584":[[0,5875000000000],[0,5875000000000],[0,5875000000000],[0,5875000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,914125000000000],[0,927375000000000]],"112":[[0,208000000000],[0,208000000000],[0,250000000000],[0,250000000000]],"896":[[0,1458000000000],[0,1500000000000],[0,1500000000000],[0,1500000000000]],"192":[[0,333000000000],[0,333000000000],[0,375000000000],[0,416000000000]],"80":[[0,125000000000],[0,166000000000],[0,167000000000],[0,167000000000]],"24":[[0,42000000000],[0,42000000000],[0,83000000000],[0,84000000000]],"40960":[[0,68125000000000],[0,68167000000000],[0,68250000000000],[0,68291000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"3072":[[0,5000000000000],[0,5042000000000],[0,5042000000000],[0,5042000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"224":[[0,375000000000],[0,375000000000],[0,375000000000],[0,541000000000]],"2560":[[0,4208000000000],[0,4208000000000],[0,4208000000000],[0,4209000000000]],"1792":[[0,2917000000000],[0,2958000000000],[0,2959000000000],[0,3375000000000]],"1024":[[0,1667000000000],[0,1667000000000],[0,1667000000000],[0,1791000000000]],"6144":[[0,10000000000000],[0,10041000000000],[0,10042000000000],[0,10042000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"786432":[[0,1398000000000000],[0,1404250000000000]],"163840":[[0,282916000000000],[0,298709000000000],[0,305084000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,42000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,47125000000000],[0,47208000000000],[0,47291000000000],[0,47291000000000]],"512":[[0,833000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"196608":[[0,336959000000000],[0,340875000000000],[0,344250000000000]],"458752":[[0,795958000000000],[0,802750000000000]],"24576":[[0,40250000000000],[0,40250000000000],[0,40375000000000],[0,40417000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,417000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2500000000000],[0,2541000000000],[0,2542000000000],[0,2666000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,541000000000],[0,542000000000],[0,542000000000],[0,625000000000]],"114688":[[0,194250000000000],[0,195250000000000],[0,197334000000000]],"131072":[[0,226250000000000],[0,234250000000000],[0,244000000000000]],"16384":[[0,26625000000000],[0,26708000000000],[0,26709000000000],[0,32541000000000]],"5120":[[0,8375000000000],[0,8375000000000],[0,8375000000000],[0,8375000000000]],"229376":[[0,394208000000000],[0,398416000000000],[0,399042000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"655360":[[0,1168917000000000],[0,1205958000000000]],"7168":[[0,11708000000000],[0,11708000000000],[0,11708000000000],[0,11708000000000]],"20480":[[0,33417000000000],[0,33459000000000],[0,33500000000000],[0,33542000000000]],"65536":[[0,110083000000000],[0,110416000000000],[0,110792000000000],[0,111000000000000]],"917504":[[0,1654958000000000],[0,1684500000000000]],"160":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"640":[[0,1042000000000],[0,1083000000000],[0,1083000000000],[0,1083000000000]],"40":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"393216":[[0,678000000000000],[0,684584000000000]],"57344":[[0,96000000000000],[0,96292000000000],[0,96292000000000],[0,96541000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,1250000000000],[0,1292000000000],[0,1292000000000],[0,1333000000000]],"448":[[0,750000000000],[0,750000000000],[0,750000000000],[0,1042000000000]],"8192":[[0,13333000000000],[0,13375000000000],[0,13416000000000],[0,13417000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,16708000000000],[0,16708000000000],[0,16709000000000],[0,16709000000000]],"14336":[[0,23333000000000],[0,23375000000000],[0,23417000000000],[0,23458000000000]],"32768":[[0,54000000000000],[0,54208000000000],[0,54209000000000],[0,54333000000000]],"128":[[0,209000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"4096":[[0,6666000000000],[0,6666000000000],[0,6708000000000],[0,6708000000000]],"49152":[[0,82292000000000],[0,82458000000000],[0,82500000000000],[0,82959000000000]],"262144":[[0,450875000000000],[0,454083000000000],[0,454625000000000]],"3":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,166500000000000],[0,166709000000000],[0,167417000000000],[0,167542000000000]]}},{"title":"Deque random swaps (discontiguous)","results":{"2048":[[0,3334000000000],[0,3375000000000],[0,3416000000000],[0,3417000000000]],"1048576":[[0,1955750000000000],[0,1966917000000000]],"96":[[0,166000000000],[0,166000000000],[0,167000000000],[0,208000000000]],"327680":[[0,577000000000000],[0,605792000000000]],"384":[[0,625000000000],[0,666000000000],[0,667000000000],[0,750000000000]],"12288":[[0,20000000000000],[0,20042000000000],[0,20125000000000],[0,21333000000000]],"81920":[[0,137750000000000],[0,138042000000000],[0,138084000000000],[0,139166000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2083000000000],[0,2125000000000],[0,2167000000000],[0,2416000000000]],"3584":[[0,5875000000000],[0,5875000000000],[0,5875000000000],[0,5875000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,910500000000000],[0,963250000000000]],"112":[[0,208000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"896":[[0,1458000000000],[0,1458000000000],[0,1500000000000],[0,1500000000000]],"192":[[0,333000000000],[0,333000000000],[0,333000000000],[0,417000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"40960":[[0,67834000000000],[0,67917000000000],[0,68041000000000],[0,68083000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,5000000000000],[0,5041000000000],[0,5041000000000],[0,5041000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"224":[[0,375000000000],[0,375000000000],[0,375000000000],[0,500000000000]],"2560":[[0,4208000000000],[0,4208000000000],[0,4208000000000],[0,4208000000000]],"1792":[[0,2958000000000],[0,2958000000000],[0,2958000000000],[0,3333000000000]],"1024":[[0,1667000000000],[0,1708000000000],[0,1708000000000],[0,1791000000000]],"6144":[[0,10041000000000],[0,10042000000000],[0,10042000000000],[0,10083000000000]],"56":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1413500000000000],[0,1464458000000000]],"163840":[[0,286375000000000],[0,296833000000000],[0,303208000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,47083000000000],[0,47125000000000],[0,47208000000000],[0,47375000000000]],"512":[[0,833000000000],[0,875000000000],[0,875000000000],[0,1083000000000]],"196608":[[0,334291000000000],[0,342833000000000],[0,345000000000000]],"458752":[[0,802041000000000],[0,830500000000000]],"24576":[[0,40167000000000],[0,40250000000000],[0,40333000000000],[0,40375000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2500000000000],[0,2500000000000],[0,2541000000000],[0,2625000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,541000000000],[0,541000000000],[0,542000000000],[0,625000000000]],"114688":[[0,194667000000000],[0,197500000000000],[0,213375000000000]],"131072":[[0,223125000000000],[0,223916000000000],[0,237250000000000]],"16384":[[0,26708000000000],[0,26708000000000],[0,26709000000000],[0,32708000000000]],"5120":[[0,8375000000000],[0,8375000000000],[0,8375000000000],[0,8375000000000]],"229376":[[0,395958000000000],[0,401584000000000],[0,404958000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"655360":[[0,1196625000000000],[0,1201375000000000]],"7168":[[0,11708000000000],[0,11708000000000],[0,11708000000000],[0,11708000000000]],"20480":[[0,33375000000000],[0,33458000000000],[0,33458000000000],[0,33500000000000]],"65536":[[0,109750000000000],[0,109792000000000],[0,109875000000000],[0,110709000000000]],"917504":[[0,1671000000000000],[0,1734792000000000]],"160":[[0,250000000000],[0,291000000000],[0,291000000000],[0,291000000000]],"640":[[0,1083000000000],[0,1083000000000],[0,1083000000000],[0,1083000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,682542000000000],[0,691792000000000]],"57344":[[0,96000000000000],[0,96083000000000],[0,96416000000000],[0,97833000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1250000000000],[0,1250000000000],[0,1291000000000],[0,1291000000000]],"448":[[0,750000000000],[0,750000000000],[0,750000000000],[0,1042000000000]],"8192":[[0,13333000000000],[0,13334000000000],[0,13375000000000],[0,13375000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,16666000000000],[0,16708000000000],[0,16708000000000],[0,16709000000000]],"14336":[[0,23333000000000],[0,23416000000000],[0,23417000000000],[0,23458000000000]],"32768":[[0,54125000000000],[0,54250000000000],[0,54333000000000],[0,54375000000000]],"128":[[0,209000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"4096":[[0,6625000000000],[0,6666000000000],[0,6667000000000],[0,6667000000000]],"49152":[[0,81834000000000],[0,81875000000000],[0,81958000000000],[0,82083000000000]],"262144":[[0,453125000000000],[0,454583000000000],[0,458833000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,165833000000000],[0,166834000000000],[0,167042000000000],[0,167375000000000]]}},{"title":"Deque partitioning around middle (contiguous)","results":{"2048":[[0,1584000000000],[0,1625000000000],[0,1625000000000],[0,1666000000000]],"1048576":[[0,2989875000000000],[0,2998000000000000]],"96":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"327680":[[0,925667000000000],[0,954041000000000]],"384":[[0,291000000000],[0,291000000000],[0,292000000000],[0,375000000000]],"12288":[[0,11125000000000],[0,16542000000000],[0,18208000000000],[0,20542000000000]],"81920":[[0,209209000000000],[0,209750000000000],[0,213042000000000],[0,222458000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,833000000000],[0,958000000000],[0,1125000000000],[0,1333000000000]],"3584":[[0,2791000000000],[0,2834000000000],[0,2875000000000],[0,3041000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,1470458000000000],[0,1547208000000000]],"112":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"896":[[0,708000000000],[0,709000000000],[0,750000000000],[0,833000000000]],"192":[[0,125000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"80":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"24":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"40960":[[0,94042000000000],[0,94250000000000],[0,94959000000000],[0,106791000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,2333000000000],[0,2333000000000],[0,2416000000000],[0,2459000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,166000000000],[0,167000000000],[0,208000000000],[0,333000000000]],"2560":[[0,1833000000000],[0,2000000000000],[0,2000000000000],[0,2125000000000]],"1792":[[0,1334000000000],[0,1417000000000],[0,1500000000000],[0,1625000000000]],"1024":[[0,750000000000],[0,792000000000],[0,792000000000],[0,1084000000000]],"6144":[[0,4667000000000],[0,5291000000000],[0,5417000000000],[0,5542000000000]],"56":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"786432":[[0,2186583000000000],[0,2194458000000000]],"163840":[[0,446042000000000],[0,453792000000000],[0,472042000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,57125000000000],[0,59208000000000],[0,61042000000000],[0,63042000000000]],"512":[[0,375000000000],[0,375000000000],[0,416000000000],[0,500000000000]],"196608":[[0,539750000000000],[0,544833000000000],[0,548625000000000]],"458752":[[0,1299625000000000],[0,1323125000000000]],"24576":[[0,45958000000000],[0,46042000000000],[0,47834000000000],[0,52750000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,167000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"1536":[[0,1125000000000],[0,1166000000000],[0,1209000000000],[0,1250000000000]],"64":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"320":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"114688":[[0,304417000000000],[0,305292000000000],[0,312833000000000]],"131072":[[0,353000000000000],[0,353292000000000],[0,361292000000000]],"16384":[[0,19000000000000],[0,19500000000000],[0,20000000000000],[0,34375000000000]],"5120":[[0,3875000000000],[0,4042000000000],[0,4083000000000],[0,4125000000000]],"229376":[[0,636375000000000],[0,649667000000000],[0,653584000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"655360":[[0,1833833000000000],[0,1837625000000000]],"7168":[[0,5542000000000],[0,5667000000000],[0,6375000000000],[0,6541000000000]],"20480":[[0,29333000000000],[0,30333000000000],[0,38583000000000],[0,41958000000000]],"65536":[[0,163042000000000],[0,163375000000000],[0,163875000000000],[0,165542000000000]],"917504":[[0,2566166000000000],[0,2607709000000000]],"160":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"640":[[0,458000000000],[0,459000000000],[0,500000000000],[0,500000000000]],"40":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"393216":[[0,1090458000000000],[0,1109709000000000]],"57344":[[0,140125000000000],[0,140250000000000],[0,141208000000000],[0,148208000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,542000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"448":[[0,292000000000],[0,333000000000],[0,334000000000],[0,375000000000]],"8192":[[0,6083000000000],[0,6458000000000],[0,6625000000000],[0,9167000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,8292000000000],[0,8292000000000],[0,8459000000000],[0,8542000000000]],"14336":[[0,14667000000000],[0,14708000000000],[0,19417000000000],[0,23834000000000]],"32768":[[0,68792000000000],[0,69458000000000],[0,71875000000000],[0,73792000000000]],"128":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"4096":[[0,3042000000000],[0,3125000000000],[0,3250000000000],[0,3250000000000]],"49152":[[0,116709000000000],[0,117917000000000],[0,118000000000000],[0,118875000000000]],"262144":[[0,722166000000000],[0,738625000000000],[0,748833000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,256834000000000],[0,259584000000000],[0,270375000000000],[0,281333000000000]]}},{"title":"Deque partitioning around middle (discontiguous)","results":{"2048":[[0,2292000000000],[0,2500000000000],[0,2625000000000],[0,2666000000000]],"1048576":[[0,4625375000000000],[0,4642042000000000]],"96":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"327680":[[0,1441833000000000],[0,1471875000000000]],"384":[[0,417000000000],[0,458000000000],[0,458000000000],[0,583000000000]],"12288":[[0,29542000000000],[0,30542000000000],[0,40459000000000],[0,46000000000000]],"81920":[[0,340958000000000],[0,345167000000000],[0,347875000000000],[0,350041000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1458000000000],[0,1459000000000],[0,1542000000000],[0,2167000000000]],"3584":[[0,5958000000000],[0,6000000000000],[0,6042000000000],[0,8458000000000]],"7":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"524288":[[0,2282000000000000],[0,2337000000000000]],"112":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"896":[[0,1000000000000],[0,1041000000000],[0,1084000000000],[0,1291000000000]],"192":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"80":[[0,83000000000],[0,84000000000],[0,125000000000],[0,167000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,161042000000000],[0,161875000000000],[0,168000000000000],[0,170417000000000]],"16":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"3072":[[0,3583000000000],[0,3583000000000],[0,4542000000000],[0,4667000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"224":[[0,250000000000],[0,250000000000],[0,291000000000],[0,375000000000]],"2560":[[0,2875000000000],[0,2959000000000],[0,3000000000000],[0,3042000000000]],"1792":[[0,2000000000000],[0,2000000000000],[0,2167000000000],[0,2291000000000]],"1024":[[0,1125000000000],[0,1167000000000],[0,1209000000000],[0,1583000000000]],"6144":[[0,8375000000000],[0,9000000000000],[0,9250000000000],[0,10167000000000]],"56":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"786432":[[0,3456500000000000],[0,3477958000000000]],"163840":[[0,696375000000000],[0,700792000000000],[0,768209000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,104209000000000],[0,105875000000000],[0,106042000000000],[0,114917000000000]],"512":[[0,583000000000],[0,584000000000],[0,625000000000],[0,791000000000]],"196608":[[0,861708000000000],[0,908958000000000],[0,916958000000000]],"458752":[[0,2050458000000000],[0,2125583000000000]],"24576":[[0,86458000000000],[0,90833000000000],[0,100125000000000],[0,100625000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,292000000000],[0,292000000000],[0,292000000000],[0,333000000000]],"1536":[[0,1708000000000],[0,1750000000000],[0,1875000000000],[0,1875000000000]],"64":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"320":[[0,375000000000],[0,416000000000],[0,417000000000],[0,417000000000]],"114688":[[0,491167000000000],[0,506000000000000],[0,515166000000000]],"131072":[[0,552542000000000],[0,565500000000000],[0,611250000000000]],"16384":[[0,59250000000000],[0,59584000000000],[0,59875000000000],[0,66208000000000]],"5120":[[0,6959000000000],[0,7041000000000],[0,7625000000000],[0,12333000000000]],"229376":[[0,1003958000000000],[0,1004083000000000],[0,1054708000000000]],"5":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,2863541000000000],[0,2898042000000000]],"7168":[[0,11125000000000],[0,11333000000000],[0,14416000000000],[0,14666000000000]],"20480":[[0,69875000000000],[0,70250000000000],[0,76667000000000],[0,79833000000000]],"65536":[[0,268750000000000],[0,271541000000000],[0,275583000000000],[0,277625000000000]],"917504":[[0,4030833000000000],[0,4075334000000000]],"160":[[0,167000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"640":[[0,708000000000],[0,709000000000],[0,750000000000],[0,750000000000]],"40":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"393216":[[0,1733750000000000],[0,1773834000000000]],"57344":[[0,240250000000000],[0,241792000000000],[0,242958000000000],[0,245875000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,875000000000],[0,875000000000],[0,875000000000],[0,1166000000000]],"448":[[0,500000000000],[0,500000000000],[0,542000000000],[0,792000000000]],"8192":[[0,14666000000000],[0,18500000000000],[0,19500000000000],[0,20042000000000]],"12":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10240":[[0,29042000000000],[0,29916000000000],[0,30417000000000],[0,30625000000000]],"14336":[[0,40167000000000],[0,42958000000000],[0,49708000000000],[0,51083000000000]],"32768":[[0,122500000000000],[0,122916000000000],[0,133500000000000],[0,133958000000000]],"128":[[0,166000000000],[0,167000000000],[0,167000000000],[0,167000000000]],"4096":[[0,4917000000000],[0,5000000000000],[0,5000000000000],[0,5208000000000]],"49152":[[0,194917000000000],[0,195584000000000],[0,195917000000000],[0,197750000000000]],"262144":[[0,1144958000000000],[0,1157625000000000],[0,1186792000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,413750000000000],[0,416125000000000],[0,417125000000000],[0,439250000000000]]}},{"title":"Deque removeFirst (discontiguous)","results":{"2048":[[0,4625000000000],[0,4625000000000],[0,4666000000000],[0,4666000000000]],"1048576":[[0,2382250000000000],[0,2385041000000000]],"96":[[0,208000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"327680":[[0,746708000000000],[0,756208000000000]],"384":[[0,834000000000],[0,875000000000],[0,875000000000],[0,1000000000000]],"12288":[[0,27833000000000],[0,27833000000000],[0,27875000000000],[0,31625000000000]],"81920":[[0,185833000000000],[0,185833000000000],[0,185875000000000],[0,185875000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,2916000000000],[0,2958000000000],[0,3042000000000],[0,4042000000000]],"3584":[[0,8083000000000],[0,8125000000000],[0,8166000000000],[0,8166000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"524288":[[0,1189875000000000],[0,1198333000000000]],"112":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"896":[[0,2041000000000],[0,2041000000000],[0,2042000000000],[0,2042000000000]],"192":[[0,416000000000],[0,416000000000],[0,417000000000],[0,459000000000]],"80":[[0,167000000000],[0,167000000000],[0,208000000000],[0,250000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"40960":[[0,92875000000000],[0,92875000000000],[0,92875000000000],[0,92875000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,6917000000000],[0,6958000000000],[0,6959000000000],[0,7000000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"224":[[0,500000000000],[0,500000000000],[0,541000000000],[0,583000000000]],"2560":[[0,5791000000000],[0,5791000000000],[0,5833000000000],[0,5833000000000]],"1792":[[0,4083000000000],[0,4083000000000],[0,4084000000000],[0,4625000000000]],"1024":[[0,2333000000000],[0,2333000000000],[0,2333000000000],[0,2334000000000]],"6144":[[0,13917000000000],[0,13917000000000],[0,13917000000000],[0,13958000000000]],"56":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"786432":[[0,1795750000000000],[0,1816625000000000]],"163840":[[0,371625000000000],[0,371708000000000],[0,389333000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"32":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,65000000000000],[0,65000000000000],[0,65041000000000],[0,65041000000000]],"512":[[0,1166000000000],[0,1166000000000],[0,1167000000000],[0,1625000000000]],"196608":[[0,448041000000000],[0,449375000000000],[0,465583000000000]],"458752":[[0,1069792000000000],[0,1072584000000000]],"24576":[[0,55709000000000],[0,55750000000000],[0,55750000000000],[0,55791000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,583000000000],[0,583000000000],[0,583000000000],[0,584000000000]],"1536":[[0,3458000000000],[0,3500000000000],[0,3500000000000],[0,3667000000000]],"64":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"320":[[0,709000000000],[0,750000000000],[0,750000000000],[0,833000000000]],"114688":[[0,260125000000000],[0,260208000000000],[0,260209000000000]],"131072":[[0,297250000000000],[0,297500000000000],[0,305292000000000]],"16384":[[0,37125000000000],[0,37166000000000],[0,37167000000000],[0,51750000000000]],"5120":[[0,11625000000000],[0,11625000000000],[0,11625000000000],[0,11625000000000]],"229376":[[0,520333000000000],[0,523917000000000],[0,533250000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"655360":[[0,1489625000000000],[0,1507125000000000]],"7168":[[0,16208000000000],[0,16250000000000],[0,16250000000000],[0,16250000000000]],"20480":[[0,46416000000000],[0,46458000000000],[0,46458000000000],[0,46542000000000]],"65536":[[0,148625000000000],[0,148666000000000],[0,148666000000000],[0,148709000000000]],"917504":[[0,2082834000000000],[0,2084958000000000]],"160":[[0,375000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"640":[[0,1458000000000],[0,1458000000000],[0,1459000000000],[0,1459000000000]],"40":[[0,83000000000],[0,83000000000],[0,125000000000],[0,125000000000]],"393216":[[0,892125000000000],[0,906750000000000]],"57344":[[0,130041000000000],[0,130083000000000],[0,130125000000000],[0,130209000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1750000000000],[0,1750000000000],[0,1750000000000],[0,1750000000000]],"448":[[0,1000000000000],[0,1041000000000],[0,1041000000000],[0,1292000000000]],"8192":[[0,18583000000000],[0,18583000000000],[0,18583000000000],[0,18583000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,23209000000000],[0,23209000000000],[0,23250000000000],[0,23292000000000]],"14336":[[0,32500000000000],[0,32500000000000],[0,32541000000000],[0,32542000000000]],"32768":[[0,74292000000000],[0,74334000000000],[0,74375000000000],[0,74458000000000]],"128":[[0,291000000000],[0,292000000000],[0,292000000000],[0,292000000000]],"4096":[[0,9250000000000],[0,9292000000000],[0,9292000000000],[0,9292000000000]],"49152":[[0,111458000000000],[0,111500000000000],[0,111500000000000],[0,111542000000000]],"262144":[[0,594792000000000],[0,596417000000000],[0,602500000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,223000000000000],[0,223000000000000],[0,223042000000000],[0,223166000000000]]}},{"title":"Deque removeLast (discontiguous)","results":{"2048":[[0,3833000000000],[0,3833000000000],[0,3833000000000],[0,3834000000000]],"1048576":[[0,1969208000000000],[0,1979250000000000]],"96":[[0,167000000000],[0,167000000000],[0,167000000000],[0,167000000000]],"327680":[[0,621625000000000],[0,623042000000000]],"384":[[0,708000000000],[0,708000000000],[0,750000000000],[0,834000000000]],"12288":[[0,23000000000000],[0,23041000000000],[0,23041000000000],[0,26041000000000]],"81920":[[0,153542000000000],[0,153625000000000],[0,153625000000000],[0,153667000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2416000000000],[0,2416000000000],[0,2584000000000],[0,3333000000000]],"3584":[[0,6708000000000],[0,6708000000000],[0,6708000000000],[0,6750000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,984625000000000],[0,996083000000000]],"112":[[0,208000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"896":[[0,1666000000000],[0,1666000000000],[0,1666000000000],[0,1667000000000]],"192":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"80":[[0,166000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,76791000000000],[0,76792000000000],[0,76833000000000],[0,76834000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"3072":[[0,5750000000000],[0,5750000000000],[0,5750000000000],[0,5750000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"224":[[0,416000000000],[0,416000000000],[0,416000000000],[0,458000000000]],"2560":[[0,4791000000000],[0,4791000000000],[0,4791000000000],[0,4833000000000]],"1792":[[0,3375000000000],[0,3375000000000],[0,3375000000000],[0,3792000000000]],"1024":[[0,1916000000000],[0,1916000000000],[0,1916000000000],[0,1917000000000]],"6144":[[0,11500000000000],[0,11500000000000],[0,11500000000000],[0,11542000000000]],"56":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1475333000000000],[0,1508625000000000]],"163840":[[0,307083000000000],[0,307250000000000],[0,336083000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,53666000000000],[0,53708000000000],[0,53750000000000],[0,58209000000000]],"512":[[0,958000000000],[0,958000000000],[0,959000000000],[0,1083000000000]],"196608":[[0,368625000000000],[0,370375000000000],[0,375625000000000]],"458752":[[0,883625000000000],[0,884083000000000]],"24576":[[0,46041000000000],[0,46042000000000],[0,46083000000000],[0,46083000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,500000000000],[0,500000000000]],"1536":[[0,2833000000000],[0,2875000000000],[0,2875000000000],[0,3000000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,625000000000],[0,625000000000],[0,625000000000],[0,709000000000]],"114688":[[0,215042000000000],[0,215083000000000],[0,215083000000000]],"131072":[[0,245625000000000],[0,245750000000000],[0,245791000000000]],"16384":[[0,30625000000000],[0,30625000000000],[0,30708000000000],[0,30709000000000]],"5120":[[0,9583000000000],[0,9583000000000],[0,9584000000000],[0,9625000000000]],"229376":[[0,433625000000000],[0,433750000000000],[0,454625000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1230083000000000],[0,1243500000000000]],"7168":[[0,13375000000000],[0,13416000000000],[0,13458000000000],[0,13458000000000]],"20480":[[0,38334000000000],[0,38375000000000],[0,38416000000000],[0,40209000000000]],"65536":[[0,122834000000000],[0,122875000000000],[0,122875000000000],[0,122917000000000]],"917504":[[0,1720375000000000],[0,1721292000000000]],"160":[[0,291000000000],[0,292000000000],[0,333000000000],[0,333000000000]],"640":[[0,1208000000000],[0,1208000000000],[0,1208000000000],[0,1209000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,737917000000000],[0,750583000000000]],"57344":[[0,107500000000000],[0,107500000000000],[0,107500000000000],[0,107625000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1417000000000],[0,1417000000000],[0,1417000000000],[0,1417000000000]],"448":[[0,791000000000],[0,833000000000],[0,875000000000],[0,917000000000]],"8192":[[0,15334000000000],[0,15375000000000],[0,15375000000000],[0,15375000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,19166000000000],[0,19167000000000],[0,19167000000000],[0,19250000000000]],"14336":[[0,26792000000000],[0,26834000000000],[0,26875000000000],[0,26875000000000]],"32768":[[0,61375000000000],[0,61416000000000],[0,61417000000000],[0,61500000000000]],"128":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"4096":[[0,7666000000000],[0,7666000000000],[0,7708000000000],[0,7708000000000]],"49152":[[0,92083000000000],[0,92125000000000],[0,92166000000000],[0,92292000000000]],"262144":[[0,491541000000000],[0,491541000000000],[0,517709000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,184250000000000],[0,184292000000000],[0,184292000000000],[0,184292000000000]]}},{"title":"Array init from unsafe buffer","results":{"2048":[[0,244590000000],[0,268330000000],[0,271660000000],[0,322080000000]],"1048576":[[0,114557250000000],[0,114777666666666]],"96":[[0,48330000000],[0,48330000000],[0,49160000000],[0,49580000000]],"327680":[[0,30583000000000],[0,37667000000000]],"384":[[0,64160000000],[0,64160000000],[0,66250000000],[0,67910000000]],"12288":[[0,1613750000000],[0,1620000000000],[0,1677090000000],[0,1751250000000]],"81920":[[0,8144160000000],[0,8159580000000],[0,8166250000000],[0,8231250000000]],"8":[[0,32910000000],[0,32910000000],[0,32910000000],[0,32920000000]],"1280":[[0,148340000000],[0,150000000000],[0,150000000000],[0,152500000000]],"3584":[[0,521250000000],[0,547080000000],[0,559590000000],[0,642910000000]],"7":[[0,35000000000],[0,35410000000],[0,35410000000],[0,35410000000]],"524288":[[0,50807080000000],[0,56819454545454]],"112":[[0,50000000000],[0,50000000000],[0,51250000000],[0,51250000000]],"896":[[0,115830000000],[0,116250000000],[0,117080000000],[0,117500000000]],"192":[[0,50410000000],[0,50420000000],[0,50830000000],[0,50830000000]],"80":[[0,46660000000],[0,46660000000],[0,47500000000],[0,47910000000]],"24":[[0,34580000000],[0,34580000000],[0,34580000000],[0,34580000000]],"40960":[[0,4487500000000],[0,4492500000000],[0,4515000000000],[0,4523330000000]],"16":[[0,32910000000],[0,32920000000],[0,33330000000],[0,33330000000]],"3072":[[0,416250000000],[0,459000000000],[0,459000000000],[0,502080000000]],"20":[[0,32920000000],[0,33330000000],[0,33330000000],[0,33340000000]],"224":[[0,52910000000],[0,53330000000],[0,54160000000],[0,54160000000]],"2560":[[0,317090000000],[0,374590000000],[0,378750000000],[0,409590000000]],"1792":[[0,194449275362],[0,203441176470],[0,214285714285],[0,255000000000]],"1024":[[0,128330000000],[0,128750000000],[0,128750000000],[0,129580000000]],"6144":[[0,1197910000000],[0,1625000000000],[0,1770840000000],[0,1777920000000]],"56":[[0,44160000000],[0,44160000000],[0,45410000000],[0,45410000000]],"786432":[[0,87056680000000],[0,87178277777777]],"163840":[[0,15562090000000],[0,15842080000000],[0,19295000000000]],"6":[[0,34580000000],[0,35000000000],[0,35000000000],[0,35410000000]],"48":[[0,43330000000],[0,43340000000],[0,44580000000],[0,44580000000]],"32":[[0,42080000000],[0,42080000000],[0,42080000000],[0,42080000000]],"14":[[0,32910000000],[0,32910000000],[0,32910000000],[0,33330000000]],"28672":[[0,3377500000000],[0,3384170000000],[0,3397910000000],[0,3402080000000]],"512":[[0,87080000000],[0,87080000000],[0,87090000000],[0,87500000000]],"196608":[[0,18727538461538],[0,19414160000000],[0,20789170000000]],"458752":[[0,47683400000000],[0,54458000000000]],"24576":[[0,3012500000000],[0,3014580000000],[0,3016670000000],[0,3026660000000]],"2":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"256":[[0,55000000000],[0,55410000000],[0,55410000000],[0,55410000000]],"1536":[[0,170830000000],[0,175830000000],[0,195840000000],[0,221660000000]],"64":[[0,45000000000],[0,45000000000],[0,45000000000],[0,45410000000]],"320":[[0,60000000000],[0,60000000000],[0,60000000000],[0,68330000000]],"114688":[[0,11097920000000],[0,11122080000000],[0,15038750000000]],"131072":[[0,12590830000000],[0,12925000000000],[0,13079170000000]],"16384":[[0,2205410000000],[0,2217920000000],[0,2223750000000],[0,2229590000000]],"5120":[[0,1072080000000],[0,1427500000000],[0,1437080000000],[0,1455000000000]],"229376":[[0,21749240740740],[0,21772080000000],[0,22019580000000]],"5":[[0,34580000000],[0,34580000000],[0,34580000000],[0,35000000000]],"10":[[0,32910000000],[0,32920000000],[0,32920000000],[0,33330000000]],"28":[[0,34580000000],[0,34580000000],[0,34590000000],[0,34590000000]],"655360":[[0,63834000000000],[0,65719580000000]],"7168":[[0,1586250000000],[0,1704160000000],[0,1782910000000],[0,1785000000000]],"20480":[[0,2646250000000],[0,2649529411764],[0,2661660000000],[0,2696670000000]],"65536":[[0,6676660000000],[0,6686961538461],[0,6726250000000],[0,6742500000000]],"917504":[[0,100812500000000],[0,100892588888888]],"160":[[0,48330000000],[0,48330000000],[0,49580000000],[0,49590000000]],"640":[[0,95830000000],[0,96660000000],[0,97080000000],[0,97090000000]],"40":[[0,42500000000],[0,42910000000],[0,43750000000],[0,43750000000]],"393216":[[0,37404170000000],[0,37417000000000]],"57344":[[0,5948750000000],[0,5949170000000],[0,6000000000000],[0,6327920000000]],"4":[[0,34160000000],[0,34580000000],[0,34580000000],[0,36250000000]],"1":[[0,35000000000],[0,35000000000],[0,35410000000],[0,35410000000]],"768":[[0,104000000000],[0,106250000000],[0,107500000000],[0,107500000000]],"448":[[0,77080000000],[0,77080000000],[0,77080000000],[0,77080000000]],"8192":[[0,1319590000000],[0,1592080000000],[0,1615846153846],[0,1767500000000]],"12":[[0,32910000000],[0,32910000000],[0,32910000000],[0,32910000000]],"10240":[[0,1529170000000],[0,1565000000000],[0,1602080000000],[0,1617090000000]],"14336":[[0,1845840000000],[0,1859160000000],[0,1859170000000],[0,1862910000000]],"32768":[[0,3744590000000],[0,3747500000000],[0,3755546666666],[0,3757500000000]],"128":[[0,45410000000],[0,45830000000],[0,45840000000],[0,46250000000]],"4096":[[0,1217500000000],[0,1224160000000],[0,1329170000000],[0,1330000000000]],"49152":[[0,5217080000000],[0,5222500000000],[0,5226250000000],[0,5226660000000]],"262144":[[0,25221250000000],[0,25586250000000],[0,26555666666666]],"3":[[0,34160000000],[0,34170000000],[0,34170000000],[0,34580000000]],"98304":[[0,9618000000000],[0,9668330000000],[0,9672910000000],[0,9715000000000]]}},{"title":"Array sequential iteration","results":{"2048":[[0,1664772727272],[0,1666670000000],[0,1667080000000],[0,1667080000000]],"1048576":[[0,857700818181818],[0,863632545454545]],"96":[[0,82080000000],[0,82080000000],[0,82080000000],[0,82090000000]],"327680":[[0,267166000000000],[0,273646454545454]],"384":[[0,315830000000],[0,315830000000],[0,316250000000],[0,335000000000]],"12288":[[0,9979000000000],[0,9979160000000],[0,9980420000000],[0,9983340000000]],"81920":[[0,66500000000000],[0,66542000000000],[0,66583000000000],[0,67013750000000]],"8":[[0,7910000000],[0,7920000000],[0,8330000000],[0,8330000000]],"1280":[[0,1042000000000],[0,1042920000000],[0,1043340000000],[0,1043750000000]],"3584":[[0,2913330000000],[0,2913750000000],[0,2913750000000],[0,2914170000000]],"7":[[0,7500000000],[0,7500000000],[0,7500000000],[0,7500000000]],"524288":[[0,425875000000000],[0,431250000000000]],"112":[[0,91600000000],[0,95000000000],[0,95000000000],[0,95410000000]],"896":[[0,729000000000],[0,731660000000],[0,731660000000],[0,731660000000]],"192":[[0,159750000000],[0,160000000000],[0,160410000000],[0,160410000000]],"80":[[0,68750000000],[0,69160000000],[0,69160000000],[0,69160000000]],"24":[[0,20830000000],[0,21250000000],[0,21250000000],[0,21250000000]],"40960":[[0,33250000000000],[0,33250000000000],[0,33291000000000],[0,33293750000000]],"16":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15830000000]],"3072":[[0,2497920000000],[0,2497920000000],[0,2498330000000],[0,2498330000000]],"20":[[0,17910000000],[0,17920000000],[0,18330000000],[0,18330000000]],"224":[[0,185830000000],[0,186250000000],[0,186250000000],[0,186250000000]],"2560":[[0,2082500000000],[0,2082500000000],[0,2082500000000],[0,2082500000000]],"1792":[[0,1458000000000],[0,1458750000000],[0,1459160000000],[0,1459160000000]],"1024":[[0,833333333333],[0,835410000000],[0,835410000000],[0,835420000000]],"6144":[[0,4991660000000],[0,4991670000000],[0,4991670000000],[0,4992080000000]],"56":[[0,49590000000],[0,50000000000],[0,50000000000],[0,50000000000]],"786432":[[0,657052800000000],[0,657875000000000]],"163840":[[0,133041000000000],[0,133375000000000],[0,139833000000000]],"6":[[0,6660000000],[0,6660000000],[0,6660000000],[0,6660000000]],"48":[[0,43750000000],[0,43750000000],[0,43750000000],[0,43750000000]],"32":[[0,27500000000],[0,27800000000],[0,27910000000],[0,27910000000]],"14":[[0,13330000000],[0,13330000000],[0,13330000000],[0,13330000000]],"28672":[[0,23292000000000],[0,23302100000000],[0,23334000000000],[0,23366670000000]],"512":[[0,416000000000],[0,419580000000],[0,420000000000],[0,420000000000]],"196608":[[0,165114406779661],[0,170403846153846],[0,174203125000000]],"458752":[[0,378250000000000],[0,380583000000000]],"24576":[[0,19959000000000],[0,20000000000000],[0,20000000000000],[0,20014170000000]],"2":[[0,3330000000],[0,3330000000],[0,3750000000],[0,3750000000]],"256":[[0,208000000000],[0,208000000000],[0,212080000000],[0,212080000000]],"1536":[[0,1250840000000],[0,1251250000000],[0,1251250000000],[0,1251250000000]],"64":[[0,56250000000],[0,56250000000],[0,56250000000],[0,56250000000]],"320":[[0,263750000000],[0,263750000000],[0,264160000000],[0,299580000000]],"114688":[[0,93119000000000],[0,95484375000000],[0,105834000000000]],"131072":[[0,106667000000000],[0,107326392857142],[0,109416000000000]],"16384":[[0,13311660000000],[0,13315000000000],[0,13333000000000],[0,13334000000000]],"5120":[[0,4159666666666],[0,4160410000000],[0,4160420000000],[0,4160830000000]],"229376":[[0,186166000000000],[0,187750000000000],[0,190157400000000]],"5":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5840000000]],"10":[[0,9580000000],[0,9580000000],[0,10000000000],[0,10000000000]],"28":[[0,24160000000],[0,24170000000],[0,24580000000],[0,24580000000]],"655360":[[0,541000000000000],[0,542363388888888]],"7168":[[0,5822920000000],[0,5822920000000],[0,5823330000000],[0,5823340000000]],"20480":[[0,16645000000000],[0,16666000000000],[0,16708000000000],[0,16791000000000]],"65536":[[0,53208000000000],[0,53222333333333],[0,53280000000000],[0,53334000000000]],"917504":[[0,746667000000000],[0,747833000000000]],"160":[[0,125000000000],[0,133750000000],[0,134160000000],[0,134160000000]],"640":[[0,523222222222],[0,523750000000],[0,523750000000],[0,523750000000]],"40":[[0,36660000000],[0,36670000000],[0,36670000000],[0,37080000000]],"393216":[[0,319333000000000],[0,327208000000000]],"57344":[[0,46560923076923],[0,46565428571428],[0,46570800000000],[0,46667000000000]],"4":[[0,5000000000],[0,5000000000],[0,5000000000],[0,5410000000]],"1":[[0,1660000000],[0,1660000000],[0,1660000000],[0,1670000000]],"768":[[0,618000000000],[0,625000000000],[0,627500000000],[0,627910000000]],"448":[[0,367500000000],[0,367910000000],[0,367910000000],[0,367920000000]],"8192":[[0,6653750000000],[0,6654170000000],[0,6654170000000],[0,6667000000000]],"12":[[0,11250000000],[0,11250000000],[0,11660000000],[0,11660000000]],"10240":[[0,8316660000000],[0,8317080000000],[0,8317080000000],[0,8333000000000]],"14336":[[0,11642500000000],[0,11644809523809],[0,11647500000000],[0,11667000000000]],"32768":[[0,26614750000000],[0,26615420000000],[0,26643340000000],[0,26897500000000]],"128":[[0,108330000000],[0,108330000000],[0,108330000000],[0,108330000000]],"4096":[[0,3329160000000],[0,3329170000000],[0,3329580000000],[0,3329580000000]],"49152":[[0,39959000000000],[0,40013750000000],[0,40042000000000],[0,40125000000000]],"262144":[[0,212875000000000],[0,213000000000000],[0,213458000000000]],"3":[[0,4160000000],[0,4170000000],[0,4580000000],[0,4580000000]],"98304":[[0,79809782608695],[0,79833000000000],[0,80052083333333],[0,81702681818181]]}},{"title":"Array subscript get, random offsets","results":{"2048":[[0,1666660000000],[0,1667000000000],[0,1667080000000],[0,1667500000000]],"1048576":[[0,872375000000000],[0,879031250000000]],"96":[[0,82090000000],[0,82500000000],[0,82500000000],[0,82500000000]],"327680":[[0,270459000000000],[0,274681250000000]],"384":[[0,315830000000],[0,315830000000],[0,316250000000],[0,337080000000]],"12288":[[0,9993750000000],[0,10056670000000],[0,10122910000000],[0,18291000000000]],"81920":[[0,66634252525252],[0,66682090000000],[0,66802920000000],[0,67373234042553]],"8":[[0,8750000000],[0,8750000000],[0,8750000000],[0,8750000000]],"1280":[[0,1041687500000],[0,1043750000000],[0,1043750000000],[0,1043750000000]],"3584":[[0,2913750000000],[0,2913750000000],[0,2914160000000],[0,2914160000000]],"7":[[0,7500000000],[0,7910000000],[0,7910000000],[0,7910000000]],"524288":[[0,426875000000000],[0,431621769230769]],"112":[[0,95000000000],[0,95410000000],[0,95410000000],[0,95410000000]],"896":[[0,732080000000],[0,732080000000],[0,732080000000],[0,732080000000]],"192":[[0,160000000000],[0,160000000000],[0,160410000000],[0,160410000000]],"80":[[0,68428571428],[0,69580000000],[0,69580000000],[0,69580000000]],"24":[[0,21250000000],[0,21250000000],[0,21250000000],[0,21660000000]],"40960":[[0,33292000000000],[0,33336250000000],[0,33415830000000],[0,33872080000000]],"16":[[0,13916666666],[0,15000000000],[0,15000000000],[0,15410000000]],"3072":[[0,2497900000000],[0,2498330000000],[0,2498330000000],[0,2498750000000]],"20":[[0,18330000000],[0,18330000000],[0,18330000000],[0,18340000000]],"224":[[0,186250000000],[0,186660000000],[0,186660000000],[0,195410000000]],"2560":[[0,2082500000000],[0,2082500000000],[0,2082500000000],[0,2082910000000]],"1792":[[0,1458000000000],[0,1458500000000],[0,1459580000000],[0,1459580000000]],"1024":[[0,823000000000],[0,835830000000],[0,835830000000],[0,835840000000]],"6144":[[0,4991660000000],[0,4992080000000],[0,4992080000000],[0,4992500000000]],"56":[[0,42000000000],[0,50000000000],[0,50000000000],[0,50000000000]],"786432":[[0,643167000000000],[0,650125000000000]],"163840":[[0,133019489361702],[0,133309307692307],[0,140064285714285]],"6":[[0,7080000000],[0,7080000000],[0,7080000000],[0,7080000000]],"48":[[0,42000000000],[0,43330000000],[0,43750000000],[0,43750000000]],"32":[[0,27910000000],[0,27920000000],[0,28330000000],[0,28330000000]],"14":[[0,13330000000],[0,13330000000],[0,13750000000],[0,13750000000]],"28672":[[0,23295454545454],[0,23296875000000],[0,23353330000000],[0,23376660000000]],"512":[[0,416500000000],[0,420000000000],[0,420410000000],[0,420410000000]],"196608":[[0,159750000000000],[0,159791500000000],[0,170862363636363]],"458752":[[0,377833000000000],[0,382795900000000]],"24576":[[0,19979000000000],[0,20000000000000],[0,20012920000000],[0,20138750000000]],"2":[[0,3750000000],[0,3750000000],[0,3750000000],[0,3750000000]],"256":[[0,208000000000],[0,209000000000],[0,209000000000],[0,212080000000]],"1536":[[0,1250000000000],[0,1251660000000],[0,1251660000000],[0,1251660000000]],"64":[[0,42000000000],[0,55555555555],[0,56660000000],[0,56660000000]],"320":[[0,250000000000],[0,264580000000],[0,264580000000],[0,301250000000]],"114688":[[0,93267615384615],[0,94844696969696],[0,110708400000000]],"131072":[[0,106687500000000],[0,107107954545454],[0,107330566666666]],"16384":[[0,13321670000000],[0,13334000000000],[0,13354170000000],[0,13357500000000]],"5120":[[0,4159294117647],[0,4160410000000],[0,4160511363636],[0,4160830000000]],"229376":[[0,186250000000000],[0,188865095238095],[0,215036680000000]],"5":[[0,5830000000],[0,6250000000],[0,6250000000],[0,6250000000]],"10":[[0,10000000000],[0,10410000000],[0,10410000000],[0,10410000000]],"28":[[0,24580000000],[0,24580000000],[0,24580000000],[0,25000000000]],"655360":[[0,534666000000000],[0,539298666666666]],"7168":[[0,5823330000000],[0,5823453608247],[0,5824160000000],[0,5857090000000]],"20480":[[0,16644580000000],[0,16713750000000],[0,16839580000000],[0,16934590000000]],"65536":[[0,53250000000000],[0,53330420000000],[0,53412500000000],[0,53818750000000]],"917504":[[0,753500000000000],[0,758991800000000]],"160":[[0,134170000000],[0,134580000000],[0,134580000000],[0,134580000000]],"640":[[0,522727272727],[0,523816326530],[0,524160000000],[0,524160000000]],"40":[[0,37080000000],[0,37500000000],[0,37500000000],[0,37500000000]],"393216":[[0,320982583333333],[0,331745388888888]],"57344":[[0,46602920000000],[0,47102500000000],[0,47249160000000],[0,47343330000000]],"4":[[0,5000000000],[0,5410000000],[0,5410000000],[0,5420000000]],"1":[[0,2080000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,625000000000],[0,627910000000],[0,627910000000],[0,627920000000]],"448":[[0,368330000000],[0,368330000000],[0,368330000000],[0,368750000000]],"8192":[[0,6657920000000],[0,6658340000000],[0,6659580000000],[0,6710410000000]],"12":[[0,11670000000],[0,12080000000],[0,12080000000],[0,12080000000]],"10240":[[0,8325830000000],[0,8325840000000],[0,8326250000000],[0,8369580000000]],"14336":[[0,11655000000000],[0,11659160000000],[0,11663330000000],[0,11690420000000]],"32768":[[0,26616554054054],[0,26653750000000],[0,26667000000000],[0,27095000000000]],"128":[[0,107920000000],[0,108330000000],[0,108340000000],[0,108750000000]],"4096":[[0,3329545454545],[0,3329580000000],[0,3330000000000],[0,3330000000000]],"49152":[[0,39935367346938],[0,39959000000000],[0,40045840000000],[0,40127080000000]],"262144":[[0,212917000000000],[0,213500000000000],[0,216917000000000]],"3":[[0,4170000000],[0,4580000000],[0,4580000000],[0,4580000000]],"98304":[[0,79958333333333],[0,80310425000000],[0,80869513157894],[0,81386075949367]]}},{"title":"Array mutate through subscript","results":{"2048":[[0,2750000000000],[0,2750000000000],[0,2791000000000],[0,2792000000000]],"1048576":[[0,1432917000000000],[0,1435209000000000]],"96":[[0,125000000000],[0,125000000000],[0,125000000000],[0,208000000000]],"327680":[[0,451708000000000],[0,464958000000000]],"384":[[0,500000000000],[0,542000000000],[0,584000000000],[0,584000000000]],"12288":[[0,16625000000000],[0,16625000000000],[0,16666000000000],[0,18792000000000]],"81920":[[0,110791000000000],[0,110833000000000],[0,110875000000000],[0,110917000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1750000000000],[0,1750000000000],[0,1750000000000],[0,1833000000000]],"3584":[[0,4833000000000],[0,4833000000000],[0,4875000000000],[0,4875000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,709625000000000],[0,719333000000000]],"112":[[0,166000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"896":[[0,1209000000000],[0,1250000000000],[0,1250000000000],[0,1250000000000]],"192":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,55416000000000],[0,55417000000000],[0,55417000000000],[0,55458000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,4125000000000],[0,4166000000000],[0,4166000000000],[0,4166000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,292000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"2560":[[0,3458000000000],[0,3458000000000],[0,3459000000000],[0,3459000000000]],"1792":[[0,2416000000000],[0,2417000000000],[0,2417000000000],[0,2542000000000]],"1024":[[0,1375000000000],[0,1375000000000],[0,1375000000000],[0,1458000000000]],"6144":[[0,8291000000000],[0,8333000000000],[0,8333000000000],[0,8333000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"786432":[[0,1064917000000000],[0,1097000000000000]],"163840":[[0,221666000000000],[0,221791000000000],[0,222000000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28672":[[0,38791000000000],[0,38791000000000],[0,38792000000000],[0,38792000000000]],"512":[[0,708000000000],[0,708000000000],[0,708000000000],[0,708000000000]],"196608":[[0,265958000000000],[0,266083000000000],[0,278250000000000]],"458752":[[0,631458000000000],[0,681167000000000]],"24576":[[0,33250000000000],[0,33250000000000],[0,33250000000000],[0,33250000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"1536":[[0,2083000000000],[0,2083000000000],[0,2083000000000],[0,2084000000000]],"64":[[0,83000000000],[0,83000000000],[0,84000000000],[0,84000000000]],"320":[[0,458000000000],[0,458000000000],[0,500000000000],[0,875000000000]],"114688":[[0,155208000000000],[0,155250000000000],[0,162750000000000]],"131072":[[0,177333000000000],[0,177375000000000],[0,177542000000000]],"16384":[[0,22125000000000],[0,22166000000000],[0,22167000000000],[0,22583000000000]],"5120":[[0,6916000000000],[0,6958000000000],[0,6958000000000],[0,6958000000000]],"229376":[[0,310416000000000],[0,310666000000000],[0,325583000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"655360":[[0,887291000000000],[0,887500000000000]],"7168":[[0,9667000000000],[0,9667000000000],[0,9708000000000],[0,9708000000000]],"20480":[[0,27708000000000],[0,27750000000000],[0,27750000000000],[0,27750000000000]],"65536":[[0,88625000000000],[0,88708000000000],[0,88750000000000],[0,88750000000000]],"917504":[[0,1241916000000000],[0,1271167000000000]],"160":[[0,208000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"640":[[0,875000000000],[0,875000000000],[0,875000000000],[0,916000000000]],"40":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"393216":[[0,532125000000000],[0,539209000000000]],"57344":[[0,77583000000000],[0,77583000000000],[0,77584000000000],[0,77584000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1041000000000],[0,1042000000000],[0,1042000000000],[0,1083000000000]],"448":[[0,625000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"8192":[[0,11083000000000],[0,11083000000000],[0,11083000000000],[0,11125000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,13875000000000],[0,13875000000000],[0,13875000000000],[0,13875000000000]],"14336":[[0,19375000000000],[0,19375000000000],[0,19375000000000],[0,19416000000000]],"32768":[[0,44291000000000],[0,44292000000000],[0,44334000000000],[0,44334000000000]],"128":[[0,166000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"4096":[[0,5541000000000],[0,5541000000000],[0,5542000000000],[0,5542000000000]],"49152":[[0,66500000000000],[0,66541000000000],[0,66541000000000],[0,66584000000000]],"262144":[[0,354750000000000],[0,358167000000000],[0,360958000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,132958000000000],[0,133000000000000],[0,133083000000000],[0,133209000000000]]}},{"title":"Array random swaps","results":{"2048":[[0,2833000000000],[0,2875000000000],[0,2875000000000],[0,2875000000000]],"1048576":[[0,1757375000000000],[0,1787542000000000]],"96":[[0,125000000000],[0,166000000000],[0,166000000000],[0,209000000000]],"327680":[[0,513250000000000],[0,559875000000000]],"384":[[0,542000000000],[0,583000000000],[0,625000000000],[0,625000000000]],"12288":[[0,17083000000000],[0,17125000000000],[0,18083000000000],[0,19541000000000]],"81920":[[0,123834000000000],[0,123958000000000],[0,124125000000000],[0,125000000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1791000000000],[0,1792000000000],[0,1834000000000],[0,1875000000000]],"3584":[[0,5000000000000],[0,5000000000000],[0,5000000000000],[0,5000000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,838709000000000],[0,842541000000000]],"112":[[0,166000000000],[0,167000000000],[0,208000000000],[0,209000000000]],"896":[[0,1250000000000],[0,1250000000000],[0,1291000000000],[0,1333000000000]],"192":[[0,250000000000],[0,291000000000],[0,292000000000],[0,292000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"24":[[0,41000000000],[0,41000000000],[0,41000000000],[0,83000000000]],"40960":[[0,59958000000000],[0,60042000000000],[0,60334000000000],[0,61750000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"3072":[[0,4292000000000],[0,4292000000000],[0,4292000000000],[0,4292000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"224":[[0,333000000000],[0,333000000000],[0,333000000000],[0,375000000000]],"2560":[[0,3583000000000],[0,3583000000000],[0,3584000000000],[0,3625000000000]],"1792":[[0,2500000000000],[0,2500000000000],[0,2541000000000],[0,2625000000000]],"1024":[[0,1416000000000],[0,1417000000000],[0,1458000000000],[0,1500000000000]],"6144":[[0,8542000000000],[0,8542000000000],[0,8583000000000],[0,8584000000000]],"56":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1324958000000000],[0,1336542000000000]],"163840":[[0,252334000000000],[0,255083000000000],[0,286959000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,40833000000000],[0,40917000000000],[0,41083000000000],[0,41166000000000]],"512":[[0,708000000000],[0,709000000000],[0,750000000000],[0,750000000000]],"196608":[[0,312417000000000],[0,318833000000000],[0,320250000000000]],"458752":[[0,727875000000000],[0,745625000000000]],"24576":[[0,34625000000000],[0,34708000000000],[0,34709000000000],[0,34750000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"1536":[[0,2125000000000],[0,2166000000000],[0,2166000000000],[0,2167000000000]],"64":[[0,84000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,458000000000],[0,500000000000],[0,541000000000],[0,1083000000000]],"114688":[[0,175375000000000],[0,175458000000000],[0,185875000000000]],"131072":[[0,201875000000000],[0,202792000000000],[0,205000000000000]],"16384":[[0,22667000000000],[0,22792000000000],[0,22792000000000],[0,22792000000000]],"5120":[[0,7125000000000],[0,7125000000000],[0,7166000000000],[0,7166000000000]],"229376":[[0,357583000000000],[0,358333000000000],[0,395167000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"655360":[[0,1088416000000000],[0,1102542000000000]],"7168":[[0,9958000000000],[0,9958000000000],[0,10000000000000],[0,10041000000000]],"20480":[[0,28625000000000],[0,28625000000000],[0,28708000000000],[0,28750000000000]],"65536":[[0,98375000000000],[0,98500000000000],[0,98625000000000],[0,99250000000000]],"917504":[[0,1526792000000000],[0,1540250000000000]],"160":[[0,208000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"640":[[0,916000000000],[0,917000000000],[0,917000000000],[0,917000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"393216":[[0,613417000000000],[0,618584000000000]],"57344":[[0,84958000000000],[0,85333000000000],[0,85917000000000],[0,86084000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1083000000000],[0,1083000000000],[0,1125000000000],[0,1166000000000]],"448":[[0,625000000000],[0,625000000000],[0,666000000000],[0,666000000000]],"8192":[[0,11375000000000],[0,11416000000000],[0,11458000000000],[0,11459000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,14250000000000],[0,14250000000000],[0,14291000000000],[0,14292000000000]],"14336":[[0,19875000000000],[0,19875000000000],[0,19917000000000],[0,19958000000000]],"32768":[[0,47375000000000],[0,47375000000000],[0,47500000000000],[0,47667000000000]],"128":[[0,166000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"4096":[[0,5708000000000],[0,5708000000000],[0,5708000000000],[0,5708000000000]],"49152":[[0,72625000000000],[0,72834000000000],[0,73000000000000],[0,73125000000000]],"262144":[[0,407583000000000],[0,412375000000000],[0,418958000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,150000000000000],[0,150125000000000],[0,150625000000000],[0,150792000000000]]}},{"title":"Array partitioning around middle","results":{"2048":[[0,1333000000000],[0,1375000000000],[0,1375000000000],[0,1375000000000]],"1048576":[[0,2955792000000000],[0,3077500000000000]],"96":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"327680":[[0,919125000000000],[0,920458000000000]],"384":[[0,291000000000],[0,292000000000],[0,292000000000],[0,292000000000]],"12288":[[0,13375000000000],[0,20959000000000],[0,21542000000000],[0,38791000000000]],"81920":[[0,218292000000000],[0,218917000000000],[0,219666000000000],[0,222584000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,792000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"3584":[[0,2375000000000],[0,2417000000000],[0,2542000000000],[0,3208000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,1477250000000000],[0,1486875000000000]],"112":[[0,83000000000],[0,83000000000],[0,84000000000],[0,84000000000]],"896":[[0,583000000000],[0,583000000000],[0,625000000000],[0,791000000000]],"192":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"80":[[0,41000000000],[0,41000000000],[0,83000000000],[0,83000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,96834000000000],[0,97208000000000],[0,100542000000000],[0,105042000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,2000000000000],[0,2084000000000],[0,2125000000000],[0,2125000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,125000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"2560":[[0,1708000000000],[0,1708000000000],[0,1750000000000],[0,1750000000000]],"1792":[[0,1167000000000],[0,1208000000000],[0,1209000000000],[0,1250000000000]],"1024":[[0,667000000000],[0,667000000000],[0,708000000000],[0,709000000000]],"6144":[[0,4166000000000],[0,4250000000000],[0,4750000000000],[0,5666000000000]],"56":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"786432":[[0,2220625000000000],[0,2235458000000000]],"163840":[[0,455417000000000],[0,466916000000000],[0,473917000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"48":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,58791000000000],[0,59084000000000],[0,60417000000000],[0,70875000000000]],"512":[[0,333000000000],[0,333000000000],[0,334000000000],[0,375000000000]],"196608":[[0,557542000000000],[0,562583000000000],[0,581708000000000]],"458752":[[0,1317625000000000],[0,1347917000000000]],"24576":[[0,43791000000000],[0,45833000000000],[0,50916000000000],[0,58791000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,166000000000],[0,166000000000],[0,167000000000],[0,208000000000]],"1536":[[0,1000000000000],[0,1000000000000],[0,1042000000000],[0,1042000000000]],"64":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"320":[[0,250000000000],[0,250000000000],[0,250000000000],[0,291000000000]],"114688":[[0,313458000000000],[0,317083000000000],[0,340250000000000]],"131072":[[0,362291000000000],[0,363792000000000],[0,364750000000000]],"16384":[[0,19250000000000],[0,19666000000000],[0,21375000000000],[0,34084000000000]],"5120":[[0,3375000000000],[0,3417000000000],[0,3750000000000],[0,4083000000000]],"229376":[[0,641959000000000],[0,648000000000000],[0,676708000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1879125000000000],[0,1889875000000000]],"7168":[[0,4875000000000],[0,4875000000000],[0,4916000000000],[0,5084000000000]],"20480":[[0,33417000000000],[0,34209000000000],[0,45708000000000],[0,46166000000000]],"65536":[[0,171584000000000],[0,174458000000000],[0,174625000000000],[0,175500000000000]],"917504":[[0,2582708000000000],[0,2643167000000000]],"160":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"640":[[0,417000000000],[0,417000000000],[0,459000000000],[0,500000000000]],"40":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"393216":[[0,1105708000000000],[0,1109792000000000]],"57344":[[0,146333000000000],[0,152583000000000],[0,153333000000000],[0,156333000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,500000000000],[0,500000000000],[0,542000000000],[0,542000000000]],"448":[[0,291000000000],[0,292000000000],[0,333000000000],[0,334000000000]],"8192":[[0,5792000000000],[0,6250000000000],[0,6709000000000],[0,8875000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,7500000000000],[0,14958000000000],[0,15041000000000],[0,15250000000000]],"14336":[[0,13208000000000],[0,14667000000000],[0,18375000000000],[0,22500000000000]],"32768":[[0,71709000000000],[0,72125000000000],[0,81291000000000],[0,81667000000000]],"128":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"4096":[[0,2625000000000],[0,2791000000000],[0,2792000000000],[0,2833000000000]],"49152":[[0,120500000000000],[0,122000000000000],[0,122583000000000],[0,123042000000000]],"262144":[[0,733916000000000],[0,744708000000000],[0,769750000000000]],"3":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,256167000000000],[0,265625000000000],[0,265916000000000],[0,267125000000000]]}},{"title":"Array sort","results":{"2048":[[0,45042000000000],[0,45250000000000],[0,46125000000000],[0,48292000000000]],"1048576":[[0,57984166000000000],[0,58791750000000000]],"96":[[0,916000000000],[0,1000000000000],[0,1000000000000],[0,1042000000000]],"327680":[[0,16667416000000000],[0,16717959000000000]],"384":[[0,4542000000000],[0,5333000000000],[0,5708000000000],[0,6125000000000]],"12288":[[0,420417000000000],[0,425791000000000],[0,437916000000000],[0,500000000000000]],"81920":[[0,3571459000000000],[0,3573375000000000],[0,3575375000000000],[0,3624375000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,24250000000000],[0,24417000000000],[0,25958000000000],[0,26084000000000]],"3584":[[0,96584000000000],[0,96709000000000],[0,97167000000000],[0,101042000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,27784958000000000],[0,27989000000000000]],"112":[[0,1208000000000],[0,1291000000000],[0,1333000000000],[0,1416000000000]],"896":[[0,14083000000000],[0,14333000000000],[0,14625000000000],[0,15542000000000]],"192":[[0,1958000000000],[0,2000000000000],[0,2042000000000],[0,2167000000000]],"80":[[0,625000000000],[0,667000000000],[0,708000000000],[0,875000000000]],"24":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"40960":[[0,1643958000000000],[0,1661084000000000],[0,1673334000000000],[0,1687291000000000]],"16":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"3072":[[0,79750000000000],[0,81584000000000],[0,81833000000000],[0,83333000000000]],"20":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"224":[[0,2625000000000],[0,2750000000000],[0,2875000000000],[0,4334000000000]],"2560":[[0,62042000000000],[0,65209000000000],[0,65583000000000],[0,72583000000000]],"1792":[[0,38250000000000],[0,39958000000000],[0,40417000000000],[0,41417000000000]],"1024":[[0,16750000000000],[0,16916000000000],[0,19375000000000],[0,23958000000000]],"6144":[[0,186542000000000],[0,186667000000000],[0,187916000000000],[0,188792000000000]],"56":[[0,375000000000],[0,417000000000],[0,417000000000],[0,458000000000]],"786432":[[0,42428709000000000],[0,42774125000000000]],"163840":[[0,7643666000000000],[0,7733958000000000],[0,7959333000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"32":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,1108166000000000],[0,1109791000000000],[0,1124458000000000],[0,1125584000000000]],"512":[[0,5167000000000],[0,5208000000000],[0,5458000000000],[0,5500000000000]],"196608":[[0,9563917000000000],[0,9572208000000000],[0,9755416000000000]],"458752":[[0,24058167000000000],[0,24717333000000000]],"24576":[[0,925542000000000],[0,930708000000000],[0,934083000000000],[0,946167000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,2250000000000],[0,2291000000000],[0,2334000000000],[0,3125000000000]],"1536":[[0,31125000000000],[0,31333000000000],[0,31917000000000],[0,32208000000000]],"64":[[0,500000000000],[0,542000000000],[0,542000000000],[0,625000000000]],"320":[[0,3125000000000],[0,3459000000000],[0,3583000000000],[0,3917000000000]],"114688":[[0,5171708000000000],[0,5172125000000000],[0,5275333000000000]],"131072":[[0,6044916000000000],[0,6046417000000000],[0,6169209000000000]],"16384":[[0,589583000000000],[0,590250000000000],[0,593917000000000],[0,595250000000000]],"5120":[[0,149833000000000],[0,150917000000000],[0,151417000000000],[0,151709000000000]],"229376":[[0,11077875000000000],[0,11092000000000000],[0,11436958000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"28":[[0,83000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"655360":[[0,35075792000000000],[0,35163500000000000]],"7168":[[0,222500000000000],[0,224125000000000],[0,225583000000000],[0,229833000000000]],"20480":[[0,752834000000000],[0,762625000000000],[0,768959000000000],[0,788375000000000]],"65536":[[0,2810792000000000],[0,2811000000000000],[0,2812208000000000],[0,2855125000000000]],"917504":[[0,50169666000000000],[0,50444458000000000]],"160":[[0,1500000000000],[0,1500000000000],[0,1584000000000],[0,1666000000000]],"640":[[0,7542000000000],[0,7584000000000],[0,7625000000000],[0,9750000000000]],"40":[[0,167000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"393216":[[0,19878792000000000],[0,19983750000000000]],"57344":[[0,2398000000000000],[0,2410208000000000],[0,2427167000000000],[0,2446041000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,10666000000000],[0,10875000000000],[0,12000000000000],[0,15125000000000]],"448":[[0,5667000000000],[0,5708000000000],[0,5917000000000],[0,5959000000000]],"8192":[[0,263833000000000],[0,264208000000000],[0,270125000000000],[0,271542000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,339583000000000],[0,340625000000000],[0,348167000000000],[0,355542000000000]],"14336":[[0,499000000000000],[0,500708000000000],[0,505209000000000],[0,512042000000000]],"32768":[[0,1295625000000000],[0,1307208000000000],[0,1310083000000000],[0,1310875000000000]],"128":[[0,1083000000000],[0,1167000000000],[0,1167000000000],[0,1208000000000]],"4096":[[0,115209000000000],[0,115459000000000],[0,117917000000000],[0,121959000000000]],"49152":[[0,2019500000000000],[0,2022208000000000],[0,2023417000000000],[0,2028250000000000]],"262144":[[0,13015958000000000],[0,13121334000000000],[0,13137333000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,4358000000000000],[0,4369542000000000],[0,4373542000000000],[0,4453042000000000]]}},{"title":"Array append","results":{"2048":[[0,1623750000000],[0,1629590000000],[0,1645420000000],[0,1653750000000]],"1048576":[[0,1286521000000000],[0,1454854000000000]],"96":[[0,316600000000],[0,316670000000],[0,316670000000],[0,317500000000]],"327680":[[0,343750000000000],[0,399262166666666]],"384":[[0,576660000000],[0,577080000000],[0,577910000000],[0,637920000000]],"12288":[[0,11334000000000],[0,11513888888888],[0,11939160000000],[0,15652500000000]],"81920":[[0,64459000000000],[0,70125000000000],[0,89489472527472],[0,92027597402597]],"8":[[0,114580000000],[0,114580000000],[0,114580000000],[0,114580000000]],"1280":[[0,1303750000000],[0,1305000000000],[0,1314160000000],[0,1329580000000]],"3584":[[0,3156670000000],[0,3321250000000],[0,3346670000000],[0,3371670000000]],"7":[[0,114160000000],[0,114160000000],[0,114170000000],[0,114580000000]],"524288":[[0,601958000000000],[0,716758300000000]],"112":[[0,322920000000],[0,323750000000],[0,323750000000],[0,324160000000]],"896":[[0,909090909090],[0,913750000000],[0,920000000000],[0,966250000000]],"192":[[0,411250000000],[0,411670000000],[0,412500000000],[0,418750000000]],"80":[[0,311660000000],[0,311670000000],[0,313750000000],[0,322920000000]],"24":[[0,198750000000],[0,198750000000],[0,198750000000],[0,199160000000]],"40960":[[0,32821670000000],[0,33917000000000],[0,34416000000000],[0,46448330000000]],"16":[[0,150410000000],[0,150410000000],[0,150830000000],[0,151660000000]],"3072":[[0,2948750000000],[0,3111702127659],[0,3123330000000],[0,3147920000000]],"20":[[0,197080000000],[0,197080000000],[0,197500000000],[0,197910000000]],"224":[[0,424590000000],[0,425000000000],[0,425000000000],[0,429160000000]],"2560":[[0,2866250000000],[0,2882500000000],[0,2892090000000],[0,2908750000000]],"1792":[[0,1520420000000],[0,1522080000000],[0,1524170000000],[0,1537080000000]],"1024":[[0,978330000000],[0,983750000000],[0,984170000000],[0,1022920000000]],"6144":[[0,6211670000000],[0,6277500000000],[0,6339170000000],[0,6444590000000]],"56":[[0,257500000000],[0,257500000000],[0,258750000000],[0,263330000000]],"786432":[[0,845916750000000],[0,870406250000000]],"163840":[[0,139167000000000],[0,149667000000000],[0,191550675675675]],"6":[[0,114160000000],[0,114160000000],[0,114160000000],[0,114170000000]],"48":[[0,254160000000],[0,254160000000],[0,254590000000],[0,256250000000]],"32":[[0,200410000000],[0,201660000000],[0,202080000000],[0,202500000000]],"14":[[0,149580000000],[0,150000000000],[0,150410000000],[0,150410000000]],"28672":[[0,28333000000000],[0,30041000000000],[0,31750000000000],[0,34209000000000]],"512":[[0,627080000000],[0,627080000000],[0,629170000000],[0,629580000000]],"196608":[[0,191285450000000],[0,234241680000000],[0,243644083333333]],"458752":[[0,613875000000000],[0,616812500000000]],"24576":[[0,26658854166666],[0,27152777777777],[0,30036100000000],[0,30276259259259]],"2":[[0,40410000000],[0,40410000000],[0,40410000000],[0,40410000000]],"256":[[0,437910000000],[0,437910000000],[0,438330000000],[0,440000000000]],"1536":[[0,1375000000000],[0,1398320000000],[0,1426660000000],[0,1430000000000]],"64":[[0,260000000000],[0,260410000000],[0,260830000000],[0,260830000000]],"320":[[0,548330000000],[0,548750000000],[0,549580000000],[0,634160000000]],"114688":[[0,115738102040816],[0,118103000000000],[0,130963636363636]],"131072":[[0,141339285714285],[0,145304200000000],[0,154866071428571]],"16384":[[0,18833250000000],[0,19238000000000],[0,19297920000000],[0,19343750000000]],"5120":[[0,4125000000000],[0,4172920000000],[0,4179170000000],[0,4183340000000]],"229376":[[0,231103260869565],[0,270084000000000],[0,273917000000000]],"5":[[0,113330000000],[0,113750000000],[0,113750000000],[0,113750000000]],"10":[[0,149170000000],[0,149580000000],[0,150000000000],[0,150410000000]],"28":[[0,199590000000],[0,199590000000],[0,201660000000],[0,202500000000]],"655360":[[0,620292000000000],[0,826910714285714]],"7168":[[0,6535714285714],[0,6736670000000],[0,6798728813559],[0,6804170000000]],"20480":[[0,15797090000000],[0,20708000000000],[0,22890827586206],[0,23132500000000]],"65536":[[0,71875000000000],[0,73807142857142],[0,74626660000000],[0,74902080000000]],"917504":[[0,744166000000000],[0,996302000000000]],"160":[[0,399580000000],[0,399590000000],[0,400410000000],[0,400830000000]],"640":[[0,807500000000],[0,808330000000],[0,811670000000],[0,812080000000]],"40":[[0,252080000000],[0,252080000000],[0,252090000000],[0,252910000000]],"393216":[[0,444892857142857],[0,506084000000000]],"57344":[[0,55134508771929],[0,58292000000000],[0,59958000000000],[0,68341032608695]],"4":[[0,78750000000],[0,79160000000],[0,79170000000],[0,79580000000]],"1":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40000000000]],"768":[[0,861250000000],[0,869160000000],[0,870830000000],[0,923750000000]],"448":[[0,606250000000],[0,606250000000],[0,607090000000],[0,607920000000]],"8192":[[0,7831250000000],[0,7840420000000],[0,7861250000000],[0,7872000000000]],"12":[[0,149580000000],[0,149580000000],[0,150000000000],[0,150000000000]],"10240":[[0,8377243243243],[0,8449021276595],[0,8636250000000],[0,11561250000000]],"14336":[[0,16828330000000],[0,17167000000000],[0,17407910000000],[0,17731250000000]],"32768":[[0,29797080000000],[0,29875000000000],[0,31288340000000],[0,32083000000000]],"128":[[0,329580000000],[0,330000000000],[0,330000000000],[0,330000000000]],"4096":[[0,3489586956521],[0,3502786666666],[0,3514580000000],[0,3533750000000]],"49152":[[0,50542000000000],[0,57911840579710],[0,58814580000000],[0,59812500000000]],"262144":[[0,263667000000000],[0,315562500000000],[0,326899529411764]],"3":[[0,77500000000],[0,77910000000],[0,77910000000],[0,77910000000]],"98304":[[0,79827148148148],[0,82792000000000],[0,109833000000000],[0,116560190476190]]}},{"title":"Array append, reserving capacity","results":{"2048":[[0,993750000000],[0,995840000000],[0,996250000000],[0,998750000000]],"1048576":[[0,598016000000000],[0,701739625000000]],"96":[[0,84160000000],[0,84160000000],[0,85410000000],[0,85410000000]],"327680":[[0,178413793103448],[0,192706409090909]],"384":[[0,216250000000],[0,216670000000],[0,217391304347],[0,218330000000]],"12288":[[0,8708000000000],[0,10734590000000],[0,10835000000000],[0,10993750000000]],"81920":[[0,41848775280898],[0,44707500000000],[0,52756406593406],[0,73607954545454]],"8":[[0,39590000000],[0,40000000000],[0,40000000000],[0,40000000000]],"1280":[[0,633200000000],[0,637080000000],[0,638750000000],[0,639170000000]],"3584":[[0,1708000000000],[0,1710420000000],[0,1713330000000],[0,1715000000000]],"7":[[0,39580000000],[0,39580000000],[0,39580000000],[0,40000000000]],"524288":[[0,265647461538461],[0,344559428571428]],"112":[[0,98750000000],[0,100000000000],[0,100840000000],[0,101250000000]],"896":[[0,458750000000],[0,458750000000],[0,458750000000],[0,459160000000]],"192":[[0,127500000000],[0,127500000000],[0,128330000000],[0,128330000000]],"80":[[0,77090000000],[0,77500000000],[0,78330000000],[0,78330000000]],"24":[[0,45830000000],[0,45830000000],[0,45830000000],[0,45830000000]],"40960":[[0,21792000000000],[0,22657848484848],[0,37364160000000],[0,37657920000000]],"16":[[0,42080000000],[0,42090000000],[0,42500000000],[0,42500000000]],"3072":[[0,1458000000000],[0,1472080000000],[0,1473750000000],[0,1475410000000]],"20":[[0,44160000000],[0,44160000000],[0,44160000000],[0,44160000000]],"224":[[0,143330000000],[0,143330000000],[0,143555555555],[0,143750000000]],"2560":[[0,1234170000000],[0,1234590000000],[0,1235840000000],[0,1236670000000]],"1792":[[0,872920000000],[0,875840000000],[0,876250000000],[0,877500000000]],"1024":[[0,517500000000],[0,520420000000],[0,520830000000],[0,521250000000]],"6144":[[0,3416000000000],[0,3417000000000],[0,3458000000000],[0,3534666666666]],"56":[[0,65840000000],[0,66660000000],[0,67500000000],[0,67910000000]],"786432":[[0,467459000000000],[0,481997000000000]],"163840":[[0,116917000000000],[0,148300695652173],[0,154358974358974]],"6":[[0,39160000000],[0,39170000000],[0,39580000000],[0,39580000000]],"48":[[0,62910000000],[0,62910000000],[0,63750000000],[0,64160000000]],"32":[[0,55420000000],[0,55830000000],[0,55830000000],[0,56250000000]],"14":[[0,41250000000],[0,41660000000],[0,41660000000],[0,41660000000]],"28672":[[0,14037920000000],[0,14044340425531],[0,14069500000000],[0,14347080000000]],"512":[[0,278750000000],[0,279170000000],[0,279170000000],[0,279580000000]],"196608":[[0,111834000000000],[0,112875000000000],[0,183779771428571]],"458752":[[0,389150000000000],[0,401208000000000]],"24576":[[0,11375000000000],[0,15542000000000],[0,22438085714285],[0,22618750000000]],"2":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40000000000]],"256":[[0,157080000000],[0,157500000000],[0,157910000000],[0,157910000000]],"1536":[[0,756250000000],[0,757500000000],[0,757910000000],[0,758330000000]],"64":[[0,70000000000],[0,70000000000],[0,70000000000],[0,70000000000]],"320":[[0,186250000000],[0,187500000000],[0,187500000000],[0,213750000000]],"114688":[[0,54000000000000],[0,54125000000000],[0,69256048387096]],"131072":[[0,62948490909090],[0,73660888888888],[0,85888406779661]],"16384":[[0,8250000000000],[0,8250000000000],[0,8336250000000],[0,8917000000000]],"5120":[[0,3000000000000],[0,3047910000000],[0,3047910000000],[0,3056250000000]],"229376":[[0,151625000000000],[0,167966871794871],[0,194125000000000]],"5":[[0,38750000000],[0,39160000000],[0,39160000000],[0,39160000000]],"10":[[0,40410000000],[0,40420000000],[0,40420000000],[0,40830000000]],"28":[[0,47080000000],[0,47080000000],[0,47500000000],[0,47500000000]],"655360":[[0,299512500000000],[0,455640625000000]],"7168":[[0,3983340000000],[0,3989590000000],[0,3993750000000],[0,3994580000000]],"20480":[[0,9958000000000],[0,10042000000000],[0,10167000000000],[0,12075840000000]],"65536":[[0,30041000000000],[0,30125000000000],[0,33125000000000],[0,59700000000000]],"917504":[[0,464825000000000],[0,655178571428571]],"160":[[0,115000000000],[0,115000000000],[0,115410000000],[0,115830000000]],"640":[[0,337500000000],[0,339580000000],[0,340410000000],[0,340420000000]],"40":[[0,59580000000],[0,59580000000],[0,60420000000],[0,60830000000]],"393216":[[0,300055555555555],[0,310750000000000]],"57344":[[0,25042000000000],[0,34000000000000],[0,51880830000000],[0,52534170000000]],"4":[[0,38750000000],[0,38750000000],[0,38750000000],[0,38750000000]],"1":[[0,39580000000],[0,39590000000],[0,39590000000],[0,39590000000]],"768":[[0,375000000000],[0,399580000000],[0,399580000000],[0,399580000000]],"448":[[0,248330000000],[0,248750000000],[0,248750000000],[0,249160000000]],"8192":[[0,4417000000000],[0,5072000000000],[0,5178330000000],[0,5219160000000]],"12":[[0,40830000000],[0,40840000000],[0,41250000000],[0,41250000000]],"10240":[[0,5333000000000],[0,5407920000000],[0,5444580000000],[0,5475840000000]],"14336":[[0,7380000000000],[0,7382090000000],[0,7441793650793],[0,8145420000000]],"32768":[[0,15500000000000],[0,17625000000000],[0,19625000000000],[0,29970250000000]],"128":[[0,103330000000],[0,103330000000],[0,103750000000],[0,103750000000]],"4096":[[0,2562500000000],[0,2569170000000],[0,2573330000000],[0,2576670000000]],"49152":[[0,23505420000000],[0,23666642857142],[0,23766222222222],[0,24976250000000]],"262144":[[0,124458000000000],[0,150667000000000],[0,170416000000000]],"3":[[0,38330000000],[0,38750000000],[0,38750000000],[0,38750000000]],"98304":[[0,44041000000000],[0,58875000000000],[0,63125000000000],[0,68375000000000]]}},{"title":"Array prepend","results":{"2048":[[0,193958250000000],[0,195625000000000],[0,196166000000000],[0,196875000000000]],"96":[[0,911250000000],[0,914580000000],[0,915000000000],[0,915830000000]],"384":[[0,7659590000000],[0,7670420000000],[0,7684160000000],[0,7692307692307]],"12288":[[0,6916625000000000],[0,6973500000000000],[0,7142041000000000],[0,7181542000000000]],"81920":[[0,440244625000000000],[0,441185166500000000],[0,441425375000000000],[0,468525187500000000]],"8":[[0,159160000000],[0,159160000000],[0,159170000000],[0,159580000000]],"1280":[[0,74667000000000],[0,76186250000000],[0,76366250000000],[0,78347920000000]],"3584":[[0,583042000000000],[0,583416000000000],[0,586975529411764],[0,597971375000000]],"7":[[0,154160000000],[0,154160000000],[0,154170000000],[0,155000000000]],"112":[[0,1086538461538],[0,1087500000000],[0,1089170000000],[0,1090420000000]],"896":[[0,37437500000000],[0,37876984126984],[0,37915000000000],[0,38686660000000]],"192":[[0,2320840000000],[0,2322090000000],[0,2322500000000],[0,2323750000000]],"80":[[0,758750000000],[0,759160000000],[0,759580000000],[0,761670000000]],"24":[[0,300420000000],[0,302080000000],[0,302080000000],[0,302080000000]],"40960":[[0,105376958500000000],[0,105670667000000000],[0,106193104000000000],[0,106904625000000000]],"16":[[0,224160000000],[0,224160000000],[0,224170000000],[0,224580000000]],"3072":[[0,429307956521739],[0,432500000000000],[0,438793666666666],[0,439125000000000]],"20":[[0,283330000000],[0,283750000000],[0,283750000000],[0,283750000000]],"224":[[0,2995000000000],[0,3001250000000],[0,3008121951219],[0,3009580000000]],"2560":[[0,298750000000000],[0,300834000000000],[0,301644433333333],[0,307343750000000]],"1792":[[0,144542000000000],[0,145314516129032],[0,145366411764705],[0,147500000000000]],"1024":[[0,52652500000000],[0,52727876543209],[0,53141250000000],[0,53342436781609]],"6144":[[0,1706166000000000],[0,1730209000000000],[0,1750633400000000],[0,1763066600000000]],"56":[[0,529170000000],[0,530410000000],[0,530420000000],[0,530830000000]],"163840":[[0,1769782250000000000],[0,1774790542000000000],[0,1806581958500000000]],"6":[[0,148330000000],[0,148750000000],[0,149160000000],[0,149160000000]],"48":[[0,481250000000],[0,481604651162],[0,481670000000],[0,482090000000]],"32":[[0,337080000000],[0,338330000000],[0,338330000000],[0,339170000000]],"14":[[0,217080000000],[0,217500000000],[0,217910000000],[0,217920000000]],"28672":[[0,48598625000000000],[0,48847959000000000],[0,49015166500000000],[0,49340291500000000]],"512":[[0,14638377358490],[0,14646250000000],[0,14694235294117],[0,14787500000000]],"24576":[[0,34118625000000000],[0,34376729000000000],[0,34442625000000000],[0,34681875000000000]],"2":[[0,53330000000],[0,53330000000],[0,53330000000],[0,53330000000]],"256":[[0,3754580000000],[0,3755000000000],[0,3759590000000],[0,3761928571428]],"1536":[[0,106946428571428],[0,107760500000000],[0,107926173913043],[0,108708000000000]],"64":[[0,582090000000],[0,582500000000],[0,582920000000],[0,583330000000]],"320":[[0,5577090000000],[0,5581670000000],[0,5602080000000],[0,5615420000000]],"114688":[[0,864015583000000000],[0,873840292000000000],[0,884949125000000000]],"131072":[[0,1131745291000000000],[0,1133971812500000000],[0,1184277041000000000]],"16384":[[0,12310167000000000],[0,12395458000000000],[0,12423521000000000],[0,12525375000000000]],"5120":[[0,1191292000000000],[0,1196500000000000],[0,1242892857142857],[0,1246601285714285]],"5":[[0,141660000000],[0,141660000000],[0,141670000000],[0,142080000000]],"10":[[0,202500000000],[0,202500000000],[0,202500000000],[0,202910000000]],"28":[[0,318750000000],[0,319333333333],[0,319580000000],[0,320410000000]],"7168":[[0,2346364750000000],[0,2364375000000000],[0,2402281250000000],[0,2410791750000000]],"20480":[[0,21816208000000000],[0,22076792000000000],[0,22105750000000000],[0,22184875000000000]],"65536":[[0,277921750000000000],[0,279177542000000000],[0,279268208000000000],[0,280837000000000000]],"160":[[0,1778750000000],[0,1781250000000],[0,1781670000000],[0,1784170000000]],"640":[[0,19832080000000],[0,19942920000000],[0,20092080000000],[0,20194590000000]],"40":[[0,433340000000],[0,433750000000],[0,434580000000],[0,435000000000]],"57344":[[0,210840208000000000],[0,212173709000000000],[0,212482916500000000],[0,215023000000000000]],"4":[[0,101250000000],[0,101250000000],[0,101250000000],[0,101250000000]],"1":[[0,41666666666],[0,46660000000],[0,46660000000],[0,46660000000]],"768":[[0,27917000000000],[0,28074160000000],[0,28174580000000],[0,28186250000000]],"448":[[0,10132920000000],[0,10153750000000],[0,10173340000000],[0,10307920000000]],"8192":[[0,3079291000000000],[0,3086667000000000],[0,3088472333333333],[0,3180000000000000]],"12":[[0,209160000000],[0,209580000000],[0,209580000000],[0,209580000000]],"10240":[[0,4792791500000000],[0,4805791500000000],[0,4877000000000000],[0,4914959000000000]],"14336":[[0,9364541000000000],[0,9381000000000000],[0,9414500000000000],[0,9988833500000000]],"32768":[[0,65044500000000000],[0,65353417000000000],[0,65398750000000000],[0,66346687500000000]],"128":[[0,1275420000000],[0,1278330000000],[0,1279580000000],[0,1280000000000]],"4096":[[0,761667000000000],[0,762375000000000],[0,766625000000000],[0,773218750000000]],"49152":[[0,154421250000000000],[0,154479292000000000],[0,155197250000000000],[0,155492792000000000]],"3":[[0,94580000000],[0,94590000000],[0,95000000000],[0,95000000000]],"98304":[[0,634430479000000000],[0,636545250000000000],[0,638048625000000000],[0,639070770500000000]]}},{"title":"Array prepend, reserving capacity","results":{"2048":[[0,199583000000000],[0,202816833333333],[0,203042000000000],[0,219708000000000]],"96":[[0,594160000000],[0,594580000000],[0,595000000000],[0,595830000000]],"384":[[0,7153750000000],[0,7155000000000],[0,7155830000000],[0,7158000000000]],"12288":[[0,6883958000000000],[0,6904208000000000],[0,7112709000000000],[0,7602125000000000]],"81920":[[0,437997437500000000],[0,439889583000000000],[0,440908416000000000],[0,442717792000000000]],"8":[[0,69160000000],[0,69160000000],[0,69160000000],[0,69170000000]],"1280":[[0,75082080000000],[0,75117500000000],[0,75169170000000],[0,76459000000000]],"3584":[[0,579536764705882],[0,581919250000000],[0,583542000000000],[0,587033875000000]],"7":[[0,64580000000],[0,64580000000],[0,65000000000],[0,65000000000]],"112":[[0,762080000000],[0,763330000000],[0,763750000000],[0,764160000000]],"896":[[0,36583000000000],[0,36789580000000],[0,37748340000000],[0,38215830000000]],"192":[[0,1928571428571],[0,1930420000000],[0,1931250000000],[0,1935420000000]],"80":[[0,445420000000],[0,445830000000],[0,447090000000],[0,449580000000]],"24":[[0,119160000000],[0,119170000000],[0,119580000000],[0,119580000000]],"40960":[[0,105562250000000000],[0,106057375000000000],[0,106086562500000000],[0,106262917000000000]],"16":[[0,92920000000],[0,92920000000],[0,93330000000],[0,93330000000]],"3072":[[0,426417000000000],[0,430320090909090],[0,436583000000000],[0,439909090909090]],"20":[[0,104160000000],[0,104160000000],[0,104160000000],[0,104170000000]],"224":[[0,2581670000000],[0,2583000000000],[0,2583750000000],[0,2588750000000]],"2560":[[0,301375000000000],[0,306083000000000],[0,308042000000000],[0,310177093750000]],"1792":[[0,143194666666666],[0,144792000000000],[0,145025735294117],[0,146541000000000]],"1024":[[0,54502666666666],[0,55458000000000],[0,55459000000000],[0,56956106666666]],"6144":[[0,1706292000000000],[0,1719300000000000],[0,1726958000000000],[0,1733916600000000]],"56":[[0,284580000000],[0,285000000000],[0,285830000000],[0,285931034482]],"163840":[[0,1773467333500000000],[0,1783305770500000000],[0,1802613750000000000]],"6":[[0,58400000000],[0,60000000000],[0,60000000000],[0,60410000000]],"48":[[0,239500000000],[0,240000000000],[0,240410000000],[0,241250000000]],"32":[[0,159580000000],[0,159580000000],[0,159580000000],[0,159580000000]],"14":[[0,87500000000],[0,87500000000],[0,87500000000],[0,87500000000]],"28672":[[0,48592833000000000],[0,48600166500000000],[0,48746417000000000],[0,48878958000000000]],"512":[[0,15852500000000],[0,15875000000000],[0,15983340000000],[0,16000000000000]],"24576":[[0,34093750000000000],[0,34164125000000000],[0,34608417000000000],[0,34649354000000000]],"2":[[0,46250000000],[0,46250000000],[0,46660000000],[0,46660000000]],"256":[[0,3330420000000],[0,3331670000000],[0,3333000000000],[0,3341125000000]],"1536":[[0,112750000000000],[0,112895833333333],[0,113958000000000],[0,116027777777777]],"64":[[0,333343750000],[0,334160000000],[0,334160000000],[0,334160000000]],"320":[[0,5064115384615],[0,5065420000000],[0,5071660000000],[0,5745830000000]],"114688":[[0,864847917000000000],[0,865456917000000000],[0,903782250000000000]],"131072":[[0,1128955166000000000],[0,1129494125000000000],[0,1149837209000000000]],"16384":[[0,12338583500000000],[0,12375583000000000],[0,12418375000000000],[0,12427750000000000]],"5120":[[0,1192531250000000],[0,1193302125000000],[0,1203542000000000],[0,1227625000000000]],"5":[[0,56250000000],[0,56250000000],[0,56660000000],[0,57080000000]],"10":[[0,74580000000],[0,74580000000],[0,74580000000],[0,74625000000]],"28":[[0,135000000000],[0,135000000000],[0,135000000000],[0,135000000000]],"7168":[[0,2327489750000000],[0,2341833000000000],[0,2346468750000000],[0,2401573000000000]],"20480":[[0,21960062500000000],[0,22046771000000000],[0,22048625000000000],[0,22133125000000000]],"65536":[[0,277559646000000000],[0,277747458500000000],[0,280174562500000000],[0,280537167000000000]],"160":[[0,1391250000000],[0,1391250000000],[0,1392080000000],[0,1392500000000]],"640":[[0,19069333333333],[0,19099590000000],[0,19930830000000],[0,20180420000000]],"40":[[0,197910000000],[0,197910000000],[0,198750000000],[0,199160000000]],"57344":[[0,211575583500000000],[0,211977917000000000],[0,213069875000000000],[0,213253729500000000]],"4":[[0,52080000000],[0,52080000000],[0,52500000000],[0,52500000000]],"1":[[0,41600000000],[0,43330000000],[0,43330000000],[0,43330000000]],"768":[[0,27165224137931],[0,27331983870967],[0,29331660000000],[0,31839285714285]],"448":[[0,9610830000000],[0,9611000000000],[0,9621670000000],[0,9630000000000]],"8192":[[0,3056083333333333],[0,3059180666666666],[0,3073319333333333],[0,3135416000000000]],"12":[[0,80840000000],[0,81250000000],[0,81250000000],[0,81250000000]],"10240":[[0,4772770500000000],[0,4806541500000000],[0,4852500000000000],[0,4954625000000000]],"14336":[[0,9301958000000000],[0,9329833000000000],[0,9445500000000000],[0,9768020500000000]],"32768":[[0,65524437500000000],[0,65573333000000000],[0,65680479000000000],[0,66692542000000000]],"128":[[0,941600000000],[0,944160000000],[0,944160000000],[0,944160000000]],"4096":[[0,752917000000000],[0,760673076923076],[0,774288166666666],[0,779899333333333]],"49152":[[0,154179375000000000],[0,154376125000000000],[0,155114167000000000],[0,155484000000000000]],"3":[[0,47642857142],[0,47910000000],[0,48330000000],[0,48330000000]],"98304":[[0,632908500000000000],[0,633085917000000000],[0,634985209000000000],[0,639984292000000000]]}},{"title":"Deque random insertions","results":{"2048":[[0,77542000000000],[0,78167000000000],[0,78334000000000],[0,79708000000000]],"96":[[0,2042000000000],[0,2084000000000],[0,2208000000000],[0,2209000000000]],"327680":[[0,1799383041000000000],[0,1815287167000000000]],"384":[[0,7667000000000],[0,7750000000000],[0,9000000000000],[0,11500000000000]],"12288":[[0,1860750000000000],[0,1885708000000000],[0,1886375000000000],[0,2168417000000000]],"81920":[[0,104147750000000000],[0,104342875000000000],[0,104529458000000000],[0,104856792000000000]],"8":[[0,333000000000],[0,334000000000],[0,375000000000],[0,375000000000]],"1280":[[0,38500000000000],[0,39208000000000],[0,40042000000000],[0,40084000000000]],"3584":[[0,191875000000000],[0,194209000000000],[0,195541000000000],[0,196708000000000]],"7":[[0,333000000000],[0,334000000000],[0,375000000000],[0,500000000000]],"524288":[[0,4572937708000000000],[0,4594848375000000000]],"112":[[0,2333000000000],[0,2375000000000],[0,2417000000000],[0,2750000000000]],"896":[[0,23334000000000],[0,23583000000000],[0,24500000000000],[0,25167000000000]],"192":[[0,3625000000000],[0,3666000000000],[0,3750000000000],[0,3750000000000]],"80":[[0,1792000000000],[0,1833000000000],[0,1875000000000],[0,1958000000000]],"24":[[0,791000000000],[0,833000000000],[0,834000000000],[0,875000000000]],"40960":[[0,23036041000000000],[0,23351291000000000],[0,23355250000000000],[0,25114459000000000]],"16":[[0,584000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"3072":[[0,150625000000000],[0,150667000000000],[0,152459000000000],[0,152834000000000]],"20":[[0,666000000000],[0,667000000000],[0,667000000000],[0,667000000000]],"224":[[0,4166000000000],[0,4291000000000],[0,4292000000000],[0,4792000000000]],"2560":[[0,110459000000000],[0,110917000000000],[0,111584000000000],[0,112916000000000]],"1792":[[0,63042000000000],[0,63417000000000],[0,64417000000000],[0,64417000000000]],"1024":[[0,28250000000000],[0,28625000000000],[0,28625000000000],[0,30209000000000]],"6144":[[0,503125000000000],[0,503167000000000],[0,505250000000000],[0,511125000000000]],"56":[[0,1292000000000],[0,1292000000000],[0,1375000000000],[0,1416000000000]],"163840":[[0,437246875000000000],[0,437837667000000000],[0,447756125000000000]],"6":[[0,333000000000],[0,334000000000],[0,375000000000],[0,375000000000]],"48":[[0,1167000000000],[0,1167000000000],[0,1250000000000],[0,1292000000000]],"32":[[0,917000000000],[0,917000000000],[0,917000000000],[0,917000000000]],"14":[[0,500000000000],[0,500000000000],[0,500000000000],[0,541000000000]],"28672":[[0,10520542000000000],[0,10545709000000000],[0,10592250000000000],[0,10597208000000000]],"512":[[0,10833000000000],[0,11125000000000],[0,11125000000000],[0,11166000000000]],"196608":[[0,637178167000000000],[0,639957417000000000],[0,640568208000000000]],"458752":[[0,3516831833000000000],[0,3545877833000000000]],"24576":[[0,7439292000000000],[0,7520167000000000],[0,7643167000000000],[0,7651959000000000]],"2":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"256":[[0,4833000000000],[0,4875000000000],[0,4875000000000],[0,5125000000000]],"1536":[[0,50208000000000],[0,50542000000000],[0,50584000000000],[0,51500000000000]],"64":[[0,1541000000000],[0,1542000000000],[0,1625000000000],[0,1708000000000]],"320":[[0,6208000000000],[0,6542000000000],[0,7000000000000],[0,8667000000000]],"114688":[[0,210441041000000000],[0,211379041000000000],[0,213083625000000000]],"131072":[[0,277890625000000000],[0,278134458000000000],[0,291486167000000000]],"16384":[[0,3226083000000000],[0,3241834000000000],[0,3283959000000000],[0,3301958000000000]],"5120":[[0,364542000000000],[0,367000000000000],[0,367708000000000],[0,371042000000000]],"229376":[[0,865471083000000000],[0,870728417000000000],[0,885183000000000000]],"5":[[0,208000000000],[0,209000000000],[0,250000000000],[0,292000000000]],"10":[[0,417000000000],[0,458000000000],[0,500000000000],[0,500000000000]],"28":[[0,833000000000],[0,834000000000],[0,875000000000],[0,875000000000]],"655360":[[0,7273490375000000000],[0,7344989083000000000]],"7168":[[0,678166000000000],[0,682041000000000],[0,683458000000000],[0,688958000000000]],"20480":[[0,5115166000000000],[0,5120417000000000],[0,5147209000000000],[0,5182709000000000]],"65536":[[0,64126708000000000],[0,64738541000000000],[0,65089709000000000],[0,65580541000000000]],"160":[[0,3208000000000],[0,3292000000000],[0,3417000000000],[0,3666000000000]],"640":[[0,14584000000000],[0,14916000000000],[0,14959000000000],[0,15125000000000]],"40":[[0,1084000000000],[0,1125000000000],[0,1167000000000],[0,1209000000000]],"393216":[[0,2577692417000000000],[0,2586244125000000000]],"57344":[[0,47996416000000000],[0,48304875000000000],[0,48539834000000000],[0,48911750000000000]],"4":[[0,208000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"768":[[0,18750000000000],[0,18875000000000],[0,19250000000000],[0,19375000000000]],"448":[[0,9417000000000],[0,9458000000000],[0,9500000000000],[0,12875000000000]],"8192":[[0,866583000000000],[0,867250000000000],[0,867959000000000],[0,877041000000000]],"12":[[0,458000000000],[0,500000000000],[0,500000000000],[0,500000000000]],"10240":[[0,1312916000000000],[0,1317125000000000],[0,1325959000000000],[0,1330250000000000]],"14336":[[0,2503542000000000],[0,2510166000000000],[0,2539292000000000],[0,2546625000000000]],"32768":[[0,13945250000000000],[0,14049333000000000],[0,14163542000000000],[0,14237750000000000]],"128":[[0,2500000000000],[0,2583000000000],[0,2625000000000],[0,2667000000000]],"4096":[[0,245375000000000],[0,245708000000000],[0,245875000000000],[0,248584000000000]],"49152":[[0,34565167000000000],[0,34734750000000000],[0,35037209000000000],[0,36129459000000000]],"262144":[[0,1140667500000000000],[0,1142460833000000000],[0,1148025750000000000]],"3":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"98304":[[0,152794084000000000],[0,153238041000000000],[0,154277416000000000],[0,155675167000000000]]}},{"title":"Array random insertions","results":{"2048":[[0,96375000000000],[0,99459000000000],[0,100042000000000],[0,101834000000000]],"96":[[0,833000000000],[0,833000000000],[0,875000000000],[0,1042000000000]],"327680":[[0,3563127708000000000],[0,3621825625000000000]],"384":[[0,5250000000000],[0,5625000000000],[0,6208000000000],[0,7917000000000]],"12288":[[0,3504583000000000],[0,3507875000000000],[0,3529792000000000],[0,3622333000000000]],"81920":[[0,211884958000000000],[0,212494167000000000],[0,212638750000000000],[0,213024166000000000]],"8":[[0,125000000000],[0,167000000000],[0,167000000000],[0,167000000000]],"1280":[[0,41542000000000],[0,42458000000000],[0,43250000000000],[0,43375000000000]],"3584":[[0,296958000000000],[0,299875000000000],[0,304917000000000],[0,309417000000000]],"7":[[0,125000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"112":[[0,917000000000],[0,917000000000],[0,958000000000],[0,1167000000000]],"896":[[0,21833000000000],[0,21834000000000],[0,21916000000000],[0,22000000000000]],"192":[[0,1750000000000],[0,1833000000000],[0,1833000000000],[0,1875000000000]],"80":[[0,708000000000],[0,709000000000],[0,750000000000],[0,792000000000]],"24":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"40960":[[0,47772000000000000],[0,47966750000000000],[0,48324333000000000],[0,49109500000000000]],"16":[[0,208000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"3072":[[0,222916000000000],[0,224833000000000],[0,226375000000000],[0,235792000000000]],"20":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"224":[[0,2250000000000],[0,2291000000000],[0,2291000000000],[0,2666000000000]],"2560":[[0,156125000000000],[0,156875000000000],[0,158666000000000],[0,160250000000000]],"1792":[[0,76541000000000],[0,77166000000000],[0,77875000000000],[0,78750000000000]],"1024":[[0,27167000000000],[0,27208000000000],[0,28000000000000],[0,29209000000000]],"6144":[[0,878833000000000],[0,886625000000000],[0,895625000000000],[0,917750000000000]],"56":[[0,500000000000],[0,500000000000],[0,541000000000],[0,542000000000]],"163840":[[0,874514916000000000],[0,878311667000000000],[0,900940417000000000]],"6":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"48":[[0,458000000000],[0,459000000000],[0,500000000000],[0,500000000000]],"32":[[0,333000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"14":[[0,208000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"28672":[[0,21473500000000000],[0,21501667000000000],[0,21509666000000000],[0,21660750000000000]],"512":[[0,8333000000000],[0,8417000000000],[0,8667000000000],[0,8958000000000]],"196608":[[0,1253092250000000000],[0,1267524792000000000],[0,1315321208000000000]],"24576":[[0,14999333000000000],[0,15094667000000000],[0,15190792000000000],[0,15406792000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,2750000000000],[0,2750000000000],[0,2792000000000],[0,2792000000000]],"1536":[[0,56041000000000],[0,58000000000000],[0,58792000000000],[0,58959000000000]],"64":[[0,541000000000],[0,542000000000],[0,542000000000],[0,583000000000]],"320":[[0,3917000000000],[0,4208000000000],[0,4209000000000],[0,4583000000000]],"114688":[[0,423671542000000000],[0,426929583000000000],[0,434068000000000000]],"131072":[[0,555018417000000000],[0,556340416000000000],[0,566469250000000000]],"16384":[[0,6235042000000000],[0,6241750000000000],[0,6253708000000000],[0,6313834000000000]],"5120":[[0,611792000000000],[0,614667000000000],[0,624042000000000],[0,624084000000000]],"229376":[[0,1732770042000000000],[0,1739194167000000000],[0,1762526542000000000]],"5":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"10":[[0,208000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"28":[[0,333000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"7168":[[0,1193041000000000],[0,1200791000000000],[0,1221084000000000],[0,1227625000000000]],"20480":[[0,10007875000000000],[0,10046458000000000],[0,10078042000000000],[0,10138708000000000]],"65536":[[0,131969666000000000],[0,132293042000000000],[0,132363583000000000],[0,134061416000000000]],"160":[[0,1459000000000],[0,1542000000000],[0,1542000000000],[0,1708000000000]],"640":[[0,12375000000000],[0,12500000000000],[0,12625000000000],[0,12834000000000]],"40":[[0,416000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"57344":[[0,99751542000000000],[0,99785917000000000],[0,100114000000000000],[0,100410333000000000]],"4":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"768":[[0,16791000000000],[0,16958000000000],[0,17042000000000],[0,17084000000000]],"448":[[0,6792000000000],[0,6875000000000],[0,6958000000000],[0,7750000000000]],"8192":[[0,1548667000000000],[0,1550875000000000],[0,1559708000000000],[0,1567167000000000]],"12":[[0,208000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"10240":[[0,2442209000000000],[0,2448292000000000],[0,2460917000000000],[0,2491541000000000]],"14336":[[0,4700583000000000],[0,4727458000000000],[0,4732625000000000],[0,4802125000000000]],"32768":[[0,29065541000000000],[0,29083208000000000],[0,29388833000000000],[0,29620334000000000]],"128":[[0,1042000000000],[0,1083000000000],[0,1084000000000],[0,1125000000000]],"4096":[[0,391292000000000],[0,399291000000000],[0,400292000000000],[0,400792000000000]],"49152":[[0,71369125000000000],[0,71795250000000000],[0,72075750000000000],[0,75652750000000000]],"262144":[[0,2264100416000000000],[0,2291629375000000000],[0,2305592875000000000]],"3":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"98304":[[0,307726959000000000],[0,308725708000000000],[0,311906209000000000],[0,315174958000000000]]}},{"title":"Array removeFirst","results":{"2048":[[0,186292000000000],[0,186334000000000],[0,186458000000000],[0,189750000000000]],"96":[[0,750000000000],[0,750000000000],[0,792000000000],[0,1041000000000]],"384":[[0,7583000000000],[0,7583000000000],[0,7625000000000],[0,7625000000000]],"12288":[[0,6817541000000000],[0,6832834000000000],[0,6965834000000000],[0,7268416000000000]],"81920":[[0,436868291000000000],[0,437877166000000000],[0,439169333000000000],[0,442099209000000000]],"8":[[0,41000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"1280":[[0,74209000000000],[0,74417000000000],[0,74584000000000],[0,77916000000000]],"3584":[[0,576375000000000],[0,576542000000000],[0,576625000000000],[0,577584000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"112":[[0,916000000000],[0,917000000000],[0,958000000000],[0,1125000000000]],"896":[[0,37375000000000],[0,37375000000000],[0,37417000000000],[0,37584000000000]],"192":[[0,2250000000000],[0,2250000000000],[0,2292000000000],[0,2292000000000]],"80":[[0,541000000000],[0,542000000000],[0,542000000000],[0,584000000000]],"24":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"40960":[[0,105067375000000000],[0,105143208000000000],[0,105212416000000000],[0,107461500000000000]],"16":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"3072":[[0,423958000000000],[0,424167000000000],[0,424542000000000],[0,424875000000000]],"20":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"224":[[0,2917000000000],[0,2959000000000],[0,2959000000000],[0,3000000000000]],"2560":[[0,293875000000000],[0,293916000000000],[0,294083000000000],[0,305500000000000]],"1792":[[0,143209000000000],[0,143375000000000],[0,143375000000000],[0,143500000000000]],"1024":[[0,48125000000000],[0,48166000000000],[0,50500000000000],[0,51791000000000]],"6144":[[0,1696000000000000],[0,1696000000000000],[0,1696125000000000],[0,1698625000000000]],"56":[[0,292000000000],[0,333000000000],[0,333000000000],[0,334000000000]],"163840":[[0,1766937291000000000],[0,1777288625000000000],[0,1792210792000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"32":[[0,125000000000],[0,166000000000],[0,166000000000],[0,167000000000]],"14":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"28672":[[0,48356792000000000],[0,49136000000000000],[0,49556708000000000],[0,49558958000000000]],"512":[[0,12917000000000],[0,12958000000000],[0,12958000000000],[0,12959000000000]],"24576":[[0,33876875000000000],[0,33895750000000000],[0,33918166000000000],[0,34052625000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,3709000000000],[0,3750000000000],[0,3792000000000],[0,3792000000000]],"1536":[[0,108208000000000],[0,110708000000000],[0,111000000000000],[0,111708000000000]],"64":[[0,375000000000],[0,375000000000],[0,375000000000],[0,458000000000]],"320":[[0,5500000000000],[0,5541000000000],[0,5833000000000],[0,6292000000000]],"114688":[[0,864377708000000000],[0,868022541000000000],[0,879795417000000000]],"131072":[[0,1124339916000000000],[0,1131278583000000000],[0,1176903250000000000]],"16384":[[0,12283625000000000],[0,12336333000000000],[0,12344333000000000],[0,12394292000000000]],"5120":[[0,1178750000000000],[0,1178833000000000],[0,1182083000000000],[0,1203542000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"7168":[[0,2315334000000000],[0,2323708000000000],[0,2324500000000000],[0,2337334000000000]],"20480":[[0,21618750000000000],[0,21742041000000000],[0,21777875000000000],[0,21789167000000000]],"65536":[[0,278570792000000000],[0,278652334000000000],[0,278937875000000000],[0,279806167000000000]],"160":[[0,1667000000000],[0,1667000000000],[0,1750000000000],[0,1917000000000]],"640":[[0,19708000000000],[0,19709000000000],[0,19833000000000],[0,19917000000000]],"40":[[0,166000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"57344":[[0,211588084000000000],[0,211860333000000000],[0,212847500000000000],[0,212972333000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,28000000000000],[0,29875000000000],[0,30000000000000],[0,30083000000000]],"448":[[0,10042000000000],[0,10083000000000],[0,10084000000000],[0,14334000000000]],"8192":[[0,3022750000000000],[0,3034417000000000],[0,3035125000000000],[0,3089834000000000]],"12":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"10240":[[0,4730666000000000],[0,4730916000000000],[0,4750667000000000],[0,4900792000000000]],"14336":[[0,9293083000000000],[0,9297083000000000],[0,9318417000000000],[0,9369584000000000]],"32768":[[0,64943541000000000],[0,64956375000000000],[0,64971708000000000],[0,66360375000000000]],"128":[[0,1125000000000],[0,1167000000000],[0,1167000000000],[0,1209000000000]],"4096":[[0,751833000000000],[0,751875000000000],[0,751917000000000],[0,752666000000000]],"49152":[[0,152998084000000000],[0,153553916000000000],[0,153691000000000000],[0,158358208000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,632928959000000000],[0,634819000000000000],[0,639937292000000000],[0,646272041000000000]]}},{"title":"Array removeLast","results":{"2048":[[0,3667000000000],[0,3708000000000],[0,3708000000000],[0,3708000000000]],"1048576":[[0,1914875000000000],[0,1934667000000000]],"96":[[0,166000000000],[0,166000000000],[0,208000000000],[0,250000000000]],"327680":[[0,594458000000000],[0,601333000000000]],"384":[[0,667000000000],[0,667000000000],[0,708000000000],[0,708000000000]],"12288":[[0,22209000000000],[0,22250000000000],[0,22250000000000],[0,25250000000000]],"81920":[[0,148542000000000],[0,148542000000000],[0,148666000000000],[0,148667000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2292000000000],[0,2333000000000],[0,2333000000000],[0,2416000000000]],"3584":[[0,6458000000000],[0,6458000000000],[0,6459000000000],[0,6459000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,963042000000000],[0,964333000000000]],"112":[[0,167000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"896":[[0,1625000000000],[0,1625000000000],[0,1625000000000],[0,1625000000000]],"192":[[0,333000000000],[0,333000000000],[0,333000000000],[0,334000000000]],"80":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,74209000000000],[0,74292000000000],[0,74292000000000],[0,77792000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,5500000000000],[0,5541000000000],[0,5583000000000],[0,5583000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"224":[[0,375000000000],[0,416000000000],[0,416000000000],[0,417000000000]],"2560":[[0,4625000000000],[0,4625000000000],[0,4625000000000],[0,4625000000000]],"1792":[[0,3209000000000],[0,3250000000000],[0,3250000000000],[0,3250000000000]],"1024":[[0,1834000000000],[0,1875000000000],[0,1875000000000],[0,1916000000000]],"6144":[[0,11125000000000],[0,11125000000000],[0,11125000000000],[0,11125000000000]],"56":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1441541000000000],[0,1450375000000000]],"163840":[[0,297208000000000],[0,297209000000000],[0,305709000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,51917000000000],[0,51959000000000],[0,52000000000000],[0,52000000000000]],"512":[[0,916000000000],[0,916000000000],[0,916000000000],[0,916000000000]],"196608":[[0,356542000000000],[0,356833000000000],[0,360750000000000]],"458752":[[0,885291000000000],[0,909709000000000]],"24576":[[0,44542000000000],[0,44583000000000],[0,44583000000000],[0,48375000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2750000000000],[0,2791000000000],[0,2791000000000],[0,2792000000000]],"64":[[0,84000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,542000000000],[0,583000000000],[0,583000000000],[0,666000000000]],"114688":[[0,208083000000000],[0,211959000000000],[0,225000000000000]],"131072":[[0,237708000000000],[0,237750000000000],[0,237750000000000]],"16384":[[0,29708000000000],[0,29708000000000],[0,29875000000000],[0,32208000000000]],"5120":[[0,9250000000000],[0,9250000000000],[0,9250000000000],[0,9291000000000]],"229376":[[0,416042000000000],[0,416042000000000],[0,422250000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1205834000000000],[0,1211417000000000]],"7168":[[0,12958000000000],[0,13000000000000],[0,13000000000000],[0,14041000000000]],"20480":[[0,37125000000000],[0,37125000000000],[0,37166000000000],[0,37166000000000]],"65536":[[0,118792000000000],[0,118833000000000],[0,118875000000000],[0,119000000000000]],"917504":[[0,1664083000000000],[0,1681250000000000]],"160":[[0,291000000000],[0,291000000000],[0,292000000000],[0,292000000000]],"640":[[0,1125000000000],[0,1166000000000],[0,1208000000000],[0,1250000000000]],"40":[[0,41000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"393216":[[0,713084000000000],[0,762458000000000]],"57344":[[0,103958000000000],[0,104041000000000],[0,104083000000000],[0,109000000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1375000000000],[0,1375000000000],[0,1375000000000],[0,1791000000000]],"448":[[0,791000000000],[0,791000000000],[0,791000000000],[0,1042000000000]],"8192":[[0,14833000000000],[0,14833000000000],[0,14834000000000],[0,14875000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,18541000000000],[0,18542000000000],[0,18542000000000],[0,18583000000000]],"14336":[[0,25917000000000],[0,26000000000000],[0,26000000000000],[0,26084000000000]],"32768":[[0,59375000000000],[0,59500000000000],[0,59625000000000],[0,64459000000000]],"128":[[0,208000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"4096":[[0,7375000000000],[0,7416000000000],[0,7417000000000],[0,8042000000000]],"49152":[[0,89042000000000],[0,89125000000000],[0,89125000000000],[0,89167000000000]],"262144":[[0,475500000000000],[0,490125000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,178250000000000],[0,178333000000000],[0,181583000000000],[0,202416000000000]]}},{"title":"Deque random removals (contiguous)","results":{"2048":[[0,67209000000000],[0,67542000000000],[0,67708000000000],[0,72125000000000]],"96":[[0,917000000000],[0,958000000000],[0,1000000000000],[0,1292000000000]],"327680":[[0,1796300667000000000],[0,1807783167000000000]],"384":[[0,5792000000000],[0,5833000000000],[0,5875000000000],[0,6333000000000]],"12288":[[0,1805292000000000],[0,1814917000000000],[0,1818833000000000],[0,1838250000000000]],"81920":[[0,102879667000000000],[0,103801875000000000],[0,103823291000000000],[0,106182542000000000]],"8":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"1280":[[0,31208000000000],[0,31958000000000],[0,32875000000000],[0,33750000000000]],"3584":[[0,173791000000000],[0,176875000000000],[0,178292000000000],[0,178459000000000]],"7":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"524288":[[0,4540974334000000000],[0,4614357583000000000]],"112":[[0,1125000000000],[0,1125000000000],[0,1167000000000],[0,1250000000000]],"896":[[0,18417000000000],[0,18458000000000],[0,18792000000000],[0,19417000000000]],"192":[[0,2125000000000],[0,2166000000000],[0,2167000000000],[0,2209000000000]],"80":[[0,792000000000],[0,792000000000],[0,833000000000],[0,875000000000]],"24":[[0,209000000000],[0,209000000000],[0,209000000000],[0,250000000000]],"40960":[[0,22933041000000000],[0,23022750000000000],[0,23441458000000000],[0,23847750000000000]],"16":[[0,166000000000],[0,166000000000],[0,208000000000],[0,209000000000]],"3072":[[0,136041000000000],[0,137500000000000],[0,138500000000000],[0,148125000000000]],"20":[[0,166000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"224":[[0,2542000000000],[0,2625000000000],[0,2625000000000],[0,2792000000000]],"2560":[[0,99500000000000],[0,99833000000000],[0,100250000000000],[0,100584000000000]],"1792":[[0,53166000000000],[0,53667000000000],[0,54375000000000],[0,54959000000000]],"1024":[[0,22584000000000],[0,22709000000000],[0,23000000000000],[0,23750000000000]],"6144":[[0,478875000000000],[0,480250000000000],[0,485167000000000],[0,488458000000000]],"56":[[0,542000000000],[0,542000000000],[0,584000000000],[0,750000000000]],"163840":[[0,435658791000000000],[0,438935958000000000],[0,440537375000000000]],"6":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"48":[[0,458000000000],[0,458000000000],[0,459000000000],[0,459000000000]],"32":[[0,291000000000],[0,292000000000],[0,292000000000],[0,333000000000]],"14":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"28672":[[0,10392792000000000],[0,10432625000000000],[0,10543250000000000],[0,10609792000000000]],"512":[[0,8084000000000],[0,8125000000000],[0,8625000000000],[0,8750000000000]],"196608":[[0,625336792000000000],[0,633694083000000000],[0,642442417000000000]],"458752":[[0,3510720792000000000],[0,3531612541000000000]],"24576":[[0,7427750000000000],[0,7499333000000000],[0,7538916000000000],[0,7591792000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,3125000000000],[0,3125000000000],[0,3166000000000],[0,3208000000000]],"1536":[[0,41583000000000],[0,41667000000000],[0,41750000000000],[0,41958000000000]],"64":[[0,583000000000],[0,583000000000],[0,625000000000],[0,666000000000]],"320":[[0,4375000000000],[0,4500000000000],[0,4667000000000],[0,5041000000000]],"114688":[[0,208903541000000000],[0,208910041000000000],[0,211485417000000000]],"131072":[[0,276030416000000000],[0,276282583000000000],[0,279459834000000000]],"16384":[[0,3186250000000000],[0,3198167000000000],[0,3213375000000000],[0,3272083000000000]],"5120":[[0,342083000000000],[0,346541000000000],[0,346666000000000],[0,355000000000000]],"229376":[[0,862069916000000000],[0,873240833000000000],[0,882546209000000000]],"5":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"10":[[0,84000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"28":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"655360":[[0,7222284042000000000],[0,7250690125000000000]],"7168":[[0,647208000000000],[0,651542000000000],[0,654333000000000],[0,663166000000000]],"20480":[[0,5009167000000000],[0,5028541000000000],[0,5033417000000000],[0,5119166000000000]],"65536":[[0,64466875000000000],[0,64737875000000000],[0,64856500000000000],[0,64911834000000000]],"160":[[0,1791000000000],[0,1791000000000],[0,1833000000000],[0,3709000000000]],"640":[[0,11042000000000],[0,11417000000000],[0,11459000000000],[0,11625000000000]],"40":[[0,333000000000],[0,375000000000],[0,375000000000],[0,417000000000]],"393216":[[0,2583790667000000000],[0,2590543417000000000]],"57344":[[0,47866667000000000],[0,47923958000000000],[0,48151042000000000],[0,48400333000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,14584000000000],[0,14584000000000],[0,14875000000000],[0,14958000000000]],"448":[[0,6583000000000],[0,7000000000000],[0,7083000000000],[0,7334000000000]],"8192":[[0,825833000000000],[0,826000000000000],[0,830625000000000],[0,835292000000000]],"12":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"10240":[[0,1288542000000000],[0,1294375000000000],[0,1303583000000000],[0,1318583000000000]],"14336":[[0,2470625000000000],[0,2490542000000000],[0,2521750000000000],[0,2537917000000000]],"32768":[[0,13858959000000000],[0,13945292000000000],[0,14076041000000000],[0,14225917000000000]],"128":[[0,1292000000000],[0,1292000000000],[0,1333000000000],[0,1417000000000]],"4096":[[0,221833000000000],[0,222208000000000],[0,223167000000000],[0,235042000000000]],"49152":[[0,34212333000000000],[0,34225583000000000],[0,34759459000000000],[0,35141667000000000]],"262144":[[0,1131187000000000000],[0,1147657041000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,152015834000000000],[0,153186583000000000],[0,153503500000000000],[0,153839042000000000]]}},{"title":"Deque random removals (discontiguous)","results":{"2048":[[0,70583000000000],[0,71125000000000],[0,71875000000000],[0,80292000000000]],"96":[[0,1000000000000],[0,1042000000000],[0,1125000000000],[0,1375000000000]],"327680":[[0,1789362125000000000],[0,1803995833000000000]],"384":[[0,6000000000000],[0,6084000000000],[0,6209000000000],[0,6291000000000]],"12288":[[0,1840416000000000],[0,1843917000000000],[0,1863125000000000],[0,1867250000000000]],"81920":[[0,103387625000000000],[0,103953541000000000],[0,104688042000000000],[0,108450709000000000]],"8":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"1280":[[0,33250000000000],[0,34084000000000],[0,34500000000000],[0,34917000000000]],"3584":[[0,183083000000000],[0,186375000000000],[0,186417000000000],[0,186959000000000]],"7":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"524288":[[0,4563766625000000000],[0,4610543917000000000]],"112":[[0,1209000000000],[0,1250000000000],[0,1250000000000],[0,1458000000000]],"896":[[0,19292000000000],[0,19333000000000],[0,20000000000000],[0,25250000000000]],"192":[[0,2250000000000],[0,2250000000000],[0,2292000000000],[0,2292000000000]],"80":[[0,833000000000],[0,875000000000],[0,875000000000],[0,917000000000]],"24":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"40960":[[0,23035500000000000],[0,23296000000000000],[0,23321375000000000],[0,23725375000000000]],"16":[[0,125000000000],[0,125000000000],[0,166000000000],[0,250000000000]],"3072":[[0,140791000000000],[0,141417000000000],[0,143417000000000],[0,143875000000000]],"20":[[0,167000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"224":[[0,2791000000000],[0,2792000000000],[0,2833000000000],[0,2875000000000]],"2560":[[0,102292000000000],[0,103084000000000],[0,103166000000000],[0,103209000000000]],"1792":[[0,55833000000000],[0,56875000000000],[0,57250000000000],[0,57416000000000]],"1024":[[0,24000000000000],[0,24333000000000],[0,24709000000000],[0,25417000000000]],"6144":[[0,487625000000000],[0,487875000000000],[0,495209000000000],[0,497292000000000]],"56":[[0,583000000000],[0,625000000000],[0,625000000000],[0,708000000000]],"163840":[[0,435343083000000000],[0,439994166000000000],[0,440677166000000000]],"6":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"48":[[0,500000000000],[0,500000000000],[0,500000000000],[0,541000000000]],"32":[[0,333000000000],[0,334000000000],[0,375000000000],[0,375000000000]],"14":[[0,125000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"28672":[[0,10487125000000000],[0,10500250000000000],[0,10521958000000000],[0,10630792000000000]],"512":[[0,8125000000000],[0,8166000000000],[0,8250000000000],[0,9667000000000]],"196608":[[0,630806333000000000],[0,635012375000000000],[0,652094958000000000]],"458752":[[0,3525657542000000000],[0,3529456125000000000]],"24576":[[0,7444500000000000],[0,7507250000000000],[0,7599292000000000],[0,7717459000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"256":[[0,3292000000000],[0,3292000000000],[0,3375000000000],[0,3459000000000]],"1536":[[0,44041000000000],[0,44250000000000],[0,44333000000000],[0,44500000000000]],"64":[[0,625000000000],[0,667000000000],[0,667000000000],[0,708000000000]],"320":[[0,4709000000000],[0,4875000000000],[0,4875000000000],[0,5375000000000]],"114688":[[0,208421084000000000],[0,210266250000000000],[0,211433042000000000]],"131072":[[0,274901584000000000],[0,275627958000000000],[0,281188250000000000]],"16384":[[0,3219375000000000],[0,3230958000000000],[0,3239667000000000],[0,3251750000000000]],"5120":[[0,348583000000000],[0,352167000000000],[0,352375000000000],[0,353416000000000]],"229376":[[0,868196666000000000],[0,871868625000000000],[0,874626083000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"28":[[0,250000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"655360":[[0,7202242000000000000],[0,7249707041000000000]],"7168":[[0,649041000000000],[0,653583000000000],[0,658125000000000],[0,665958000000000]],"20480":[[0,5062333000000000],[0,5095291000000000],[0,5111375000000000],[0,5154375000000000]],"65536":[[0,64346250000000000],[0,64677666000000000],[0,64708041000000000],[0,65053000000000000]],"160":[[0,1875000000000],[0,1917000000000],[0,2625000000000],[0,4042000000000]],"640":[[0,11333000000000],[0,11667000000000],[0,11750000000000],[0,12000000000000]],"40":[[0,416000000000],[0,417000000000],[0,417000000000],[0,458000000000]],"393216":[[0,2574145375000000000],[0,2589748875000000000]],"57344":[[0,48031333000000000],[0,48073000000000000],[0,48336291000000000],[0,48368792000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,15125000000000],[0,15375000000000],[0,15458000000000],[0,15666000000000]],"448":[[0,6959000000000],[0,7125000000000],[0,7458000000000],[0,7583000000000]],"8192":[[0,833625000000000],[0,833875000000000],[0,852250000000000],[0,855084000000000]],"12":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"10240":[[0,1291333000000000],[0,1300209000000000],[0,1315542000000000],[0,1317375000000000]],"14336":[[0,2487875000000000],[0,2488833000000000],[0,2497417000000000],[0,2510584000000000]],"32768":[[0,13996167000000000],[0,14065208000000000],[0,14127583000000000],[0,14207541000000000]],"128":[[0,1417000000000],[0,1417000000000],[0,1417000000000],[0,1458000000000]],"4096":[[0,236666000000000],[0,236917000000000],[0,237250000000000],[0,237416000000000]],"49152":[[0,34557583000000000],[0,34576042000000000],[0,34934042000000000],[0,34978292000000000]],"262144":[[0,1133198125000000000],[0,1158030500000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,151353000000000000],[0,153338250000000000],[0,154086333000000000]]}},{"title":"Array random removals","results":{"2048":[[0,100458000000000],[0,101125000000000],[0,102792000000000],[0,122000000000000]],"96":[[0,500000000000],[0,500000000000],[0,542000000000],[0,542000000000]],"327680":[[0,3559716167000000000],[0,3565444500000000000]],"384":[[0,4542000000000],[0,4875000000000],[0,5125000000000],[0,5125000000000]],"12288":[[0,3447000000000000],[0,3462833000000000],[0,3562792000000000],[0,3619334000000000]],"81920":[[0,209812125000000000],[0,210154916000000000],[0,211326666000000000],[0,212324083000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"1280":[[0,43500000000000],[0,44625000000000],[0,45042000000000],[0,46250000000000]],"3584":[[0,292792000000000],[0,298500000000000],[0,298750000000000],[0,299166000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"112":[[0,583000000000],[0,583000000000],[0,625000000000],[0,708000000000]],"896":[[0,20667000000000],[0,20791000000000],[0,20875000000000],[0,22458000000000]],"192":[[0,1375000000000],[0,1458000000000],[0,1459000000000],[0,1542000000000]],"80":[[0,416000000000],[0,417000000000],[0,417000000000],[0,458000000000]],"24":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"40960":[[0,47248709000000000],[0,47435292000000000],[0,47686542000000000],[0,47871292000000000]],"16":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"3072":[[0,222833000000000],[0,224417000000000],[0,225083000000000],[0,230167000000000]],"20":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"224":[[0,1875000000000],[0,1875000000000],[0,1917000000000],[0,1958000000000]],"2560":[[0,155708000000000],[0,156917000000000],[0,158334000000000],[0,160417000000000]],"1792":[[0,73625000000000],[0,74500000000000],[0,75167000000000],[0,75917000000000]],"1024":[[0,25917000000000],[0,25917000000000],[0,26625000000000],[0,27416000000000]],"6144":[[0,866875000000000],[0,872000000000000],[0,879458000000000],[0,897041000000000]],"56":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"163840":[[0,877871042000000000],[0,883954125000000000],[0,906897250000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,208000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"32":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"14":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28672":[[0,21064334000000000],[0,21143958000000000],[0,21162375000000000],[0,21607125000000000]],"512":[[0,7416000000000],[0,7750000000000],[0,7792000000000],[0,8042000000000]],"196608":[[0,1264192708000000000],[0,1274076875000000000],[0,1318074875000000000]],"24576":[[0,14806875000000000],[0,14830666000000000],[0,14896500000000000],[0,15118584000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,2333000000000],[0,2417000000000],[0,2417000000000],[0,2458000000000]],"1536":[[0,55500000000000],[0,56541000000000],[0,58167000000000],[0,59167000000000]],"64":[[0,333000000000],[0,333000000000],[0,333000000000],[0,334000000000]],"320":[[0,3834000000000],[0,3917000000000],[0,4333000000000],[0,4667000000000]],"114688":[[0,421166375000000000],[0,423334375000000000],[0,425622000000000000]],"131072":[[0,556071709000000000],[0,556959334000000000],[0,562054875000000000]],"16384":[[0,6146333000000000],[0,6177084000000000],[0,6216500000000000],[0,6229583000000000]],"5120":[[0,601333000000000],[0,603750000000000],[0,608708000000000],[0,614375000000000]],"229376":[[0,1727134416000000000],[0,1737635834000000000],[0,1743512375000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"28":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"7168":[[0,1172791000000000],[0,1181209000000000],[0,1192959000000000],[0,1222417000000000]],"20480":[[0,9855459000000000],[0,9890500000000000],[0,9951042000000000],[0,9954208000000000]],"65536":[[0,131104333000000000],[0,131168083000000000],[0,131741792000000000],[0,132521667000000000]],"160":[[0,1042000000000],[0,1083000000000],[0,1125000000000],[0,1459000000000]],"640":[[0,11417000000000],[0,13208000000000],[0,13334000000000],[0,13500000000000]],"40":[[0,166000000000],[0,166000000000],[0,167000000000],[0,208000000000]],"57344":[[0,98051959000000000],[0,98891500000000000],[0,99060500000000000],[0,99224750000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,15750000000000],[0,15917000000000],[0,16083000000000],[0,17667000000000]],"448":[[0,5875000000000],[0,6042000000000],[0,6042000000000],[0,6250000000000]],"8192":[[0,1546500000000000],[0,1546875000000000],[0,1567333000000000],[0,1598000000000000]],"12":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"10240":[[0,2394875000000000],[0,2401459000000000],[0,2421542000000000],[0,2458583000000000]],"14336":[[0,4673750000000000],[0,4675417000000000],[0,4735292000000000],[0,4748416000000000]],"32768":[[0,28673792000000000],[0,28710583000000000],[0,29020334000000000],[0,29311292000000000]],"128":[[0,708000000000],[0,708000000000],[0,750000000000],[0,791000000000]],"4096":[[0,384125000000000],[0,387916000000000],[0,391541000000000],[0,393250000000000]],"49152":[[0,70881208000000000],[0,71110166000000000],[0,71232125000000000],[0,72713584000000000]],"262144":[[0,2258017208000000000],[0,2260444792000000000]],"3":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,306931542000000000],[0,309892958000000000],[0,313012417000000000]]}},{"title":"std::deque constructor from buffer","results":{"2048":[[0,357090000000],[0,364160000000],[0,377910000000],[0,402080000000]],"1048576":[[0,318125000000000],[0,327476888888888]],"96":[[0,44580000000],[0,44580000000],[0,45000000000],[0,45000000000]],"327680":[[0,100620290322580],[0,101398255813953]],"384":[[0,65000000000],[0,65830000000],[0,65830000000],[0,66250000000]],"12288":[[0,1632500000000],[0,1730769230769],[0,1820830000000],[0,1842920000000]],"81920":[[0,24593750000000],[0,24708000000000],[0,24725000000000],[0,24837500000000]],"8":[[0,38750000000],[0,38750000000],[0,39160000000],[0,39160000000]],"1280":[[0,179160000000],[0,179580000000],[0,180830000000],[0,181250000000]],"3584":[[0,481670000000],[0,492500000000],[0,514580000000],[0,540000000000]],"7":[[0,40000000000],[0,40000000000],[0,40410000000],[0,40410000000]],"524288":[[0,158561608695652],[0,159031250000000]],"112":[[0,45830000000],[0,45830000000],[0,45830000000],[0,52500000000]],"896":[[0,126660000000],[0,127080000000],[0,127500000000],[0,131250000000]],"192":[[0,51250000000],[0,51250000000],[0,51660000000],[0,51660000000]],"80":[[0,43330000000],[0,43330000000],[0,43330000000],[0,43750000000]],"24":[[0,39580000000],[0,40000000000],[0,40000000000],[0,40000000000]],"40960":[[0,11660420000000],[0,12415420000000],[0,12457500000000],[0,13121023809523]],"16":[[0,39170000000],[0,39170000000],[0,39580000000],[0,39590000000]],"3072":[[0,436250000000],[0,455410000000],[0,465410000000],[0,474590000000]],"20":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40410000000]],"224":[[0,53330000000],[0,53750000000],[0,53750000000],[0,53750000000]],"2560":[[0,378330000000],[0,390410000000],[0,393330000000],[0,408330000000]],"1792":[[0,242080000000],[0,242500000000],[0,244590000000],[0,247920000000]],"1024":[[0,157080000000],[0,162920000000],[0,163330000000],[0,164160000000]],"6144":[[0,855830000000],[0,859170000000],[0,865830000000],[0,1033340000000]],"56":[[0,41660000000],[0,42080000000],[0,42500000000],[0,42500000000]],"786432":[[0,233583000000000],[0,241169740740740]],"163840":[[0,49125000000000],[0,49703340000000],[0,51115966666666]],"6":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40000000000]],"48":[[0,40840000000],[0,41250000000],[0,41250000000],[0,41250000000]],"32":[[0,40410000000],[0,40410000000],[0,40410000000],[0,40420000000]],"14":[[0,40000000000],[0,40410000000],[0,40410000000],[0,40410000000]],"28672":[[0,7809590000000],[0,7835227272727],[0,7875000000000],[0,7901670000000]],"512":[[0,93750000000],[0,95000000000],[0,95000000000],[0,95830000000]],"196608":[[0,57542000000000],[0,58000000000000],[0,58125000000000]],"458752":[[0,139021358974358],[0,140483200000000]],"24576":[[0,6925830000000],[0,7071670000000],[0,7126670000000],[0,7140000000000]],"2":[[0,38750000000],[0,38750000000],[0,39160000000],[0,39160000000]],"256":[[0,55830000000],[0,55830000000],[0,56250000000],[0,56250000000]],"1536":[[0,221250000000],[0,221670000000],[0,225830000000],[0,227080000000]],"64":[[0,42080000000],[0,42090000000],[0,42090000000],[0,42500000000]],"320":[[0,60000000000],[0,60420000000],[0,60830000000],[0,64580000000]],"114688":[[0,33083000000000],[0,33432692307692],[0,33855000000000]],"131072":[[0,38472080000000],[0,38583000000000],[0,38994590000000]],"16384":[[0,2501670000000],[0,2566660000000],[0,2566670000000],[0,2586660000000]],"5120":[[0,702080000000],[0,725000000000],[0,730420000000],[0,740420000000]],"229376":[[0,68333000000000],[0,68917000000000],[0,70595238095238]],"5":[[0,39160000000],[0,39580000000],[0,39590000000],[0,40000000000]],"10":[[0,39160000000],[0,39170000000],[0,39580000000],[0,39580000000]],"28":[[0,40000000000],[0,40410000000],[0,40420000000],[0,40830000000]],"655360":[[0,196798500000000],[0,198600000000000]],"7168":[[0,954170000000],[0,961660000000],[0,995000000000],[0,1008750000000]],"20480":[[0,6112080000000],[0,6243750000000],[0,6247090000000],[0,6308340000000]],"65536":[[0,19334000000000],[0,19358200000000],[0,19378649122807],[0,19472080000000]],"917504":[[0,281209000000000],[0,282102272727272]],"160":[[0,49160000000],[0,49170000000],[0,49170000000],[0,49580000000]],"640":[[0,105420000000],[0,105830000000],[0,105830000000],[0,106250000000]],"40":[[0,40410000000],[0,40830000000],[0,40830000000],[0,40830000000]],"393216":[[0,119250000000000],[0,125099137931034]],"57344":[[0,13070696969696],[0,15465000000000],[0,15517857142857],[0,15667000000000]],"4":[[0,39580000000],[0,39580000000],[0,39580000000],[0,39590000000]],"1":[[0,38330000000],[0,38330000000],[0,38330000000],[0,38750000000]],"768":[[0,114500000000],[0,116250000000],[0,116600000000],[0,117080000000]],"448":[[0,70410000000],[0,71250000000],[0,71250000000],[0,71250000000]],"8192":[[0,1054160000000],[0,1077090000000],[0,1100000000000],[0,1273750000000]],"12":[[0,39170000000],[0,39590000000],[0,39590000000],[0,39590000000]],"10240":[[0,1320420000000],[0,1330000000000],[0,1353750000000],[0,1517920000000]],"14336":[[0,2051366666666],[0,2064363636363],[0,2127976190476],[0,2162500000000]],"32768":[[0,8641660000000],[0,8722500000000],[0,8727080000000],[0,8892500000000]],"128":[[0,47080000000],[0,47080000000],[0,47080000000],[0,47500000000]],"4096":[[0,569580000000],[0,575000000000],[0,592920000000],[0,720000000000]],"49152":[[0,13875000000000],[0,13959000000000],[0,14011250000000],[0,14041750000000]],"262144":[[0,78021604938271],[0,81722727272727]],"3":[[0,39160000000],[0,39170000000],[0,39580000000],[0,39580000000]],"98304":[[0,27917000000000],[0,27942080000000],[0,28048330000000]]}},{"title":"VecDeque constructor from buffer","results":{"2048":[[0,1206250000000],[0,1206660000000],[0,1206660000000],[0,1207910000000]],"1048576":[[0,848000000000000],[0,941548666666666]],"96":[[0,79160000000],[0,79170000000],[0,79580000000],[0,79580000000]],"327680":[[0,192862764705882],[0,236392176470588]],"384":[[0,245830000000],[0,246250000000],[0,246250000000],[0,246250000000]],"12288":[[0,7915420000000],[0,8195410000000],[0,8500000000000],[0,11333000000000]],"81920":[[0,49250000000000],[0,50073770270270],[0,51667000000000],[0,66239297297297]],"8":[[0,18750000000],[0,18750000000],[0,19160000000],[0,19160000000]],"1280":[[0,766153061224],[0,766250000000],[0,766250000000],[0,766660000000]],"3584":[[0,2090557692307],[0,2090830000000],[0,2090840000000],[0,2091250000000]],"7":[[0,17910000000],[0,18330000000],[0,18330000000],[0,18340000000]],"524288":[[0,322803571428571],[0,333083000000000]],"112":[[0,95410000000],[0,95830000000],[0,95830000000],[0,107090000000]],"896":[[0,541000000000],[0,545000000000],[0,545410000000],[0,545410000000]],"192":[[0,135410000000],[0,135410000000],[0,135420000000],[0,135420000000]],"80":[[0,67910000000],[0,69580000000],[0,69590000000],[0,70000000000]],"24":[[0,27920000000],[0,28330000000],[0,28330000000],[0,28330000000]],"40960":[[0,24273320000000],[0,25458000000000],[0,25625000000000],[0,26760830000000]],"16":[[0,23330000000],[0,23340000000],[0,23750000000],[0,23750000000]],"3072":[[0,1796250000000],[0,1796511627906],[0,1796660000000],[0,1796670000000]],"20":[[0,25830000000],[0,25830000000],[0,25840000000],[0,26250000000]],"224":[[0,153750000000],[0,153750000000],[0,153750000000],[0,154160000000]],"2560":[[0,1502080000000],[0,1502090000000],[0,1502090000000],[0,1502500000000]],"1792":[[0,1060410000000],[0,1060410000000],[0,1060420000000],[0,1060420000000]],"1024":[[0,616071428571],[0,618166666666],[0,619160000000],[0,619160000000]],"6144":[[0,4193965517241],[0,4195000000000],[0,4203340000000],[0,4204580000000]],"56":[[0,52910000000],[0,53330000000],[0,53330000000],[0,53330000000]],"786432":[[0,465625000000000],[0,624708000000000]],"163840":[[0,95750000000000],[0,96167000000000],[0,103958000000000]],"6":[[0,19160000000],[0,19170000000],[0,19170000000],[0,19580000000]],"48":[[0,50420000000],[0,50420000000],[0,50420000000],[0,50830000000]],"32":[[0,32076923076],[0,32910000000],[0,32910000000],[0,32920000000]],"14":[[0,22080000000],[0,22090000000],[0,22090000000],[0,22500000000]],"28672":[[0,17245410000000],[0,17267988636363],[0,31972500000000],[0,32067625000000]],"512":[[0,317500000000],[0,319580000000],[0,319580000000],[0,319580000000]],"196608":[[0,121732516129032],[0,145145833333333],[0,212952392857142]],"458752":[[0,282375000000000],[0,478521000000000]],"24576":[[0,14944590000000],[0,18250000000000],[0,20447080000000],[0,27550000000000]],"2":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"256":[[0,172080000000],[0,172500000000],[0,172500000000],[0,172500000000]],"1536":[[0,912645161290],[0,913330000000],[0,913330000000],[0,913330000000]],"64":[[0,60000000000],[0,60000000000],[0,60000000000],[0,60000000000]],"320":[[0,207500000000],[0,207500000000],[0,207500000000],[0,217080000000]],"114688":[[0,68708000000000],[0,69750000000000],[0,72541000000000]],"131072":[[0,78417000000000],[0,81625000000000],[0,118459000000000]],"16384":[[0,10208000000000],[0,15250000000000],[0,18483750000000],[0,18513330000000]],"5120":[[0,3586670000000],[0,3586670000000],[0,3592500000000],[0,3594580000000]],"229376":[[0,139166000000000],[0,187667000000000],[0,235041000000000]],"5":[[0,18750000000],[0,19160000000],[0,19160000000],[0,19160000000]],"10":[[0,19580000000],[0,20000000000],[0,20000000000],[0,20000000000]],"28":[[0,30830000000],[0,30830000000],[0,30830000000],[0,30830000000]],"655360":[[0,384407333333333],[0,401542000000000]],"7168":[[0,4797080000000],[0,4798330000000],[0,4799170000000],[0,4802080000000]],"20480":[[0,12541000000000],[0,12987920000000],[0,23011250000000],[0,23027230769230]],"65536":[[0,39875000000000],[0,40125000000000],[0,40292000000000],[0,83020454545454]],"917504":[[0,668154714285714],[0,1234042000000000]],"160":[[0,115000000000],[0,115410000000],[0,115410000000],[0,117080000000]],"640":[[0,397910000000],[0,398330000000],[0,398330000000],[0,398330000000]],"40":[[0,41500000000],[0,43330000000],[0,45410000000],[0,45410000000]],"393216":[[0,246584000000000],[0,515395857142857]],"57344":[[0,34583000000000],[0,54500000000000],[0,63804545454545],[0,64053330000000]],"4":[[0,17920000000],[0,18330000000],[0,18330000000],[0,18330000000]],"1":[[0,14160000000],[0,14580000000],[0,14580000000],[0,14580000000]],"768":[[0,469580000000],[0,470410000000],[0,470410000000],[0,471660000000]],"448":[[0,282500000000],[0,282910000000],[0,282910000000],[0,293750000000]],"8192":[[0,5435410000000],[0,5439076923076],[0,5442910000000],[0,5445000000000]],"12":[[0,20830000000],[0,20830000000],[0,21250000000],[0,21250000000]],"10240":[[0,7000000000000],[0,9476063829787],[0,9482920000000],[0,9594170000000]],"14336":[[0,10375000000000],[0,15735410000000],[0,15823750000000],[0,15854170000000]],"32768":[[0,20166000000000],[0,36692500000000],[0,36869170000000],[0,37387500000000]],"128":[[0,105000000000],[0,105000000000],[0,105000000000],[0,105000000000]],"4096":[[0,2385000000000],[0,2385420000000],[0,2385830000000],[0,2731250000000]],"49152":[[0,40205981132075],[0,47750410000000],[0,54958330000000],[0,55686670000000]],"262144":[[0,156792000000000],[0,291456000000000]],"3":[[0,17910000000],[0,17910000000],[0,17910000000],[0,17910000000]],"98304":[[0,57305333333333],[0,114768360000000],[0,140375688524590]]}},{"title":"std::deque sequential iteration","results":{"2048":[[0,2208000000000],[0,2243750000000],[0,2244160000000],[0,2244160000000]],"1048576":[[0,1158031250000000],[0,1169072875000000]],"96":[[0,110410000000],[0,110410000000],[0,110410000000],[0,113750000000]],"327680":[[0,358084000000000],[0,395035000000000]],"384":[[0,422080000000],[0,422500000000],[0,422500000000],[0,422500000000]],"12288":[[0,13417000000000],[0,13426250000000],[0,13426470588235],[0,13613330000000]],"81920":[[0,89503818181818],[0,89675410000000],[0,89921333333333],[0,91094590000000]],"8":[[0,8400000000],[0,10000000000],[0,10000000000],[0,10410000000]],"1280":[[0,1402080000000],[0,1402322580645],[0,1402500000000],[0,1402500000000]],"3584":[[0,3920830000000],[0,3920830000000],[0,3921250000000],[0,3926250000000]],"7":[[0,9160000000],[0,9160000000],[0,9170000000],[0,9170000000]],"524288":[[0,613145500000000],[0,619167000000000]],"112":[[0,127500000000],[0,127910000000],[0,127910000000],[0,145000000000]],"896":[[0,980190476190],[0,981250000000],[0,981660000000],[0,981660000000]],"192":[[0,208000000000],[0,209000000000],[0,214170000000],[0,214580000000]],"80":[[0,92910000000],[0,92910000000],[0,92920000000],[0,92920000000]],"24":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,44757545454545],[0,44874160000000],[0,44891660000000],[0,45088750000000]],"16":[[0,18750000000],[0,19160000000],[0,19160000000],[0,19160000000]],"3072":[[0,3354250000000],[0,3362090000000],[0,3362500000000],[0,3362910000000]],"20":[[0,21000000000],[0,23330000000],[0,23330000000],[0,23330000000]],"224":[[0,248750000000],[0,249160000000],[0,249160000000],[0,250000000000]],"2560":[[0,2802500000000],[0,2802910000000],[0,2802910000000],[0,2803750000000]],"1792":[[0,1958000000000],[0,1958000000000],[0,1961660000000],[0,1962080000000]],"1024":[[0,1125420000000],[0,1125420000000],[0,1125830000000],[0,1125830000000]],"6144":[[0,6715830000000],[0,6715830000000],[0,6716250000000],[0,6718330000000]],"56":[[0,66600000000],[0,67080000000],[0,67500000000],[0,67500000000]],"786432":[[0,872208000000000],[0,874416727272727]],"163840":[[0,180958500000000],[0,183457538461538],[0,188709208333333]],"6":[[0,7920000000],[0,8330000000],[0,8330000000],[0,8330000000]],"48":[[0,58750000000],[0,58750000000],[0,58750000000],[0,58750000000]],"32":[[0,41250000000],[0,41660000000],[0,41660000000],[0,41660000000]],"14":[[0,16660000000],[0,16660000000],[0,16670000000],[0,16670000000]],"28672":[[0,31337090000000],[0,31365000000000],[0,31541000000000],[0,31734580000000]],"512":[[0,560420000000],[0,560830000000],[0,560830000000],[0,561250000000]],"196608":[[0,214777666666666],[0,219500000000000],[0,225833500000000]],"458752":[[0,501925421052631],[0,510625000000000]],"24576":[[0,26854580000000],[0,26875000000000],[0,26916000000000],[0,27229170000000]],"2":[[0,3750000000],[0,3750000000],[0,3750000000],[0,3750000000]],"256":[[0,283750000000],[0,283750000000],[0,283750000000],[0,283750000000]],"1536":[[0,1684580000000],[0,1684580000000],[0,1684590000000],[0,1685000000000]],"64":[[0,75830000000],[0,75830000000],[0,75840000000],[0,76250000000]],"320":[[0,352920000000],[0,353330000000],[0,370000000000],[0,378340000000]],"114688":[[0,126875000000000],[0,127311264705882],[0,128259315789473]],"131072":[[0,143384057971014],[0,144500000000000],[0,144833000000000]],"16384":[[0,17900000000000],[0,17909738095238],[0,17933340000000],[0,17938750000000]],"5120":[[0,5584000000000],[0,5597920000000],[0,5597920000000],[0,5598750000000]],"229376":[[0,253750000000000],[0,271357142857142],[0,273667000000000]],"5":[[0,7080000000],[0,7080000000],[0,7080000000],[0,7080000000]],"10":[[0,12500000000],[0,12500000000],[0,12500000000],[0,12500000000]],"28":[[0,36660000000],[0,36670000000],[0,37080000000],[0,37080000000]],"655360":[[0,719917000000000],[0,722025692307692]],"7168":[[0,7833750000000],[0,7834051724137],[0,7834580000000],[0,7835000000000]],"20480":[[0,22375000000000],[0,22428330000000],[0,22429170000000],[0,22488750000000]],"65536":[[0,71709000000000],[0,71927918918918],[0,72135000000000],[0,72283340000000]],"917504":[[0,1014676000000000],[0,1074984375000000]],"160":[[0,179580000000],[0,180000000000],[0,180000000000],[0,180410000000]],"640":[[0,704160000000],[0,704580000000],[0,704580000000],[0,704580000000]],"40":[[0,49580000000],[0,50000000000],[0,50000000000],[0,52910000000]],"393216":[[0,440166000000000],[0,478458500000000]],"57344":[[0,62666000000000],[0,62745067796610],[0,62952586206896],[0,63334070175438]],"4":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5840000000]],"1":[[0,2080000000],[0,2080000000],[0,2080000000],[0,2090000000]],"768":[[0,842910000000],[0,842910000000],[0,842910000000],[0,843330000000]],"448":[[0,491250000000],[0,491660000000],[0,491660000000],[0,499590000000]],"8192":[[0,8952500000000],[0,8952500000000],[0,8990410000000],[0,9004160000000]],"12":[[0,14170000000],[0,14580000000],[0,14580000000],[0,14580000000]],"10240":[[0,11188635135135],[0,11189430232558],[0,11199580000000],[0,11238352941176]],"14336":[[0,15661670000000],[0,15664062500000],[0,15666000000000],[0,15670830000000]],"32768":[[0,35802080000000],[0,35924580000000],[0,36208000000000],[0,36375000000000]],"128":[[0,145410000000],[0,145410000000],[0,145410000000],[0,145410000000]],"4096":[[0,4479166666666],[0,4479580000000],[0,4479580000000],[0,5709000000000]],"49152":[[0,53933750000000],[0,53968750000000],[0,54100000000000],[0,54515000000000]],"262144":[[0,290083000000000],[0,306497290322580]],"3":[[0,4590000000],[0,5000000000],[0,5000000000],[0,5000000000]],"98304":[[0,107449111111111],[0,108167000000000],[0,108542000000000]]}},{"title":"std::deque random-access offset lookups (operator [])","results":{"2048":[[0,2219681818181],[0,2220830000000],[0,2220840000000],[0,2221250000000]],"1048576":[[0,1210334000000000],[0,1214458400000000]],"96":[[0,107500000000],[0,107910000000],[0,108330000000],[0,109160000000]],"327680":[[0,361425000000000],[0,367529411764705]],"384":[[0,416666666666],[0,420830000000],[0,420840000000],[0,422950000000]],"12288":[[0,13291000000000],[0,13306250000000],[0,13307090000000],[0,13307500000000]],"81920":[[0,88769170000000],[0,88926660000000],[0,90042920000000],[0,90737500000000]],"8":[[0,10000000000],[0,10410000000],[0,10410000000],[0,10410000000]],"1280":[[0,1375000000000],[0,1385500000000],[0,1388000000000],[0,1389580000000]],"3584":[[0,3875000000000],[0,3883330000000],[0,3883330000000],[0,3883750000000]],"7":[[0,8750000000],[0,8750000000],[0,9160000000],[0,9160000000]],"524288":[[0,589683400000000],[0,596359909090909]],"112":[[0,125000000000],[0,125000000000],[0,125410000000],[0,126250000000]],"896":[[0,968750000000],[0,973500000000],[0,973750000000],[0,973750000000]],"192":[[0,209000000000],[0,212910000000],[0,212920000000],[0,213330000000]],"80":[[0,90410000000],[0,90410000000],[0,90830000000],[0,91670000000]],"24":[[0,27090000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,44405684210526],[0,44460000000000],[0,44475708333333],[0,44526500000000]],"16":[[0,18750000000],[0,18750000000],[0,18750000000],[0,18750000000]],"3072":[[0,3329160000000],[0,3329160000000],[0,3329170000000],[0,3329580000000]],"20":[[0,22910000000],[0,22910000000],[0,22910000000],[0,22920000000]],"224":[[0,246541666666],[0,247080000000],[0,248330000000],[0,248340000000]],"2560":[[0,2774580000000],[0,2774580000000],[0,2775000000000],[0,2776250000000]],"1792":[[0,1943340000000],[0,1943750000000],[0,1943750000000],[0,1944170000000]],"1024":[[0,1112381578947],[0,1112500000000],[0,1112500000000],[0,1112500000000]],"6144":[[0,6653761904761],[0,6655000000000],[0,6655000000000],[0,6655000000000]],"56":[[0,64160000000],[0,64580000000],[0,65000000000],[0,65830000000]],"786432":[[0,862151000000000],[0,871356444444444]],"163840":[[0,179396000000000],[0,183550925925925],[0,184672571428571]],"6":[[0,7910000000],[0,7910000000],[0,7910000000],[0,8330000000]],"48":[[0,55830000000],[0,55830000000],[0,55840000000],[0,56250000000]],"32":[[0,35830000000],[0,35840000000],[0,36250000000],[0,36250000000]],"14":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"28672":[[0,31073750000000],[0,31083333333333],[0,31167000000000],[0,31845420000000]],"512":[[0,557910000000],[0,559580000000],[0,559580000000],[0,559580000000]],"196608":[[0,212958000000000],[0,216287111111111],[0,225317750000000]],"458752":[[0,502575562500000],[0,531991600000000]],"24576":[[0,26606670000000],[0,26625000000000],[0,26625000000000],[0,26642080000000]],"2":[[0,3330000000],[0,3750000000],[0,3750000000],[0,3750000000]],"256":[[0,280830000000],[0,281250000000],[0,282080000000],[0,282500000000]],"1536":[[0,1663166666666],[0,1666660000000],[0,1666660000000],[0,1666660000000]],"64":[[0,73330000000],[0,73330000000],[0,73330000000],[0,74160000000]],"320":[[0,333000000000],[0,350410000000],[0,351660000000],[0,367080000000]],"114688":[[0,124145750000000],[0,124151000000000],[0,125520833333333]],"131072":[[0,141917000000000],[0,142716800000000],[0,143354250000000]],"16384":[[0,17739160000000],[0,17750000000000],[0,17772090000000],[0,17964170000000]],"5120":[[0,5500000000000],[0,5545830000000],[0,5546250000000],[0,5546250000000]],"229376":[[0,255148437500000],[0,270450222222222],[0,350875000000000]],"5":[[0,6660000000],[0,6958333333],[0,7080000000],[0,7080000000]],"10":[[0,12080000000],[0,12500000000],[0,12500000000],[0,12500000000]],"28":[[0,31250000000],[0,31660000000],[0,31670000000],[0,32080000000]],"655360":[[0,712154857142857],[0,717917000000000]],"7168":[[0,7762500000000],[0,7762500000000],[0,7763330000000],[0,7798750000000]],"20480":[[0,22167000000000],[0,22173750000000],[0,22187500000000],[0,22250954545454]],"65536":[[0,71190179487179],[0,71612947368421],[0,71770597701149],[0,71832080000000]],"917504":[[0,1001625000000000],[0,1019777833333333]],"160":[[0,175000000000],[0,177080000000],[0,177090000000],[0,177500000000]],"640":[[0,696660000000],[0,696660000000],[0,696660000000],[0,696660000000]],"40":[[0,47910000000],[0,47910000000],[0,48330000000],[0,48330000000]],"393216":[[0,427656250000000],[0,439459000000000]],"57344":[[0,62042000000000],[0,62537500000000],[0,62632067796610],[0,62673016949152]],"4":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5830000000]],"1":[[0,1660000000],[0,1660000000],[0,1660000000],[0,1660000000]],"768":[[0,833000000000],[0,833000000000],[0,834000000000],[0,835420000000]],"448":[[0,488750000000],[0,489160000000],[0,489160000000],[0,490410000000]],"8192":[[0,8871660000000],[0,8872500000000],[0,8875000000000],[0,8905410000000]],"12":[[0,14580000000],[0,14580000000],[0,14580000000],[0,14580000000]],"10240":[[0,11083500000000],[0,11089580000000],[0,11091567901234],[0,11094170000000]],"14336":[[0,15521428571428],[0,15523750000000],[0,15525653846153],[0,15534160000000]],"32768":[[0,35500000000000],[0,35500000000000],[0,35582753424657],[0,35997080000000]],"128":[[0,142080000000],[0,142500000000],[0,142910000000],[0,143330000000]],"4096":[[0,4437080000000],[0,4437080000000],[0,4437910000000],[0,4516250000000]],"49152":[[0,53291000000000],[0,53332500000000],[0,53458325000000],[0,53737095238095]],"262144":[[0,293018750000000],[0,480375000000000]],"3":[[0,4590000000],[0,5000000000],[0,5000000000],[0,5000000000]],"98304":[[0,107728917647058],[0,108097418918918],[0,108729000000000]]}},{"title":"std::deque at, random offsets","results":{"2048":[[0,1667000000000],[0,1667080000000],[0,1667080000000],[0,1667500000000]],"1048576":[[0,1070202428571428],[0,1087095285714285]],"96":[[0,82080000000],[0,82500000000],[0,82500000000],[0,82500000000]],"327680":[[0,288222333333333],[0,290634093750000]],"384":[[0,316250000000],[0,316250000000],[0,316660000000],[0,317080000000]],"12288":[[0,9996250000000],[0,9997500000000],[0,10003750000000],[0,10023148148148]],"81920":[[0,67651595744680],[0,67886363636363],[0,68208000000000],[0,70575000000000]],"8":[[0,7910000000],[0,8330000000],[0,8330000000],[0,8340000000]],"1280":[[0,1043750000000],[0,1043750000000],[0,1043750000000],[0,1043750000000]],"3584":[[0,2913750000000],[0,2913750000000],[0,2913793103448],[0,2914170000000]],"7":[[0,7500000000],[0,7500000000],[0,7500000000],[0,7910000000]],"524288":[[0,487914473684210],[0,491354000000000]],"112":[[0,95410000000],[0,95420000000],[0,95420000000],[0,95830000000]],"896":[[0,731670000000],[0,732080000000],[0,732080000000],[0,732090000000]],"192":[[0,160000000000],[0,160410000000],[0,160410000000],[0,160410000000]],"80":[[0,69170000000],[0,69580000000],[0,69580000000],[0,69580000000]],"24":[[0,20830000000],[0,20850000000],[0,21250000000],[0,21250000000]],"40960":[[0,33312080000000],[0,33333000000000],[0,33413750000000],[0,33584000000000]],"16":[[0,14580000000],[0,14590000000],[0,15000000000],[0,15000000000]],"3072":[[0,2498047619047],[0,2498330000000],[0,2498340000000],[0,2498750000000]],"20":[[0,17920000000],[0,18330000000],[0,18330000000],[0,18330000000]],"224":[[0,186660000000],[0,186660000000],[0,186660000000],[0,186660000000]],"2560":[[0,2082500000000],[0,2082500000000],[0,2082500000000],[0,2082500000000]],"1792":[[0,1458000000000],[0,1458000000000],[0,1459000000000],[0,1459580000000]],"1024":[[0,833000000000],[0,833333333333],[0,835830000000],[0,836250000000]],"6144":[[0,4992920000000],[0,4993363636363],[0,4993589743589],[0,4993750000000]],"56":[[0,42000000000],[0,50000000000],[0,50000000000],[0,50000000000]],"786432":[[0,728896000000000],[0,732159666666666]],"163840":[[0,141500000000000],[0,142372579710144],[0,145291000000000]],"6":[[0,6660000000],[0,6660000000],[0,6660000000],[0,6660000000]],"48":[[0,42000000000],[0,43750000000],[0,44160000000],[0,44160000000]],"32":[[0,27500000000],[0,27500000000],[0,27910000000],[0,27910000000]],"14":[[0,12920000000],[0,13330000000],[0,13330000000],[0,13330000000]],"28672":[[0,23326670000000],[0,23327500000000],[0,23347920000000],[0,23500000000000]],"512":[[0,416000000000],[0,416000000000],[0,416750000000],[0,417000000000]],"196608":[[0,170208000000000],[0,170659482758620],[0,182158340000000]],"458752":[[0,414584000000000],[0,416726434782608]],"24576":[[0,20012500000000],[0,20050830000000],[0,20082500000000],[0,20118750000000]],"2":[[0,3330000000],[0,3330000000],[0,3330000000],[0,3330000000]],"256":[[0,212080000000],[0,212090000000],[0,212500000000],[0,212500000000]],"1536":[[0,1250000000000],[0,1251660000000],[0,1251660000000],[0,1251660000000]],"64":[[0,56250000000],[0,56250000000],[0,56250000000],[0,56660000000]],"320":[[0,250000000000],[0,264580000000],[0,276670000000],[0,277080000000]],"114688":[[0,96458000000000],[0,96472333333333],[0,100025938775510]],"131072":[[0,110875000000000],[0,112167000000000],[0,112334000000000]],"16384":[[0,13314024390243],[0,13314393939393],[0,13315340909090],[0,13393330000000]],"5120":[[0,4160830000000],[0,4160830000000],[0,4161250000000],[0,4161670000000]],"229376":[[0,204479000000000],[0,210670619047619],[0,263583000000000]],"5":[[0,5410000000],[0,5830000000],[0,5830000000],[0,6250000000]],"10":[[0,10000000000],[0,10000000000],[0,10000000000],[0,10000000000]],"28":[[0,24170000000],[0,24170000000],[0,24170000000],[0,24580000000]],"655360":[[0,594667000000000],[0,628711357142857]],"7168":[[0,5825000000000],[0,5826670000000],[0,5827500000000],[0,5843117647058]],"20480":[[0,16653750000000],[0,16681250000000],[0,16750000000000],[0,17052910000000]],"65536":[[0,53551950617283],[0,53717090000000],[0,53951250000000],[0,55375000000000]],"917504":[[0,861078666666666],[0,878333000000000]],"160":[[0,134170000000],[0,134170000000],[0,134580000000],[0,134580000000]],"640":[[0,524160000000],[0,524160000000],[0,524160000000],[0,524160000000]],"40":[[0,36660000000],[0,36660000000],[0,37080000000],[0,37500000000]],"393216":[[0,358649703703703],[0,365958000000000]],"57344":[[0,46666727272727],[0,46731444444444],[0,46923330000000],[0,47179170000000]],"4":[[0,4580000000],[0,5000000000],[0,5000000000],[0,5000000000]],"1":[[0,1660000000],[0,1660000000],[0,1660000000],[0,1670000000]],"768":[[0,627910000000],[0,627910000000],[0,628330000000],[0,628330000000]],"448":[[0,368330000000],[0,368330000000],[0,368330000000],[0,368330000000]],"8192":[[0,6658750000000],[0,6659170000000],[0,6660410000000],[0,6696660000000]],"12":[[0,11660000000],[0,11660000000],[0,11660000000],[0,11660000000]],"10240":[[0,8312500000000],[0,8325420000000],[0,8325830000000],[0,8329580000000]],"14336":[[0,11625000000000],[0,11651250000000],[0,11660000000000],[0,11681250000000]],"32768":[[0,26625000000000],[0,26625000000000],[0,26646000000000],[0,26791000000000]],"128":[[0,108330000000],[0,108750000000],[0,108750000000],[0,108750000000]],"4096":[[0,3329580000000],[0,3329580000000],[0,3329580000000],[0,3461250000000]],"49152":[[0,40083000000000],[0,40167000000000],[0,40208000000000],[0,40521250000000]],"262144":[[0,230729000000000],[0,247745388888888]],"3":[[0,4170000000],[0,4170000000],[0,4580000000],[0,4580000000]],"98304":[[0,81934875000000],[0,82487080000000],[0,82956000000000]]}},{"title":"std::deque push_back","results":{"2048":[[0,2270420000000],[0,2296250000000],[0,2296660000000],[0,2298330000000]],"1048576":[[0,1362916000000000],[0,1421083333333333]],"96":[[0,132080000000],[0,132500000000],[0,132500000000],[0,133330000000]],"327680":[[0,426145833333333],[0,430820210526315]],"384":[[0,415000000000],[0,415000000000],[0,415000000000],[0,416250000000]],"12288":[[0,13665000000000],[0,13813750000000],[0,14167000000000],[0,14255420000000]],"81920":[[0,102741650000000],[0,102875000000000],[0,105409090909090],[0,109180811320754]],"8":[[0,41250000000],[0,41660000000],[0,41660000000],[0,42920000000]],"1280":[[0,1410830000000],[0,1411250000000],[0,1411670000000],[0,1419580000000]],"3584":[[0,3928750000000],[0,3932500000000],[0,3935830000000],[0,4453750000000]],"7":[[0,40830000000],[0,40830000000],[0,40830000000],[0,42500000000]],"524288":[[0,699425000000000],[0,717370900000000]],"112":[[0,148330000000],[0,148330000000],[0,148330000000],[0,149160000000]],"896":[[0,975830000000],[0,975840000000],[0,976250000000],[0,978330000000]],"192":[[0,226250000000],[0,226660000000],[0,226660000000],[0,227500000000]],"80":[[0,116660000000],[0,116660000000],[0,116660000000],[0,117910000000]],"24":[[0,57080000000],[0,57080000000],[0,57080000000],[0,58330000000]],"40960":[[0,49958000000000],[0,51159580000000],[0,51607500000000],[0,53488750000000]],"16":[[0,48583333333],[0,49170000000],[0,49170000000],[0,50420000000]],"3072":[[0,3360410000000],[0,3385416666666],[0,3385420000000],[0,3391250000000]],"20":[[0,52910000000],[0,53330000000],[0,53330000000],[0,55000000000]],"224":[[0,257500000000],[0,257910000000],[0,257910000000],[0,259160000000]],"2560":[[0,2812500000000],[0,2840830000000],[0,2841660000000],[0,2841670000000]],"1792":[[0,1958330000000],[0,1958750000000],[0,1959000000000],[0,1960000000000]],"1024":[[0,1145833333333],[0,1147500000000],[0,1149170000000],[0,1159170000000]],"6144":[[0,6697500000000],[0,6707500000000],[0,6713750000000],[0,6829170000000]],"56":[[0,92920000000],[0,92920000000],[0,93330000000],[0,94160000000]],"786432":[[0,989959000000000],[0,1045062500000000]],"163840":[[0,206416666666666],[0,212172642857142],[0,214056571428571]],"6":[[0,39580000000],[0,40000000000],[0,40000000000],[0,41250000000]],"48":[[0,86250000000],[0,86250000000],[0,86250000000],[0,87080000000]],"32":[[0,65000000000],[0,65000000000],[0,65000000000],[0,66660000000]],"14":[[0,47080000000],[0,47080000000],[0,47500000000],[0,48750000000]],"28672":[[0,35584000000000],[0,36444029850746],[0,36575000000000],[0,37523330000000]],"512":[[0,583333333333],[0,587080000000],[0,587080000000],[0,589580000000]],"196608":[[0,256485142857142],[0,259540178571428],[0,263141800000000]],"458752":[[0,604243000000000],[0,614170800000000]],"24576":[[0,28549590000000],[0,31159666666666],[0,31773330000000],[0,32671670000000]],"2":[[0,36660000000],[0,36670000000],[0,37080000000],[0,37910000000]],"256":[[0,289580000000],[0,289580000000],[0,289580000000],[0,290410000000]],"1536":[[0,1692090000000],[0,1692500000000],[0,1692907407407],[0,1694160000000]],"64":[[0,100830000000],[0,100830000000],[0,101250000000],[0,101660000000]],"320":[[0,352080000000],[0,352080000000],[0,352500000000],[0,353330000000]],"114688":[[0,148416636363636],[0,148491700000000],[0,150157000000000]],"131072":[[0,166833500000000],[0,168810636363636],[0,170958333333333]],"16384":[[0,18629666666666],[0,19035000000000],[0,19298340000000],[0,19349580000000]],"5120":[[0,5608750000000],[0,5625000000000],[0,5640420000000],[0,5647500000000]],"229376":[[0,307422607142857],[0,308395818181818],[0,446292000000000]],"5":[[0,38750000000],[0,39160000000],[0,39160000000],[0,40410000000]],"10":[[0,42920000000],[0,43330000000],[0,43340000000],[0,45000000000]],"28":[[0,60830000000],[0,60830000000],[0,60840000000],[0,62500000000]],"655360":[[0,837792000000000],[0,845021000000000]],"7168":[[0,7843330000000],[0,7899291666666],[0,7990000000000],[0,8024160000000]],"20480":[[0,23717920000000],[0,23763750000000],[0,24558330000000],[0,24636670000000]],"65536":[[0,81083000000000],[0,81334000000000],[0,83848750000000],[0,85105705263157]],"917504":[[0,1230857142857142],[0,1272722166666666]],"160":[[0,195000000000],[0,195410000000],[0,195410000000],[0,196250000000]],"640":[[0,723750000000],[0,724160000000],[0,724160000000],[0,726250000000]],"40":[[0,77910000000],[0,77910000000],[0,77920000000],[0,79160000000]],"393216":[[0,516230769230769],[0,528431571428571]],"57344":[[0,71334000000000],[0,71583000000000],[0,73562920000000],[0,73612910000000]],"4":[[0,38750000000],[0,38750000000],[0,39160000000],[0,40000000000]],"1":[[0,34170000000],[0,34580000000],[0,34580000000],[0,35830000000]],"768":[[0,850830000000],[0,850830000000],[0,850830000000],[0,853330000000]],"448":[[0,477500000000],[0,477910000000],[0,478330000000],[0,478330000000]],"8192":[[0,9021000000000],[0,9080420000000],[0,9089170000000],[0,9260420000000]],"12":[[0,45000000000],[0,45000000000],[0,45000000000],[0,46670000000]],"10240":[[0,11416000000000],[0,11456660000000],[0,11721823529411],[0,11859160000000]],"14336":[[0,16332080000000],[0,16569160000000],[0,16625000000000],[0,16677090000000]],"32768":[[0,40875931818181],[0,42688330000000],[0,42780410000000],[0,43101670000000]],"128":[[0,163750000000],[0,163750000000],[0,163750000000],[0,165000000000]],"4096":[[0,4497500000000],[0,4502910000000],[0,4529170000000],[0,4740410000000]],"49152":[[0,63037920000000],[0,63282732142857],[0,64770000000000],[0,65265000000000]],"262144":[[0,344182571428571],[0,344541571428571]],"3":[[0,38330000000],[0,38330000000],[0,38330000000],[0,39170000000]],"98304":[[0,123625000000000],[0,127508680555555],[0,130001317460317]]}},{"title":"VecDeque push_back","results":{"2048":[[0,1778750000000],[0,1786250000000],[0,1818750000000],[0,1837920000000]],"1048576":[[0,1231583000000000],[0,1977812500000000]],"96":[[0,253750000000],[0,255420000000],[0,255840000000],[0,258750000000]],"327680":[[0,318646000000000],[0,397388888888888]],"384":[[0,555830000000],[0,556670000000],[0,560000000000],[0,563750000000]],"12288":[[0,11677920000000],[0,13060420000000],[0,14635000000000],[0,15163750000000]],"81920":[[0,51750000000000],[0,57875000000000],[0,65505712328767],[0,69231739726027]],"8":[[0,52910000000],[0,52910000000],[0,52910000000],[0,52910000000]],"1280":[[0,1379580000000],[0,1389590000000],[0,1397920000000],[0,1399170000000]],"3584":[[0,2888330000000],[0,2896250000000],[0,2897920000000],[0,3309590000000]],"7":[[0,52080000000],[0,52500000000],[0,52500000000],[0,52500000000]],"524288":[[0,516541000000000],[0,559834000000000]],"112":[[0,263340000000],[0,264580000000],[0,265000000000],[0,267080000000]],"896":[[0,947500000000],[0,953330000000],[0,957090000000],[0,957596491228]],"192":[[0,367500000000],[0,370000000000],[0,371250000000],[0,372500000000]],"80":[[0,245000000000],[0,245420000000],[0,246670000000],[0,247500000000]],"24":[[0,117910000000],[0,118750000000],[0,118750000000],[0,119160000000]],"40960":[[0,28239160000000],[0,28300000000000],[0,32880617977528],[0,47927253968253]],"16":[[0,84580000000],[0,84580000000],[0,84580000000],[0,85000000000]],"3072":[[0,2593750000000],[0,2603330000000],[0,2641250000000],[0,2702080000000]],"20":[[0,115420000000],[0,115840000000],[0,116660000000],[0,116670000000]],"224":[[0,382920000000],[0,386670000000],[0,387500000000],[0,389170000000]],"2560":[[0,2336734693877],[0,2349590000000],[0,2372500000000],[0,2376660000000]],"1792":[[0,1625000000000],[0,1635830000000],[0,1642080000000],[0,1668750000000]],"1024":[[0,1027500000000],[0,1034170000000],[0,1036660000000],[0,1038330000000]],"6144":[[0,5974170000000],[0,6077080000000],[0,6087500000000],[0,6093340000000]],"56":[[0,177500000000],[0,179160000000],[0,179580000000],[0,180000000000]],"786432":[[0,1010292000000000],[0,1038875000000000]],"163840":[[0,105833000000000],[0,142956157894736],[0,149011133333333]],"6":[[0,51660000000],[0,51660000000],[0,51660000000],[0,52080000000]],"48":[[0,172920000000],[0,174160000000],[0,174170000000],[0,174170000000]],"32":[[0,123330000000],[0,123330000000],[0,123330000000],[0,123750000000]],"14":[[0,83750000000],[0,83750000000],[0,83750000000],[0,83750000000]],"28672":[[0,20000000000000],[0,32208000000000],[0,32937920000000],[0,33107090000000]],"512":[[0,627080000000],[0,630000000000],[0,632080000000],[0,637500000000]],"196608":[[0,120667000000000],[0,168583000000000],[0,209729692307692]],"458752":[[0,509953125000000],[0,519180666666666]],"24576":[[0,18867500000000],[0,19083000000000],[0,21958000000000],[0,28522910000000]],"2":[[0,20420000000],[0,20420000000],[0,20830000000],[0,21250000000]],"256":[[0,408330000000],[0,410840000000],[0,412080000000],[0,412910000000]],"1536":[[0,1496250000000],[0,1527080000000],[0,1528750000000],[0,1552080000000]],"64":[[0,183340000000],[0,183750000000],[0,183750000000],[0,183750000000]],"320":[[0,513750000000],[0,514580000000],[0,515830000000],[0,525000000000]],"114688":[[0,77084000000000],[0,82916000000000],[0,98617472222222]],"131072":[[0,116979500000000],[0,126872200000000],[0,154162162162162]],"16384":[[0,13917000000000],[0,14791000000000],[0,15417000000000],[0,19405000000000]],"5120":[[0,5336236111111],[0,5368750000000],[0,5381670000000],[0,5389170000000]],"229376":[[0,145833000000000],[0,206438735294117],[0,268333400000000]],"5":[[0,50830000000],[0,51250000000],[0,51250000000],[0,51250000000]],"10":[[0,80830000000],[0,81250000000],[0,81250000000],[0,81250000000]],"28":[[0,120000000000],[0,120410000000],[0,120420000000],[0,120840000000]],"655360":[[0,842709000000000],[0,879666000000000]],"7168":[[0,6427920000000],[0,6430410000000],[0,6470451612903],[0,6496670000000]],"20480":[[0,15964170000000],[0,22167000000000],[0,23806571428571],[0,23892857142857]],"65536":[[0,51125000000000],[0,53109756097560],[0,53208000000000],[0,62928571428571]],"917504":[[0,1251000000000000],[0,1381167000000000]],"160":[[0,345840000000],[0,348750000000],[0,350420000000],[0,351660000000]],"640":[[0,802500000000],[0,806660000000],[0,809160000000],[0,811250000000]],"40":[[0,168750000000],[0,169580000000],[0,170000000000],[0,171250000000]],"393216":[[0,321500000000000],[0,492681571428571]],"57344":[[0,39000000000000],[0,64320000000000],[0,64881670000000],[0,64927096153846]],"4":[[0,22500000000],[0,22500000000],[0,22500000000],[0,22500000000]],"1":[[0,19160000000],[0,19160000000],[0,19160000000],[0,19160000000]],"768":[[0,875830000000],[0,883340000000],[0,889170000000],[0,892910000000]],"448":[[0,588750000000],[0,592920000000],[0,594580000000],[0,595410000000]],"8192":[[0,7919170000000],[0,7925000000000],[0,8312920000000],[0,8736670000000]],"12":[[0,82080000000],[0,82500000000],[0,82500000000],[0,82910000000]],"10240":[[0,9031250000000],[0,9708000000000],[0,10149580000000],[0,10962920000000]],"14336":[[0,11298750000000],[0,11301670000000],[0,12756250000000],[0,13318330000000]],"32768":[[0,24274703703703],[0,24825657894736],[0,29805000000000],[0,35561670000000]],"128":[[0,272090000000],[0,273330000000],[0,275830000000],[0,276670000000]],"4096":[[0,3188750000000],[0,3188750000000],[0,3238866666666],[0,3315840000000]],"49152":[[0,49250000000000],[0,56518581081081],[0,56687920000000],[0,56908109589041]],"262144":[[0,255550310344827],[0,271054200000000]],"3":[[0,21670000000],[0,21670000000],[0,22080000000],[0,22080000000]],"98304":[[0,74583000000000],[0,96670562500000],[0,110139583333333]]}},{"title":"UniqueDeque append","results":{"2048":[[0,5122500000000],[0,5130420000000],[0,5136660000000],[0,5163750000000]],"1048576":[[0,2795708000000000],[0,2890437500000000]],"96":[[0,449170000000],[0,452920000000],[0,454160000000],[0,454170000000]],"327680":[[0,865542000000000],[0,877312500000000]],"384":[[0,1183340000000],[0,1191670000000],[0,1194580000000],[0,1197920000000]],"12288":[[0,31384160000000],[0,31854170000000],[0,33072500000000],[0,33123330000000]],"81920":[[0,188875000000000],[0,189419941176470],[0,193151156862745],[0,203673604166666]],"8":[[0,113750000000],[0,113750000000],[0,114160000000],[0,114160000000]],"1280":[[0,3481670000000],[0,3487910000000],[0,3488750000000],[0,3493330000000]],"3584":[[0,8580357142857],[0,8590000000000],[0,8616250000000],[0,16209000000000]],"7":[[0,112500000000],[0,112910000000],[0,112910000000],[0,113330000000]],"524288":[[0,1295042000000000],[0,1371917000000000]],"112":[[0,488330000000],[0,491250000000],[0,492090000000],[0,492500000000]],"896":[[0,2469580000000],[0,2472500000000],[0,2473330000000],[0,2489160000000]],"192":[[0,709170000000],[0,711250000000],[0,711670000000],[0,713750000000]],"80":[[0,416250000000],[0,419580000000],[0,420830000000],[0,421250000000]],"24":[[0,175000000000],[0,175410000000],[0,175410000000],[0,175830000000]],"40960":[[0,97042000000000],[0,97278000000000],[0,97666800000000],[0,100543478260869]],"16":[[0,166250000000],[0,166250000000],[0,166250000000],[0,166670000000]],"3072":[[0,7504170000000],[0,7513750000000],[0,7562920000000],[0,7607500000000]],"20":[[0,170410000000],[0,170830000000],[0,171250000000],[0,171670000000]],"224":[[0,848750000000],[0,849590000000],[0,853750000000],[0,855566666666]],"2560":[[0,6464000000000],[0,6474580000000],[0,6489590000000],[0,6523750000000]],"1792":[[0,4574580000000],[0,4593340000000],[0,4598330000000],[0,4598750000000]],"1024":[[0,2741600000000],[0,2753750000000],[0,2753750000000],[0,2755410000000]],"6144":[[0,15673750000000],[0,15681670000000],[0,15715000000000],[0,15718340000000]],"56":[[0,305830000000],[0,305840000000],[0,306250000000],[0,311670000000]],"786432":[[0,2010468750000000],[0,2022479250000000]],"163840":[[0,399541000000000],[0,403896000000000],[0,419581250000000]],"6":[[0,110830000000],[0,110830000000],[0,111250000000],[0,111250000000]],"48":[[0,290000000000],[0,290830000000],[0,292500000000],[0,295000000000]],"32":[[0,219160000000],[0,219580000000],[0,219580000000],[0,220410000000]],"14":[[0,142910000000],[0,142920000000],[0,142920000000],[0,143330000000]],"28672":[[0,68125000000000],[0,68296288888888],[0,68333000000000],[0,69486119047619]],"512":[[0,1535830000000],[0,1538750000000],[0,1538847457627],[0,1540420000000]],"196608":[[0,478108400000000],[0,522544250000000],[0,552636066666666]],"458752":[[0,1149979000000000],[0,1236583333333333]],"24576":[[0,60243330000000],[0,60375410000000],[0,60477500000000],[0,61215000000000]],"2":[[0,37080000000],[0,37080000000],[0,37080000000],[0,37080000000]],"256":[[0,914580000000],[0,917080000000],[0,919590000000],[0,924170000000]],"1536":[[0,4010830000000],[0,4014000000000],[0,4031670000000],[0,4042920000000]],"64":[[0,317910000000],[0,317920000000],[0,318330000000],[0,322500000000]],"320":[[0,1049160000000],[0,1055000000000],[0,1056250000000],[0,1057090000000]],"114688":[[0,274792000000000],[0,279542000000000],[0,288250000000000]],"131072":[[0,304250000000000],[0,314750000000000],[0,322764379310344]],"16384":[[0,39865000000000],[0,40189326086956],[0,40362080000000],[0,40568750000000]],"5120":[[0,13260000000000],[0,13275410000000],[0,13284170000000],[0,13585840000000]],"229376":[[0,569125000000000],[0,607524250000000],[0,646719727272727]],"5":[[0,87080000000],[0,87080000000],[0,87500000000],[0,87500000000]],"10":[[0,137500000000],[0,137910000000],[0,138330000000],[0,138330000000]],"28":[[0,215000000000],[0,215830000000],[0,216250000000],[0,216250000000]],"655360":[[0,1788593750000000],[0,1826218750000000]],"7168":[[0,19529580000000],[0,19562500000000],[0,19657920000000],[0,19782080000000]],"20480":[[0,51480830000000],[0,51559160000000],[0,51917000000000],[0,51923527472527]],"65536":[[0,157516129032258],[0,158541666666666],[0,158724049180327],[0,163078781818181]],"917504":[[0,2301972333333333],[0,2392264000000000]],"160":[[0,644590000000],[0,645000000000],[0,646670000000],[0,648330000000]],"640":[[0,1806660000000],[0,1807920000000],[0,1809170000000],[0,1810410000000]],"40":[[0,230830000000],[0,230840000000],[0,232080000000],[0,232080000000]],"393216":[[0,1035685111111111],[0,1058958500000000]],"57344":[[0,131445611111111],[0,131521123287671],[0,132466600000000],[0,132555666666666]],"4":[[0,85410000000],[0,85830000000],[0,85830000000],[0,85830000000]],"1":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17920000000]],"768":[[0,2200420000000],[0,2203340000000],[0,2207090000000],[0,2209160000000]],"448":[[0,1397920000000],[0,1400000000000],[0,1401660000000],[0,1403330000000]],"8192":[[0,21253330000000],[0,21619040816326],[0,21750000000000],[0,22635000000000]],"12":[[0,140000000000],[0,140410000000],[0,140410000000],[0,140830000000]],"10240":[[0,25333750000000],[0,25392910000000],[0,25838750000000],[0,25937220779220]],"14336":[[0,35604000000000],[0,35845420000000],[0,36331597222222],[0,36334000000000]],"32768":[[0,77026250000000],[0,77158330000000],[0,77955000000000],[0,78915038461538]],"128":[[0,578330000000],[0,578750000000],[0,579580000000],[0,582920000000]],"4096":[[0,10891250000000],[0,10952806122448],[0,10972090000000],[0,11166000000000]],"49152":[[0,115937500000000],[0,116104000000000],[0,117110445783132],[0,117976678571428]],"262144":[[0,641416000000000],[0,654406250000000]],"3":[[0,61250000000],[0,61250000000],[0,61250000000],[0,61660000000]],"98304":[[0,228708000000000],[0,232434702702702],[0,241375000000000]]}},{"title":"VecDeque push_back, reserving capacity","results":{"2048":[[0,1209000000000],[0,1209160000000],[0,1209580000000],[0,1210000000000]],"1048576":[[0,686458000000000],[0,1014708000000000]],"96":[[0,79170000000],[0,79580000000],[0,79580000000],[0,79580000000]],"327680":[[0,215047363636363],[0,266101142857142]],"384":[[0,247500000000],[0,247910000000],[0,247910000000],[0,247910000000]],"12288":[[0,7806491525423],[0,7820000000000],[0,7833000000000],[0,8250000000000]],"81920":[[0,50065878378378],[0,52238679012345],[0,53125000000000],[0,66958750000000]],"8":[[0,19230769230],[0,20000000000],[0,20000000000],[0,20000000000]],"1280":[[0,767920000000],[0,767920000000],[0,767920000000],[0,767920000000]],"3584":[[0,2092500000000],[0,2092920000000],[0,2092920000000],[0,2094590000000]],"7":[[0,19580000000],[0,19580000000],[0,19580000000],[0,19580000000]],"524288":[[0,397907227272727],[0,443570800000000]],"112":[[0,95000000000],[0,95410000000],[0,95410000000],[0,95410000000]],"896":[[0,547080000000],[0,547080000000],[0,547080000000],[0,547090000000]],"192":[[0,137090000000],[0,137500000000],[0,137500000000],[0,137500000000]],"80":[[0,69170000000],[0,69580000000],[0,69580000000],[0,70000000000]],"24":[[0,28330000000],[0,28750000000],[0,28750000000],[0,28750000000]],"40960":[[0,24458000000000],[0,24583000000000],[0,28246660000000],[0,28398035294117]],"16":[[0,24160000000],[0,24580000000],[0,24580000000],[0,24580000000]],"3072":[[0,1798330000000],[0,1798330000000],[0,1798330000000],[0,1798750000000]],"20":[[0,26250000000],[0,26660000000],[0,26660000000],[0,26660000000]],"224":[[0,155830000000],[0,155830000000],[0,155830000000],[0,155830000000]],"2560":[[0,1503750000000],[0,1504160000000],[0,1504170000000],[0,1504580000000]],"1792":[[0,1060923076923],[0,1061250000000],[0,1062500000000],[0,1062500000000]],"1024":[[0,620420000000],[0,620830000000],[0,620830000000],[0,620830000000]],"6144":[[0,4195000000000],[0,4202920000000],[0,4207500000000],[0,4215840000000]],"56":[[0,52000000000],[0,53750000000],[0,53750000000],[0,55410000000]],"786432":[[0,651366666666666],[0,773003500000000]],"163840":[[0,96667000000000],[0,100625000000000],[0,157922322033898]],"6":[[0,20830000000],[0,21000000000],[0,21250000000],[0,21250000000]],"48":[[0,50000000000],[0,50410000000],[0,50410000000],[0,50410000000]],"32":[[0,32910000000],[0,32910000000],[0,33330000000],[0,33330000000]],"14":[[0,23330000000],[0,23330000000],[0,23330000000],[0,23330000000]],"28672":[[0,17237080000000],[0,17320461538461],[0,17334000000000],[0,32104000000000]],"512":[[0,319580000000],[0,321250000000],[0,321660000000],[0,321660000000]],"196608":[[0,115792000000000],[0,138250000000000],[0,224393179487179]],"458752":[[0,334833000000000],[0,336075772727272]],"24576":[[0,14865410000000],[0,14889608247422],[0,17590420000000],[0,27592500000000]],"2":[[0,14580000000],[0,14580000000],[0,14590000000],[0,15410000000]],"256":[[0,174160000000],[0,174160000000],[0,174160000000],[0,174580000000]],"1536":[[0,915000000000],[0,915000000000],[0,915000000000],[0,915000000000]],"64":[[0,60000000000],[0,60000000000],[0,60000000000],[0,60000000000]],"320":[[0,210830000000],[0,210830000000],[0,211250000000],[0,211250000000]],"114688":[[0,77125000000000],[0,85167000000000],[0,100583500000000]],"131072":[[0,77958000000000],[0,110542000000000],[0,140000000000000]],"16384":[[0,10209000000000],[0,10334000000000],[0,17666000000000],[0,18482920000000]],"5120":[[0,3587080000000],[0,3588330000000],[0,3595830000000],[0,3609574074074]],"229376":[[0,153934782608695],[0,181105200000000],[0,260158088235294]],"5":[[0,20420000000],[0,20420000000],[0,20830000000],[0,20830000000]],"10":[[0,20857142857],[0,21250000000],[0,21250000000],[0,21250000000]],"28":[[0,30410000000],[0,30420000000],[0,30830000000],[0,30830000000]],"655360":[[0,459229250000000],[0,608879666666666]],"7168":[[0,4793842105263],[0,4801250000000],[0,4809580000000],[0,4906882352941]],"20480":[[0,12541000000000],[0,12558400000000],[0,12583000000000],[0,23017080000000]],"65536":[[0,39000000000000],[0,42042000000000],[0,52292000000000],[0,56061827956989]],"917504":[[0,561042000000000],[0,740625000000000]],"160":[[0,118750000000],[0,118750000000],[0,119160000000],[0,119160000000]],"640":[[0,399580000000],[0,399636363636],[0,400000000000],[0,400000000000]],"40":[[0,41666666666],[0,45000000000],[0,45410000000],[0,45830000000]],"393216":[[0,230791000000000],[0,343750000000000]],"57344":[[0,34166000000000],[0,34167000000000],[0,34167000000000],[0,34417000000000]],"4":[[0,19580000000],[0,19580000000],[0,19580000000],[0,19580000000]],"1":[[0,13750000000],[0,13750000000],[0,13750000000],[0,14160000000]],"768":[[0,472333333333],[0,473340000000],[0,473750000000],[0,473750000000]],"448":[[0,282500000000],[0,284580000000],[0,284580000000],[0,284580000000]],"8192":[[0,5444160000000],[0,5447920000000],[0,5819170000000],[0,6042000000000]],"12":[[0,22080000000],[0,22080000000],[0,22090000000],[0,22500000000]],"10240":[[0,6750000000000],[0,9470830000000],[0,9505840000000],[0,9537080000000]],"14336":[[0,9041000000000],[0,9166000000000],[0,15816670000000],[0,15914580000000]],"32768":[[0,19708000000000],[0,19833000000000],[0,19875000000000],[0,20042000000000]],"128":[[0,105000000000],[0,105000000000],[0,105000000000],[0,105000000000]],"4096":[[0,2387080000000],[0,2387090000000],[0,2387500000000],[0,2387500000000]],"49152":[[0,29333000000000],[0,34694170000000],[0,35567090000000],[0,56278330000000]],"262144":[[0,166333000000000],[0,191375000000000]],"3":[[0,18330000000],[0,18340000000],[0,18750000000],[0,19160000000]],"98304":[[0,58250000000000],[0,58708000000000],[0,63312500000000]]}},{"title":"RigidDeque append, reserving capacity","results":{"2048":[[0,176670000000],[0,177500000000],[0,177920000000],[0,191660000000]],"1048576":[[0,152167000000000],[0,164583327586206]],"96":[[0,32920000000],[0,32920000000],[0,32920000000],[0,33330000000]],"327680":[[0,48008200000000],[0,49210051546391]],"384":[[0,49160000000],[0,49160000000],[0,49160000000],[0,49170000000]],"12288":[[0,1630000000000],[0,1665420000000],[0,1668750000000],[0,1706250000000]],"81920":[[0,12447010869565],[0,12458330000000],[0,12459000000000],[0,12515682352941]],"8":[[0,17500000000],[0,17910000000],[0,17910000000],[0,17910000000]],"1280":[[0,132500000000],[0,132500000000],[0,133750000000],[0,161250000000]],"3584":[[0,281670000000],[0,297080000000],[0,311660000000],[0,372920000000]],"7":[[0,17500000000],[0,17500000000],[0,17500000000],[0,17500000000]],"524288":[[0,76125000000000],[0,83234000000000]],"112":[[0,34580000000],[0,34580000000],[0,34580000000],[0,34580000000]],"896":[[0,100000000000],[0,101250000000],[0,101250000000],[0,101660000000]],"192":[[0,35830000000],[0,35840000000],[0,36250000000],[0,36660000000]],"80":[[0,31250000000],[0,31250000000],[0,31250000000],[0,31660000000]],"24":[[0,18750000000],[0,18750000000],[0,18750000000],[0,18750000000]],"40960":[[0,5837080000000],[0,6540000000000],[0,6562500000000],[0,6566660000000]],"16":[[0,17920000000],[0,18330000000],[0,18330000000],[0,18330000000]],"3072":[[0,246670000000],[0,247080000000],[0,281660000000],[0,282080000000]],"20":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17910000000]],"224":[[0,37910000000],[0,37910000000],[0,37920000000],[0,38330000000]],"2560":[[0,275000000000],[0,285000000000],[0,296660000000],[0,368910112359]],"1792":[[0,157500000000],[0,160000000000],[0,174580000000],[0,219580000000]],"1024":[[0,109580000000],[0,111250000000],[0,111660000000],[0,117500000000]],"6144":[[0,1461250000000],[0,1466250000000],[0,1491250000000],[0,1559580000000]],"56":[[0,26670000000],[0,29160000000],[0,29160000000],[0,29170000000]],"786432":[[0,115041000000000],[0,115208000000000]],"163840":[[0,24375000000000],[0,24698330000000],[0,25112090000000]],"6":[[0,17080000000],[0,17080000000],[0,17080000000],[0,17080000000]],"48":[[0,27910000000],[0,29160000000],[0,29160000000],[0,29580000000]],"32":[[0,19580000000],[0,19580000000],[0,19580000000],[0,19580000000]],"14":[[0,17500000000],[0,17910000000],[0,18330000000],[0,18330000000]],"28672":[[0,4693750000000],[0,4775420000000],[0,4797500000000],[0,4798340000000]],"512":[[0,56250000000],[0,57090000000],[0,57910000000],[0,57910000000]],"196608":[[0,29092080000000],[0,29416000000000],[0,29542000000000]],"458752":[[0,67133333333333],[0,70065420000000]],"24576":[[0,3996250000000],[0,4186670000000],[0,4200840000000],[0,4239590000000]],"2":[[0,14580000000],[0,14580000000],[0,14580000000],[0,14580000000]],"256":[[0,40000000000],[0,40410000000],[0,40410000000],[0,40410000000]],"1536":[[0,142080000000],[0,154170000000],[0,154170000000],[0,175830000000]],"64":[[0,29590000000],[0,29590000000],[0,30000000000],[0,30000000000]],"320":[[0,42910000000],[0,44580000000],[0,44580000000],[0,44580000000]],"114688":[[0,17105000000000],[0,17169590000000],[0,17222500000000]],"131072":[[0,19495830000000],[0,19535840000000],[0,19708000000000]],"16384":[[0,2574160000000],[0,2595420000000],[0,2621660000000],[0,2624590000000]],"5120":[[0,1230000000000],[0,1295830000000],[0,1335000000000],[0,1356306122448]],"229376":[[0,33615000000000],[0,33708333333333],[0,33852500000000]],"5":[[0,16660000000],[0,17080000000],[0,17080000000],[0,17080000000]],"10":[[0,16250000000],[0,16250000000],[0,16660000000],[0,16660000000]],"28":[[0,18330000000],[0,18340000000],[0,18750000000],[0,18750000000]],"655360":[[0,84684083333333],[0,96834000000000]],"7168":[[0,1549160000000],[0,1623750000000],[0,1625000000000],[0,1635000000000]],"20480":[[0,3427910000000],[0,3575000000000],[0,3583000000000],[0,3624590000000]],"65536":[[0,10080000000000],[0,10082500000000],[0,10101470588235],[0,10162162162162]],"917504":[[0,135631849315068],[0,141287184615384]],"160":[[0,33750000000],[0,33750000000],[0,33750000000],[0,33750000000]],"640":[[0,73750000000],[0,73750000000],[0,73750000000],[0,74160000000]],"40":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27500000000]],"393216":[[0,58875000000000],[0,61566372881355]],"57344":[[0,6387090000000],[0,8657500000000],[0,8944500000000],[0,8985420000000]],"4":[[0,18330000000],[0,18330000000],[0,18340000000],[0,19170000000]],"1":[[0,14344827586],[0,14580000000],[0,14580000000],[0,14580000000]],"768":[[0,85000000000],[0,85000000000],[0,85000000000],[0,86660000000]],"448":[[0,53330000000],[0,53330000000],[0,53330000000],[0,53750000000]],"8192":[[0,1608750000000],[0,1639590000000],[0,1660410000000],[0,1667080000000]],"12":[[0,16670000000],[0,17080000000],[0,17080000000],[0,17080000000]],"10240":[[0,1526250000000],[0,1558750000000],[0,1562080000000],[0,1615420000000]],"14336":[[0,1822920000000],[0,1830830000000],[0,1849590000000],[0,1857558139534]],"32768":[[0,5319580000000],[0,5346250000000],[0,5389580000000],[0,5428340000000]],"128":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"4096":[[0,352080000000],[0,468750000000],[0,517080000000],[0,545000000000]],"49152":[[0,7626670000000],[0,7735830000000],[0,7743330000000],[0,7802920000000]],"262144":[[0,38750000000000],[0,39083000000000]],"3":[[0,17920000000],[0,17920000000],[0,17920000000],[0,18330000000]],"98304":[[0,14788750000000],[0,14917000000000],[0,15013750000000]]}},{"title":"UniqueDeque append, reserving capacity","results":{"2048":[[0,4273437500000],[0,4284580000000],[0,4285000000000],[0,4287698412698]],"1048576":[[0,2346542000000000],[0,2499111333333333]],"96":[[0,209000000000],[0,218750000000],[0,218750000000],[0,218750000000]],"327680":[[0,728291692307692],[0,749542000000000]],"384":[[0,809129032258],[0,810750000000],[0,812500000000],[0,812910000000]],"12288":[[0,26356000000000],[0,26755830000000],[0,26867500000000],[0,26883750000000]],"81920":[[0,174542000000000],[0,177342418181818],[0,177531250000000],[0,178946963636363]],"8":[[0,25830000000],[0,25840000000],[0,26250000000],[0,26250000000]],"1280":[[0,2684590000000],[0,2685410000000],[0,2685420000000],[0,2685420000000]],"3584":[[0,7458000000000],[0,7483340000000],[0,7485000000000],[0,7600000000000]],"7":[[0,24580000000],[0,24580000000],[0,24580000000],[0,24580000000]],"524288":[[0,1187208000000000],[0,1229750000000000]],"112":[[0,252080000000],[0,252080000000],[0,252500000000],[0,252500000000]],"896":[[0,1883330000000],[0,1883750000000],[0,1884160000000],[0,1885000000000]],"192":[[0,413330000000],[0,413750000000],[0,413750000000],[0,414580000000]],"80":[[0,184580000000],[0,184590000000],[0,185000000000],[0,185000000000]],"24":[[0,52500000000],[0,52500000000],[0,52500000000],[0,52500000000]],"40960":[[0,86871769230769],[0,87862153846153],[0,88156250000000],[0,88583300000000]],"16":[[0,36670000000],[0,37080000000],[0,37080000000],[0,37080000000]],"3072":[[0,6419160000000],[0,6420850000000],[0,6421670000000],[0,6422920000000]],"20":[[0,42000000000],[0,44160000000],[0,44170000000],[0,44580000000]],"224":[[0,479580000000],[0,480000000000],[0,480000000000],[0,480410000000]],"2560":[[0,5348083333333],[0,5349170000000],[0,5352910000000],[0,5367080000000]],"1792":[[0,3747080000000],[0,3747722222222],[0,3750000000000],[0,3751250000000]],"1024":[[0,2150420000000],[0,2150830000000],[0,2150830000000],[0,2153330000000]],"6144":[[0,13462821428571],[0,13484160000000],[0,13509590000000],[0,13511670000000]],"56":[[0,132910000000],[0,133350000000],[0,134160000000],[0,134580000000]],"786432":[[0,1757292000000000],[0,1767433400000000]],"163840":[[0,366667000000000],[0,370011230769230],[0,379897727272727]],"6":[[0,22920000000],[0,23330000000],[0,23330000000],[0,23330000000]],"48":[[0,117090000000],[0,117910000000],[0,117920000000],[0,118330000000]],"32":[[0,75410000000],[0,75830000000],[0,75830000000],[0,75830000000]],"14":[[0,33750000000],[0,33750000000],[0,34580000000],[0,34580000000]],"28672":[[0,60959650793650],[0,61842090000000],[0,63334000000000],[0,63833000000000]],"512":[[0,1078330000000],[0,1078340000000],[0,1078750000000],[0,1079170000000]],"196608":[[0,408958000000000],[0,435098500000000],[0,490729166666666]],"458752":[[0,1028000000000000],[0,1037250000000000]],"24576":[[0,52175840000000],[0,52447500000000],[0,52560602272727],[0,52774160000000]],"2":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"256":[[0,542000000000],[0,546250000000],[0,546250000000],[0,547080000000]],"1536":[[0,3217500000000],[0,3218330000000],[0,3218330000000],[0,3218750000000]],"64":[[0,151250000000],[0,151250000000],[0,151250000000],[0,151250000000]],"320":[[0,667000000000],[0,677500000000],[0,679580000000],[0,680555555555]],"114688":[[0,248486842105263],[0,249178710526315],[0,251736000000000]],"131072":[[0,283160333333333],[0,284270823529411],[0,295375000000000]],"16384":[[0,35194170000000],[0,35270840000000],[0,35346660000000],[0,35393750000000]],"5120":[[0,11285000000000],[0,11290830000000],[0,11301670000000],[0,11339590000000]],"229376":[[0,506792000000000],[0,507917000000000],[0,518416000000000]],"5":[[0,21660000000],[0,21670000000],[0,21670000000],[0,22080000000]],"10":[[0,28330000000],[0,28750000000],[0,28750000000],[0,28750000000]],"28":[[0,67080000000],[0,67080000000],[0,67080000000],[0,67080000000]],"655360":[[0,1462000000000000],[0,1527917000000000]],"7168":[[0,15888157894736],[0,15899470588235],[0,15997200000000],[0,16069500000000]],"20480":[[0,43784090909090],[0,44069170000000],[0,44165000000000],[0,44434523809523]],"65536":[[0,140876253731343],[0,142051923076923],[0,142919117647058],[0,143735911764705]],"917504":[[0,2053010250000000],[0,2103968750000000]],"160":[[0,347080000000],[0,347080000000],[0,347500000000],[0,347500000000]],"640":[[0,1351250000000],[0,1351660000000],[0,1351670000000],[0,1351670000000]],"40":[[0,101250000000],[0,101250000000],[0,101250000000],[0,106660000000]],"393216":[[0,872917000000000],[0,921000000000000]],"57344":[[0,120020750000000],[0,122518513888888],[0,122921405063291],[0,124202464788732]],"4":[[0,21250000000],[0,21250000000],[0,21670000000],[0,22500000000]],"1":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"768":[[0,1617500000000],[0,1617910000000],[0,1618750000000],[0,1618750000000]],"448":[[0,947500000000],[0,948750000000],[0,949170000000],[0,990420000000]],"8192":[[0,18029094339622],[0,18037080000000],[0,18079170000000],[0,18625000000000]],"12":[[0,31250000000],[0,31250000000],[0,31660000000],[0,31660000000]],"10240":[[0,22359590000000],[0,22741660000000],[0,22785830000000],[0,23016250000000]],"14336":[[0,30773750000000],[0,30780736842105],[0,30801136363636],[0,31220420000000]],"32768":[[0,69288634146341],[0,70005952380952],[0,70820184210526],[0,71657500000000]],"128":[[0,285830000000],[0,285830000000],[0,285840000000],[0,286250000000]],"4096":[[0,8542000000000],[0,8551670000000],[0,8553750000000],[0,8631250000000]],"49152":[[0,104500000000000],[0,104541500000000],[0,105658890109890],[0,109042000000000]],"262144":[[0,581917000000000],[0,602667000000000]],"3":[[0,20410000000],[0,20410000000],[0,20420000000],[0,20830000000]],"98304":[[0,209041000000000],[0,210171195652173],[0,213804622222222]]}},{"title":"std::deque push_front","results":{"2048":[[0,7060420000000],[0,7062080000000],[0,7069580000000],[0,7070830000000]],"1048576":[[0,3789541500000000],[0,4043167000000000]],"96":[[0,332910000000],[0,333330000000],[0,333750000000],[0,337920000000]],"327680":[[0,1164333375000000],[0,1211145875000000]],"384":[[0,1333000000000],[0,1343750000000],[0,1345410000000],[0,1347920000000]],"12288":[[0,43138330000000],[0,43182500000000],[0,43690420000000],[0,43932910000000]],"81920":[[0,288542000000000],[0,290354000000000],[0,293792000000000],[0,295251272727272]],"8":[[0,42500000000],[0,42910000000],[0,42910000000],[0,46250000000]],"1280":[[0,4395840000000],[0,4397541666666],[0,4399160000000],[0,4399580000000]],"3584":[[0,12367500000000],[0,12397920000000],[0,12458000000000],[0,12550420000000]],"7":[[0,41250000000],[0,41660000000],[0,41670000000],[0,42920000000]],"524288":[[0,1938250000000000],[0,1964906250000000]],"112":[[0,386250000000],[0,386660000000],[0,387080000000],[0,391250000000]],"896":[[0,3110830000000],[0,3111250000000],[0,3114500000000],[0,3123750000000]],"192":[[0,652500000000],[0,652920000000],[0,653273809523],[0,657920000000]],"80":[[0,279580000000],[0,280000000000],[0,280000000000],[0,285000000000]],"24":[[0,94170000000],[0,94580000000],[0,95000000000],[0,98750000000]],"40960":[[0,143354250000000],[0,143566600000000],[0,143800373134328],[0,146611116666666]],"16":[[0,67910000000],[0,67920000000],[0,68330000000],[0,72500000000]],"3072":[[0,10595830000000],[0,10619318181818],[0,10623750000000],[0,10689590000000]],"20":[[0,81250000000],[0,81250000000],[0,81250000000],[0,86250000000]],"224":[[0,757920000000],[0,758750000000],[0,759170000000],[0,764170000000]],"2560":[[0,8849190476190],[0,8860000000000],[0,8860420000000],[0,8862500000000]],"1792":[[0,6125000000000],[0,6147080000000],[0,6148330000000],[0,6148340000000]],"1024":[[0,3541660000000],[0,3542080000000],[0,3542080000000],[0,3553750000000]],"6144":[[0,21176437500000],[0,21208000000000],[0,21217500000000],[0,21239417910447]],"56":[[0,200420000000],[0,200830000000],[0,201250000000],[0,205000000000]],"786432":[[0,2832555666666666],[0,2868097000000000]],"163840":[[0,586833000000000],[0,603316666666666],[0,612030533333333]],"6":[[0,40420000000],[0,40420000000],[0,40830000000],[0,41670000000]],"48":[[0,173330000000],[0,173750000000],[0,174160000000],[0,178750000000]],"32":[[0,120410000000],[0,120830000000],[0,121250000000],[0,125420000000]],"14":[[0,60830000000],[0,61250000000],[0,61250000000],[0,65830000000]],"28672":[[0,98959000000000],[0,99000000000000],[0,101453125000000],[0,101596010869565]],"512":[[0,1767500000000],[0,1767910000000],[0,1767920000000],[0,1771670000000]],"196608":[[0,698958000000000],[0,711557692307692],[0,768121583333333]],"458752":[[0,1639958000000000],[0,1698233400000000]],"24576":[[0,85267080000000],[0,85517500000000],[0,85687080000000],[0,85734375000000]],"2":[[0,35840000000],[0,36250000000],[0,36250000000],[0,37344827586]],"256":[[0,865420000000],[0,865830000000],[0,866660000000],[0,870689655172]],"1536":[[0,5250000000000],[0,5273330000000],[0,5281250000000],[0,5289160000000]],"64":[[0,226670000000],[0,226670000000],[0,227080000000],[0,232080000000]],"320":[[0,1130420000000],[0,1130830000000],[0,1130840000000],[0,1130857142857]],"114688":[[0,405125000000000],[0,406833000000000],[0,417292000000000]],"131072":[[0,470390368421052],[0,470454380952380],[0,472375000000000]],"16384":[[0,57028750000000],[0,57884847222222],[0,57959000000000],[0,58342090000000]],"5120":[[0,17676587301587],[0,17689170000000],[0,17689580000000],[0,17770830000000]],"229376":[[0,830417000000000],[0,831996181818181],[0,864972222222222]],"5":[[0,39160000000],[0,39580000000],[0,39580000000],[0,40830000000]],"10":[[0,47910000000],[0,47920000000],[0,48330000000],[0,52910000000]],"28":[[0,107090000000],[0,107910000000],[0,107910000000],[0,112080000000]],"655360":[[0,2411187500000000],[0,2414739750000000]],"7168":[[0,24785000000000],[0,24833000000000],[0,24867614583333],[0,24946808510638]],"20480":[[0,70916000000000],[0,71050420000000],[0,71135425000000],[0,71432500000000]],"65536":[[0,230270750000000],[0,230875000000000],[0,231887500000000],[0,233404761904761]],"917504":[[0,3280791500000000],[0,3352875000000000]],"160":[[0,541500000000],[0,545840000000],[0,546250000000],[0,550830000000]],"640":[[0,2194170000000],[0,2194580000000],[0,2195000000000],[0,2199160000000]],"40":[[0,146000000000],[0,147500000000],[0,147500000000],[0,152090000000]],"393216":[[0,1425729166666666],[0,1488270833333333]],"57344":[[0,202167000000000],[0,202375000000000],[0,202652666666666],[0,203219444444444]],"4":[[0,38750000000],[0,38750000000],[0,39160000000],[0,40000000000]],"1":[[0,33750000000],[0,34160000000],[0,34160000000],[0,35420000000]],"768":[[0,2618330000000],[0,2619318181818],[0,2621660000000],[0,2622920000000]],"448":[[0,1554580000000],[0,1554580000000],[0,1560410000000],[0,1645000000000]],"8192":[[0,28310420000000],[0,28333000000000],[0,28543842105263],[0,28599630434782]],"12":[[0,54160000000],[0,54580000000],[0,54580000000],[0,59160000000]],"10240":[[0,35312500000000],[0,35458000000000],[0,36125000000000],[0,36189590000000]],"14336":[[0,49583500000000],[0,49868340000000],[0,50433330000000],[0,50708330000000]],"32768":[[0,113375000000000],[0,113416000000000],[0,114604000000000],[0,115510500000000]],"128":[[0,439170000000],[0,439170000000],[0,440000000000],[0,444580000000]],"4096":[[0,14111670000000],[0,14123750000000],[0,14142080000000],[0,14194160000000]],"49152":[[0,172543140350877],[0,174000000000000],[0,174125000000000],[0,174292000000000]],"262144":[[0,945120800000000],[0,957262500000000]],"3":[[0,37500000000],[0,37500000000],[0,37500000000],[0,38750000000]],"98304":[[0,348431571428571],[0,350441964285714],[0,350597333333333]]}},{"title":"VecDeque push_front","results":{"2048":[[0,5350000000000],[0,5375000000000],[0,5382080000000],[0,5407500000000]],"1048576":[[0,3438916000000000],[0,3591000000000000]],"96":[[0,374160000000],[0,374170000000],[0,375000000000],[0,377910000000]],"327680":[[0,856709000000000],[0,870428000000000]],"384":[[0,1155000000000],[0,1155000000000],[0,1157080000000],[0,1161660000000]],"12288":[[0,31770833333333],[0,31842920000000],[0,32140420000000],[0,32271000000000]],"81920":[[0,202791000000000],[0,203250000000000],[0,203875000000000],[0,205917000000000]],"8":[[0,50410000000],[0,50410000000],[0,50830000000],[0,58750000000]],"1280":[[0,3583330000000],[0,3621250000000],[0,3626250000000],[0,3627080000000]],"3584":[[0,9215410000000],[0,9260420000000],[0,9277080000000],[0,9375000000000]],"7":[[0,50410000000],[0,50420000000],[0,50420000000],[0,50830000000]],"524288":[[0,1337250000000000],[0,1354250000000000]],"112":[[0,411250000000],[0,411670000000],[0,412090000000],[0,415830000000]],"896":[[0,2466670000000],[0,2467080000000],[0,2470000000000],[0,2471250000000]],"192":[[0,623330000000],[0,626670000000],[0,627080000000],[0,627500000000]],"80":[[0,336670000000],[0,337500000000],[0,337500000000],[0,339580000000]],"24":[[0,147500000000],[0,147910000000],[0,148330000000],[0,148330000000]],"40960":[[0,101458000000000],[0,101708000000000],[0,102917000000000],[0,103750000000000]],"16":[[0,100000000000],[0,100410000000],[0,100410000000],[0,100420000000]],"3072":[[0,8000000000000],[0,8017333333333],[0,8050830000000],[0,8076670000000]],"20":[[0,135420000000],[0,135830000000],[0,136670000000],[0,137080000000]],"224":[[0,696670000000],[0,699580000000],[0,700000000000],[0,703750000000]],"2560":[[0,6828750000000],[0,6845000000000],[0,6845500000000],[0,6853330000000]],"1792":[[0,4746670000000],[0,4750830000000],[0,4767080000000],[0,4800420000000]],"1024":[[0,2768750000000],[0,2768750000000],[0,2771660000000],[0,2775420000000]],"6144":[[0,16990420000000],[0,17003676470588],[0,17012500000000],[0,17056660000000]],"56":[[0,236250000000],[0,237080000000],[0,237500000000],[0,237910000000]],"786432":[[0,2529416666666666],[0,2529541000000000]],"163840":[[0,404625000000000],[0,419141304347826],[0,428875000000000]],"6":[[0,50000000000],[0,50410000000],[0,50420000000],[0,50830000000]],"48":[[0,217910000000],[0,217920000000],[0,218330000000],[0,218750000000]],"32":[[0,149160000000],[0,149580000000],[0,150000000000],[0,150000000000]],"14":[[0,98750000000],[0,98750000000],[0,98750000000],[0,100000000000]],"28672":[[0,71583000000000],[0,71587090000000],[0,72019057142857],[0,72445000000000]],"512":[[0,1450000000000],[0,1458750000000],[0,1460000000000],[0,1460420000000]],"196608":[[0,482837500000000],[0,487500000000000],[0,529645833333333]],"458752":[[0,1161739625000000],[0,1175458250000000]],"24576":[[0,62135000000000],[0,62270000000000],[0,62338900000000],[0,63035420000000]],"2":[[0,20000000000],[0,20000000000],[0,20000000000],[0,20410000000]],"256":[[0,774590000000],[0,775000000000],[0,776250000000],[0,779170000000]],"1536":[[0,4158203125000],[0,4212500000000],[0,4219160000000],[0,4229000000000]],"64":[[0,255000000000],[0,255410000000],[0,255830000000],[0,256670000000]],"320":[[0,1005000000000],[0,1007080000000],[0,1007500000000],[0,1011670000000]],"114688":[[0,281250000000000],[0,281292000000000],[0,282794212121212]],"131072":[[0,320236548387096],[0,330916000000000],[0,333280172413793]],"16384":[[0,41334000000000],[0,41553330000000],[0,41625000000000],[0,42114170000000]],"5120":[[0,14486250000000],[0,14495420000000],[0,14514580000000],[0,14723330000000]],"229376":[[0,561500000000000],[0,564250000000000],[0,569042000000000]],"5":[[0,51250000000],[0,52090000000],[0,52920000000],[0,54590000000]],"10":[[0,96670000000],[0,96670000000],[0,97080000000],[0,97080000000]],"28":[[0,142080000000],[0,142500000000],[0,142500000000],[0,142500000000]],"655360":[[0,2204177000000000],[0,2224468750000000]],"7168":[[0,19259170000000],[0,19309160000000],[0,19317090000000],[0,19408400000000]],"20480":[[0,52286250000000],[0,52292000000000],[0,52375000000000],[0,54240000000000]],"65536":[[0,159375000000000],[0,159750000000000],[0,161556704918032],[0,164316600000000]],"917504":[[0,2946916000000000],[0,3102709000000000]],"160":[[0,549170000000],[0,551660000000],[0,551670000000],[0,554580000000]],"640":[[0,1870000000000],[0,1870420000000],[0,1873330000000],[0,1875000000000]],"40":[[0,202500000000],[0,202920000000],[0,203330000000],[0,203750000000]],"393216":[[0,1007125000000000],[0,1027209000000000]],"57344":[[0,140250000000000],[0,140625000000000],[0,140916000000000],[0,141517257142857]],"4":[[0,20420000000],[0,20830000000],[0,20840000000],[0,21250000000]],"1":[[0,19160000000],[0,19170000000],[0,19580000000],[0,19580000000]],"768":[[0,2165000000000],[0,2172920000000],[0,2174580000000],[0,2175420000000]],"448":[[0,1300830000000],[0,1301250000000],[0,1305548387096],[0,1333000000000]],"8192":[[0,21889580000000],[0,21920000000000],[0,21988330000000],[0,23032910000000]],"12":[[0,97500000000],[0,97500000000],[0,97500000000],[0,97500000000]],"10240":[[0,26989724637681],[0,27007920000000],[0,27424580000000],[0,27655420000000]],"14336":[[0,36549295774647],[0,36625000000000],[0,36635830000000],[0,37254580000000]],"32768":[[0,80984818181818],[0,81278409090909],[0,81292000000000],[0,81306250000000]],"128":[[0,449170000000],[0,449170000000],[0,451250000000],[0,453750000000]],"4096":[[0,10407500000000],[0,10444500000000],[0,10450420000000],[0,10500410000000]],"49152":[[0,120833000000000],[0,121041000000000],[0,122750000000000],[0,127963740259740]],"262144":[[0,641625000000000],[0,654333000000000]],"3":[[0,20410000000],[0,20410000000],[0,20410000000],[0,21250000000]],"98304":[[0,241916500000000],[0,242167000000000],[0,243270825000000]]}},{"title":"UniqueDeque prepend","results":{"2048":[[0,4601250000000],[0,4602920000000],[0,4610420000000],[0,4612910000000]],"1048576":[[0,2568222333333333],[0,2648834000000000]],"96":[[0,445000000000],[0,450840000000],[0,454580000000],[0,458000000000]],"327680":[[0,772805583333333],[0,817459000000000]],"384":[[0,1101670000000],[0,1108340000000],[0,1112500000000],[0,1112910000000]],"12288":[[0,29539405405405],[0,29540840000000],[0,29583000000000],[0,29692500000000]],"81920":[[0,182167000000000],[0,182292000000000],[0,183097750000000],[0,190387254901960]],"8":[[0,120420000000],[0,120420000000],[0,120420000000],[0,120420000000]],"1280":[[0,3123340000000],[0,3127920000000],[0,3148330000000],[0,3174580000000]],"3584":[[0,7800420000000],[0,7818330000000],[0,7848843137254],[0,7875000000000]],"7":[[0,118750000000],[0,118750000000],[0,118750000000],[0,118750000000]],"524288":[[0,1195750000000000],[0,1244922714285714]],"112":[[0,482080000000],[0,482500000000],[0,484580000000],[0,489170000000]],"896":[[0,2231670000000],[0,2235830000000],[0,2237500000000],[0,2237920000000]],"192":[[0,684580000000],[0,685000000000],[0,685830000000],[0,686660000000]],"80":[[0,419590000000],[0,426250000000],[0,426660000000],[0,444580000000]],"24":[[0,194580000000],[0,195000000000],[0,195410000000],[0,195420000000]],"40960":[[0,92334000000000],[0,92964285714285],[0,93073684210526],[0,96135000000000]],"16":[[0,185410000000],[0,185830000000],[0,186250000000],[0,186660000000]],"3072":[[0,6792080000000],[0,6798611111111],[0,6821670000000],[0,6821670000000]],"20":[[0,189580000000],[0,190410000000],[0,190420000000],[0,191250000000]],"224":[[0,803330000000],[0,811250000000],[0,813330000000],[0,813750000000]],"2560":[[0,5831250000000],[0,5842080000000],[0,5844590000000],[0,5855830000000]],"1792":[[0,4083000000000],[0,4113330000000],[0,4122500000000],[0,4142090000000]],"1024":[[0,2480000000000],[0,2480420000000],[0,2484170000000],[0,2485000000000]],"6144":[[0,14041670000000],[0,14063750000000],[0,14065830000000],[0,14123750000000]],"56":[[0,317910000000],[0,318330000000],[0,318340000000],[0,323340000000]],"786432":[[0,1805042000000000],[0,1818111000000000]],"163840":[[0,371437500000000],[0,372333000000000],[0,377485000000000]],"6":[[0,116250000000],[0,116250000000],[0,117080000000],[0,117080000000]],"48":[[0,302500000000],[0,302910000000],[0,307500000000],[0,307500000000]],"32":[[0,237500000000],[0,238750000000],[0,240420000000],[0,240830000000]],"14":[[0,158330000000],[0,158330000000],[0,158340000000],[0,158750000000]],"28672":[[0,64382910000000],[0,64947080000000],[0,65543750000000],[0,65665830000000]],"512":[[0,1413320000000],[0,1414580000000],[0,1416250000000],[0,1419590000000]],"196608":[[0,456351190476190],[0,471943750000000],[0,478908300000000]],"458752":[[0,1043417000000000],[0,1070680555555555]],"24576":[[0,55951923076923],[0,56412090000000],[0,56968750000000],[0,57085830000000]],"2":[[0,37500000000],[0,37500000000],[0,37500000000],[0,37910000000]],"256":[[0,862500000000],[0,870000000000],[0,870000000000],[0,870420000000]],"1536":[[0,3605000000000],[0,3607920000000],[0,3608750000000],[0,3645500000000]],"64":[[0,328340000000],[0,328750000000],[0,329580000000],[0,334580000000]],"320":[[0,977500000000],[0,986670000000],[0,987920000000],[0,992080000000]],"114688":[[0,259687500000000],[0,263802250000000],[0,265757352941176]],"131072":[[0,289958000000000],[0,292813121212121],[0,306387931034482]],"16384":[[0,37385587301587],[0,37435830000000],[0,37681451612903],[0,38054170000000]],"5120":[[0,11992920000000],[0,12002500000000],[0,12040000000000],[0,12058330000000]],"229376":[[0,514042000000000],[0,519750000000000],[0,543333000000000]],"5":[[0,89580000000],[0,89580000000],[0,90000000000],[0,90420000000]],"10":[[0,150830000000],[0,150840000000],[0,151224719101],[0,151670000000]],"28":[[0,235410000000],[0,235830000000],[0,236250000000],[0,236660000000]],"655360":[[0,1589591600000000],[0,1604708000000000]],"7168":[[0,17750000000000],[0,17856924528301],[0,17927920000000],[0,18270000000000]],"20480":[[0,48132000000000],[0,48312500000000],[0,48724170000000],[0,49020840000000]],"65536":[[0,149667287878787],[0,150623645161290],[0,150883620689655],[0,151524460317460]],"917504":[[0,2078722333333333],[0,2108667000000000]],"160":[[0,620410000000],[0,625000000000],[0,627080000000],[0,627500000000]],"640":[[0,1652920000000],[0,1657920000000],[0,1658340000000],[0,1658750000000]],"40":[[0,248330000000],[0,248750000000],[0,250000000000],[0,252080000000]],"393216":[[0,959958000000000],[0,967893555555555]],"57344":[[0,125000000000000],[0,125264453333333],[0,125709000000000],[0,126125000000000]],"4":[[0,87920000000],[0,88330000000],[0,88340000000],[0,88750000000]],"1":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17920000000]],"768":[[0,1986250000000],[0,1994170000000],[0,1996250000000],[0,1999170000000]],"448":[[0,1286250000000],[0,1295000000000],[0,1295000000000],[0,1295830000000]],"8192":[[0,19792000000000],[0,19834000000000],[0,19851250000000],[0,20724170000000]],"12":[[0,155428571428],[0,155830000000],[0,156250000000],[0,156250000000]],"10240":[[0,23601660000000],[0,23645500000000],[0,23664062500000],[0,24021250000000]],"14336":[[0,33444590000000],[0,33590000000000],[0,33662080000000],[0,33818330000000]],"32768":[[0,72268027027027],[0,72442500000000],[0,72723750000000],[0,73514590000000]],"128":[[0,567920000000],[0,568750000000],[0,568750000000],[0,570000000000]],"4096":[[0,9916660000000],[0,9932080000000],[0,9934170000000],[0,10057080000000]],"49152":[[0,109417000000000],[0,110187988372093],[0,110574077777777],[0,111878230769230]],"262144":[[0,584062500000000],[0,608646000000000]],"3":[[0,63750000000],[0,63750000000],[0,63750000000],[0,64160000000]],"98304":[[0,215416000000000],[0,216791000000000],[0,218924595238095]]}},{"title":"VecDeque push_front, reserving capacity","results":{"2048":[[0,4757584415584],[0,4759170000000],[0,4760000000000],[0,4762090000000]],"1048576":[[0,2522333333333333],[0,2673542000000000]],"96":[[0,231660000000],[0,231660000000],[0,231660000000],[0,232500000000]],"327680":[[0,807003500000000],[0,807017333333333]],"384":[[0,892910000000],[0,892920000000],[0,893330000000],[0,896250000000]],"12288":[[0,29478750000000],[0,29560830000000],[0,29597500000000],[0,29722080000000]],"81920":[[0,192083000000000],[0,195166000000000],[0,195250000000000],[0,204709000000000]],"8":[[0,20410000000],[0,20410000000],[0,20830000000],[0,20830000000]],"1280":[[0,2976214285714],[0,2978330000000],[0,2978330000000],[0,2979580000000]],"3584":[[0,8322080000000],[0,8326250000000],[0,8328750000000],[0,8329590000000]],"7":[[0,17910000000],[0,17910000000],[0,18330000000],[0,18330000000]],"524288":[[0,1268583000000000],[0,1319571428571428]],"112":[[0,271660000000],[0,271670000000],[0,273330000000],[0,277090000000]],"896":[[0,2087500000000],[0,2087655172413],[0,2087910000000],[0,2090000000000]],"192":[[0,446660000000],[0,446660000000],[0,447090000000],[0,454160000000]],"80":[[0,193330000000],[0,193750000000],[0,193750000000],[0,195000000000]],"24":[[0,56250000000],[0,56250000000],[0,56250000000],[0,56250000000]],"40960":[[0,96597333333333],[0,96805333333333],[0,97159666666666],[0,97750000000000]],"16":[[0,37500000000],[0,37500000000],[0,37500000000],[0,37500000000]],"3072":[[0,7128340000000],[0,7131670000000],[0,7132500000000],[0,7136670000000]],"20":[[0,46660000000],[0,46670000000],[0,46670000000],[0,47080000000]],"224":[[0,521250000000],[0,522500000000],[0,524160000000],[0,524170000000]],"2560":[[0,5942209677419],[0,5944160000000],[0,5944170000000],[0,5946565217391]],"1792":[[0,4162500000000],[0,4164580000000],[0,4166660000000],[0,4169170000000]],"1024":[[0,2383750000000],[0,2384170000000],[0,2385000000000],[0,2386660000000]],"6144":[[0,14873340000000],[0,14882920000000],[0,14924170000000],[0,14950830000000]],"56":[[0,131660000000],[0,131660000000],[0,137500000000],[0,138330000000]],"786432":[[0,1888000000000000],[0,1894584000000000]],"163840":[[0,389166000000000],[0,389417000000000],[0,395898521739130]],"6":[[0,18340000000],[0,18750000000],[0,18750000000],[0,18750000000]],"48":[[0,118330000000],[0,119160000000],[0,119170000000],[0,119580000000]],"32":[[0,75000000000],[0,75000000000],[0,75000000000],[0,75000000000]],"14":[[0,32910000000],[0,32920000000],[0,33330000000],[0,33330000000]],"28672":[[0,67889170000000],[0,68092910000000],[0,68250000000000],[0,68583000000000]],"512":[[0,1189590000000],[0,1190420000000],[0,1197910000000],[0,1198340000000]],"196608":[[0,468000000000000],[0,485584000000000],[0,502535105263157]],"458752":[[0,1088875000000000],[0,1090042000000000]],"24576":[[0,58125000000000],[0,58249580000000],[0,58435000000000],[0,58440000000000]],"2":[[0,14170000000],[0,14580000000],[0,14580000000],[0,14580000000]],"256":[[0,595420000000],[0,595840000000],[0,596250000000],[0,600000000000]],"1536":[[0,3542000000000],[0,3570000000000],[0,3571250000000],[0,3571670000000]],"64":[[0,157500000000],[0,157910000000],[0,157910000000],[0,157920000000]],"320":[[0,744170000000],[0,744590000000],[0,751670000000],[0,787500000000]],"114688":[[0,272667000000000],[0,273042000000000],[0,274704676470588]],"131072":[[0,310208000000000],[0,317282258064516],[0,318589103448275]],"16384":[[0,38958000000000],[0,39044076923076],[0,39257500000000],[0,39516268292682]],"5120":[[0,12494170000000],[0,12500000000000],[0,12501660000000],[0,12505000000000]],"229376":[[0,545750000000000],[0,547625000000000],[0,548625000000000]],"5":[[0,18330000000],[0,18330000000],[0,18330000000],[0,18330000000]],"10":[[0,23750000000],[0,24160000000],[0,24580000000],[0,24580000000]],"28":[[0,65420000000],[0,65420000000],[0,65830000000],[0,65830000000]],"655360":[[0,1599888833333333],[0,1605850000000000]],"7168":[[0,17328750000000],[0,17339160000000],[0,17339170000000],[0,17529580000000]],"20480":[[0,48528000000000],[0,48708000000000],[0,48875000000000],[0,49056250000000]],"65536":[[0,154784666666666],[0,154791000000000],[0,156167000000000],[0,164237500000000]],"917504":[[0,2203489500000000],[0,2204145750000000]],"160":[[0,372500000000],[0,372920000000],[0,375830000000],[0,375830000000]],"640":[[0,1492080000000],[0,1493750000000],[0,1494580000000],[0,1496250000000]],"40":[[0,98750000000],[0,100420000000],[0,100420000000],[0,102500000000]],"393216":[[0,945333000000000],[0,975583300000000]],"57344":[[0,134958500000000],[0,135379561643835],[0,136042000000000],[0,136250000000000]],"4":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17910000000]],"1":[[0,13340000000],[0,13750000000],[0,13750000000],[0,13750000000]],"768":[[0,1790420000000],[0,1790420000000],[0,1790830000000],[0,1791250000000]],"448":[[0,1040840000000],[0,1041670000000],[0,1041673684210],[0,1048750000000]],"8192":[[0,19877090000000],[0,19909590000000],[0,19941670000000],[0,20042000000000]],"12":[[0,27910000000],[0,27910000000],[0,28330000000],[0,28330000000]],"10240":[[0,24750000000000],[0,24763750000000],[0,24834000000000],[0,24958000000000]],"14336":[[0,34243220930232],[0,34291000000000],[0,34292000000000],[0,34687500000000]],"32768":[[0,77540038461538],[0,77546142857142],[0,78037920000000],[0,78125000000000]],"128":[[0,307910000000],[0,307920000000],[0,308330000000],[0,308330000000]],"4096":[[0,9506660000000],[0,9507891891891],[0,9541500000000],[0,9600830000000]],"49152":[[0,116062500000000],[0,116347058823529],[0,117734130952380],[0,120834000000000]],"262144":[[0,629167000000000],[0,672672571428571]],"3":[[0,17500000000],[0,17500000000],[0,17500000000],[0,17910000000]],"98304":[[0,229958000000000],[0,233791000000000],[0,235292000000000]]}},{"title":"RigidDeque prepend, reserving capacity","results":{"2048":[[0,1152080000000],[0,1152500000000],[0,1152500000000],[0,1152910000000]],"1048576":[[0,579125000000000],[0,580265625000000]],"96":[[0,75830000000],[0,75830000000],[0,75830000000],[0,76250000000]],"327680":[[0,179583000000000],[0,185294018867924]],"384":[[0,236250000000],[0,236660000000],[0,236660000000],[0,236670000000]],"12288":[[0,7332910000000],[0,7352920000000],[0,7356670000000],[0,7568750000000]],"81920":[[0,45167000000000],[0,45252733333333],[0,45750000000000],[0,45890420000000]],"8":[[0,18750000000],[0,18750000000],[0,18750000000],[0,19160000000]],"1280":[[0,729170000000],[0,730410000000],[0,730410000000],[0,730420000000]],"3584":[[0,1983750000000],[0,1983750000000],[0,1983750000000],[0,1984170000000]],"7":[[0,17920000000],[0,17920000000],[0,18330000000],[0,18330000000]],"524288":[[0,289000000000000],[0,298542000000000]],"112":[[0,95830000000],[0,95830000000],[0,95830000000],[0,95830000000]],"896":[[0,518330000000],[0,519580000000],[0,519580000000],[0,521250000000]],"192":[[0,132090000000],[0,132090000000],[0,132090000000],[0,132500000000]],"80":[[0,66670000000],[0,66670000000],[0,66670000000],[0,69580000000]],"24":[[0,27080000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,22926400000000],[0,22979580000000],[0,22987080000000],[0,23264423076923]],"16":[[0,22920000000],[0,23330000000],[0,23330000000],[0,23340000000]],"3072":[[0,1706660000000],[0,1706660000000],[0,1706660000000],[0,1707080000000]],"20":[[0,25000000000],[0,25410000000],[0,25410000000],[0,25410000000]],"224":[[0,149580000000],[0,149580000000],[0,150000000000],[0,150000000000]],"2560":[[0,1429580000000],[0,1429580000000],[0,1429580000000],[0,1430000000000]],"1792":[[0,1011538461538],[0,1011670000000],[0,1011670000000],[0,1014160000000]],"1024":[[0,584000000000],[0,590410000000],[0,590830000000],[0,590840000000]],"6144":[[0,3982920000000],[0,3995830000000],[0,3997500000000],[0,3997920000000]],"56":[[0,51250000000],[0,53330000000],[0,53330000000],[0,53330000000]],"786432":[[0,426959000000000],[0,434890136363636]],"163840":[[0,90375000000000],[0,90417000000000],[0,93673330000000]],"6":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17910000000]],"48":[[0,48340000000],[0,52080000000],[0,52090000000],[0,52500000000]],"32":[[0,31670000000],[0,31670000000],[0,32080000000],[0,32080000000]],"14":[[0,21670000000],[0,22080000000],[0,22080000000],[0,22500000000]],"28672":[[0,16257080000000],[0,16273857142857],[0,16337920000000],[0,16467910000000]],"512":[[0,304170000000],[0,304580000000],[0,304580000000],[0,305000000000]],"196608":[[0,109125000000000],[0,112269543209876],[0,113542000000000]],"458752":[[0,251000000000000],[0,256041000000000]],"24576":[[0,14065830000000],[0,14067500000000],[0,14068340000000],[0,14109580000000]],"2":[[0,15410000000],[0,15410000000],[0,15410000000],[0,15420000000]],"256":[[0,166666666666],[0,167080000000],[0,167080000000],[0,167500000000]],"1536":[[0,875000000000],[0,875000000000],[0,877910000000],[0,877910000000]],"64":[[0,57500000000],[0,57500000000],[0,57500000000],[0,57500000000]],"320":[[0,200000000000],[0,201660000000],[0,201670000000],[0,211670000000]],"114688":[[0,63500000000000],[0,63562090000000],[0,64402500000000]],"131072":[[0,72333000000000],[0,72625000000000],[0,72667000000000]],"16384":[[0,9610410000000],[0,9616600000000],[0,9620420000000],[0,9639170000000]],"5120":[[0,3414160000000],[0,3415000000000],[0,3415830000000],[0,3426250000000]],"229376":[[0,125834000000000],[0,126167000000000],[0,126208000000000]],"5":[[0,17080000000],[0,17080000000],[0,17090000000],[0,17500000000]],"10":[[0,20000000000],[0,20000000000],[0,20000000000],[0,20000000000]],"28":[[0,29580000000],[0,29590000000],[0,30000000000],[0,30000000000]],"655360":[[0,363042000000000],[0,368916000000000]],"7168":[[0,4541250000000],[0,4541670000000],[0,4543750000000],[0,4545840000000]],"20480":[[0,11821660000000],[0,11842487804878],[0,11867500000000],[0,11870840000000]],"65536":[[0,36263330000000],[0,36405420000000],[0,36545420000000],[0,36841936507936]],"917504":[[0,498209000000000],[0,499000000000000]],"160":[[0,114580000000],[0,114580000000],[0,115000000000],[0,115000000000]],"640":[[0,381250000000],[0,381250000000],[0,381660000000],[0,382080000000]],"40":[[0,43750000000],[0,43750000000],[0,43750000000],[0,44160000000]],"393216":[[0,214458000000000],[0,217084000000000]],"57344":[[0,31859818181818],[0,31871250000000],[0,31879590000000],[0,32380000000000]],"4":[[0,18750000000],[0,19160000000],[0,19160000000],[0,23330000000]],"1":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"768":[[0,451250000000],[0,451660000000],[0,451670000000],[0,452080000000]],"448":[[0,270500000000],[0,271250000000],[0,271250000000],[0,271660000000]],"8192":[[0,5099160000000],[0,5102678571428],[0,5105420000000],[0,5113330000000]],"12":[[0,20830000000],[0,20830000000],[0,20830000000],[0,20840000000]],"10240":[[0,6208000000000],[0,6231250000000],[0,6231670000000],[0,6237920000000]],"14336":[[0,8466250000000],[0,8469339622641],[0,8483062500000],[0,8499580000000]],"32768":[[0,18505830000000],[0,18512920000000],[0,18532090000000],[0,18551660000000]],"128":[[0,105000000000],[0,105410000000],[0,105830000000],[0,109170000000]],"4096":[[0,2260830000000],[0,2260840000000],[0,2261250000000],[0,2261670000000]],"49152":[[0,27422916666666],[0,27438330000000],[0,27528340000000],[0,27916000000000]],"262144":[[0,144250000000000],[0,152823000000000]],"3":[[0,18330000000],[0,18330000000],[0,18750000000],[0,18750000000]],"98304":[[0,54499170000000],[0,54583000000000],[0,55795000000000]]}},{"title":"UniqueDeque prepend, reserving capacity","results":{"2048":[[0,3900000000000],[0,3900410000000],[0,3901670000000],[0,3910000000000]],"1048576":[[0,2069041000000000],[0,2076708000000000]],"96":[[0,209580000000],[0,209580000000],[0,209590000000],[0,210000000000]],"327680":[[0,654167000000000],[0,654917000000000]],"384":[[0,744170000000],[0,744580000000],[0,744590000000],[0,745000000000]],"12288":[[0,24266600000000],[0,24292000000000],[0,24333000000000],[0,26125000000000]],"81920":[[0,158708000000000],[0,160708000000000],[0,162556016393442],[0,174977207547169]],"8":[[0,25410000000],[0,25830000000],[0,25830000000],[0,25830000000]],"1280":[[0,2445830000000],[0,2446250000000],[0,2446250000000],[0,2447080000000]],"3584":[[0,6810000000000],[0,6810410000000],[0,6811475000000],[0,6815410000000]],"7":[[0,24170000000],[0,24580000000],[0,24580000000],[0,24580000000]],"524288":[[0,1026334000000000],[0,1083546222222222]],"112":[[0,239170000000],[0,239580000000],[0,239580000000],[0,240000000000]],"896":[[0,1717920000000],[0,1718750000000],[0,1719160000000],[0,1719580000000]],"192":[[0,382500000000],[0,382500000000],[0,382500000000],[0,382910000000]],"80":[[0,167000000000],[0,179160000000],[0,179170000000],[0,179580000000]],"24":[[0,50410000000],[0,50410000000],[0,50410000000],[0,50410000000]],"40960":[[0,79083000000000],[0,79125000000000],[0,79375000000000],[0,80166000000000]],"16":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"3072":[[0,5838750000000],[0,5839160000000],[0,5840830000000],[0,5841670000000]],"20":[[0,42910000000],[0,42910000000],[0,42910000000],[0,43330000000]],"224":[[0,441660000000],[0,442080000000],[0,442080000000],[0,442080000000]],"2560":[[0,4870000000000],[0,4870830000000],[0,4870830000000],[0,4927920000000]],"1792":[[0,3413750000000],[0,3413750000000],[0,3414170000000],[0,3425830000000]],"1024":[[0,1961250000000],[0,1961660000000],[0,1962920000000],[0,1971660000000]],"6144":[[0,12284590000000],[0,12304170000000],[0,12334000000000],[0,12392500000000]],"56":[[0,130830000000],[0,132080000000],[0,133750000000],[0,134160000000]],"786432":[[0,1559000000000000],[0,1597763833333333]],"163840":[[0,318500000000000],[0,319833000000000],[0,333709000000000]],"6":[[0,22920000000],[0,22920000000],[0,23330000000],[0,23330000000]],"48":[[0,117500000000],[0,118330000000],[0,118750000000],[0,119160000000]],"32":[[0,77500000000],[0,77910000000],[0,77910000000],[0,78330000000]],"14":[[0,33750000000],[0,33750000000],[0,33750000000],[0,34170000000]],"28672":[[0,55667000000000],[0,55792000000000],[0,56125000000000],[0,56250000000000]],"512":[[0,985000000000],[0,985000000000],[0,985410000000],[0,995420000000]],"196608":[[0,382500000000000],[0,392186680000000],[0,400889478260869]],"458752":[[0,892417000000000],[0,925716700000000]],"24576":[[0,47708000000000],[0,47708400000000],[0,47750000000000],[0,47764000000000]],"2":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"256":[[0,501660000000],[0,502090000000],[0,502500000000],[0,526250000000]],"1536":[[0,2930830000000],[0,2931106666666],[0,2932500000000],[0,2932910000000]],"64":[[0,145750000000],[0,147080000000],[0,147090000000],[0,148750000000]],"320":[[0,622500000000],[0,623340000000],[0,623750000000],[0,627500000000]],"114688":[[0,223250000000000],[0,223555863636363],[0,223833000000000]],"131072":[[0,253833000000000],[0,256000000000000],[0,259417000000000]],"16384":[[0,31989750000000],[0,32000000000000],[0,32099170000000],[0,32167000000000]],"5120":[[0,10335000000000],[0,10335000000000],[0,10342080000000],[0,10368750000000]],"229376":[[0,446292000000000],[0,448416000000000],[0,457083000000000]],"5":[[0,21660000000],[0,21660000000],[0,21660000000],[0,21660000000]],"10":[[0,28330000000],[0,28330000000],[0,28330000000],[0,28330000000]],"28":[[0,70410000000],[0,70830000000],[0,70840000000],[0,71250000000]],"655360":[[0,1296875000000000],[0,1320875000000000]],"7168":[[0,14312500000000],[0,14330420000000],[0,14348786516853],[0,14416000000000]],"20480":[[0,39992431818181],[0,40125000000000],[0,40167000000000],[0,40209000000000]],"65536":[[0,126083000000000],[0,127258400000000],[0,127709000000000],[0,128291666666666]],"917504":[[0,1809875000000000],[0,1809958000000000]],"160":[[0,322910000000],[0,322920000000],[0,322920000000],[0,323330000000]],"640":[[0,1232920000000],[0,1235000000000],[0,1235000000000],[0,1244160000000]],"40":[[0,100830000000],[0,101250000000],[0,101250000000],[0,101670000000]],"393216":[[0,786750000000000],[0,787292000000000]],"57344":[[0,111375000000000],[0,111542000000000],[0,111583000000000],[0,112208000000000]],"4":[[0,22080000000],[0,22500000000],[0,22500000000],[0,25410000000]],"1":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15410000000]],"768":[[0,1476670000000],[0,1477090000000],[0,1477500000000],[0,1486660000000]],"448":[[0,875000000000],[0,875830000000],[0,876250000000],[0,876660000000]],"8192":[[0,16334000000000],[0,16458000000000],[0,16458000000000],[0,16542000000000]],"12":[[0,30420000000],[0,30830000000],[0,30830000000],[0,31250000000]],"10240":[[0,20458000000000],[0,20500000000000],[0,20508340000000],[0,20856660000000]],"14336":[[0,28229160000000],[0,28333000000000],[0,28397500000000],[0,28458000000000]],"32768":[[0,63458000000000],[0,63916000000000],[0,64000000000000],[0,65700410000000]],"128":[[0,268909090909],[0,269580000000],[0,270410000000],[0,270410000000]],"4096":[[0,7780830000000],[0,7792000000000],[0,7825772727272],[0,7826250000000]],"49152":[[0,95000000000000],[0,95013666666666],[0,95550000000000],[0,95875000000000]],"262144":[[0,518375000000000],[0,556247529411764]],"3":[[0,20830000000],[0,20857142857],[0,21250000000],[0,21250000000]],"98304":[[0,188875000000000],[0,190305666666666],[0,195125000000000]]}},{"title":"std::deque random insertions","results":{"2048":[[0,85219466666666],[0,86039666666666],[0,87441250000000],[0,88508333333333]],"96":[[0,982500000000],[0,997920000000],[0,1012080000000],[0,1078750000000]],"327680":[[0,2071825521000000000],[0,2103164250000000000]],"384":[[0,5863750000000],[0,5909170000000],[0,5979250000000],[0,5990840000000]],"12288":[[0,2051948000000000],[0,2056052250000000],[0,2076833000000000],[0,2333375000000000]],"81920":[[0,119747041500000000],[0,120203375000000000],[0,121243500000000000],[0,121413687500000000]],"8":[[0,105410000000],[0,110420000000],[0,119160000000],[0,120000000000]],"1280":[[0,38842920000000],[0,39559027777777],[0,39650000000000],[0,39750000000000]],"3584":[[0,224708500000000],[0,229104500000000],[0,229875000000000],[0,232165589743589]],"7":[[0,75830000000],[0,77500000000],[0,104170000000],[0,104580000000]],"524288":[[0,5390294750000000000],[0,5421634791000000000]],"112":[[0,1177500000000],[0,1194580000000],[0,1284090909090],[0,1292920000000]],"896":[[0,20652311475409],[0,20771000000000],[0,21190000000000],[0,22083330000000]],"192":[[0,2284580000000],[0,2375000000000],[0,2491250000000],[0,2541250000000]],"80":[[0,819170000000],[0,838750000000],[0,866250000000],[0,870410000000]],"24":[[0,254160000000],[0,257080000000],[0,264580000000],[0,267910000000]],"40960":[[0,25262167000000000],[0,25897583000000000],[0,26060958000000000],[0,26097083000000000]],"16":[[0,168750000000],[0,182090000000],[0,188750000000],[0,193330000000]],"3072":[[0,172680333333333],[0,173732142857142],[0,175729000000000],[0,176277666666666]],"20":[[0,206250000000],[0,211670000000],[0,217080000000],[0,225830000000]],"224":[[0,2767920000000],[0,2892080000000],[0,2907920000000],[0,2948340000000]],"2560":[[0,127208500000000],[0,128791750000000],[0,129478013888888],[0,129864500000000]],"1792":[[0,68916000000000],[0,69178736842105],[0,70415830000000],[0,70491878048780]],"1024":[[0,25750000000000],[0,26375000000000],[0,27186250000000],[0,27390830000000]],"6144":[[0,581625000000000],[0,586041000000000],[0,593229187500000],[0,593828125000000]],"56":[[0,551250000000],[0,556250000000],[0,574170000000],[0,594170000000]],"163840":[[0,514239083500000000],[0,517731979000000000],[0,520127916500000000]],"6":[[0,94160000000],[0,96250000000],[0,96660000000],[0,104580000000]],"48":[[0,485410000000],[0,499580000000],[0,516250000000],[0,520000000000]],"32":[[0,336670000000],[0,342080000000],[0,360000000000],[0,363750000000]],"14":[[0,151670000000],[0,159580000000],[0,161250000000],[0,166250000000]],"28672":[[0,11367208000000000],[0,11498625000000000],[0,11506500000000000],[0,11730875000000000]],"512":[[0,8347333333333],[0,8627080000000],[0,8717285714285],[0,8982080000000]],"196608":[[0,730011375000000000],[0,758665666500000000],[0,758683292000000000]],"458752":[[0,4152893042000000000],[0,4159420791000000000]],"24576":[[0,8051750000000000],[0,8239750000000000],[0,8295583000000000],[0,8323375000000000]],"2":[[0,42910000000],[0,42910000000],[0,74160000000],[0,76250000000]],"256":[[0,3264590000000],[0,3333750000000],[0,3347090000000],[0,3638000000000]],"1536":[[0,52916500000000],[0,52984696202531],[0,53527666666666],[0,53728146341463]],"64":[[0,627080000000],[0,654170000000],[0,681250000000],[0,699170000000]],"320":[[0,4396250000000],[0,4437920000000],[0,4529580000000],[0,4771250000000]],"114688":[[0,243777312500000000],[0,245059084000000000],[0,246152333000000000]],"131072":[[0,323916000000000000],[0,325964375000000000],[0,326597562500000000]],"16384":[[0,3501584000000000],[0,3583937500000000],[0,3601584000000000],[0,3611729500000000]],"5120":[[0,426791652173913],[0,427579695652173],[0,433417000000000],[0,434240500000000]],"229376":[[0,1032004812500000000],[0,1032061125000000000],[0,1035364291000000000]],"5":[[0,55410000000],[0,88750000000],[0,92500000000],[0,95000000000]],"10":[[0,126250000000],[0,127910000000],[0,132080000000],[0,140830000000]],"28":[[0,287910000000],[0,302080000000],[0,316250000000],[0,323750000000]],"7168":[[0,768295083333333],[0,772534750000000],[0,775187500000000],[0,800958000000000]],"20480":[[0,5501791000000000],[0,5531416000000000],[0,5576916000000000],[0,5580250000000000]],"65536":[[0,73943000000000000],[0,74440375000000000],[0,74503709000000000],[0,74895333000000000]],"160":[[0,1923750000000],[0,1953320000000],[0,1965830000000],[0,1967090000000]],"640":[[0,12169642857142],[0,12312500000000],[0,12543330000000],[0,13207500000000]],"40":[[0,400830000000],[0,425000000000],[0,435830000000],[0,442910000000]],"393216":[[0,3073541271000000000],[0,3085176750000000000]],"57344":[[0,54521667000000000],[0,54942500000000000],[0,55510062500000000],[0,55707167000000000]],"4":[[0,53330000000],[0,86660000000],[0,88750000000],[0,98750000000]],"1":[[0,37080000000],[0,37080000000],[0,37080000000],[0,37111111111]],"768":[[0,16407500000000],[0,16669590000000],[0,16853330000000],[0,16888200000000]],"448":[[0,6927500000000],[0,7021000000000],[0,7231382978723],[0,7812500000000]],"8192":[[0,978292000000000],[0,980209000000000],[0,980334000000000],[0,1010203777777777]],"12":[[0,137080000000],[0,144580000000],[0,145000000000],[0,148330000000]],"10240":[[0,1471888833333333],[0,1493889000000000],[0,1495284666666666],[0,1525409666666666]],"14336":[[0,2763152666666666],[0,2767861333333333],[0,2789305666666666],[0,2793597333333333]],"32768":[[0,15368708000000000],[0,15504209000000000],[0,15535792000000000],[0,15539375000000000]],"128":[[0,1408330000000],[0,1417500000000],[0,1467080000000],[0,1483330000000]],"4096":[[0,286694454545454],[0,288927000000000],[0,295627515151515],[0,295875000000000]],"49152":[[0,38351709000000000],[0,38850437500000000],[0,38973770500000000],[0,40275666500000000]],"262144":[[0,1328818771000000000],[0,1341204041000000000]],"3":[[0,80410000000],[0,80830000000],[0,81250000000],[0,82500000000]],"98304":[[0,180338187500000000],[0,180430229000000000],[0,185341334000000000]]}},{"title":"VecDeque random insertions","results":{"2048":[[0,5022500000000],[0,5028750000000],[0,5039590000000],[0,5050000000000]],"1048576":[[0,2761875000000000],[0,3063542000000000]],"96":[[0,427920000000],[0,428750000000],[0,429160000000],[0,430840000000]],"327680":[[0,813250000000000],[0,850333363636363]],"384":[[0,1180840000000],[0,1181250000000],[0,1182090000000],[0,1189580000000]],"12288":[[0,29003330000000],[0,29163750000000],[0,29632080000000],[0,32837080000000]],"81920":[[0,181690979166666],[0,183626660000000],[0,188958000000000],[0,193958000000000]],"8":[[0,66250000000],[0,66250000000],[0,66250000000],[0,75420000000]],"1280":[[0,3373330000000],[0,3410420000000],[0,3422920000000],[0,3433750000000]],"3584":[[0,8514170000000],[0,8516250000000],[0,8518340000000],[0,8624590000000]],"7":[[0,64160000000],[0,64160000000],[0,64170000000],[0,64170000000]],"524288":[[0,1215062500000000],[0,1276298500000000]],"112":[[0,461670000000],[0,463750000000],[0,463750000000],[0,466250000000]],"896":[[0,2376670000000],[0,2378750000000],[0,2379590000000],[0,2385830000000]],"192":[[0,697500000000],[0,699580000000],[0,700000000000],[0,701250000000]],"80":[[0,389580000000],[0,389590000000],[0,390410000000],[0,392080000000]],"24":[[0,158330000000],[0,158330000000],[0,158750000000],[0,160000000000]],"40960":[[0,90687500000000],[0,92333000000000],[0,94375000000000],[0,94625000000000]],"16":[[0,111250000000],[0,111660000000],[0,111660000000],[0,111660000000]],"3072":[[0,7421250000000],[0,7425410000000],[0,7428750000000],[0,7434170000000]],"20":[[0,149580000000],[0,150000000000],[0,150420000000],[0,151660000000]],"224":[[0,766670000000],[0,769580000000],[0,770000000000],[0,770420000000]],"2560":[[0,6325000000000],[0,6329590000000],[0,6360420000000],[0,6375000000000]],"1792":[[0,4471250000000],[0,4473750000000],[0,4515000000000],[0,4525000000000]],"1024":[[0,2655272727272],[0,2657910000000],[0,2659170000000],[0,2660000000000]],"6144":[[0,15653656250000],[0,15688340000000],[0,15796250000000],[0,16008330000000]],"56":[[0,276250000000],[0,276670000000],[0,277090000000],[0,278750000000]],"786432":[[0,2255333000000000],[0,2708000000000000]],"163840":[[0,375834000000000],[0,380625000000000],[0,389125000000000]],"6":[[0,62080000000],[0,62500000000],[0,62500000000],[0,62500000000]],"48":[[0,253330000000],[0,254160000000],[0,254580000000],[0,256250000000]],"32":[[0,174580000000],[0,175000000000],[0,175410000000],[0,175420000000]],"14":[[0,107080000000],[0,107080000000],[0,107500000000],[0,107500000000]],"28672":[[0,65660410000000],[0,66500000000000],[0,66750000000000],[0,67625000000000]],"512":[[0,1452500000000],[0,1458750000000],[0,1459580000000],[0,1463330000000]],"196608":[[0,454041000000000],[0,457083000000000],[0,463625000000000]],"458752":[[0,1143625000000000],[0,1148111166666666]],"24576":[[0,56665840000000],[0,56750000000000],[0,57784042253521],[0,58821507462686]],"2":[[0,22920000000],[0,22920000000],[0,23330000000],[0,23330000000]],"256":[[0,833000000000],[0,835830000000],[0,836660000000],[0,838750000000]],"1536":[[0,3958333333333],[0,3972080000000],[0,3973750000000],[0,3975000000000]],"64":[[0,292920000000],[0,293750000000],[0,294580000000],[0,294580000000]],"320":[[0,1043750000000],[0,1044170000000],[0,1044580000000],[0,1046250000000]],"114688":[[0,260223388888888],[0,264209000000000],[0,266334000000000]],"131072":[[0,290000000000000],[0,305979000000000],[0,330584758620689]],"16384":[[0,38249580000000],[0,38709000000000],[0,38975420000000],[0,39120000000000]],"5120":[[0,13346670000000],[0,13407080000000],[0,13437500000000],[0,13470588235294]],"229376":[[0,539250000000000],[0,563026941176470],[0,572274529411764]],"5":[[0,60410000000],[0,60410000000],[0,60410000000],[0,60420000000]],"10":[[0,99580000000],[0,99580000000],[0,99590000000],[0,100410000000]],"28":[[0,166670000000],[0,166670000000],[0,167910000000],[0,168330000000]],"655360":[[0,1945933400000000],[0,1976906250000000]],"7168":[[0,17708000000000],[0,17717910000000],[0,17977080000000],[0,18062500000000]],"20480":[[0,46437500000000],[0,46510250000000],[0,46824160000000],[0,48125000000000]],"65536":[[0,146104000000000],[0,148412169230769],[0,151597888888888],[0,152834000000000]],"917504":[[0,2563458000000000],[0,2769417000000000]],"160":[[0,631660000000],[0,631670000000],[0,631670000000],[0,636250000000]],"640":[[0,1834580000000],[0,1834590000000],[0,1837080000000],[0,1838750000000]],"40":[[0,237080000000],[0,237910000000],[0,238750000000],[0,239170000000]],"393216":[[0,933500000000000],[0,966875000000000]],"57344":[[0,129602371428571],[0,131834000000000],[0,133066205479452],[0,133189044776119]],"4":[[0,27500000000],[0,31250000000],[0,32080000000],[0,32910000000]],"1":[[0,20000000000],[0,20410000000],[0,20410000000],[0,20410000000]],"768":[[0,2102920000000],[0,2107500000000],[0,2108750000000],[0,2117500000000]],"448":[[0,1318750000000],[0,1320830000000],[0,1320840000000],[0,1325420000000]],"8192":[[0,20230000000000],[0,20432500000000],[0,20435000000000],[0,20459000000000]],"12":[[0,103330000000],[0,103330000000],[0,103750000000],[0,104160000000]],"10240":[[0,24291000000000],[0,24350000000000],[0,24892500000000],[0,25088340000000]],"14336":[[0,33177080000000],[0,34039170000000],[0,34257500000000],[0,34491279069767]],"32768":[[0,73265055555555],[0,76032750000000],[0,76084000000000],[0,87833000000000]],"128":[[0,496250000000],[0,497080000000],[0,497920000000],[0,500830000000]],"4096":[[0,9610000000000],[0,9613340000000],[0,9680333333333],[0,9946250000000]],"49152":[[0,111668586206896],[0,112000000000000],[0,113583000000000],[0,113833000000000]],"262144":[[0,594209000000000],[0,626125000000000]],"3":[[0,27080000000],[0,27500000000],[0,27910000000],[0,27920000000]],"98304":[[0,224728674418604],[0,226010250000000],[0,271417000000000]]}},{"title":"UniqueDeque random insertions","results":{"2048":[[0,65245420000000],[0,65246745098039],[0,65667000000000],[0,66338550000000]],"96":[[0,940410000000],[0,947080000000],[0,965830000000],[0,974580000000]],"327680":[[0,1784625334000000000],[0,1812723041500000000]],"384":[[0,3941666666666],[0,4000840000000],[0,4439160000000],[0,23625000000000]],"12288":[[0,1832167000000000],[0,1844625000000000],[0,1868591800000000],[0,2072458500000000]],"81920":[[0,104136729000000000],[0,104443979000000000],[0,104797437500000000],[0,105185333000000000]],"8":[[0,135420000000],[0,140410000000],[0,140420000000],[0,162500000000]],"1280":[[0,28104644444444],[0,28330410000000],[0,29230830000000],[0,29368750000000]],"3584":[[0,175354000000000],[0,177583333333333],[0,178208000000000],[0,182008666666666]],"7":[[0,131250000000],[0,135410000000],[0,135830000000],[0,144580000000]],"524288":[[0,4759029937500000000],[0,4803660333000000000]],"112":[[0,1040410000000],[0,1051250000000],[0,1088330000000],[0,1117080000000]],"896":[[0,14834000000000],[0,15546660000000],[0,15551250000000],[0,15741250000000]],"192":[[0,1800420000000],[0,1808330000000],[0,1810000000000],[0,1833330000000]],"80":[[0,821250000000],[0,825410000000],[0,839580000000],[0,846670000000]],"24":[[0,291670000000],[0,301250000000],[0,301670000000],[0,307080000000]],"40960":[[0,22904875000000000],[0,23024854500000000],[0,23206104500000000],[0,23279417000000000]],"16":[[0,230830000000],[0,235000000000],[0,245840000000],[0,248330000000]],"3072":[[0,133927250000000],[0,135583250000000],[0,136262072463768],[0,139055666666666]],"20":[[0,248330000000],[0,257500000000],[0,263750000000],[0,266670000000]],"224":[[0,2155410000000],[0,2163750000000],[0,2179590000000],[0,2200000000000]],"2560":[[0,97365777777777],[0,97678000000000],[0,98346322580645],[0,99029975609756]],"1792":[[0,51128330000000],[0,51857954545454],[0,52084000000000],[0,53088750000000]],"1024":[[0,19020812500000],[0,19207910000000],[0,19837910000000],[0,20394184210526]],"6144":[[0,481843750000000],[0,483291650000000],[0,485835450000000],[0,487687500000000]],"56":[[0,580830000000],[0,602500000000],[0,615410000000],[0,624580000000]],"163840":[[0,441280542000000000],[0,441939062500000000],[0,447409604000000000]],"6":[[0,126250000000],[0,126670000000],[0,127080000000],[0,137920000000]],"48":[[0,531660000000],[0,535410000000],[0,541250000000],[0,544160000000]],"32":[[0,379160000000],[0,397500000000],[0,397910000000],[0,407080000000]],"14":[[0,192910000000],[0,195000000000],[0,200830000000],[0,201250000000]],"28672":[[0,10418542000000000],[0,10466958500000000],[0,10477625000000000],[0,10562604500000000]],"512":[[0,5820000000000],[0,5940217391304],[0,5965830000000],[0,6007500000000]],"196608":[[0,637279625000000000],[0,640841041500000000],[0,643633834000000000]],"458752":[[0,3540987709000000000],[0,3573798542000000000]],"24576":[[0,7435958000000000],[0,7487750000000000],[0,7526958000000000],[0,7575291000000000]],"2":[[0,38330000000],[0,38330000000],[0,38330000000],[0,38330000000]],"256":[[0,2491670000000],[0,2495410000000],[0,2501670000000],[0,2564580000000]],"1536":[[0,38824170000000],[0,38834000000000],[0,39003330000000],[0,40944160000000]],"64":[[0,651670000000],[0,666660000000],[0,668330000000],[0,668750000000]],"320":[[0,3198340000000],[0,3199160000000],[0,3211250000000],[0,3296250000000]],"114688":[[0,209447667000000000],[0,210372083500000000],[0,210453500000000000]],"131072":[[0,276044417000000000],[0,276632833000000000],[0,288519500000000000]],"16384":[[0,3210902666666666],[0,3246041666666666],[0,3277750000000000],[0,3278778000000000]],"5120":[[0,343958000000000],[0,348706821428571],[0,349709821428571],[0,354542000000000]],"229376":[[0,874590917000000000],[0,884354333000000000],[0,887685062500000000]],"5":[[0,88330000000],[0,90840000000],[0,95000000000],[0,100000000000]],"10":[[0,177080000000],[0,180420000000],[0,181670000000],[0,189160000000]],"28":[[0,345000000000],[0,359170000000],[0,360420000000],[0,365000000000]],"655360":[[0,7236591333000000000],[0,7330207125000000000]],"7168":[[0,653866666666666],[0,657708000000000],[0,658752800000000],[0,688098214285714]],"20480":[[0,4994250000000000],[0,5016709000000000],[0,5063458000000000],[0,5147000000000000]],"65536":[[0,64177354000000000],[0,64941000000000000],[0,65006167000000000],[0,66268042000000000]],"160":[[0,1557920000000],[0,1559160000000],[0,1570830000000],[0,1582500000000]],"640":[[0,8245000000000],[0,8450559322033],[0,8612080000000],[0,8833000000000]],"40":[[0,423330000000],[0,449580000000],[0,460840000000],[0,463340000000]],"393216":[[0,2567459959000000000],[0,2626992541500000000]],"57344":[[0,47767729000000000],[0,48259250000000000],[0,48304021000000000],[0,48635167000000000]],"4":[[0,90840000000],[0,92910000000],[0,93330000000],[0,93340000000]],"1":[[0,18330000000],[0,18340000000],[0,19170000000],[0,19170000000]],"768":[[0,11122080000000],[0,11432303571428],[0,11795830000000],[0,12317500000000]],"448":[[0,4923611111111],[0,4966670000000],[0,4979580000000],[0,5122920000000]],"8192":[[0,842292000000000],[0,845996272727272],[0,847621181818181],[0,849750000000000]],"12":[[0,176660000000],[0,188750000000],[0,190000000000],[0,193330000000]],"10240":[[0,1286839285714285],[0,1310542000000000],[0,1313654714285714],[0,1314273857142857]],"14336":[[0,2507736000000000],[0,2522486333333333],[0,2524625000000000],[0,2528958000000000]],"32768":[[0,13937333000000000],[0,14047208500000000],[0,14077125000000000],[0,14321583500000000]],"128":[[0,1216660000000],[0,1247920000000],[0,1262080000000],[0,1272920000000]],"4096":[[0,228042000000000],[0,230153000000000],[0,234010904761904],[0,234988829268292]],"49152":[[0,34225625000000000],[0,34470646000000000],[0,34523729000000000],[0,34671667000000000]],"262144":[[0,1132786542000000000],[0,1180922396000000000]],"3":[[0,62500000000],[0,65420000000],[0,65830000000],[0,65830000000]],"98304":[[0,153663833000000000],[0,153740792000000000],[0,158549583500000000]]}},{"title":"std::deque pop_front","results":{"2048":[[0,6708000000000],[0,6708000000000],[0,6708000000000],[0,6709000000000]],"1048576":[[0,3494083000000000],[0,3496958000000000]],"96":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"327680":[[0,1083042000000000],[0,1185209000000000]],"384":[[0,1250000000000],[0,1250000000000],[0,1292000000000],[0,1458000000000]],"12288":[[0,40375000000000],[0,40375000000000],[0,40375000000000],[0,46625000000000]],"81920":[[0,270334000000000],[0,270375000000000],[0,271083000000000],[0,278917000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,4166000000000],[0,4166000000000],[0,4167000000000],[0,4208000000000]],"3584":[[0,11750000000000],[0,11750000000000],[0,11792000000000],[0,12750000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,1784917000000000],[0,1982000000000000]],"112":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"896":[[0,2875000000000],[0,2916000000000],[0,2916000000000],[0,3291000000000]],"192":[[0,625000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"80":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"24":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"40960":[[0,134958000000000],[0,134958000000000],[0,135000000000000],[0,135334000000000]],"16":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"3072":[[0,10042000000000],[0,10083000000000],[0,10084000000000],[0,10084000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"224":[[0,708000000000],[0,708000000000],[0,708000000000],[0,709000000000]],"2560":[[0,8416000000000],[0,8416000000000],[0,8417000000000],[0,8417000000000]],"1792":[[0,5833000000000],[0,5875000000000],[0,5875000000000],[0,5875000000000]],"1024":[[0,3333000000000],[0,3333000000000],[0,3375000000000],[0,3500000000000]],"6144":[[0,20125000000000],[0,20167000000000],[0,20208000000000],[0,22875000000000]],"56":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"786432":[[0,2622417000000000],[0,2647083000000000]],"163840":[[0,540625000000000],[0,545042000000000],[0,561542000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,125000000000],[0,166000000000],[0,167000000000],[0,167000000000]],"32":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,94583000000000],[0,94583000000000],[0,94625000000000],[0,94625000000000]],"512":[[0,1666000000000],[0,1666000000000],[0,1666000000000],[0,1666000000000]],"196608":[[0,649916000000000],[0,665042000000000],[0,665834000000000]],"458752":[[0,1523709000000000],[0,1530208000000000]],"24576":[[0,81083000000000],[0,81084000000000],[0,81125000000000],[0,81166000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,833000000000],[0,833000000000],[0,833000000000],[0,833000000000]],"1536":[[0,5041000000000],[0,5041000000000],[0,5042000000000],[0,5291000000000]],"64":[[0,208000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"320":[[0,1041000000000],[0,1041000000000],[0,1083000000000],[0,1417000000000]],"114688":[[0,378583000000000],[0,378875000000000],[0,379459000000000]],"131072":[[0,433166000000000],[0,437542000000000],[0,443916000000000]],"16384":[[0,53834000000000],[0,53834000000000],[0,53875000000000],[0,53916000000000]],"5120":[[0,16791000000000],[0,16791000000000],[0,16792000000000],[0,16792000000000]],"229376":[[0,758958000000000],[0,763542000000000],[0,765292000000000]],"5":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"655360":[[0,2167792000000000],[0,2170292000000000]],"7168":[[0,23500000000000],[0,23541000000000],[0,23542000000000],[0,23542000000000]],"20480":[[0,67333000000000],[0,67375000000000],[0,67375000000000],[0,74166000000000]],"65536":[[0,216542000000000],[0,216584000000000],[0,216666000000000],[0,217208000000000]],"917504":[[0,3030917000000000],[0,3034541000000000]],"160":[[0,459000000000],[0,500000000000],[0,500000000000],[0,583000000000]],"640":[[0,2083000000000],[0,2083000000000],[0,2083000000000],[0,2084000000000]],"40":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"393216":[[0,1298917000000000],[0,1302834000000000]],"57344":[[0,189125000000000],[0,189166000000000],[0,189167000000000],[0,189208000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,2458000000000],[0,2500000000000],[0,2500000000000],[0,2542000000000]],"448":[[0,1458000000000],[0,1458000000000],[0,1458000000000],[0,1458000000000]],"8192":[[0,26875000000000],[0,26875000000000],[0,26875000000000],[0,26917000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,33584000000000],[0,33625000000000],[0,33625000000000],[0,33666000000000]],"14336":[[0,47083000000000],[0,47083000000000],[0,47125000000000],[0,47125000000000]],"32768":[[0,108041000000000],[0,108042000000000],[0,108084000000000],[0,108084000000000]],"128":[[0,416000000000],[0,416000000000],[0,417000000000],[0,417000000000]],"4096":[[0,13417000000000],[0,13458000000000],[0,13458000000000],[0,13458000000000]],"49152":[[0,162209000000000],[0,162291000000000],[0,162292000000000],[0,162333000000000]],"262144":[[0,865959000000000],[0,885666000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,324458000000000],[0,324792000000000],[0,328333000000000]]}},{"title":"std::deque pop_back","results":{"2048":[[0,3625000000000],[0,3667000000000],[0,3708000000000],[0,3709000000000]],"1048576":[[0,1922209000000000],[0,1930833000000000]],"96":[[0,166000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"327680":[[0,596000000000000],[0,655333000000000]],"384":[[0,667000000000],[0,708000000000],[0,708000000000],[0,1000000000000]],"12288":[[0,22125000000000],[0,22125000000000],[0,22167000000000],[0,27958000000000]],"81920":[[0,148625000000000],[0,148666000000000],[0,148875000000000],[0,149125000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2250000000000],[0,2291000000000],[0,2291000000000],[0,2291000000000]],"3584":[[0,6416000000000],[0,6417000000000],[0,6458000000000],[0,6959000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,955375000000000],[0,1086834000000000]],"112":[[0,208000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"896":[[0,1583000000000],[0,1583000000000],[0,1583000000000],[0,1791000000000]],"192":[[0,333000000000],[0,333000000000],[0,333000000000],[0,375000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"24":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,74167000000000],[0,74250000000000],[0,74375000000000],[0,74458000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,5459000000000],[0,5500000000000],[0,5500000000000],[0,5500000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"224":[[0,375000000000],[0,416000000000],[0,416000000000],[0,416000000000]],"2560":[[0,4583000000000],[0,4583000000000],[0,4583000000000],[0,4584000000000]],"1792":[[0,3167000000000],[0,3167000000000],[0,3208000000000],[0,3208000000000]],"1024":[[0,1833000000000],[0,1833000000000],[0,1833000000000],[0,1917000000000]],"6144":[[0,11042000000000],[0,11083000000000],[0,11083000000000],[0,11708000000000]],"56":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1432000000000000],[0,1434791000000000]],"163840":[[0,297708000000000],[0,298667000000000],[0,298875000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,52000000000000],[0,52125000000000],[0,52209000000000],[0,52291000000000]],"512":[[0,875000000000],[0,875000000000],[0,916000000000],[0,917000000000]],"196608":[[0,357667000000000],[0,358167000000000],[0,365167000000000]],"458752":[[0,841125000000000],[0,941458000000000]],"24576":[[0,44708000000000],[0,44750000000000],[0,44791000000000],[0,44917000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2750000000000],[0,2750000000000],[0,2750000000000],[0,2875000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,541000000000],[0,542000000000],[0,583000000000],[0,750000000000]],"114688":[[0,208625000000000],[0,208625000000000],[0,208666000000000]],"131072":[[0,238416000000000],[0,238917000000000],[0,243542000000000]],"16384":[[0,29500000000000],[0,29541000000000],[0,29542000000000],[0,29542000000000]],"5120":[[0,9167000000000],[0,9208000000000],[0,9208000000000],[0,9208000000000]],"229376":[[0,417041000000000],[0,417792000000000],[0,418667000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1192041000000000],[0,1196791000000000]],"7168":[[0,12875000000000],[0,12916000000000],[0,12917000000000],[0,12917000000000]],"20480":[[0,36958000000000],[0,37000000000000],[0,37000000000000],[0,37000000000000]],"65536":[[0,119167000000000],[0,119167000000000],[0,119292000000000],[0,119333000000000]],"917504":[[0,1669958000000000],[0,1671750000000000]],"160":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"640":[[0,1125000000000],[0,1125000000000],[0,1125000000000],[0,1125000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,716250000000000],[0,722667000000000]],"57344":[[0,104000000000000],[0,104083000000000],[0,104125000000000],[0,104250000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1333000000000],[0,1333000000000],[0,1375000000000],[0,1416000000000]],"448":[[0,791000000000],[0,791000000000],[0,791000000000],[0,792000000000]],"8192":[[0,14708000000000],[0,14750000000000],[0,14750000000000],[0,14791000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,18416000000000],[0,18417000000000],[0,18417000000000],[0,18458000000000]],"14336":[[0,25792000000000],[0,25833000000000],[0,25916000000000],[0,25917000000000]],"32768":[[0,59417000000000],[0,59459000000000],[0,59500000000000],[0,59583000000000]],"128":[[0,208000000000],[0,208000000000],[0,250000000000],[0,250000000000]],"4096":[[0,7333000000000],[0,7375000000000],[0,7375000000000],[0,7416000000000]],"49152":[[0,89375000000000],[0,89417000000000],[0,89500000000000],[0,89583000000000]],"262144":[[0,476541000000000],[0,481041000000000]],"3":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,178708000000000],[0,178917000000000],[0,179125000000000]]}},{"title":"std::deque random removals","results":{"2048":[[0,93042000000000],[0,93584000000000],[0,94167000000000],[0,96084000000000]],"96":[[0,1000000000000],[0,1000000000000],[0,1000000000000],[0,1042000000000]],"327680":[[0,1992577250000000000],[0,2004815250000000000]],"384":[[0,6708000000000],[0,6917000000000],[0,10667000000000],[0,18666000000000]],"12288":[[0,2077125000000000],[0,2082125000000000],[0,2106666000000000],[0,2148125000000000]],"81920":[[0,115903542000000000],[0,117050542000000000],[0,117583917000000000],[0,118761875000000000]],"8":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"1280":[[0,47292000000000],[0,47750000000000],[0,49792000000000],[0,50167000000000]],"3584":[[0,238917000000000],[0,240750000000000],[0,243250000000000],[0,244708000000000]],"7":[[0,41000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"524288":[[0,5238552500000000000],[0,5276722000000000000]],"112":[[0,1125000000000],[0,1209000000000],[0,1250000000000],[0,1292000000000]],"896":[[0,27625000000000],[0,28042000000000],[0,28666000000000],[0,31208000000000]],"192":[[0,2458000000000],[0,2458000000000],[0,2542000000000],[0,2666000000000]],"80":[[0,792000000000],[0,833000000000],[0,834000000000],[0,875000000000]],"24":[[0,209000000000],[0,209000000000],[0,209000000000],[0,250000000000]],"40960":[[0,25303250000000000],[0,25340000000000000],[0,25587416000000000],[0,25743125000000000]],"16":[[0,125000000000],[0,125000000000],[0,125000000000],[0,209000000000]],"3072":[[0,182083000000000],[0,182542000000000],[0,183875000000000],[0,184500000000000]],"20":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"224":[[0,3083000000000],[0,3084000000000],[0,3166000000000],[0,3375000000000]],"2560":[[0,137500000000000],[0,138583000000000],[0,139000000000000],[0,143042000000000]],"1792":[[0,78000000000000],[0,79584000000000],[0,79916000000000],[0,80750000000000]],"1024":[[0,31375000000000],[0,31583000000000],[0,32375000000000],[0,33125000000000]],"6144":[[0,593416000000000],[0,594500000000000],[0,596416000000000],[0,601584000000000]],"56":[[0,541000000000],[0,542000000000],[0,583000000000],[0,625000000000]],"163840":[[0,493038959000000000],[0,493476166000000000],[0,500329375000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,458000000000],[0,458000000000],[0,459000000000],[0,541000000000]],"32":[[0,292000000000],[0,333000000000],[0,334000000000],[0,375000000000]],"14":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"28672":[[0,11481000000000000],[0,11481458000000000],[0,11540542000000000],[0,11603625000000000]],"512":[[0,10250000000000],[0,10333000000000],[0,10500000000000],[0,10958000000000]],"196608":[[0,710619917000000000],[0,720175000000000000],[0,726276458000000000]],"458752":[[0,3976208833000000000],[0,3989472208000000000]],"24576":[[0,8045542000000000],[0,8220542000000000],[0,8228250000000000],[0,8290083000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,3750000000000],[0,3917000000000],[0,3959000000000],[0,5125000000000]],"1536":[[0,61750000000000],[0,62000000000000],[0,62375000000000],[0,62416000000000]],"64":[[0,625000000000],[0,625000000000],[0,667000000000],[0,667000000000]],"320":[[0,5208000000000],[0,5584000000000],[0,5625000000000],[0,6833000000000]],"114688":[[0,237708042000000000],[0,239383833000000000],[0,239488917000000000]],"131072":[[0,312269834000000000],[0,315215917000000000],[0,323288667000000000]],"16384":[[0,3496208000000000],[0,3556000000000000],[0,3574208000000000],[0,3593125000000000]],"5120":[[0,435250000000000],[0,437250000000000],[0,440416000000000],[0,440459000000000]],"229376":[[0,986884625000000000],[0,987525084000000000],[0,1003159375000000000]],"5":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"28":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"655360":[[0,7910439833000000000]],"7168":[[0,778792000000000],[0,785375000000000],[0,790958000000000],[0,808209000000000]],"20480":[[0,5454916000000000],[0,5552291000000000],[0,5560708000000000],[0,5574375000000000]],"65536":[[0,71944000000000000],[0,72166167000000000],[0,73725625000000000],[0,73876875000000000]],"160":[[0,1958000000000],[0,2000000000000],[0,2041000000000],[0,2584000000000]],"640":[[0,16791000000000],[0,17333000000000],[0,17417000000000],[0,17583000000000]],"40":[[0,375000000000],[0,375000000000],[0,417000000000],[0,417000000000]],"393216":[[0,2898900667000000000],[0,2924784500000000000]],"57344":[[0,53296542000000000],[0,53747208000000000],[0,54045833000000000],[0,54933875000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,22375000000000],[0,22625000000000],[0,23792000000000],[0,24083000000000]],"448":[[0,8417000000000],[0,8625000000000],[0,8833000000000],[0,9083000000000]],"8192":[[0,992250000000000],[0,993000000000000],[0,1000083000000000],[0,1009542000000000]],"12":[[0,83000000000],[0,83000000000],[0,125000000000],[0,125000000000]],"10240":[[0,1485875000000000],[0,1489459000000000],[0,1500959000000000],[0,1506250000000000]],"14336":[[0,2770292000000000],[0,2777500000000000],[0,2786667000000000],[0,2839333000000000]],"32768":[[0,15326459000000000],[0,15389333000000000],[0,15573250000000000],[0,15608916000000000]],"128":[[0,1375000000000],[0,1417000000000],[0,1458000000000],[0,1500000000000]],"4096":[[0,295667000000000],[0,295750000000000],[0,296292000000000],[0,316792000000000]],"49152":[[0,37890625000000000],[0,37953833000000000],[0,38378958000000000],[0,38392250000000000]],"262144":[[0,1272504459000000000],[0,1288432416000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,172334667000000000],[0,175118375000000000],[0,175305291000000000]]}},{"title":"std::deque sort","results":{"2048":[[0,48417000000000],[0,48500000000000],[0,49209000000000],[0,49792000000000]],"1048576":[[0,57343750000000000],[0,58297833000000000]],"96":[[0,542000000000],[0,542000000000],[0,584000000000],[0,584000000000]],"327680":[[0,16536667000000000],[0,16715125000000000]],"384":[[0,3042000000000],[0,3167000000000],[0,3250000000000],[0,10625000000000]],"12288":[[0,439209000000000],[0,444041000000000],[0,444875000000000],[0,456625000000000]],"81920":[[0,3660375000000000],[0,3690875000000000],[0,3703417000000000],[0,3707083000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1280":[[0,20417000000000],[0,20708000000000],[0,24791000000000],[0,25584000000000]],"3584":[[0,102041000000000],[0,104042000000000],[0,104667000000000],[0,106791000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"524288":[[0,28461375000000000],[0,29110791000000000]],"112":[[0,667000000000],[0,708000000000],[0,709000000000],[0,792000000000]],"896":[[0,9917000000000],[0,9917000000000],[0,13417000000000],[0,14500000000000]],"192":[[0,1250000000000],[0,1250000000000],[0,1291000000000],[0,1333000000000]],"80":[[0,458000000000],[0,458000000000],[0,458000000000],[0,500000000000]],"24":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"40960":[[0,1722125000000000],[0,1726208000000000],[0,1732292000000000],[0,1742917000000000]],"16":[[0,41000000000],[0,42000000000],[0,83000000000],[0,84000000000]],"3072":[[0,85041000000000],[0,85625000000000],[0,86250000000000],[0,90541000000000]],"20":[[0,83000000000],[0,84000000000],[0,84000000000],[0,125000000000]],"224":[[0,1541000000000],[0,1584000000000],[0,1584000000000],[0,1625000000000]],"2560":[[0,67416000000000],[0,68833000000000],[0,69041000000000],[0,71292000000000]],"1792":[[0,39083000000000],[0,39583000000000],[0,39917000000000],[0,39958000000000]],"1024":[[0,13250000000000],[0,13292000000000],[0,13292000000000],[0,16084000000000]],"6144":[[0,197750000000000],[0,199667000000000],[0,200208000000000],[0,205292000000000]],"56":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"786432":[[0,42764291000000000],[0,42883791000000000]],"163840":[[0,7982792000000000],[0,8068583000000000],[0,8134208000000000]],"6":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"32":[[0,125000000000],[0,166000000000],[0,166000000000],[0,209000000000]],"14":[[0,41000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"28672":[[0,1154083000000000],[0,1154250000000000],[0,1158000000000000],[0,1176291000000000]],"512":[[0,4458000000000],[0,4708000000000],[0,5875000000000],[0,6083000000000]],"196608":[[0,9598917000000000],[0,9662917000000000],[0,10034792000000000]],"458752":[[0,23678125000000000],[0,23887458000000000]],"24576":[[0,961291000000000],[0,976333000000000],[0,981166000000000],[0,982875000000000]],"2":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,1834000000000],[0,1875000000000],[0,1875000000000],[0,2625000000000]],"1536":[[0,29375000000000],[0,29792000000000],[0,30125000000000],[0,30375000000000]],"64":[[0,334000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"320":[[0,2417000000000],[0,2541000000000],[0,2542000000000],[0,2625000000000]],"114688":[[0,5294792000000000],[0,5381666000000000],[0,5521625000000000]],"131072":[[0,6011708000000000],[0,6112125000000000],[0,6283958000000000]],"16384":[[0,608375000000000],[0,623250000000000],[0,637083000000000],[0,638000000000000]],"5120":[[0,161167000000000],[0,161834000000000],[0,162375000000000],[0,168500000000000]],"229376":[[0,11287417000000000],[0,11748166000000000],[0,11834958000000000]],"5":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"655360":[[0,35053792000000000],[0,35118834000000000]],"7168":[[0,238625000000000],[0,241416000000000],[0,242708000000000],[0,243792000000000]],"20480":[[0,783583000000000],[0,800584000000000],[0,808542000000000],[0,821833000000000]],"65536":[[0,2886166000000000],[0,2905792000000000],[0,2911417000000000],[0,2927042000000000]],"917504":[[0,49658875000000000],[0,50835125000000000]],"160":[[0,1041000000000],[0,1042000000000],[0,1083000000000],[0,1334000000000]],"640":[[0,6958000000000],[0,7083000000000],[0,7167000000000],[0,7750000000000]],"40":[[0,208000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"393216":[[0,19996916000000000],[0,21280417000000000]],"57344":[[0,2486916000000000],[0,2507208000000000],[0,2511750000000000],[0,2530125000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,7708000000000],[0,9625000000000],[0,10584000000000],[0,10958000000000]],"448":[[0,3750000000000],[0,4042000000000],[0,4083000000000],[0,4167000000000]],"8192":[[0,278959000000000],[0,284291000000000],[0,284875000000000],[0,287416000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,356792000000000],[0,361375000000000],[0,365959000000000],[0,366625000000000]],"14336":[[0,521625000000000],[0,536459000000000],[0,540417000000000],[0,545792000000000]],"32768":[[0,1322292000000000],[0,1332375000000000],[0,1337291000000000],[0,1355291000000000]],"128":[[0,792000000000],[0,833000000000],[0,833000000000],[0,833000000000]],"4096":[[0,122167000000000],[0,122667000000000],[0,124416000000000],[0,131500000000000]],"49152":[[0,2103959000000000],[0,2108958000000000],[0,2129708000000000],[0,2134334000000000]],"262144":[[0,13283041000000000],[0,13660208000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,4514417000000000],[0,4582917000000000],[0,4627916000000000]]}},{"title":"VecDeque sequential iteration","results":{"2048":[[0,583000000000],[0,584000000000],[0,585410000000]],"1048576":[[0,283833000000000],[0,284042000000000]],"96":[[0,30830000000],[0,31250000000],[0,31250000000]],"327680":[[0,88833000000000],[0,97398437500000]],"384":[[0,125000000000],[0,135000000000],[0,135410000000]],"12288":[[0,3356250000000],[0,3356250000000],[0,3356670000000]],"81920":[[0,22197500000000],[0,22200830000000],[0,22230000000000]],"8":[[0,4160000000],[0,4160000000],[0,4160000000]],"1280":[[0,375000000000],[0,377910000000],[0,377920000000]],"3584":[[0,1001250000000],[0,1001250000000],[0,1001250000000]],"7":[[0,3750000000],[0,3750000000],[0,3750000000]],"524288":[[0,145166625000000],[0,151387096774193]],"112":[[0,40830000000],[0,40840000000],[0,42920000000]],"896":[[0,274160000000],[0,274160000000],[0,274580000000]],"192":[[0,65420000000],[0,65420000000],[0,65830000000]],"80":[[0,25410000000],[0,25410000000],[0,25420000000]],"24":[[0,6916666666],[0,8330000000],[0,8330000000]],"40960":[[0,11083000000000],[0,11114580000000],[0,11170000000000]],"16":[[0,6250000000],[0,6250000000],[0,6250000000]],"3072":[[0,833000000000],[0,862875000000],[0,863330000000]],"20":[[0,7500000000],[0,7500000000],[0,7500000000]],"224":[[0,77910000000],[0,78330000000],[0,78330000000]],"2560":[[0,724160000000],[0,724170000000],[0,724580000000]],"1792":[[0,516660000000],[0,516666666666],[0,516670000000]],"1024":[[0,291000000000],[0,308330000000],[0,308750000000]],"6144":[[0,1693750000000],[0,1694160000000],[0,1694170000000]],"56":[[0,16660000000],[0,17080000000],[0,17080000000]],"786432":[[0,212958000000000],[0,215857804347826]],"163840":[[0,45400000000000],[0,46583000000000]],"6":[[0,3750000000],[0,3750000000],[0,3750000000]],"48":[[0,14580000000],[0,14590000000],[0,15000000000]],"32":[[0,10410000000],[0,10420000000],[0,10830000000]],"14":[[0,5250000000],[0,5410000000],[0,5830000000]],"28672":[[0,7790410000000],[0,7790420000000],[0,7791670000000]],"512":[[0,167000000000],[0,169923076923],[0,170830000000]],"196608":[[0,53375000000000],[0,57208500000000]],"458752":[[0,124375000000000],[0,124417000000000]],"24576":[[0,6625000000000],[0,6681670000000],[0,6682500000000]],"2":[[0,2500000000],[0,2910000000],[0,2910000000]],"256":[[0,83000000000],[0,83000000000],[0,87500000000]],"1536":[[0,447347222222],[0,447500000000],[0,447500000000]],"64":[[0,19580000000],[0,19913043478],[0,20000000000]],"320":[[0,106250000000],[0,106250000000],[0,106250000000]],"114688":[[0,31070420000000],[0,31516670000000]],"131072":[[0,35666671052631],[0,35667000000000]],"16384":[[0,4458333333333],[0,4459000000000],[0,4464590000000]],"5120":[[0,1417080000000],[0,1417080000000],[0,1417500000000]],"229376":[[0,62167000000000],[0,62208000000000]],"5":[[0,3340000000],[0,3750000000],[0,3750000000]],"10":[[0,4580000000],[0,4580000000],[0,4580000000]],"28":[[0,9160000000],[0,9170000000],[0,9580000000]],"655360":[[0,177458000000000],[0,185625803921568]],"7168":[[0,1970536585365],[0,1970830000000],[0,1970830000000]],"20480":[[0,5542000000000],[0,5573340000000],[0,5574170000000]],"65536":[[0,17797500000000],[0,17798330000000],[0,17923750000000]],"917504":[[0,250916000000000],[0,262640485714285]],"160":[[0,56670000000],[0,57080000000],[0,57080000000]],"640":[[0,204580000000],[0,204580000000],[0,205000000000]],"40":[[0,12500000000],[0,12500000000],[0,12910000000]],"393216":[[0,110225000000000],[0,110322916666666]],"57344":[[0,15541000000000],[0,15542000000000],[0,15599590000000]],"4":[[0,2910000000],[0,2910000000],[0,3330000000]],"1":[[0,1250000000],[0,1250000000],[0,1660000000]],"768":[[0,229000000000],[0,239160000000],[0,239160000000]],"448":[[0,152090000000],[0,152500000000],[0,152500000000]],"8192":[[0,2248750000000],[0,2248750000000],[0,2248750000000]],"12":[[0,5000000000],[0,5000000000],[0,5410000000]],"10240":[[0,2802500000000],[0,2802500000000],[0,2802910000000]],"14336":[[0,3910830000000],[0,3910830000000],[0,3911250000000]],"32768":[[0,8897500000000],[0,8917000000000],[0,8958000000000]],"128":[[0,46660000000],[0,46670000000],[0,47080000000]],"4096":[[0,1125000000000],[0,1140000000000],[0,1292920000000]],"49152":[[0,13331670000000],[0,13332080000000],[0,13333000000000]],"262144":[[0,71166000000000],[0,74768750000000]],"3":[[0,2500000000],[0,2910000000],[0,2920000000]],"98304":[[0,26697614285714],[0,26711250000000]]}},{"title":"UniqueDeque sequential iteration","results":{"2048":[[0,1666660000000],[0,1666660000000],[0,1666670000000]],"1048576":[[0,856500000000000],[0,880143909090909]],"96":[[0,81670000000],[0,82080000000],[0,82080000000]],"327680":[[0,271792000000000],[0,286800235294117]],"384":[[0,315830000000],[0,315830000000],[0,315830000000]],"12288":[[0,9958000000000],[0,9979590000000],[0,10102920000000]],"81920":[[0,66623306122448],[0,66708000000000],[0,66721938775510]],"8":[[0,7910000000],[0,8330000000],[0,8330000000]],"1280":[[0,1042920000000],[0,1043330000000],[0,1043340000000]],"3584":[[0,2913330000000],[0,2913750000000],[0,2913750000000]],"7":[[0,7090000000],[0,7500000000],[0,7500000000]],"524288":[[0,425833000000000],[0,459373047619047]],"112":[[0,93750000000],[0,95000000000],[0,95000000000]],"896":[[0,731250000000],[0,731250000000],[0,731250000000]],"192":[[0,159580000000],[0,160000000000],[0,160000000000]],"80":[[0,68464285714],[0,68750000000],[0,69160000000]],"24":[[0,20830000000],[0,20840000000],[0,21250000000]],"40960":[[0,33257989898989],[0,33370000000000],[0,33459000000000]],"16":[[0,14160000000],[0,14580000000],[0,14580000000]],"3072":[[0,2497910000000],[0,2497920000000],[0,2497920000000]],"20":[[0,17500000000],[0,17910000000],[0,17910000000]],"224":[[0,185830000000],[0,185830000000],[0,185830000000]],"2560":[[0,2081250000000],[0,2082080000000],[0,2082080000000]],"1792":[[0,1458750000000],[0,1458750000000],[0,1459160000000]],"1024":[[0,834745762711],[0,835400000000],[0,835420000000]],"6144":[[0,4991250000000],[0,4991660000000],[0,4992080000000]],"56":[[0,41000000000],[0,49170000000],[0,49580000000]],"786432":[[0,640500000000000],[0,648958285714285]],"163840":[[0,133250000000000],[0,139583000000000]],"6":[[0,6250000000],[0,6250000000],[0,6660000000]],"48":[[0,43330000000],[0,43330000000],[0,43330000000]],"32":[[0,27500000000],[0,27500000000],[0,27500000000]],"14":[[0,12500000000],[0,12910000000],[0,12910000000]],"28672":[[0,23283000000000],[0,23284294117647],[0,23316660000000]],"512":[[0,419117647058],[0,419580000000],[0,419580000000]],"196608":[[0,163166000000000],[0,167334000000000]],"458752":[[0,373875000000000],[0,389896680000000]],"24576":[[0,19958500000000],[0,19979000000000],[0,20002500000000]],"2":[[0,3330000000],[0,3330000000],[0,3330000000]],"256":[[0,208250000000],[0,212080000000],[0,212080000000]],"1536":[[0,1250000000000],[0,1250830000000],[0,1251250000000]],"64":[[0,42000000000],[0,55830000000],[0,55830000000]],"320":[[0,263750000000],[0,263750000000],[0,264170000000]],"114688":[[0,93133200000000],[0,93375000000000]],"131072":[[0,106625000000000],[0,109350000000000]],"16384":[[0,13305000000000],[0,13305232558139],[0,13305420000000]],"5120":[[0,4160000000000],[0,4160410000000],[0,4161670000000]],"229376":[[0,186458000000000],[0,188333000000000]],"5":[[0,5420000000],[0,5830000000],[0,5830000000]],"10":[[0,9580000000],[0,9580000000],[0,9580000000]],"28":[[0,24170000000],[0,24580000000],[0,24580000000]],"655360":[[0,532583000000000],[0,543699111111111]],"7168":[[0,5822500000000],[0,5822910000000],[0,5823330000000]],"20480":[[0,16666500000000],[0,16667090000000],[0,16917000000000]],"65536":[[0,53208500000000],[0,53229000000000],[0,53459000000000]],"917504":[[0,755958000000000],[0,763310846153846]],"160":[[0,133750000000],[0,133750000000],[0,134160000000]],"640":[[0,523340000000],[0,523600000000],[0,523750000000]],"40":[[0,36250000000],[0,36250000000],[0,36660000000]],"393216":[[0,333500000000000],[0,348302071428571]],"57344":[[0,46556818181818],[0,46667000000000],[0,46750000000000]],"4":[[0,5000000000],[0,5000000000],[0,5000000000]],"1":[[0,1250000000],[0,1250000000],[0,1250000000]],"768":[[0,625000000000],[0,627210526315],[0,627500000000]],"448":[[0,367500000000],[0,367910000000],[0,367910000000]],"8192":[[0,6655000000000],[0,6687920000000],[0,6690000000000]],"12":[[0,10375000000],[0,11250000000],[0,11250000000]],"10240":[[0,8316250000000],[0,8319170000000],[0,8368330000000]],"14336":[[0,11641250000000],[0,11642920000000],[0,11750000000000]],"32768":[[0,26583000000000],[0,26669170000000],[0,26792000000000]],"128":[[0,107910000000],[0,107910000000],[0,107910000000]],"4096":[[0,3329160000000],[0,3329160000000],[0,12071500000000]],"49152":[[0,39959000000000],[0,40083000000000],[0,40125000000000]],"262144":[[0,212917000000000],[0,213167000000000]],"3":[[0,3750000000],[0,4160000000],[0,4160000000]],"98304":[[0,79842391304347],[0,81743750000000]]}}],"version":1} \ No newline at end of file diff --git a/Benchmarks/results.html b/Benchmarks/results.html new file mode 100644 index 00000000..708b20ce --- /dev/null +++ b/Benchmarks/results.html @@ -0,0 +1,3247 @@ + + + + + Benchmark results + + + +

Benchmark results

+

Click to expand individual items below.

+
+ Deque Benchmarks +
+
+ Operations +
+
+ 01 operations +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 10 ps + 10 ps + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> init from unsafe buffer + + + Deque<Int> sequential iteration (contiguous, iterator) + + + Deque<Int> subscript get, random offsets (contiguous) + + + Deque<Int> append + + + Deque<Int> append, reserving capacity + + + Deque<Int> prepend + + + Deque<Int> prepend, reserving capacity + + + Deque<Int> removeFirst (contiguous) + + + Deque<Int> removeLast (contiguous) + + + Deque<Int> sort (contiguous) + + + Deque<Int> sort (discontiguous) + + +
+
+
+ 02 iteration +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> sequential iteration (contiguous, iterator) + + + Deque<Int> sequential iteration (discontiguous, iterator) + + + Deque<Int> sequential iteration (contiguous, indices) + + + Deque<Int> sequential iteration (discontiguous, indices) + + +
+
+
+ 03 access +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> subscript get, random offsets (contiguous) + + + Deque<Int> subscript get, random offsets (discontiguous) + + + Deque<Int> mutate through subscript (contiguous) + + + Deque<Int> mutate through subscript (discontiguous) + + +
+
+
+ 04 mutate +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> mutate through subscript (contiguous) + + + Deque<Int> mutate through subscript (discontiguous) + + + Deque<Int> random swaps (contiguous) + + + Deque<Int> random swaps (discontiguous) + + + Deque<Int> partitioning around middle (contiguous) + + + Deque<Int> partitioning around middle (discontiguous) + + + Deque<Int> sort (contiguous) + + + Deque<Int> sort (discontiguous) + + +
+
+
+ 05 push +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> append + + + Deque<Int> append, reserving capacity + + + Deque<Int> prepend + + + Deque<Int> prepend, reserving capacity + + +
+
+
+ 06 pop +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> removeFirst (contiguous) + + + Deque<Int> removeFirst (discontiguous) + + + Deque<Int> removeLast (contiguous) + + + Deque<Int> removeLast (discontiguous) + + +
+
+
+
+
+ Deque vs Array +
+
+ 01 init from buffer of integers +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 10 ps + 10 ps + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> init from unsafe buffer + + + Array<Int> init from unsafe buffer + + +
+
+
+ 02 sequential iteration +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> sequential iteration (contiguous, iterator) + + + Deque<Int> sequential iteration (contiguous, indices) + + + Deque<Int> sequential iteration (discontiguous, iterator) + + + Deque<Int> sequential iteration (discontiguous, indices) + + + Array<Int> sequential iteration + + +
+
+
+ 03 random-access offset lookups +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> subscript get, random offsets (contiguous) + + + Deque<Int> subscript get, random offsets (discontiguous) + + + Array<Int> subscript get, random offsets + + +
+
+
+ 04 mutate through subscript +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> mutate through subscript (contiguous) + + + Deque<Int> mutate through subscript (discontiguous) + + + Array<Int> mutate through subscript + + +
+
+
+ 05 random swaps +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> random swaps (contiguous) + + + Deque<Int> random swaps (discontiguous) + + + Array<Int> random swaps + + +
+
+
+ 06 partitioning around middle +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> partitioning around middle (contiguous) + + + Deque<Int> partitioning around middle (discontiguous) + + + Array<Int> partitioning around middle + + +
+
+
+ 07 sort +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> sort (contiguous) + + + Deque<Int> sort (discontiguous) + + + Array<Int> sort + + +
+
+
+ 08 append individual integers +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> append + + + Deque<Int> append, reserving capacity + + + Array<Int> append + + + Array<Int> append, reserving capacity + + +
+
+
+ 09 prepend individual integers +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + 10 µs + 10 µs + + 100 µs + 100 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> prepend + + + Deque<Int> prepend, reserving capacity + + + Array<Int> prepend + + + Array<Int> prepend, reserving capacity + + +
+
+
+ 10 random insertions +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + 10 µs + 10 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> random insertions + + + Array<Int> random insertions + + +
+
+
+ 11 removeFirst +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + 10 µs + 10 µs + + 100 µs + 100 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> removeFirst (contiguous) + + + Deque<Int> removeFirst (discontiguous) + + + Array<Int> removeFirst + + +
+
+
+ 12 removeLast +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> removeLast (contiguous) + + + Deque<Int> removeLast (discontiguous) + + + Array<Int> removeLast + + +
+
+
+ 13 random removals +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + 10 µs + 10 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Deque<Int> random removals (contiguous) + + + Deque<Int> random removals (discontiguous) + + + Array<Int> random removals + + +
+
+
+
+
+ Deque vs std::deque vs VecDeque vs RigidDeque vs UniqueDeque +
+
+ 01 init from buffer of integers +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 10 ps + 10 ps + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> constructor from buffer + + + VecDeque<isize> constructor from buffer + + + Deque<Int> init from unsafe buffer + + +
+
+
+ 02 sequential iteration +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> sequential iteration + + + VecDeque<isize> sequential iteration + + + Deque<Int> sequential iteration (contiguous, iterator) + + + Deque<Int> sequential iteration (contiguous, indices) + + + Deque<Int> sequential iteration (discontiguous, iterator) + + + Deque<Int> sequential iteration (discontiguous, indices) + + + UniqueDeque<Int> sequential iteration + + +
+
+
+ 03 random-access offset lookups +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + + + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> random-access offset lookups (operator []) + + + std::deque<intptr_t> at, random offsets + + + Deque<Int> subscript get, random offsets (contiguous) + + + Deque<Int> subscript get, random offsets (discontiguous) + + +
+
+
+ 04 append individual integers +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> push_back + + + VecDeque<isize> push_back + + + Deque<Int> append + + + UniqueDeque<Int> append + + +
+
+
+ 05 append individual integers, reserving capacity +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 10 ps + 10 ps + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + VecDeque<isize> push_back, reserving capacity + + + Deque<Int> append, reserving capacity + + + RigidDeque<Int> append, reserving capacity + + + UniqueDeque<Int> append, reserving capacity + + +
+
+
+ 06 prepend individual integers +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> push_front + + + VecDeque<isize> push_front + + + Deque<Int> prepend + + + UniqueDeque<Int> prepend + + +
+
+
+ 07 prepend individual integers, reserving capacity +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 100 ps + 100 ps + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + VecDeque<isize> push_front, reserving capacity + + + Deque<Int> prepend, reserving capacity + + + RigidDeque<Int> prepend, reserving capacity + + + UniqueDeque<Int> prepend, reserving capacity + + +
+
+
+ 08 random insertions +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + 10 µs + 10 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> random insertions + + + VecDeque<isize> random insertions + + + Deque<Int> random insertions + + + UniqueDeque<Int> random insertions + + +
+
+
+ 09 removeFirst +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> pop_front + + + Deque<Int> removeFirst (contiguous) + + + Deque<Int> removeFirst (discontiguous) + + +
+
+
+ 10 removeLast +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> pop_back + + + Deque<Int> removeLast (contiguous) + + + Deque<Int> removeLast (discontiguous) + + +
+
+
+ 11 random removals +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + 1 µs + 1 µs + + 10 µs + 10 µs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> random removals + + + Deque<Int> random removals (contiguous) + + + Deque<Int> random removals (discontiguous) + + +
+
+
+ 12 sort +
+ + + Average per-element processing time over input size (bands: min, mean, mean + 2stddev) + swift-collections-benchmark + + 1 + + 2 + + 4 + + 8 + + 16 + + 32 + + 64 + + 128 + + 256 + + 512 + + 1k + + 2k + + 4k + + 8k + + 16k + + 32k + + 64k + + 128k + + 256k + + 1 ns + 1 ns + + 10 ns + 10 ns + + 100 ns + 100 ns + + + + + + + + + + + + + + + + + + + + + + + + + std::deque<intptr_t> sort + + + Deque<Int> sort (contiguous) + + + Deque<Int> sort (discontiguous) + + +
+
+
+
+
+
+ + diff --git a/Package.swift b/Package.swift index 8a1903e5..f961f974 100644 --- a/Package.swift +++ b/Package.swift @@ -266,7 +266,7 @@ let targets: [CustomTarget] = [ .target( kind: .exported, name: "DequeModule", - dependencies: ["InternalCollectionsUtilities"], + dependencies: ["ContainersPreview", "InternalCollectionsUtilities"], exclude: ["CMakeLists.txt"]), .target( kind: .test, diff --git a/Sources/ContainersPreview/Mut.swift b/Sources/ContainersPreview/Mut.swift index 983b6314..9fab3986 100644 --- a/Sources/ContainersPreview/Mut.swift +++ b/Sources/ContainersPreview/Mut.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if compiler(>=6.2) import Builtin // FIXME: A better name for the generic argument. @@ -79,7 +79,7 @@ extension Mut where T: ~Copyable { unsafeAddress { unsafe UnsafePointer(_pointer) } - + @_transparent @_lifetime(self: copy self) unsafeMutableAddress { diff --git a/Sources/ContainersPreview/Ref.swift b/Sources/ContainersPreview/Ref.swift index ab7edecc..bc6ffae4 100644 --- a/Sources/ContainersPreview/Ref.swift +++ b/Sources/ContainersPreview/Ref.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if compiler(>=6.2) import Builtin @frozen diff --git a/Sources/DequeModule/Deque._UnsafeHandle.swift b/Sources/DequeModule/Deque._UnsafeHandle.swift index 8302b635..c44333af 100644 --- a/Sources/DequeModule/Deque._UnsafeHandle.swift +++ b/Sources/DequeModule/Deque._UnsafeHandle.swift @@ -172,7 +172,7 @@ extension Deque._UnsafeHandle { extension Deque._UnsafeHandle { @inlinable - internal func segments() -> _UnsafeWrappedBuffer { + internal func segments() -> _UnsafeDequeSegments { let wrap = capacity - startSlot.position if count <= wrap { return .init(start: ptr(at: startSlot), count: count) @@ -184,7 +184,7 @@ extension Deque._UnsafeHandle { @inlinable internal func segments( forOffsets offsets: Range - ) -> _UnsafeWrappedBuffer { + ) -> _UnsafeDequeSegments { assert(offsets.lowerBound >= 0 && offsets.upperBound <= count) let lower = slot(forOffset: offsets.lowerBound) let upper = slot(forOffset: offsets.upperBound) @@ -197,7 +197,7 @@ extension Deque._UnsafeHandle { @inlinable @inline(__always) - internal func mutableSegments() -> _UnsafeMutableWrappedBuffer { + internal func mutableSegments() -> _UnsafeMutableDequeSegments { assertMutable() return .init(mutating: segments()) } @@ -206,7 +206,7 @@ extension Deque._UnsafeHandle { @inline(__always) internal func mutableSegments( forOffsets range: Range - ) -> _UnsafeMutableWrappedBuffer { + ) -> _UnsafeMutableDequeSegments { assertMutable() return .init(mutating: segments(forOffsets: range)) } @@ -214,7 +214,7 @@ extension Deque._UnsafeHandle { extension Deque._UnsafeHandle { @inlinable - internal func availableSegments() -> _UnsafeMutableWrappedBuffer { + internal func availableSegments() -> _UnsafeMutableDequeSegments { assertMutable() let endSlot = self.endSlot guard count < capacity else { return .init(start: ptr(at: endSlot), count: 0) } @@ -224,8 +224,6 @@ extension Deque._UnsafeHandle { } } - - extension Deque._UnsafeHandle { @inlinable @discardableResult @@ -269,8 +267,6 @@ extension Deque._UnsafeHandle { } } - - extension Deque._UnsafeHandle { /// Copy elements into a new storage instance without changing capacity or /// layout. @@ -498,7 +494,7 @@ extension Deque._UnsafeHandle { internal func mutableWrappedBuffer( between start: Slot, and end: Slot - ) -> _UnsafeMutableWrappedBuffer { + ) -> _UnsafeMutableDequeSegments { assert(start.position <= capacity) assert(end.position <= capacity) if start < end { @@ -523,7 +519,7 @@ extension Deque._UnsafeHandle { internal func openGap( ofSize gapSize: Int, atOffset offset: Int - ) -> _UnsafeMutableWrappedBuffer { + ) -> _UnsafeMutableDequeSegments { assertMutable() assert(offset >= 0 && offset <= self.count) assert(self.count + gapSize <= capacity) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift new file mode 100644 index 00000000..e22e0a99 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -0,0 +1,150 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedAppend(_ newElement: consuming Element) { + _handle.uncheckedAppend(newElement) + } + + /// Adds an element to the end of the deque. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this triggers a runtime error. + /// + /// - Parameter item: The element to append to the collection. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public mutating func append(_ newElement: consuming Element) { + precondition(!isFull, "RigidDeque is full") + uncheckedAppend(newElement) + } + + /// Adds an element to the end of the deque, if possible. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this returns the given item without appending it; otherwise it + /// returns nil. + /// + /// - Parameter item: The element to append to the collection. + /// - Returns: `item` if the deque is full; otherwise nil. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public mutating func pushLast(_ item: consuming Element) -> Element? { + // FIXME: Remove this in favor of a standard algorithm. + if isFull { return item } + append(item) + return nil + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*where Element: Copyable*/ { + /// Copies the elements of a buffer to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// buffer, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`newElements.count`) + @_alwaysEmitIntoClient + public mutating func append( + copying newElements: UnsafeBufferPointer + ) { + precondition( + newElements.count <= freeCapacity, + "RigidDeque capacity overflow") + guard newElements.count > 0 else { return } + _handle.uncheckedAppend(contentsOf: newElements) + } + + /// Copies the elements of a buffer to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// buffer, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`newElements.count`) + @_alwaysEmitIntoClient + public mutating func append( + copying items: UnsafeMutableBufferPointer + ) { + unsafe self.append(copying: UnsafeBufferPointer(items)) + } + + /// Copies the elements of a span to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// span, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: A span whose contents to copy into the deque. + /// + /// - Complexity: O(`newElements.count`) + @_alwaysEmitIntoClient + public mutating func append(copying items: Span) { + unsafe items.withUnsafeBufferPointer { source in + unsafe self.append(copying: source) + } + } + + @_alwaysEmitIntoClient + @inline(__always) + internal mutating func _append>( + prefixOf items: S + ) -> S.Iterator { + let (it, c) = _handle.availableSegments().initialize(fromSequencePrefix: items) + _handle.count += c + return it + } + + /// Copies the elements of a sequence to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func append(copying newElements: some Sequence) { + let done: Void? = newElements.withContiguousStorageIfAvailable { buffer in + unsafe self.append(copying: buffer) + return + } + if done != nil { return } + + var it = self._append(prefixOf: newElements) + precondition(it.next() == nil, "RigidDeque capacity overflow") + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift new file mode 100644 index 00000000..0202b0f9 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + public init(capacity: Int) { + self.init(_handle: .allocate(capacity: capacity)) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*where Element: Copyable*/ { + /// Creates a new deque containing the specified number of a single, + /// repeated value. + /// + /// - Parameters: + /// - repeatedValue: The element to repeat. + /// - count: The number of times to repeat the value passed in the + /// `repeating` parameter. `count` must be zero or greater. + /// + /// - Complexity: O(`count`) + public init(repeating repeatedValue: Element, count: Int) { + self.init(capacity: count) + _handle.mutableBuffer.initialize(repeating: repeatedValue) + _handle.count = count + } + + /// Creates a new deque with the specified capacity, holding a copy + /// of the contents of a given sequence. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque. + /// - contents: The sequence whose contents to copy into the new deque. + /// The sequence must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init( + capacity: Int, + copying contents: some Sequence + ) { + self.init(capacity: capacity) + self.append(copying: contents) + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift new file mode 100644 index 00000000..018806ed --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + public mutating func insert(_ newElement: consuming Element, at index: Int) { + precondition(!isFull, "RigidDeque is full") + precondition(index >= 0 && index <= count, + "Can't insert element at invalid index") + _handle.uncheckedInsert(newElement, at: index) + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift new file mode 100644 index 00000000..4ee3b0e8 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedPrepend(_ newElement: consuming Element) { + _handle.uncheckedPrepend(newElement) + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func prepend(_ newElement: consuming Element) { + precondition(!isFull, "RigidDeque is full") + uncheckedPrepend(newElement) + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift new file mode 100644 index 00000000..51104a35 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @discardableResult + @_alwaysEmitIntoClient + @_transparent + public mutating func remove(at index: Int) -> Element { + precondition(index >= 0 && index < count, + "Can't remove element at invalid index") + return _handle.uncheckedRemove(at: index) + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeSubrange(_ bounds: Range) { + precondition(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index range out of bounds") + _handle.uncheckedRemove(offsets: bounds) + } + + @discardableResult + @_alwaysEmitIntoClient + @_transparent + public mutating func removeFirst() -> Element { + precondition(!isEmpty, "Cannot remove first element of an empty RigidDeque") + return _handle.uncheckedRemoveFirst() + } + + @discardableResult + @_alwaysEmitIntoClient + @_transparent + public mutating func removeLast() -> Element { + precondition(!isEmpty, "Cannot remove last element of an empty RigidDeque") + return _handle.uncheckedRemoveLast() + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeFirst(_ n: Int) { + precondition(n >= 0, "Can't remove a negative number of elements") + precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") + _handle.uncheckedRemoveFirst(n) + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeLast(_ n: Int) { + precondition(n >= 0, "Can't remove a negative number of elements") + precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") + _handle.uncheckedRemoveLast(n) + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeAll() { + _handle.uncheckedRemoveAll() + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func popFirst() -> Element? { + guard !isEmpty else { return nil } + return _handle.uncheckedRemoveFirst() + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func popLast() -> Element? { + guard !isEmpty else { return nil } + return _handle.uncheckedRemoveLast() + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index ec321103..1a958d71 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -27,13 +27,165 @@ public struct RigidDeque: ~Copyable { #else @available(SwiftStdlib 5.0, *) -@safe @frozen +@safe public struct RigidDeque: ~Copyable { + @usableFromInline + internal typealias _Slot = _DequeSlot + @usableFromInline + internal typealias _UnsafeHandle = _UnsafeDequeHandle + + @usableFromInline + internal var _handle: _UnsafeHandle + + @_alwaysEmitIntoClient + @_transparent + internal init(_handle: consuming _UnsafeHandle) { + self._handle = _handle + } + + @_alwaysEmitIntoClient + @_transparent + deinit { + _handle.dispose() + } } @available(SwiftStdlib 5.0, *) extension RigidDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_INTERNAL_CHECKS + @usableFromInline @inline(never) @_effects(releasenone) + internal func _checkInvariants() { + _handle._checkInvariants() + } +#else + @inlinable @inline(__always) + internal func _checkInvariants() {} +#endif // COLLECTIONS_INTERNAL_CHECKS +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @usableFromInline + internal var description: String { + _handle.description + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + @_lifetime(borrow self) + internal func _span(over slots: Range<_DequeSlot>) -> Span { + let span = Span(_unsafeElements: _handle.buffer(for: slots)) + return _overrideLifetime(span, borrowing: self) + } + + @_alwaysEmitIntoClient + @_transparent + @_lifetime(&self) + internal mutating func _mutableSpan(over slots: Range<_DequeSlot>) -> MutableSpan { + let span = MutableSpan(_unsafeElements: _handle.mutableBuffer(for: slots)) + return _overrideLifetime(span, mutating: &self) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + public typealias Index = Int + + @_alwaysEmitIntoClient + @_transparent + public var isEmpty: Bool { _handle.count == 0 } + + @_alwaysEmitIntoClient + @_transparent + public var count: Int { _handle.count } + + @_alwaysEmitIntoClient + @_transparent + public var startIndex: Int { 0 } + + @_alwaysEmitIntoClient + @_transparent + public var endIndex: Int { _handle.count } + + @_alwaysEmitIntoClient + @_transparent + @_lifetime(borrow self) + public func borrowElement(at index: Int) -> Ref { + precondition(index >= 0 && index < count, "Index out of bounds") + let slot = _handle.slot(forOffset: index) + return Ref(unsafeAddress: _handle.ptr(at: slot), borrowing: self) + } + + @_alwaysEmitIntoClient + @_transparent + @_lifetime(&self) + public mutating func mutateElement(at index: Int) -> Mut { + precondition(index >= 0 && index < count, "Index out of bounds") + let slot = _handle.slot(forOffset: index) + return Mut(unsafeAddress: _handle.mutablePtr(at: slot), mutating: &self) + } + + @_alwaysEmitIntoClient + public subscript(position: Int) -> Element { + @inline(__always) + @_transparent + unsafeAddress { + precondition(position >= 0 && position < count, "Index out of bounds") + let slot = _handle.slot(forOffset: position) + return _handle.ptr(at: slot) + } + @inline(__always) + @_transparent + unsafeMutableAddress { + precondition(position >= 0 && position < count, "Index out of bounds") + let slot = _handle.slot(forOffset: position) + return _handle.mutablePtr(at: slot) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + public var capacity: Int { _handle.capacity } + + @_alwaysEmitIntoClient + @_transparent + public var freeCapacity: Int { capacity - count } + + @_alwaysEmitIntoClient + @_transparent + public var isFull: Bool { count == capacity } + + @_alwaysEmitIntoClient + @_transparent + public mutating func resize(to newCapacity: Int) { + _handle.reallocate(capacity: newCapacity) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque { + @_alwaysEmitIntoClient + @_transparent + internal func _copy() -> Self { + RigidDeque(_handle: _handle.allocateCopy()) + } + + @_alwaysEmitIntoClient + @_transparent + internal func _copy(capacity: Int) -> Self { + RigidDeque(_handle: _handle.allocateCopy(capacity: capacity)) + } +} + #endif // compiler(<6.2) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift new file mode 100644 index 00000000..47b7fc02 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Adds an element to the end of the deque. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameter item: The element to append to the collection. + /// + /// - Complexity: O(1) as amortized over many invocations on the same deque. + @_alwaysEmitIntoClient + @_transparent + public mutating func append(_ newElement: consuming Element) { + _ensureFreeCapacity(1) + _storage.uncheckedAppend(newElement) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*where Element: Copyable*/ { + /// Copies the elements of a buffer to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items + /// in the source buffer, then this automatically grows the deque's + /// capacity, using a geometric growth rate. + /// + /// - Parameters + /// - newElements: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`newElements.count`) when amortized over many + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func append( + copying newElements: UnsafeBufferPointer + ) { + _ensureFreeCapacity(newElements.count) + unsafe _storage.append(copying: newElements) + } + + /// Copies the elements of a buffer to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold enough elements, + /// then this reallocates the deque's storage to extend its capacity, using + /// a geometric growth rate. + /// + /// - Parameters + /// - newElements: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`newElements.count`) when amortized over many + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func append( + copying newElements: UnsafeMutableBufferPointer + ) { + unsafe self.append(copying: UnsafeBufferPointer(newElements)) + } + + /// Copies the elements of a span to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold enough elements, + /// then this reallocates the deque's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - newElements: A span whose contents to copy into the deque. + /// + /// - Complexity: O(`newElements.count`) when amortized over many + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func append(copying newElements: Span) { + _ensureFreeCapacity(newElements.count) + _storage.append(copying: newElements) + } + + /// Copies the elements of a sequence to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold enough elements, + /// then this reallocates the deque's storage to extend its capacity, using + /// a geometric growth rate. If the input sequence does not provide a correct + /// estimate of its count, then the deque's storage may need to be resized + /// more than once. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`, when + /// amortized over many invocations over the same deque. + @_alwaysEmitIntoClient + public mutating func append(copying newElements: some Sequence) { + let done: Void? = newElements.withContiguousStorageIfAvailable { buffer in + _ensureFreeCapacity(buffer.count) + unsafe _storage.append(copying: buffer) + return + } + if done != nil { return } + + _ensureFreeCapacity(newElements.underestimatedCount) + var it = _storage._append(prefixOf: newElements) + while let item = it.next() { + _ensureFreeCapacity(1) + _storage.append(item) + } + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift new file mode 100644 index 00000000..36d04b12 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + public init() { + _storage = .init(capacity: 0) + } + + @_alwaysEmitIntoClient + @_transparent + public init(capacity: Int) { + _storage = .init(capacity: capacity) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*where Element: Copyable*/ { + /// Creates a new deque with the specified initial capacity, holding a copy + /// of the contents of a given sequence. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque, or nil to allocate + /// just enough capacity to store the contents. + /// - contents: The sequence whose contents to copy into the new deque. + @_alwaysEmitIntoClient + @inline(__always) + public init( + capacity: Int? = nil, + copying contents: some Sequence + ) { + self.init(capacity: capacity ?? 0) + self.append(copying: contents) + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift new file mode 100644 index 00000000..d6e9c5c3 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + public mutating func insert(_ newElement: consuming Element, at index: Int) { + _ensureFreeCapacity(1) + _storage.insert(newElement, at: index) + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift new file mode 100644 index 00000000..4e493a0d --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + public mutating func prepend(_ newElement: consuming Element) { + _ensureFreeCapacity(1) + _storage.uncheckedPrepend(newElement) + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift new file mode 100644 index 00000000..41e1eebd --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + @discardableResult + @_alwaysEmitIntoClient + @_transparent + public mutating func remove(at index: Int) -> Element { + _storage.remove(at: index) + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeSubrange(_ bounds: Range) { + _storage.removeSubrange(bounds) + } + + @discardableResult + @_alwaysEmitIntoClient + @_transparent + public mutating func removeFirst() -> Element { + _storage.removeFirst() + } + + @discardableResult + @_alwaysEmitIntoClient + @_transparent + public mutating func removeLast() -> Element { + _storage.removeLast() + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeFirst(_ n: Int) { + _storage.removeFirst(n) + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeLast(_ n: Int) { + _storage.removeLast(n) + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func removeAll() { + _storage.removeAll() + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func popFirst() -> Element? { + _storage.popFirst() + } + + @_alwaysEmitIntoClient + @_transparent + public mutating func popLast() -> Element? { + _storage.popLast() + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift index 31cd6e61..c70dc20c 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -17,8 +17,8 @@ import ContainersPreview #if compiler(<6.2) @frozen -@available(*, unavailable, message: "RigidDeque requires a Swift 6.2 toolchain") -public struct RigidDeque: ~Copyable { +@available(*, unavailable, message: "UniqueDeque requires a Swift 6.2 toolchain") +public struct UniqueDeque: ~Copyable { public init() { fatalError() } @@ -27,13 +27,117 @@ public struct RigidDeque: ~Copyable { #else @available(SwiftStdlib 5.0, *) -@safe @frozen +@safe public struct UniqueDeque: ~Copyable { - + @usableFromInline + internal var _storage: RigidDeque } @available(SwiftStdlib 5.0, *) extension UniqueDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + public typealias Index = Int + + /// A Boolean value indicating whether this deque contains no elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public var isEmpty: Bool { _storage.isEmpty } + + /// The number of elements in this deque. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public var count: Int { _storage.count } + + /// The position of the first element in a nonempty deque. This is always zero. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public var startIndex: Int { _storage.startIndex } + + /// The deque’s "past the end” position—that is, the position one greater than + /// the last valid subscript argument. This is always equal to deque's count. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public var endIndex: Int { _storage.endIndex } + + /// The range of indices that are valid for subscripting the deque. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var indices: Range { unsafe Range(uncheckedBounds: (0, count)) } + + @_alwaysEmitIntoClient + @_transparent + @_lifetime(borrow self) + public func borrowElement(at index: Int) -> Ref { + _storage.borrowElement(at: index) + } + + @_alwaysEmitIntoClient + @_transparent + @_lifetime(&self) + public mutating func mutateElement(at index: Int) -> Mut { + _storage.mutateElement(at: index) + } + + @_alwaysEmitIntoClient + public subscript(position: Int) -> Element { + @inline(__always) + @_transparent + unsafeAddress { + precondition(position >= 0 && position < count, "Index out of bounds") + let slot = _storage._handle.slot(forOffset: position) + return _storage._handle.ptr(at: slot) + } + @inline(__always) + @_transparent + unsafeMutableAddress { + precondition(position >= 0 && position < count, "Index out of bounds") + let slot = _storage._handle.slot(forOffset: position) + return _storage._handle.mutablePtr(at: slot) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal var _capacity: Int { _storage.capacity } + + @_alwaysEmitIntoClient + @_transparent + internal var _freeCapacity: Int { _storage.freeCapacity } + + @_alwaysEmitIntoClient + @_transparent + internal var _isFull: Bool { _storage.isFull } + + @inlinable + internal mutating func _grow(to minimumCapacity: Int) { + if _fastPath(minimumCapacity <= _capacity) { + return + } + + let c = Swift.max(minimumCapacity, 7 * _capacity / 4) + _storage.resize(to: c) + } + + @inlinable + internal mutating func _ensureFreeCapacity(_ freeCapacity: Int) { + _grow(to: count + freeCapacity) + } +} + #endif // compiler(<6.2) diff --git a/Sources/DequeModule/_DequeSlot.swift b/Sources/DequeModule/_DequeSlot.swift index 2d281cb9..22365c9a 100644 --- a/Sources/DequeModule/_DequeSlot.swift +++ b/Sources/DequeModule/_DequeSlot.swift @@ -15,8 +15,8 @@ internal struct _DequeSlot { @usableFromInline internal var position: Int - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent init(at position: Int) { assert(position >= 0) self.position = position @@ -24,18 +24,18 @@ internal struct _DequeSlot { } extension _DequeSlot { - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal static var zero: Self { Self(at: 0) } - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal func advanced(by delta: Int) -> Self { Self(at: position &+ delta) } - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal func orIfZero(_ value: Int) -> Self { guard position > 0 else { return Self(at: value) } return self @@ -50,23 +50,29 @@ extension _DequeSlot: CustomStringConvertible { } extension _DequeSlot: Equatable { - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent static func ==(left: Self, right: Self) -> Bool { left.position == right.position } } extension _DequeSlot: Comparable { - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent static func <(left: Self, right: Self) -> Bool { left.position < right.position } } extension Range where Bound == _DequeSlot { - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal var _count: Int { upperBound.position - lowerBound.position } + + @_alwaysEmitIntoClient + @_transparent + internal var _offsets: Range { + Range(uncheckedBounds: (lowerBound.position, upperBound.position)) + } } diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift new file mode 100644 index 00000000..6a6a5b93 --- /dev/null +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -0,0 +1,980 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +@frozen +@usableFromInline +internal struct _UnsafeDequeHandle: ~Copyable { + @usableFromInline + internal typealias Slot = _DequeSlot + + @usableFromInline + internal var _buffer: UnsafeMutableBufferPointer + + @usableFromInline + internal var count: Int + + @usableFromInline + internal var startSlot: Slot + + @_alwaysEmitIntoClient + @_transparent + internal init( + buffer: UnsafeMutableBufferPointer, + count: Int, + startSlot: _DequeSlot + ) { + self._buffer = buffer + self.count = count + self.startSlot = startSlot + } + + @inlinable + internal consuming func dispose() { + _checkInvariants() + self.mutableSegments().deinitialize() + _buffer.deallocate() + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal static var empty: Self { + Self(buffer: ._empty, count: 0, startSlot: .zero) + } + + @_alwaysEmitIntoClient + @_transparent + internal static func allocate( + capacity: Int + ) -> Self { + Self( + buffer: capacity > 0 ? .allocate(capacity: capacity) : ._empty, + count: 0, + startSlot: .zero) + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { +#if COLLECTIONS_INTERNAL_CHECKS + @usableFromInline @inline(never) @_effects(releasenone) + internal func _checkInvariants() { + precondition(capacity >= 0) + precondition(count >= 0 && count <= capacity) + precondition(startSlot.position >= 0 && startSlot.position <= capacity) + } +#else + @inlinable @inline(__always) + internal func _checkInvariants() {} +#endif // COLLECTIONS_INTERNAL_CHECKS +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @usableFromInline + internal var description: String { + "(capacity: \(capacity), count: \(count), start: \(startSlot))" + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal var _baseAddress: UnsafeMutablePointer { + _buffer.baseAddress.unsafelyUnwrapped + } + + @_alwaysEmitIntoClient + @_transparent + internal var capacity: Int { + _buffer.count + } +} + +// MARK: Test initializer + +extension _UnsafeDequeHandle where Element: ~Copyable { + internal static func allocate( + capacity: Int, + startSlot: Slot, + count: Int, + generator: (Int) -> Element + ) -> Self { + precondition(capacity >= 0) + precondition( + startSlot.position >= 0 && + (startSlot.position < capacity || (capacity == 0 && startSlot.position == 0))) + precondition(count <= capacity) + + var h = Self.allocate(capacity: capacity) + h.count = count + h.startSlot = startSlot + if h.count > 0 { + let segments = h.mutableSegments() + let c = segments.first.count + for i in 0 ..< c { + segments.first.initializeElement(at: i, to: generator(i)) + } + if let second = segments.second { + for i in c ..< h.count { + second.initializeElement(at: i - c, to: generator(i)) + } + } + } + return h + } +} + +// MARK: Slots + +extension _UnsafeDequeHandle where Element: ~Copyable { + /// The slot immediately following the last valid one. (`endSlot` refers to + /// the valid slot corresponding to `endIndex`, which is a different thing + /// entirely.) + @_alwaysEmitIntoClient + @_transparent + internal var limSlot: Slot { + Slot(at: capacity) + } + + @_alwaysEmitIntoClient + @_transparent + internal func slot(after slot: Slot) -> Slot { + assert(slot.position < capacity) + let position = slot.position + 1 + if position >= capacity { + return Slot(at: 0) + } + return Slot(at: position) + } + + @_alwaysEmitIntoClient + @_transparent + internal func slot(before slot: Slot) -> Slot { + assert(slot.position < capacity) + if slot.position == 0 { return Slot(at: capacity - 1) } + return Slot(at: slot.position - 1) + } + + @_alwaysEmitIntoClient + @_transparent + internal func slot(_ slot: Slot, offsetBy delta: Int) -> Slot { + assert(slot.position <= capacity) + let position = slot.position + delta + if delta >= 0 { + if position >= capacity { return Slot(at: position - capacity) } + } else { + if position < 0 { return Slot(at: position + capacity) } + } + return Slot(at: position) + } + + @_alwaysEmitIntoClient + @_transparent + internal var endSlot: Slot { + slot(startSlot, offsetBy: count) + } + + /// Return the storage slot corresponding to the specified offset, which may + /// or may not address an existing element. + @_alwaysEmitIntoClient + @_transparent + internal func slot(forOffset offset: Int) -> Slot { + assert(offset >= 0) + assert(offset <= capacity) // Not `count`! + + // Note: The use of wrapping addition/subscription is justified here by the + // fact that `offset` is guaranteed to fall in the range `0 ..< capacity`. + // Eliminating the overflow checks leads to a measurable speedup for + // random-access subscript operations. (Up to 2x on some microbenchmarks.) + let position = startSlot.position &+ offset + guard position < capacity else { return Slot(at: position &- capacity) } + return Slot(at: position) + } +} + +// MARK: Element Access + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal func ptr(at slot: Slot) -> UnsafePointer { + assert(slot.position >= 0 && slot.position <= capacity) + return UnsafePointer(_baseAddress + slot.position) + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func mutablePtr( + at slot: Slot + ) -> UnsafeMutablePointer { + assert(slot.position >= 0 && slot.position <= capacity) + return _baseAddress + slot.position + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @inlinable + internal subscript(offset offset: Int) -> Element { + @inline(__always) + _read { + precondition(offset >= 0 && offset < count, "Index out of bounds") + let slot = slot(forOffset: offset) + yield ptr(at: slot).pointee + } + @inline(__always) + _modify { + precondition(offset >= 0 && offset < count, "Index out of bounds") + let slot = slot(forOffset: offset) + yield &mutablePtr(at: slot).pointee + } + } +} + +// MARK: Access to contiguous regions + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal var mutableBuffer: UnsafeMutableBufferPointer { + mutating get { + _buffer + } + } + + @_alwaysEmitIntoClient + @_transparent + internal func buffer(for range: Range) -> UnsafeBufferPointer { + assert(range.upperBound.position <= capacity) + return .init(_buffer._extracting(unchecked: range._offsets)) + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func mutableBuffer( + for range: Range + ) -> UnsafeMutableBufferPointer { + assert(range.upperBound.position <= capacity) + return _buffer._extracting(unchecked: range._offsets) + } +} + +extension _UnsafeDequeHandle { + @discardableResult + @_alwaysEmitIntoClient + @_transparent + internal mutating func initialize( + at start: Slot, + from source: UnsafeBufferPointer + ) -> Slot { + assert(start.position + source.count <= capacity) + guard source.count > 0 else { return start } + mutablePtr(at: start).initialize(from: source.baseAddress!, count: source.count) + return Slot(at: start.position + source.count) + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @discardableResult + @_alwaysEmitIntoClient + @_transparent + internal mutating func moveInitialize( + at start: Slot, + from source: UnsafeMutableBufferPointer + ) -> Slot { + assert(start.position + source.count <= capacity) + guard source.count > 0 else { return start } + mutablePtr(at: start) + .moveInitialize(from: source.baseAddress!, count: source.count) + return Slot(at: start.position + source.count) + } +} + +// MARK: Access to Segments + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal func segments() -> _UnsafeDequeSegments { + guard _buffer.baseAddress != nil else { + return .init(._empty) + } + let wrap = capacity - startSlot.position + if count <= wrap { + return .init(start: ptr(at: startSlot), count: count) + } + return .init(first: ptr(at: startSlot), count: wrap, + second: ptr(at: .zero), count: count - wrap) + } + + @_alwaysEmitIntoClient + @_transparent + internal func segments( + forOffsets offsets: Range + ) -> _UnsafeDequeSegments { + assert(offsets.lowerBound >= 0 && offsets.upperBound <= count) + guard _buffer.baseAddress != nil else { + return .init(._empty) + } + let lower = slot(forOffset: offsets.lowerBound) + let upper = slot(forOffset: offsets.upperBound) + if offsets.count == 0 || lower < upper { + return .init(start: ptr(at: lower), count: offsets.count) + } + return .init(first: ptr(at: lower), count: capacity - lower.position, + second: ptr(at: .zero), count: upper.position) + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func mutableSegments() -> _UnsafeMutableDequeSegments { + .init(mutating: segments()) + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func mutableSegments( + forOffsets range: Range + ) -> _UnsafeMutableDequeSegments { + .init(mutating: segments(forOffsets: range)) + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func mutableSegments( + between start: Slot, + and end: Slot + ) -> _UnsafeMutableDequeSegments { + assert(start.position <= capacity) + assert(end.position <= capacity) + if start < end { + return .init( + start: mutablePtr(at: start), + count: end.position - start.position) + } + return .init( + first: mutablePtr(at: start), count: capacity - start.position, + second: mutablePtr(at: .zero), count: end.position) + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func availableSegments() -> _UnsafeMutableDequeSegments { + guard _buffer.baseAddress != nil else { + return .init(._empty) + } + let endSlot = self.endSlot + guard count < capacity else { return .init(start: mutablePtr(at: endSlot), count: 0) } + if endSlot < startSlot { return .init(mutableBuffer(for: endSlot ..< startSlot)) } + return .init(mutableBuffer(for: endSlot ..< limSlot), + mutableBuffer(for: .zero ..< startSlot)) + } +} + +// MARK: Wholesale Copying and Reallocation + +extension _UnsafeDequeHandle { + /// Copy elements in `handle` into a newly allocated handle without changing its + /// capacity or layout. + @_alwaysEmitIntoClient + @_transparent + internal borrowing func allocateCopy() -> Self { + var result: _UnsafeDequeHandle = .allocate(capacity: self.capacity) + result.count = self.count + result.startSlot = self.startSlot + let src = self.segments() + result.initialize(at: self.startSlot, from: src.first) + if let second = src.second { + result.initialize(at: .zero, from: second) + } + return result + } + + /// Copy elements in `handle` into a newly allocated handle with the specified + /// minimum capacity. This operation does not preserve layout. + @_alwaysEmitIntoClient + @_transparent + internal borrowing func allocateCopy(capacity: Int) -> Self { + precondition(capacity >= self.count) + var result: _UnsafeDequeHandle = .allocate(capacity: capacity) + result.count = self.count + let src = self.segments() + let next = result.initialize(at: .zero, from: src.first) + if let second = src.second { + result.initialize(at: next, from: second) + } + return result + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func reallocate(capacity newCapacity: Int) { + precondition(newCapacity >= count) + guard newCapacity != capacity else { return } + + var new = _UnsafeDequeHandle.allocate(capacity: newCapacity) + let source = self.mutableSegments() + let next = new.moveInitialize(at: .zero, from: source.first) + if let second = source.second { + new.moveInitialize(at: next, from: second) + } + _buffer.deallocate() + _buffer = new._buffer + startSlot = .zero + } +} + +// MARK: Iteration + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal func slotRange(following offset: inout Int) -> Range { + precondition(offset >= 0 && offset <= count, "Index out of bounds") + guard _buffer.baseAddress != nil else { + return Range(uncheckedBounds: (Slot.zero, Slot.zero)) + } + let wrapOffset = Swift.min(capacity - startSlot.position, count) + + if offset < wrapOffset { + defer { offset += wrapOffset - offset } + return Range( + uncheckedBounds: (startSlot.advanced(by: offset), startSlot.advanced(by: wrapOffset))) + } + let lowerSlot = Slot.zero.advanced(by: offset - wrapOffset) + let upperSlot = lowerSlot.advanced(by: count - wrapOffset) + defer { offset += count - offset } + return Range(uncheckedBounds: (lower: lowerSlot, upper: upperSlot)) + } + + @_alwaysEmitIntoClient + @_transparent + internal func slotRange(preceding offset: inout Int) -> Range { + precondition(offset >= 0 && offset <= count, "Index out of bounds") + guard _buffer.baseAddress != nil else { + return Range(uncheckedBounds: (Slot.zero, Slot.zero)) + } + let wrapOffset = Swift.min(capacity - startSlot.position, count) + + if offset <= wrapOffset { + defer { offset = 0 } + return Range( + uncheckedBounds: (startSlot, startSlot.advanced(by: offset))) + } + let lowerSlot = Slot.zero + let upperSlot = lowerSlot.advanced(by: offset - wrapOffset) + defer { offset = wrapOffset } + return Range(uncheckedBounds: (lower: lowerSlot, upper: upperSlot)) + } +} + +// MARK: Replacement + +extension _UnsafeDequeHandle { + /// Replace the elements in `range` with `newElements`. The deque's count must + /// not change as a result of calling this function. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedReplaceInPlace( + inOffsets range: Range, + with newElements: C + ) where C.Element == Element { + assert(range.upperBound <= count) + assert(newElements.count == range.count) + guard !range.isEmpty else { return } + let target = mutableSegments(forOffsets: range) + target.assign(from: newElements) + } +} + +// MARK: Appending + +extension _UnsafeDequeHandle where Element: ~Copyable { + /// Append `element` to this buffer. The buffer must have enough free capacity + /// to insert one new element. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedAppend(_ element: consuming Element) { + assert(count < capacity) + mutablePtr(at: endSlot).initialize(to: element) + count += 1 + } +} + +extension _UnsafeDequeHandle { + /// Append the contents of `source` to this buffer. The buffer must have + /// enough free capacity to insert the new elements. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedAppend(contentsOf source: UnsafeBufferPointer) { + assert(count + source.count <= capacity) + guard source.count > 0 else { return } + let c = self.count + count += source.count + let gap = mutableSegments(forOffsets: c ..< count) + gap.initialize(from: source) + } +} + +// MARK: Prepending + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedPrepend(_ element: consuming Element) { + assert(count < capacity) + let slot = self.slot(before: startSlot) + mutablePtr(at: slot).initialize(to: element) + startSlot = slot + count += 1 + } +} + +extension _UnsafeDequeHandle { + /// Prepend the contents of `source` to this buffer. The buffer must have + /// enough free capacity to insert the new elements. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedPrepend(contentsOf source: UnsafeBufferPointer) { + assert(count + source.count <= capacity) + guard source.count > 0 else { return } + let oldStart = startSlot + let newStart = self.slot(startSlot, offsetBy: -source.count) + startSlot = newStart + count += source.count + + let gap = mutableSegments(between: newStart, and: oldStart) + gap.initialize(from: source) + } +} + +// MARK: Opening and Closing Gaps + +extension _UnsafeDequeHandle where Element: ~Copyable { + @discardableResult + @_alwaysEmitIntoClient + @_transparent + internal mutating func move( + from source: Slot, + to target: Slot, + count: Int + ) -> (source: Slot, target: Slot) { + assert(count >= 0) + assert(source.position + count <= self.capacity) + assert(target.position + count <= self.capacity) + guard count > 0 else { return (source, target) } + mutablePtr(at: target) + .moveInitialize(from: mutablePtr(at: source), count: count) + return (slot(source, offsetBy: count), slot(target, offsetBy: count)) + } + + /// Slide elements around so that there is a gap of uninitialized slots of + /// size `gapSize` starting at `offset`, and return a (potentially wrapped) + /// buffer holding the newly inserted slots. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + /// + /// - Parameter gapSize: The number of uninitialized slots to create. + /// - Parameter offset: The offset from the start at which the uninitialized + /// slots should start. + @_alwaysEmitIntoClient + @_transparent + internal mutating func openGap( + ofSize gapSize: Int, + atOffset offset: Int + ) -> _UnsafeMutableDequeSegments { + assert(offset >= 0 && offset <= self.count) + assert(self.count + gapSize <= capacity) + assert(gapSize > 0) + + let headCount = offset + let tailCount = count - offset + if tailCount <= headCount { + // Open the gap by sliding elements to the right. + + let originalEnd = self.slot(startSlot, offsetBy: count) + let newEnd = self.slot(startSlot, offsetBy: count + gapSize) + let gapStart = self.slot(forOffset: offset) + let gapEnd = self.slot(gapStart, offsetBy: gapSize) + + let sourceIsContiguous = gapStart <= originalEnd.orIfZero(capacity) + let targetIsContiguous = gapEnd <= newEnd.orIfZero(capacity) + + if sourceIsContiguous && targetIsContiguous { + // No need to deal with wrapping; we just need to slide + // elements after the gap. + + // Illustrated steps: (underscores mark eventual gap position) + // + // 0) ....ABCDE̲F̲G̲H..... EFG̲H̲.̲........ABCD .̲.......ABCDEFGH̲.̲ + // 1) ....ABCD.̲.̲.̲EFGH.. EF.̲.̲.̲GH......ABCD .̲H......ABCDEFG.̲.̲ + move(from: gapStart, to: gapEnd, count: tailCount) + } else if targetIsContiguous { + // The gap itself will be wrapped. + + // Illustrated steps: (underscores mark eventual gap position) + // + // 0) E̲FGH.........ABC̲D̲ + // 1) .̲..EFGH......ABC̲D̲ + // 2) .̲CDEFGH......AB.̲.̲ + assert(startSlot > originalEnd.orIfZero(capacity)) + move(from: .zero, to: Slot.zero.advanced(by: gapSize), count: originalEnd.position) + move(from: gapStart, to: gapEnd, count: capacity - gapStart.position) + } else if sourceIsContiguous { + // Opening the gap pushes subsequent elements across the wrap. + + // Illustrated steps: (underscores mark eventual gap position) + // + // 0) ........ABC̲D̲E̲FGH. + // 1) GH......ABC̲D̲E̲F... + // 2) GH......AB.̲.̲.̲CDEF + move(from: limSlot.advanced(by: -gapSize), to: .zero, count: newEnd.position) + move(from: gapStart, to: gapEnd, count: tailCount - newEnd.position) + } else { + // The rest of the items are wrapped, and will remain so. + + // Illustrated steps: (underscores mark eventual gap position) + // + // 0) GH.........AB̲C̲D̲EF + // 1) ...GH......AB̲C̲D̲EF + // 2) DEFGH......AB̲C̲.̲.. + // 3) DEFGH......A.̲.̲.̲BC + move(from: .zero, to: Slot.zero.advanced(by: gapSize), count: originalEnd.position) + move(from: limSlot.advanced(by: -gapSize), to: .zero, count: gapSize) + move(from: gapStart, to: gapEnd, count: tailCount - gapSize - originalEnd.position) + } + count += gapSize + return mutableSegments(between: gapStart, and: gapEnd.orIfZero(capacity)) + } + + // Open the gap by sliding elements to the left. + + let originalStart = self.startSlot + let newStart = self.slot(originalStart, offsetBy: -gapSize) + let gapEnd = self.slot(forOffset: offset) + let gapStart = self.slot(gapEnd, offsetBy: -gapSize) + + let sourceIsContiguous = originalStart <= gapEnd.orIfZero(capacity) + let targetIsContiguous = newStart <= gapStart.orIfZero(capacity) + + if sourceIsContiguous && targetIsContiguous { + // No need to deal with any wrapping. + + // Illustrated steps: (underscores mark eventual gap position) + // + // 0) ....A̲B̲C̲DEFGH... GH.........̲A̲B̲CDEF .̲A̲B̲CDEFGH.......̲.̲ + // 1) .ABC.̲.̲.̲DEFGH... GH......AB.̲.̲.̲CDEF .̲.̲.̲CDEFGH....AB.̲.̲ + move(from: originalStart, to: newStart, count: headCount) + } else if targetIsContiguous { + // The gap itself will be wrapped. + + // Illustrated steps: (underscores mark eventual gap position) + // + // 0) C̲D̲EFGH.........A̲B̲ + // 1) C̲D̲EFGH.....AB...̲.̲ + // 2) .̲.̲EFGH.....ABCD.̲.̲ + assert(originalStart >= newStart) + move(from: originalStart, to: newStart, count: capacity - originalStart.position) + move(from: .zero, to: limSlot.advanced(by: -gapSize), count: gapEnd.position) + } else if sourceIsContiguous { + // Opening the gap pushes preceding elements across the wrap. + + // Illustrated steps: (underscores mark eventual gap position) + // + // 0) .AB̲C̲D̲EFGH......... + // 1) ...̲C̲D̲EFGH.......AB + // 2) CD.̲.̲.̲EFGH.......AB + move(from: originalStart, to: newStart, count: capacity - newStart.position) + move(from: Slot.zero.advanced(by: gapSize), to: .zero, count: gapStart.position) + } else { + // The preceding of the items are wrapped, and will remain so. + + // Illustrated steps: (underscores mark eventual gap position) + // 0) CD̲E̲F̲GHIJKL.........AB + // 1) CD̲E̲F̲GHIJKL......AB... + // 2) ..̲.̲F̲GHIJKL......ABCDE + // 3) F.̲.̲.̲GHIJKL......ABCDE + move(from: originalStart, to: newStart, count: capacity - originalStart.position) + move(from: .zero, to: limSlot.advanced(by: -gapSize), count: gapSize) + move(from: Slot.zero.advanced(by: gapSize), to: .zero, count: gapStart.position) + } + startSlot = newStart + count += gapSize + return mutableSegments(between: gapStart, and: gapEnd.orIfZero(capacity)) + } + + /// Close the gap of already uninitialized elements in `bounds`, sliding + /// elements outside of the gap to eliminate it, and updating `count` to + /// reflect the removal. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func closeGap(offsets bounds: Range) { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= self.count) + let gapSize = bounds.count + guard gapSize > 0 else { return } + + let gapStart = self.slot(forOffset: bounds.lowerBound) + let gapEnd = self.slot(forOffset: bounds.upperBound) + + let headCount = bounds.lowerBound + let tailCount = count - bounds.upperBound + + if headCount >= tailCount { + // Close the gap by sliding elements to the left. + let originalEnd = endSlot + let newEnd = self.slot(forOffset: count - gapSize) + + let sourceIsContiguous = gapEnd < originalEnd.orIfZero(capacity) + let targetIsContiguous = gapStart <= newEnd.orIfZero(capacity) + if tailCount == 0 { + // No need to move any elements. + } else if sourceIsContiguous && targetIsContiguous { + // No need to deal with wrapping. + + // 0) ....ABCD.̲.̲.̲EFGH.. EF.̲.̲.̲GH........ABCD .̲.̲.̲E..........ABCD.̲.̲ .̲.̲.̲EF........ABCD .̲.̲.̲DE.......ABC + // 1) ....ABCDE̲F̲G̲H..... EFG̲H̲.̲..........ABCD .̲.̲.̲...........ABCDE̲.̲ E̲F̲.̲..........ABCD D̲E̲.̲.........ABC + move(from: gapEnd, to: gapStart, count: tailCount) + } else if sourceIsContiguous { + // The gap lies across the wrap from the subsequent elements. + + // 0) .̲.̲.̲EFGH.......ABCD.̲.̲ EFGH.......ABCD.̲.̲.̲ + // 1) .̲.̲.̲..GH.......ABCDE̲F̲ ..GH.......ABCDE̲F̲G̲ + // 2) G̲H̲.̲...........ABCDE̲F̲ GH.........ABCDE̲F̲G̲ + let c = capacity - gapStart.position + assert(tailCount > c) + let next = move(from: gapEnd, to: gapStart, count: c) + move(from: next.source, to: .zero, count: tailCount - c) + } else if targetIsContiguous { + // We need to move elements across a wrap, but the wrap will + // disappear when we're done. + + // 0) HI....ABCDE.̲.̲.̲FG + // 1) HI....ABCDEF̲G̲.̲.. + // 2) ......ABCDEF̲G̲H̲I. + let next = move(from: gapEnd, to: gapStart, count: capacity - gapEnd.position) + move(from: .zero, to: next.target, count: originalEnd.position) + } else { + // We need to move elements across a wrap that won't go away. + + // 0) HIJKL....ABCDE.̲.̲.̲FG + // 1) HIJKL....ABCDEF̲G̲.̲.. + // 2) ...KL....ABCDEF̲G̲H̲IJ + // 3) KL.......ABCDEF̲G̲H̲IJ + var next = move(from: gapEnd, to: gapStart, count: capacity - gapEnd.position) + next = move(from: .zero, to: next.target, count: gapSize) + move(from: next.source, to: .zero, count: newEnd.position) + } + count -= gapSize + } else { + // Close the gap by sliding elements to the right. + let originalStart = startSlot + let newStart = slot(startSlot, offsetBy: gapSize) + + let sourceIsContiguous = originalStart < gapStart.orIfZero(capacity) + let targetIsContiguous = newStart <= gapEnd.orIfZero(capacity) + + if headCount == 0 { + // No need to move any elements. + } else if sourceIsContiguous && targetIsContiguous { + // No need to deal with wrapping. + + // 0) ....ABCD.̲.̲.̲EFGH..... EFGH........AB.̲.̲.̲CD .̲.̲.̲CDEFGH.......AB.̲.̲ DEFGH.......ABC.̲.̲ + // 1) .......AB̲C̲D̲EFGH..... EFGH...........̲A̲B̲CD .̲A̲B̲CDEFGH..........̲.̲ DEFGH.........AB̲C̲ ABCDEFGH........̲.̲.̲ + move(from: originalStart, to: newStart, count: headCount) + } else if sourceIsContiguous { + // The gap lies across the wrap from the preceding elements. + + // 0) .̲.̲DEFGH.......ABC.̲.̲ .̲.̲.̲EFGH.......ABCD + // 1) B̲C̲DEFGH.......A...̲.̲ B̲C̲D̲DEFGH......A... + // 2) B̲C̲DEFGH...........̲A̲ B̲C̲D̲DEFGH.........A + move(from: limSlot.advanced(by: -gapSize), to: .zero, count: gapEnd.position) + move(from: startSlot, to: newStart, count: headCount - gapEnd.position) + } else if targetIsContiguous { + // We need to move elements across a wrap, but the wrap will + // disappear when we're done. + + // 0) CD.̲.̲.̲EFGHI.....AB + // 1) ...̲C̲D̲EFGHI.....AB + // 1) .AB̲C̲D̲EFGHI....... + move(from: .zero, to: gapEnd.advanced(by: -gapStart.position), count: gapStart.position) + move(from: startSlot, to: newStart, count: headCount - gapStart.position) + } else { + // We need to move elements across a wrap that won't go away. + // 0) FG.̲.̲.̲HIJKLMNO....ABCDE + // 1) ...̲F̲G̲HIJKLMNO....ABCDE + // 2) CDE̲F̲G̲HIJKLMNO....AB... + // 3) CDE̲F̲G̲HIJKLMNO.......AB + move(from: .zero, to: Slot.zero.advanced(by: gapSize), count: gapStart.position) + move(from: limSlot.advanced(by: -gapSize), to: .zero, count: gapSize) + move(from: startSlot, to: newStart, count: headCount - gapEnd.position) + } + startSlot = newStart + count -= gapSize + } + } +} + +// MARK: Insertion + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedInsert( + _ newElement: consuming Element, at offset: Int + ) { + assert(count < capacity) + if offset == 0 { + uncheckedPrepend(newElement) + return + } + if offset == count { + uncheckedAppend(newElement) + return + } + let gap = openGap(ofSize: 1, atOffset: offset) + assert(gap.first.count == 1) + gap.first.baseAddress!.initialize(to: newElement) + } +} + +extension _UnsafeDequeHandle { + /// Insert all elements from `newElements` into this deque, starting at + /// `offset`. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + /// + /// - Parameter newElements: The elements to insert. + /// - Parameter newCount: Must be equal to `newElements.count`. Used to + /// prevent calling `count` more than once. + /// - Parameter offset: The desired offset from the start at which to place + /// the first element. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedInsert( + contentsOf newElements: __owned C, + count newCount: Int, + atOffset offset: Int + ) where C.Element == Element { + assert(offset <= count) + assert(newElements.count == newCount) + guard newCount > 0 else { return } + let gap = openGap(ofSize: newCount, atOffset: offset) + gap.initialize(from: newElements) + } +} + +// MARK: Removal + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedRemove(at offset: Int) -> Element { + let slot = self.slot(forOffset: offset) + let result = mutablePtr(at: slot).move() + closeGap(offsets: Range(uncheckedBounds: (offset, offset + 1))) + return result + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedRemoveFirst() -> Element { + assert(count > 0) + let result = mutablePtr(at: startSlot).move() + startSlot = slot(after: startSlot) + count -= 1 + return result + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedRemoveLast() -> Element { + assert(count > 0) + let slot = self.slot(forOffset: count - 1) + let result = mutablePtr(at: slot).move() + count -= 1 + return result + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedRemoveFirst(_ n: Int) { + assert(count >= n) + guard n > 0 else { return } + let target = mutableSegments(forOffsets: 0 ..< n) + target.deinitialize() + startSlot = slot(startSlot, offsetBy: n) + count -= n + } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedRemoveLast(_ n: Int) { + assert(count >= n) + guard n > 0 else { return } + let target = mutableSegments(forOffsets: count - n ..< count) + target.deinitialize() + count -= n + } + + /// Remove all elements stored in this instance, deinitializing their storage. + /// + /// This method does not ensure that the storage buffer is uniquely + /// referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedRemoveAll() { + guard count > 0 else { return } + let target = mutableSegments() + target.deinitialize() + count = 0 + startSlot = .zero + } + + /// Remove all elements in `bounds`, deinitializing their storage and sliding + /// remaining elements to close the resulting gap. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedRemove(offsets bounds: Range) { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= self.count) + + // Deinitialize elements in `bounds`. + mutableSegments(forOffsets: bounds).deinitialize() + closeGap(offsets: bounds) + } +} diff --git a/Sources/DequeModule/_UnsafeWrappedBuffer.swift b/Sources/DequeModule/_UnsafeDequeSegments.swift similarity index 74% rename from Sources/DequeModule/_UnsafeWrappedBuffer.swift rename to Sources/DequeModule/_UnsafeDequeSegments.swift index 1faefacc..98bb9985 100644 --- a/Sources/DequeModule/_UnsafeWrappedBuffer.swift +++ b/Sources/DequeModule/_UnsafeDequeSegments.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2025 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 @@ -11,19 +11,20 @@ #if !COLLECTIONS_SINGLE_MODULE import InternalCollectionsUtilities +import ContainersPreview #endif @frozen @usableFromInline -internal struct _UnsafeWrappedBuffer { +internal struct _UnsafeDequeSegments { @usableFromInline internal let first: UnsafeBufferPointer @usableFromInline internal let second: UnsafeBufferPointer? - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal init( _ first: UnsafeBufferPointer, _ second: UnsafeBufferPointer? = nil @@ -33,7 +34,8 @@ internal struct _UnsafeWrappedBuffer { assert(first.count > 0 || second == nil) } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal init( start: UnsafePointer, count: Int @@ -41,7 +43,8 @@ internal struct _UnsafeWrappedBuffer { self.init(UnsafeBufferPointer(start: start, count: count)) } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal init( first start1: UnsafePointer, count count1: Int, @@ -52,21 +55,33 @@ internal struct _UnsafeWrappedBuffer { UnsafeBufferPointer(start: start2, count: count2)) } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal var count: Int { first.count + (second?.count ?? 0) } + + @_alwaysEmitIntoClient + @_transparent + internal func isIdentical(to other: Self) -> Bool { + guard self.first._isIdentical(to: other.first) else { return false } + switch (self.second, other.second) { + case (nil, nil): return true + case let (a?, b?): return a._isIdentical(to: b) + default: return false + } + } } @frozen @usableFromInline -internal struct _UnsafeMutableWrappedBuffer { +internal struct _UnsafeMutableDequeSegments { @usableFromInline internal let first: UnsafeMutableBufferPointer @usableFromInline internal let second: UnsafeMutableBufferPointer? - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal init( _ first: UnsafeMutableBufferPointer, _ second: UnsafeMutableBufferPointer? = nil @@ -76,26 +91,8 @@ internal struct _UnsafeMutableWrappedBuffer { assert(first.count > 0 || second == nil) } - @inlinable - @inline(__always) - internal init( - _ first: UnsafeMutableBufferPointer.SubSequence, - _ second: UnsafeMutableBufferPointer? = nil - ) { - self.init(UnsafeMutableBufferPointer(rebasing: first), second) - } - - @inlinable - @inline(__always) - internal init( - _ first: UnsafeMutableBufferPointer, - _ second: UnsafeMutableBufferPointer.SubSequence - ) { - self.init(first, UnsafeMutableBufferPointer(rebasing: second)) - } - - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal init( start: UnsafeMutablePointer, count: Int @@ -103,8 +100,8 @@ internal struct _UnsafeMutableWrappedBuffer { self.init(UnsafeMutableBufferPointer(start: start, count: count)) } - @inlinable - @inline(__always) + @_alwaysEmitIntoClient + @_transparent internal init( first start1: UnsafeMutablePointer, count count1: Int, @@ -115,56 +112,82 @@ internal struct _UnsafeMutableWrappedBuffer { UnsafeMutableBufferPointer(start: start2, count: count2)) } - @inlinable - @inline(__always) - internal init(mutating buffer: _UnsafeWrappedBuffer) { + @_alwaysEmitIntoClient + @_transparent + internal init(mutating buffer: _UnsafeDequeSegments) { self.init(.init(mutating: buffer.first), buffer.second.map { .init(mutating: $0) }) } } -extension _UnsafeMutableWrappedBuffer { - @inlinable - @inline(__always) +extension _UnsafeMutableDequeSegments { + @_alwaysEmitIntoClient + @_transparent + internal init( + _ first: UnsafeMutableBufferPointer.SubSequence, + _ second: UnsafeMutableBufferPointer? = nil + ) { + self.init(UnsafeMutableBufferPointer(rebasing: first), second) + } + + @_alwaysEmitIntoClient + @_transparent + internal init( + _ first: UnsafeMutableBufferPointer, + _ second: UnsafeMutableBufferPointer.SubSequence + ) { + self.init(first, UnsafeMutableBufferPointer(rebasing: second)) + } +} + +extension _UnsafeMutableDequeSegments where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent internal var count: Int { first.count + (second?.count ?? 0) } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal func prefix(_ n: Int) -> Self { assert(n >= 0) if n >= self.count { return self } if n <= first.count { - return Self(first.prefix(n)) + return Self(first._extracting(first: n)) } - return Self(first, second!.prefix(n - first.count)) + return Self(first, second!._extracting(first: n - first.count)) } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal func suffix(_ n: Int) -> Self { assert(n >= 0) if n >= self.count { return self } guard let second = second else { - return Self(first.suffix(n)) + return Self(first._extracting(last: n)) } if n <= second.count { - return Self(second.suffix(n)) + return Self(second._extracting(last: n)) } - return Self(first.suffix(n - second.count), second) + return Self(first._extracting(last: n - second.count), second) } } -extension _UnsafeMutableWrappedBuffer { - @inlinable +extension _UnsafeMutableDequeSegments where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent internal func deinitialize() { first.deinitialize() second?.deinitialize() } +} - @inlinable +extension _UnsafeMutableDequeSegments { @discardableResult + @_alwaysEmitIntoClient + @_transparent internal func initialize( fromPrefixOf iterator: inout I ) -> Int @@ -186,7 +209,8 @@ extension _UnsafeMutableWrappedBuffer { return wrapped ? first.count + copied : copied } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal func initialize( fromSequencePrefix elements: __owned S ) -> (iterator: S.Iterator, count: Int) @@ -214,7 +238,8 @@ extension _UnsafeMutableWrappedBuffer { return (it, copied) } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal func initialize( from elements: __owned C ) where C.Element == Element { @@ -228,7 +253,8 @@ extension _UnsafeMutableWrappedBuffer { } } - @inlinable + @_alwaysEmitIntoClient + @_transparent internal func assign( from elements: C ) where C.Element == Element { diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift b/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift index dc38cb86..15dc9717 100644 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift +++ b/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift @@ -13,7 +13,7 @@ extension FixedWidthInteger { /// Round up `self` to the nearest power of two, assuming it's representable. /// Returns 0 if `self` isn't positive. @inlinable - package func _roundUpToPowerOfTwo() -> Self { + public func _roundUpToPowerOfTwo() -> Self { guard self > 0 else { return 0 } let l = Self.bitWidth - (self &- 1).leadingZeroBitCount return 1 << l diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index 5cc4116a..ba05e636 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -25,6 +25,12 @@ extension UnsafeBufferPointer where Element: ~Copyable { package func _isIdentical(to other: Self) -> Bool { (self.baseAddress == other.baseAddress) && (self.count == other.count) } + + @inlinable + @inline(__always) + package static var _empty: Self { + .init(start: nil, count: 0) + } } extension UnsafeBufferPointer where Element: ~Copyable { @@ -74,4 +80,3 @@ extension UnsafeBufferPointer where Element: ~Copyable { return extracting(Range(uncheckedBounds: (count - newCount, count))) } } - diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index a9eaadcb..c47b632e 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -17,9 +17,27 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { package func _isIdentical(to other: Self) -> Bool { (self.baseAddress == other.baseAddress) && (self.count == other.count) } + + @inlinable + @inline(__always) + package static var _empty: Self { + .init(start: nil, count: 0) + } } extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a buffer pointer within the + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(unchecked bounds: Range) -> Self { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index out of range") + guard let start = self.baseAddress else { + return Self(start: nil, count: 0) + } + return Self(start: start + bounds.lowerBound, count: bounds.count) + } + /// Returns a buffer pointer containing the initial elements of this buffer, /// up to the specified maximum length. /// From 8320ac8215d0a8046719617d42424c645faca6c6 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Fri, 31 Oct 2025 13:10:24 -0500 Subject: [PATCH 03/75] Add additional API and tests --- .../RigidDeque/RigidDeque+Append.swift | 8 +- .../RigidDeque/RigidDeque+Initializers.swift | 82 +++ .../RigidDeque/RigidDeque+Prepend.swift | 122 ++++ .../DequeModule/RigidDeque/RigidDeque.swift | 1 + Sources/DequeModule/_UnsafeDequeHandle.swift | 47 +- Tests/DequeTests/RigidDequeTests.swift | 544 ++++++++++++++++++ 6 files changed, 799 insertions(+), 5 deletions(-) create mode 100644 Tests/DequeTests/RigidDequeTests.swift diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index e22e0a99..6bfe93d3 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -94,9 +94,9 @@ extension RigidDeque /*where Element: Copyable*/ { /// - Complexity: O(`newElements.count`) @_alwaysEmitIntoClient public mutating func append( - copying items: UnsafeMutableBufferPointer + copying newElements: UnsafeMutableBufferPointer ) { - unsafe self.append(copying: UnsafeBufferPointer(items)) + unsafe self.append(copying: UnsafeBufferPointer(newElements)) } /// Copies the elements of a span to the end of this deque. @@ -109,8 +109,8 @@ extension RigidDeque /*where Element: Copyable*/ { /// /// - Complexity: O(`newElements.count`) @_alwaysEmitIntoClient - public mutating func append(copying items: Span) { - unsafe items.withUnsafeBufferPointer { source in + public mutating func append(copying newElements: Span) { + unsafe newElements.withUnsafeBufferPointer { source in unsafe self.append(copying: source) } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index 0202b0f9..74f7ee55 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -18,11 +18,79 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { + /// Creates an empty rigid deque with the specified capacity. @_alwaysEmitIntoClient @_transparent public init(capacity: Int) { self.init(_handle: .allocate(capacity: capacity)) } + + /// Creates a rigid deque with the specified capacity, then calls the given + /// closure with an output span covering the deque's uninitialized memory. + /// + /// - Parameters: + /// - capacity: The number of elements to allocate space for in the new + /// rigid deque. + /// - initializer: A closure that initializes the elements of the new deque. + /// - Parameter outputSpan: An `OutputSpan` allowing initialization of the + /// deque's initial elements. + @inlinable + public init( + capacity: Int, + initializingWith initializer: (inout OutputSpan) throws -> Void + ) rethrows { + self.init(_handle: .allocate(capacity: capacity)) + var newCount = 0 + let buffer = _handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) + var span = OutputSpan(buffer: buffer, initializedCount: 0) + defer { + _handle.count = span.finalize(for: buffer) + span = OutputSpan() + } + try initializer(&span) + } + + /// Creates a rigid deque with the specified capacity, then calls the given + /// closure with a buffer covering the deque's uninitialized memory. + /// + /// Inside the closure, set the `initializedCount` parameter to the number of + /// elements that are initialized by the closure. The memory in the range + /// `buffer[0.., inout Int) throws -> Void + ) rethrows { + self.init(_handle: .allocate(capacity: capacity)) + var newCount = 0 + var buffer = _handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) + + defer { + precondition(newCount <= capacity, + "Initialized count set to greater than specified capacity") + let b = _handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) + precondition(buffer.baseAddress == b.baseAddress && buffer.count == b.count, + "Initializer relocated Deque storage") + _handle.count = newCount + } + try initializer(&buffer, &newCount) + } } @available(SwiftStdlib 5.0, *) @@ -58,6 +126,20 @@ extension RigidDeque /*where Element: Copyable*/ { self.init(capacity: capacity) self.append(copying: contents) } + + /// Creates a new rigid deque from the given collection, with the capacity + /// derived from the collection's count. + /// + /// - Parameters: + /// - contents: The contents whose contents to copy into the new deque. + @_alwaysEmitIntoClient + @inline(__always) + public init( + copying contents: some Collection + ) { + self.init(capacity: contents.count) + self.append(copying: contents) + } } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 4ee3b0e8..30633fc3 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -32,4 +32,126 @@ extension RigidDeque where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*where Element: Copyable*/ { + /// Copies the elements of a buffer to the front of this rigid deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// buffer, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`newElements.count`) + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying newElements: UnsafeBufferPointer + ) { + precondition( + newElements.count <= freeCapacity, + "RigidDeque capacity overflow") + guard newElements.count > 0 else { return } + _handle.uncheckedPrepend(contentsOf: newElements) + } + + /// Copies the elements of a buffer to the front of this rigid deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// buffer, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`newElements.count`) + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying newElements: UnsafeMutableBufferPointer + ) { + unsafe self.prepend(copying: UnsafeBufferPointer(newElements)) + } + + /// Copies the elements of a span to the front of this rigid deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// span, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: A span whose contents to copy into the deque. + /// + /// - Complexity: O(`newElements.count`) + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend(copying newElements: Span) { + unsafe newElements.withUnsafeBufferPointer { source in + unsafe self.prepend(copying: source) + } + } + + /// Copies the elements of a collection to the front of the rigid deque. + /// + /// Use this method to prepend the elements of a collection to the front of + /// this deque. This example prepends the elements of a `Range` instance + /// to a rigid deque of integers. + /// + /// var numbers = RigidDeque(capacity: 10) + /// numbers.append(contentsOf: [1, 2, 3, 4, 5]) + /// numbers.prepend(contentsOf: 10...15) + /// print(numbers) + /// // Prints "[10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5]" + /// + /// - Parameter newElements: The elements to prepend to the deque. + /// + /// - Complexity: O(`newElements.count`) + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying newElements: some Collection + ) { + let done: Void? = newElements.withContiguousStorageIfAvailable { source in + unsafe self.prepend(copying: source) + return + } + guard done == nil else { return } + let c = newElements.count + guard c > 0 else { return } + precondition(c <= freeCapacity, "RigidDeque capacity overflow") + _handle.uncheckedPrepend(contentsOf: newElements, count: c) + } + + /// Copies the elements of a sequence to the front of the rigid deque. + /// + /// Use this method to prepend the elements of a sequence to the front of this + /// deque. This example prepends the elements of a `Range` instance to a + /// rigid deque of integers. + /// + /// var numbers = RigidDeque(capacity: 10) + /// numbers.append(contentsOf: [1, 2, 3, 4, 5]) + /// numbers.prepend(contentsOf: 10...15) + /// print(numbers) + /// // Prints "[10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5]" + /// + /// - Parameter newElements: The elements to prepend to the deque. + /// + /// - Complexity: O(`newElements.count`) + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend(copying newElements: some Sequence) { + let done: Void? = newElements.withContiguousStorageIfAvailable { source in + unsafe self.prepend(copying: source) + return + } + guard done == nil else { return } + + // Add new elements as suffix and check that all elements were copied. + let oldEndSlot = _handle.endSlot + var it = self._append(prefixOf: newElements) + precondition(it.next() == nil, "RigidDeque capacity overflow") + _handle.rotate(toStartAt: oldEndSlot) + } +} + #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index 1a958d71..4f67b278 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -26,6 +26,7 @@ public struct RigidDeque: ~Copyable { #else +/// A fixed-capacity container implementing a double-ended queue. @available(SwiftStdlib 5.0, *) @frozen @safe diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 6a6a5b93..eda6eee8 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -555,7 +555,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } -extension _UnsafeDequeHandle { +extension _UnsafeDequeHandle /*where Element: Copyable*/ { /// Prepend the contents of `source` to this buffer. The buffer must have /// enough free capacity to insert the new elements. /// @@ -570,6 +570,28 @@ extension _UnsafeDequeHandle { let newStart = self.slot(startSlot, offsetBy: -source.count) startSlot = newStart count += source.count + + let gap = mutableSegments(between: newStart, and: oldStart) + gap.initialize(from: source) + } + + /// Prepend the contents of `source` to this buffer. The buffer must have + /// enough free capacity to insert the new elements. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedPrepend( + contentsOf source: some Collection, + count sourceCount: Int + ) { + assert(count + sourceCount <= capacity) + guard sourceCount > 0 else { return } + let oldStart = startSlot + let newStart = self.slot(startSlot, offsetBy: -sourceCount) + startSlot = newStart + count += sourceCount let gap = mutableSegments(between: newStart, and: oldStart) gap.initialize(from: source) @@ -846,6 +868,29 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +// MARK: Rotating elements + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func rotate( + toStartAt newStart: Slot + ) { + let currentCount = count + + // Open a gap at `newStart` that's the size of the free capacity, pushing + // all elements to the right of `newStart` until they wrap around and close + // the gap with the current start of the collection. + // FIXME: If the elements to the left of `newStart` are fewer in number, + // it would be more efficient to move those to the end. + _ = openGap(ofSize: capacity - count, atOffset: newStart.position) + // With the latter elements now shifted to the front, update the starting + // slot and restore the count. + startSlot = newStart + count = currentCount + } +} + // MARK: Insertion extension _UnsafeDequeHandle where Element: ~Copyable { diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests.swift new file mode 100644 index 00000000..af09f2e4 --- /dev/null +++ b/Tests/DequeTests/RigidDequeTests.swift @@ -0,0 +1,544 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +import Testing +#if COLLECTIONS_SINGLE_MODULE +import Collections +#else +import DequeModule +import ContainersPreview +#endif + +#if compiler(>=6.2) +@Suite("RigidDeque Tests") +struct RigidDequeTests { + + // MARK: - Basic Initializers + + @Test("Init with capacity") + func initWithCapacity() { + let deque = RigidDeque(capacity: 5) + #expect(deque.capacity == 5) + #expect(deque.count == 0) + #expect(deque.freeCapacity == 5) + } + + @Test("Init repeating value") + func initRepeatingValue() { + let deque = RigidDeque(repeating: 42, count: 3) + #expect(deque.count == 3) + #expect(deque.capacity == 3) + #expect(deque[0] == 42) + #expect(deque[1] == 42) + #expect(deque[2] == 42) + } + + @Test("Init copying sequence") + func initCopyingSequence() { + let source = [1, 2, 3, 4, 5] + let deque = RigidDeque(capacity: 10, copying: source) + #expect(deque.count == 5) + #expect(deque.capacity == 10) + for i in 0..<5 { + #expect(deque[i] == source[i]) + } + } + + @Test("Init copying collection") + func initCopyingCollection() { + let source = [1, 2, 3, 4, 5] + let deque = RigidDeque(copying: source) + #expect(deque.count == 5) + #expect(deque.capacity == 5) + for i in 0..<5 { + #expect(deque[i] == source[i]) + } + } + + @Test("Init with initializing closure") + func initWithInitializingClosure() { + let deque = RigidDeque(capacity: 5) { span in + span.append(10) + span.append(20) + span.append(30) + } + #expect(deque.count == 3) + #expect(deque.capacity == 5) + #expect(deque[0] == 10) + #expect(deque[1] == 20) + #expect(deque[2] == 30) + } + + @Test("Init with unsafe uninitialized capacity") + func initWithUnsafeUninitializedCapacity() { + let deque = RigidDeque(unsafeUninitializedCapacity: 5) { buffer, count in + buffer[0] = 100 + buffer[1] = 200 + count = 2 + } + #expect(deque.count == 2) + #expect(deque.capacity == 5) + #expect(deque[0] == 100) + #expect(deque[1] == 200) + } + + // MARK: - Basic Properties + + @Test("Basic properties") + func basicProperties() { + var deque = RigidDeque(capacity: 10) + + // Empty deque + #expect(deque.isEmpty == true) + #expect(deque.isFull == false) + #expect(deque.count == 0) + #expect(deque.capacity == 10) + #expect(deque.freeCapacity == 10) + #expect(deque.startIndex == 0) + #expect(deque.endIndex == 0) + + // Add some elements + deque.append(1) + deque.append(2) + deque.append(3) + + #expect(deque.isEmpty == false) + #expect(deque.isFull == false) + #expect(deque.count == 3) + #expect(deque.capacity == 10) + #expect(deque.freeCapacity == 7) + #expect(deque.startIndex == 0) + #expect(deque.endIndex == 3) + + // Fill to capacity + for i in 4...10 { + deque.append(i) + } + + #expect(deque.isEmpty == false) + #expect(deque.isFull == true) + #expect(deque.count == 10) + #expect(deque.freeCapacity == 0) + } + + // MARK: - Element Access + + @Test("Subscript access") + func subscriptAccess() { + var deque = RigidDeque(copying: [10, 20, 30, 40, 50]) + + // Read access + #expect(deque[0] == 10) + #expect(deque[2] == 30) + #expect(deque[4] == 50) + + // Write access + deque[1] = 99 + #expect(deque[1] == 99) + } + + @Test("Borrow element") + func borrowElement() { + let deque = RigidDeque(copying: [1, 2, 3]) + let ref = deque.borrowElement(at: 1) + #expect(ref[] == 2) + } + + @Test("Mutate element") + func mutateElement() { + var deque = RigidDeque(copying: [1, 2, 3]) + var mut = deque.mutateElement(at: 1) + mut[] = 99 + #expect(deque[1] == 99) + } + + // MARK: - Append Operations + + @Test("Append single element") + func appendSingleElement() { + var deque = RigidDeque(capacity: 5) + + deque.append(10) + #expect(deque.count == 1) + #expect(deque[0] == 10) + + deque.append(20) + #expect(deque.count == 2) + #expect(deque[1] == 20) + } + + @Test("PushLast returns element when full") + func pushLastReturnsBehavior() { + var deque = RigidDeque(capacity: 2) + deque.append(1) + deque.append(2) + + let result = deque.pushLast(99) + #expect(result == 99) // Should return the item when full + #expect(deque.count == 2) // Count unchanged + + // When not full, should return nil + let result2 = deque.pushLast(3) // This should fail since deque is full + #expect(result2 == 3) + } + + @Test("Append copying buffer") + func appendCopyingBuffer() { + var deque = RigidDeque(capacity: 10) + let buffer = [1, 2, 3, 4, 5] + + buffer.withUnsafeBufferPointer { ptr in + deque.append(copying: ptr) + } + + #expect(deque.count == 5) + for i in 0..<5 { + #expect(deque[i] == buffer[i]) + } + } + + @Test("Append copying sequence") + func appendCopyingSequence() { + var deque = RigidDeque(capacity: 10) + let source = [1, 2, 3, 4] + + deque.append(copying: source) + + #expect(deque.count == 4) + for i in 0..<4 { + #expect(deque[i] == source[i]) + } + } + + // MARK: - Prepend Operations + + @Test("Prepend single element") + func prependSingleElement() { + var deque = RigidDeque(capacity: 5) + + deque.prepend(10) + #expect(deque.count == 1) + #expect(deque[0] == 10) + + deque.prepend(20) + #expect(deque.count == 2) + #expect(deque[0] == 20) + #expect(deque[1] == 10) + } + + @Test("Prepend copying buffer") + func prependCopyingBuffer() { + var deque = RigidDeque(capacity: 10) + deque.append(5) + + let buffer = [1, 2, 3, 4] + buffer.withUnsafeBufferPointer { ptr in + deque.prepend(copying: ptr) + } + + #expect(deque.count == 5) + #expect(deque[0] == 1) + #expect(deque[1] == 2) + #expect(deque[2] == 3) + #expect(deque[3] == 4) + #expect(deque[4] == 5) + } + + @Test("Prepend copying collection") + func prependCopyingCollection() { + var deque = RigidDeque(capacity: 10) + deque.append(copying: [5, 6]) + + deque.prepend(copying: [1, 2, 3, 4]) + + #expect(deque.count == 6) + #expect(deque[0] == 1) + #expect(deque[1] == 2) + #expect(deque[2] == 3) + #expect(deque[3] == 4) + #expect(deque[4] == 5) + #expect(deque[5] == 6) + } + + @Test("Prepend copying sequence") + func prependCopyingSequence() { + do { + var deque = RigidDeque(capacity: 10) + deque.append(100) + + let seq = stride(from: 10, through: 30, by: 10) + deque.prepend(copying: seq) + + #expect(deque.count == 4) + #expect(deque[0] == 10) + #expect(deque[1] == 20) + #expect(deque[2] == 30) + #expect(deque[3] == 100) + } + + do { + var deque = RigidDeque(repeating: 100, count: 10) + deque.removeFirst(9) + + let seq = stride(from: 10, through: 30, by: 10) + deque.prepend(copying: seq) + + #expect(deque.count == 4) + #expect(deque[0] == 10) + #expect(deque[1] == 20) + #expect(deque[2] == 30) + #expect(deque[3] == 100) + } + } + + // MARK: - Removal Operations + + @Test("Remove at index") + func removeAtIndex() { + var deque = RigidDeque(copying: [10, 20, 30, 40, 50]) + + let removed = deque.remove(at: 2) + #expect(removed == 30) + #expect(deque.count == 4) + #expect(deque[0] == 10) + #expect(deque[1] == 20) + #expect(deque[2] == 40) + #expect(deque[3] == 50) + } + + @Test("Remove subrange") + func removeSubrange() { + var deque = RigidDeque(copying: [1, 2, 3, 4, 5, 6]) + + deque.removeSubrange(1..<4) + #expect(deque.count == 3) + #expect(deque[0] == 1) + #expect(deque[1] == 5) + #expect(deque[2] == 6) + } + + @Test("RemoveFirst operations") + func removeFirstOperations() { + var deque = RigidDeque(copying: [1, 2, 3, 4, 5]) + + // Remove single first + let first = deque.removeFirst() + #expect(first == 1) + #expect(deque.count == 4) + #expect(deque[0] == 2) + + // Remove multiple first + deque.removeFirst(2) + #expect(deque.count == 2) + #expect(deque[0] == 4) + #expect(deque[1] == 5) + } + + @Test("RemoveLast operations") + func removeLastOperations() { + var deque = RigidDeque(copying: [1, 2, 3, 4, 5]) + + // Remove single last + let last = deque.removeLast() + #expect(last == 5) + #expect(deque.count == 4) + #expect(deque[3] == 4) + + // Remove multiple last + deque.removeLast(2) + #expect(deque.count == 2) + #expect(deque[0] == 1) + #expect(deque[1] == 2) + } + + @Test("PopFirst and PopLast") + func popOperations() { + var deque = RigidDeque(copying: [10, 20]) + + // Pop when not empty + let first = deque.popFirst() + #expect(first == 10) + #expect(deque.count == 1) + + let last = deque.popLast() + #expect(last == 20) + #expect(deque.count == 0) + + // Pop when empty + let emptyFirst = deque.popFirst() + let emptyLast = deque.popLast() + #expect(emptyFirst == nil) + #expect(emptyLast == nil) + } + + @Test("Remove all") + func removeAll() { + var deque = RigidDeque(copying: [1, 2, 3, 4, 5]) + + deque.removeAll() + #expect(deque.isEmpty == true) + #expect(deque.count == 0) + #expect(deque.capacity == 5) // Capacity should remain unchanged + } + + // MARK: - Capacity Management + + @Test("Resize capacity") + func resizeCapacity() { + var deque = RigidDeque(copying: [1, 2, 3]) + #expect(deque.capacity == 3) + + // Increase capacity + deque.resize(to: 10) + #expect(deque.capacity == 10) + #expect(deque.count == 3) + #expect(deque[0] == 1) + #expect(deque[1] == 2) + #expect(deque[2] == 3) + + // Decrease capacity (but still fits existing elements) + deque.resize(to: 5) + #expect(deque.capacity == 5) + #expect(deque.count == 3) + } + + // MARK: - Edge Cases and Error Conditions + + @Test("Append to full deque fails") + func appendToFullDequeFails() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 2) + deque.append(1) + deque.append(2) + + #expect(deque.isFull == true) + deque.append(3) // Traps with "RigidDeque is full" + } + } + + @Test("Prepend to full deque fails") + func prependToFullDequeFails() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 2) + deque.append(1) + deque.append(2) + + #expect(deque.isFull == true) + deque.prepend(0) // Traps with "RigidDeque is full" + } + } + + @Test("Resize too small") + func resizeTooSmall() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(repeating: 0, count: 5) + deque.resize(to: 3) + } + } + + @Test("Invalid index access") + func invalidIndexAccess() async { + await #expect(processExitsWith: .failure) { + let deque = RigidDeque(copying: [1, 2, 3]) + let _ = deque[-1] // Index out of bounds + } + await #expect(processExitsWith: .failure) { + let deque = RigidDeque(copying: [1, 2, 3]) + let _ = deque[3] // Index out of bounds + } + await #expect(processExitsWith: .failure) { + let deque = RigidDeque(copying: [1, 2, 3]) + let _ = deque.borrowElement(at: 5) // Index out of bounds + } + } + + @Test("Remove from empty deque") + func removeFromEmptyDeque() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 5) + deque.removeFirst() // Can't remove first element of an empty RigidDeque + } + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 5) + deque.removeLast() // Can't remove last element of an empty RigidDeque + } + } + + // MARK: - Mixed Operations + + @Test("Mixed append and prepend operations") + func mixedAppendPrependOperations() { + var deque = RigidDeque(capacity: 10) + + deque.append(5) + deque.prepend(4) + deque.append(6) + deque.prepend(3) + + #expect(deque.count == 4) + #expect(deque[0] == 3) + #expect(deque[1] == 4) + #expect(deque[2] == 5) + #expect(deque[3] == 6) + } + + @Test("Complex operations sequence") + func complexOperationsSequence() { + var deque = RigidDeque(capacity: 20) + + // Initial setup + deque.append(copying: [10, 20, 30]) + deque.prepend(copying: [5, 7]) + #expect(deque.count == 5) + + // Remove some elements + deque.removeFirst() + deque.removeLast() + #expect(deque.count == 3) + #expect(deque[0] == 7) + #expect(deque[1] == 10) + #expect(deque[2] == 20) + } + + // MARK: - Type Safety Tests (Non-Copyable) + + @Test("Non-copyable element type") + func nonCopyableElementType() { + struct NonCopyable: ~Copyable { + let id: Int + init(_ id: Int) { self.id = id } + } + + var deque = RigidDeque(capacity: 5) + deque.append(NonCopyable(1)) + deque.append(NonCopyable(2)) + + #expect(deque.count == 2) + #expect(deque[0].id == 1) + #expect(deque[1].id == 2) + + let removed = deque.removeFirst() + #expect(removed.id == 1) + #expect(deque.count == 1) + } +} + +#else +// RigidDeque requires Swift 6.2+ compiler +@Suite("RigidDeque Tests") +struct RigidDequeTests { + @Test("Compiler version check") + func compilerVersionCheck() { + // This test suite requires Swift 6.2+ for RigidDeque availability + #expect(true, "RigidDeque requires Swift 6.2+ compiler") + } +} +#endif From ec89f90bd0afb5f8a4b9212d4607c5f902154cc4 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Wed, 5 Nov 2025 11:18:33 -0600 Subject: [PATCH 04/75] Expand RigidDeque test coverage --- .../RigidDeque/RigidDeque+Collection.swift | 37 ++ .../RigidDeque/RigidDeque+Container.swift | 61 ++ .../RigidDeque/RigidDeque+Initializers.swift | 1 - .../RigidDeque/RigidDeque+Testing.swift | 58 ++ Sources/DequeModule/_UnsafeDequeHandle.swift | 52 +- Tests/DequeTests/DequeInternals.swift | 27 +- ...ts.swift => RigidDequeTests+Testing.swift} | 5 +- Tests/DequeTests/RigidDequeTests+XCTest.swift | 549 ++++++++++++++++++ 8 files changed, 773 insertions(+), 17 deletions(-) create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Container.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift rename Tests/DequeTests/{RigidDequeTests.swift => RigidDequeTests+Testing.swift} (99%) create mode 100644 Tests/DequeTests/RigidDequeTests+XCTest.swift diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift new file mode 100644 index 00000000..9caae9ba --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque { + @inlinable + public func _copyToContiguousArray() -> ContiguousArray { + ContiguousArray(unsafeUninitializedCapacity: count) { target, count in + let segments = _handle.segments() + let c = segments.first.count + target[..=6.2) + +// MARK: Borrowing + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + public struct BorrowIterator: ~Escapable { + var currentSegment: Span + var nextSegment: Span + + @_lifetime(borrow deque) + internal init(deque: borrowing RigidDeque, iteratedCount: Int = 0) { + let segments = deque._handle.segments() + self.currentSegment = _overrideLifetime( + Span(_unsafeElements: segments.first), + borrowing: deque) + self.nextSegment = _overrideLifetime( + Span( + _unsafeElements: segments.second ?? UnsafeBufferPointer(start: nil, count: 0)), + borrowing: deque) + } + + @_lifetime(copy self) + @_lifetime(self: copy self) + public mutating func nextSpan(maximumCount: Int? = nil) -> Span { + let max = maximumCount ?? Int.max + let c = Swift.min(currentSegment.count, max) + let result = currentSegment.extracting(first: c) + if c == currentSegment.count { + currentSegment = nextSegment + nextSegment = Span() + } else { + currentSegment = currentSegment.extracting(droppingFirst: c) + } + return result + } + } + + @_lifetime(borrow self) + public borrowing func startBorrowIteration() -> BorrowIterator { + BorrowIterator(deque: self) + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index 74f7ee55..15e6d7bd 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -40,7 +40,6 @@ extension RigidDeque where Element: ~Copyable { initializingWith initializer: (inout OutputSpan) throws -> Void ) rethrows { self.init(_handle: .allocate(capacity: capacity)) - var newCount = 0 let buffer = _handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) var span = OutputSpan(buffer: buffer, initializedCount: 0) defer { diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift new file mode 100644 index 00000000..a1706ab0 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +// This file contains exported but non-public entry points to support clear box +// testing. + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// The number of the storage slot in this deque that holds the first element. + /// (Or would hold it after an insertion in case the deque is currently + /// empty.) + /// + /// This property isn't intended to be used outside of `Deque`'s own test + /// target. + @_spi(Testing) + public var _startSlot: Int { + _handle.startSlot.position + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque { + /// Constructs a deque instance of the specified contents and layout. Exposed + /// as public to allow exhaustive input/output tests for `Deque`'s members. + /// This isn't intended to be used outside of `Deque`'s own test target. + @_spi(Testing) + public init( + _capacity capacity: Int, + startSlot: Int, + copying contents: some Sequence + ) { + let contents = Array(contents) + + self.init(capacity: capacity) + _handle.startSlot = _handle.slot(_handle.startSlot, offsetBy: startSlot) + self.append(copying: contents) + assert(self.capacity == capacity) + assert(self._startSlot == startSlot) + assert(self.count == contents.count) + } +} + +#endif diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index eda6eee8..6b1543b0 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -16,7 +16,7 @@ import ContainersPreview @frozen @usableFromInline -internal struct _UnsafeDequeHandle: ~Copyable { +internal struct _UnsafeDequeHandle { @usableFromInline internal typealias Slot = _DequeSlot @@ -203,6 +203,20 @@ extension _UnsafeDequeHandle where Element: ~Copyable { guard position < capacity else { return Slot(at: position &- capacity) } return Slot(at: position) } + + @_alwaysEmitIntoClient + @_transparent + internal func distance(from start: Slot, to end: Slot) -> Int { + assert(start.position >= 0 && start.position <= capacity) + assert(end.position >= 0 && end.position <= capacity) + + if end.position >= start.position { + return end.position - start.position + } else { + // Handle wrap-around case + return capacity - start.position + end.position + } + } } // MARK: Element Access @@ -408,7 +422,7 @@ extension _UnsafeDequeHandle { /// minimum capacity. This operation does not preserve layout. @_alwaysEmitIntoClient @_transparent - internal borrowing func allocateCopy(capacity: Int) -> Self { + internal func allocateCopy(capacity: Int) -> Self { precondition(capacity >= self.count) var result: _UnsafeDequeHandle = .allocate(capacity: capacity) result.count = self.count @@ -873,21 +887,35 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent + @discardableResult internal mutating func rotate( toStartAt newStart: Slot - ) { + ) -> Slot { let currentCount = count + let suffixCount = distance(from: newStart, to: endSlot) + + // Open a gap at `newStart` that's the size of the free capacity, swapping + // the positions of the prefix (`startSlot.. 0 { + _ = openGap(ofSize: gapSize, atOffset: gapOffset) + } + + // With the prefix and suffix swapped, update the starting slot and + // restore the count. + let oldStart = startSlot + startSlot = slot(startSlot, offsetBy: -suffixCount) count = currentCount + return oldStart } } diff --git a/Tests/DequeTests/DequeInternals.swift b/Tests/DequeTests/DequeInternals.swift index f9fc9b4b..67798119 100644 --- a/Tests/DequeTests/DequeInternals.swift +++ b/Tests/DequeTests/DequeInternals.swift @@ -16,7 +16,17 @@ import _CollectionsTestSupport @_spi(Testing) import DequeModule #endif -internal struct DequeLayout: CustomStringConvertible { +internal struct RigidTestData: ~Copyable { + var deque: RigidDeque + var contents: [Element] + + init(_ deque: consuming RigidDeque, _ contents: [Element]) { + self.deque = deque + self.contents = contents + } +} + +internal struct DequeLayout: Hashable, CustomStringConvertible { let capacity: Int let startSlot: Int let count: Int @@ -52,6 +62,13 @@ extension Deque { } } +extension RigidDeque { + init(layout: DequeLayout, contents: C) where C.Element == Element { + precondition(contents.count == layout.count) + self.init(_capacity: layout.capacity, startSlot: layout.startSlot, copying: contents) + } +} + extension LifetimeTracker { func deque( with layout: DequeLayout @@ -60,6 +77,14 @@ extension LifetimeTracker { let deque = Deque(layout: layout, contents: contents) return (deque, contents) } + + func rigidDeque( + with layout: DequeLayout + ) -> RigidTestData> { + let contents = self.instances(for: layout.valueRange) + let deque = RigidDeque(layout: layout, contents: contents) + return RigidTestData(deque, contents) + } } func withEveryDeque( diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests+Testing.swift similarity index 99% rename from Tests/DequeTests/RigidDequeTests.swift rename to Tests/DequeTests/RigidDequeTests+Testing.swift index af09f2e4..1ceb653f 100644 --- a/Tests/DequeTests/RigidDequeTests.swift +++ b/Tests/DequeTests/RigidDequeTests+Testing.swift @@ -19,9 +19,8 @@ import ContainersPreview #if compiler(>=6.2) @Suite("RigidDeque Tests") -struct RigidDequeTests { - - // MARK: - Basic Initializers +struct RigidDequeTests_Testing { + // MARK: - Initializers @Test("Init with capacity") func initWithCapacity() { diff --git a/Tests/DequeTests/RigidDequeTests+XCTest.swift b/Tests/DequeTests/RigidDequeTests+XCTest.swift new file mode 100644 index 00000000..f6aa51d9 --- /dev/null +++ b/Tests/DequeTests/RigidDequeTests+XCTest.swift @@ -0,0 +1,549 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +import XCTest +#if COLLECTIONS_SINGLE_MODULE +@_spi(Testing) import Collections +#else +import _CollectionsTestSupport +@_spi(Testing) import DequeModule +#endif + +#if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +public func expectContainerContents< + Element: Equatable, + C2: Collection, +>( + _ left: borrowing RigidDeque, + equalTo right: C2, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #file, + line: UInt = #line +) { + expectContainerContents( + left, + equivalentTo: right, + by: ==, + message(), trapping: trapping, file: file, line: line) +} + +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +public func expectContainerContents< + E1: ~Copyable, + C2: Collection, +>( + _ left: borrowing RigidDeque, + equivalentTo right: C2, + by areEquivalent: (borrowing E1, C2.Element) -> Bool, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #file, + line: UInt = #line +) { + var spanIterator = left.startBorrowIteration() + var iteratedCount = 0 +// print("-------\nstarting") + while true { + let span = spanIterator.nextSpan() +// print("Span count: \(span.count)") + + if span.isEmpty { + break + } + expectContainerContents( + span, + equivalentTo: right.dropFirst(iteratedCount).prefix(span.count), + by: areEquivalent, + message(), trapping: trapping, file: file, line: line) + iteratedCount += span.count + } +} +#endif + +final class RigidDequeTests: CollectionTestCase { + func test_testingSPIs() { + // TODO + } + + func test_copyToContiguousArray() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + let data = tracker.rigidDeque(with: layout) + let actual = data.deque._copyToContiguousArray() + expectEqualElements(actual, data.contents) + } + } + } + + func test_unsafeUninitializedInitializer_nothrow() { + withEvery("capacity", in: 0 ..< 100) { cap in + withEvery("count", in: [0, cap / 3, cap / 2, 2 * cap / 3, cap] as Set) { count in + withLifetimeTracking { tracker in + let contents = tracker.instances(for: 0 ..< count) + let d1 = RigidDeque>( + unsafeUninitializedCapacity: cap, + initializingWith: { target, c in + guard target.count > 0 else { + expectNil(target.baseAddress) + return + } + expectNotNil(target.baseAddress) + expectEqual(target.count, cap) + expectEqual(c, 0) + contents.withUnsafeBufferPointer { source in + precondition(source.count <= target.count) + target.baseAddress!.initialize( + from: source.baseAddress!, + count: source.count) + } + c = count + }) + expectContainerContents(d1, equalTo: contents) + } + } + } + } + + struct TestError: Error, Equatable { + let value: Int + init(_ value: Int) { self.value = value } + } + + func test_unsafeUninitializedInitializer_throw() { + func createDeque(cap: Int, count: Int, contents: [LifetimeTracked.Element>]) throws { + _ = try RigidDeque>( + unsafeUninitializedCapacity: cap, + initializingWith: { target, c in + guard target.count > 0 else { + expectNil(target.baseAddress) + throw TestError(count) + } + expectNotNil(target.baseAddress) + expectEqual(target.count, cap) + expectEqual(c, 0) + contents.withUnsafeBufferPointer { source in + precondition(source.count <= target.count) + target.baseAddress!.initialize( + from: source.baseAddress!, + count: source.count) + } + c = count + throw TestError(count) + }) + } + + func workaroundSR14134(cap: Int, count: Int, tracker: LifetimeTracker) { + // This function works around https://bugs.swift.org/browse/SR-14134 + let contents = tracker.instances(for: 0 ..< count) + expectThrows(try createDeque(cap: cap, count: count, contents: contents)) { error in + expectEqual(error as? TestError, TestError(count)) + } + } + + withEvery("capacity", in: 0 ..< 100) { cap in + withEvery("count", in: [0, cap / 3, cap / 2, 2 * cap / 3, cap] as Set) { count in + withLifetimeTracking { tracker in + workaroundSR14134(cap: cap, count: count, tracker: tracker) + } + } + } + } + + func test_popFirst() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents[...].popFirst() + let actual = data.deque.popFirst() + expectEqual(actual, expected) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + + func test_popLast() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents[...].popLast() + let actual = data.deque.popLast() + expectEqual(actual, expected) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + + func test_prependOne() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + guard !data.deque.isFull else { return } + data.contents.insert(extra, at: 0) + data.deque.prepend(extra) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + + func test_appendOne() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + guard !data.deque.isFull else { return } + data.contents.insert(extra, at: data.contents.count) + data.deque.append(extra) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + + func test_prependManyFromMinimalSequence() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, prependCount))]) { underestimatedCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) + data.contents.insert(contentsOf: extras, at: 0) + guard extras.count <= data.deque.freeCapacity else { return } + data.deque.prepend(copying: sequence) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + } + + func test_prependManyFromMinimalCollection() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instances(for: layout.count ..< layout.count + prependCount) + guard extra.count <= data.deque.freeCapacity else { return } + let minimal = MinimalCollection(extra) + data.contents.insert(contentsOf: extra, at: 0) + data.deque.prepend(copying: minimal) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prependManyFromContiguousArray_asCollection() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + prependCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.insert(contentsOf: extra, at: 0) + data.deque.prepend(copying: extra) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prependManyFromContiguousArray_asSequence() { + // This calls the Sequence-based `Deque.prepend` overload, even if + // `elements` happens to be of a Collection type. + func prependSequence( + contentsOf elements: S, + to deque: inout RigidDeque + ) { + deque.prepend(copying: elements) + } + + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + prependCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.insert(contentsOf: extra, at: 0) + prependSequence(contentsOf: extra, to: &data.deque) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prependManyFromBridgedArray() { + // https://github.com/apple/swift-collections/issues/27 + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } + var deque = RigidDeque(layout: layout, contents: contents) + guard appendCount <= deque.freeCapacity else { return } + let extra: [NSObject] = (0 ..< appendCount) + .map { _ in NSObject() } + .withUnsafeBufferPointer { buffer in + NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] + } + guard extra.count <= deque.freeCapacity else { return } + contents.insert(contentsOf: extra, at: 0) + deque.prepend(copying: extra) + expectContainerContents(deque, equivalentTo: contents, by: ==) + } + } + } + + func test_appendManyFromMinimalSequence() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, appendCount))]) { underestimatedCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extras = tracker.instances(for: layout.count ..< layout.count + appendCount) + let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) + data.contents.append(contentsOf: extras) + guard extras.count <= data.deque.freeCapacity else { return } + data.deque.append(copying: sequence) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + } + + func test_appendManyFromMinimalCollection() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instances(for: layout.count ..< layout.count + appendCount) + guard extra.count <= data.deque.freeCapacity else { return } + let minimal = MinimalCollection(extra) + data.contents.append(contentsOf: extra) + data.deque.append(copying: minimal) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_appendManyFromContiguousArray_asCollection() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + appendCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.append(contentsOf: extra) + data.deque.append(copying: extra) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_appendManyFromContiguousArray_asSequence() { + // This calls the Sequence-based `Deque.append` overload, even if + // `elements` happens to be of a Collection type. + func appendSequence( + contentsOf elements: S, + to deque: inout RigidDeque + ) { + deque.append(copying: elements) + } + + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + appendCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.append(contentsOf: extra) + appendSequence(contentsOf: extra, to: &data.deque) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_appendManyFromBridgedArray() { + // https://github.com/apple/swift-collections/issues/27 + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } + var deque = RigidDeque(layout: layout, contents: contents) + guard appendCount <= deque.freeCapacity else { return } + let extra: [NSObject] = (0 ..< appendCount) + .map { _ in NSObject() } + .withUnsafeBufferPointer { buffer in + NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] + } + guard extra.count <= deque.freeCapacity else { return } + contents.append(contentsOf: extra) + deque.append(copying: extra) + expectContainerContents(deque, equivalentTo: contents, by: ==) + } + } + } + + func test_insertOneElement() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("offset", in: 0 ... layout.count) { offset in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + guard !data.deque.isFull else { return } + data.contents.insert(extra, at: offset) + data.deque.insert(extra, at: offset) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + +// func test_insertFromMinimalCollection() { +// withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in +// withEvery("offset", in: 0 ... layout.count) { offset in +// withEvery("insertCount", in: 0 ..< 10) { insertCount in +// withLifetimeTracking { tracker in +// var data = tracker.rigidDeque(with: layout) +// let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) +// let minimal = MinimalCollection(extras) +// data.contents.insert(contentsOf: extras, at: offset) +// data.deque.insert(contentsOf: minimal, at: offset) +// expectContainerContents(data.deque, equalTo: data.contents) +// } +// } +// } +// } +// } +// +// func test_insertFromArray() { +// withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in +// withEvery("offset", in: 0 ... layout.count) { offset in +// withEvery("insertCount", in: 0 ..< 10) { insertCount in +// withLifetimeTracking { tracker in +// var data = tracker.rigidDeque(with: layout) +// let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) +// data.contents.insert(contentsOf: extras, at: offset) +// data.deque.insert(contentsOf: extras, at: offset) +// expectContainerContents(data.deque, equalTo: data.contents) +// } +// } +// } +// } +// } + + func test_removeOne() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("offset", in: 0 ..< layout.count) { offset in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents.remove(at: offset) + let actual = data.deque.remove(at: offset) + expectEqual(actual, expected) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeSubrange() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryRange("range", in: 0 ..< layout.count) { range in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.contents.removeSubrange(range) + data.deque.removeSubrange(range) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeLast() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents.removeLast() + let actual = data.deque.removeLast() + expectEqual(actual, expected) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + + func test_removeLast_many() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withEvery("n", in: 0 ... layout.count) { n in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.contents.removeLast(n) + data.deque.removeLast(n) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeFirst_one() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents.removeFirst() + let actual = data.deque.removeFirst() + expectEqual(actual, expected) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + + func test_removeFirst_many() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withEvery("n", in: 0 ... layout.count) { n in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.contents.removeFirst(n) + data.deque.removeFirst(n) + expectContainerContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeAll_keepingCapacity() { + withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("isShared", in: [false, true]) { isShared in + guard layout.count > 0 else { return } + var data: RigidTestData> = .init(.init(capacity: 0), []) + withLifetimeTracking { tracker in + data = tracker.rigidDeque(with: layout) + data.contents.removeAll(keepingCapacity: true) + data.deque.removeAll() + expectEqual(data.deque.count, 0) + expectEqual(data.deque.capacity, layout.capacity) + } // All elements must be deinitialized at this point. + withExtendedLifetime(data.deque) {} + } + } + } +} From 4e93bbdb8d82c990e3c1fef02ad2e7f83b4c0420 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 5 Jan 2026 16:29:01 -0800 Subject: [PATCH 05/75] [DequeModule] Move Deque sources to a subdirectory --- Sources/DequeModule/CMakeLists.txt | 46 +++++++++++++------ .../{ => Deque}/Deque+Codable.swift | 0 .../{ => Deque}/Deque+Collection.swift | 0 .../{ => Deque}/Deque+CustomReflectable.swift | 0 .../{ => Deque}/Deque+Descriptions.swift | 0 .../{ => Deque}/Deque+Equatable.swift | 0 .../Deque+ExpressibleByArrayLiteral.swift | 0 .../{ => Deque}/Deque+Extras.swift | 0 .../{ => Deque}/Deque+Hashable.swift | 0 .../{ => Deque}/Deque+Testing.swift | 0 .../{ => Deque}/Deque._Storage.swift | 0 .../{ => Deque}/Deque._UnsafeHandle.swift | 0 Sources/DequeModule/{ => Deque}/Deque.swift | 0 .../{ => Deque}/_DequeBuffer.swift | 0 .../{ => Deque}/_DequeBufferHeader.swift | 0 15 files changed, 31 insertions(+), 15 deletions(-) rename Sources/DequeModule/{ => Deque}/Deque+Codable.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+Collection.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+CustomReflectable.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+Descriptions.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+Equatable.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+ExpressibleByArrayLiteral.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+Extras.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+Hashable.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque+Testing.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque._Storage.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque._UnsafeHandle.swift (100%) rename Sources/DequeModule/{ => Deque}/Deque.swift (100%) rename Sources/DequeModule/{ => Deque}/_DequeBuffer.swift (100%) rename Sources/DequeModule/{ => Deque}/_DequeBufferHeader.swift (100%) diff --git a/Sources/DequeModule/CMakeLists.txt b/Sources/DequeModule/CMakeLists.txt index f1c8cae8..97927d00 100644 --- a/Sources/DequeModule/CMakeLists.txt +++ b/Sources/DequeModule/CMakeLists.txt @@ -23,20 +23,36 @@ else() endif() target_sources(${module_name} PRIVATE - "Deque+Codable.swift" - "Deque+Collection.swift" - "Deque+CustomReflectable.swift" - "Deque+Descriptions.swift" - "Deque+Equatable.swift" - "Deque+ExpressibleByArrayLiteral.swift" - "Deque+Extras.swift" - "Deque+Hashable.swift" - "Deque+Testing.swift" - "Deque._Storage.swift" - "Deque._UnsafeHandle.swift" - "Deque.swift" - "_DequeBuffer.swift" - "_DequeBufferHeader.swift" + "_UnsafeDequeSegments.swift" + "_UnsafeDequeHandle.swift" "_DequeSlot.swift" - "_UnsafeWrappedBuffer.swift" + "RigidDeque/RigidDeque+Append.swift" + "RigidDeque/RigidDeque+Container.swift" + "RigidDeque/RigidDeque.swift" + "RigidDeque/RigidDeque+Initializers.swift" + "RigidDeque/RigidDeque+Testing.swift" + "RigidDeque/RigidDeque+Insertions.swift" + "RigidDeque/RigidDeque+Collection.swift" + "RigidDeque/RigidDeque+Prepend.swift" + "RigidDeque/RigidDeque+Removals.swift" + "UniqueDeque/UniqueDeque+Initializers.swift" + "UniqueDeque/UniqueDeque+Insertions.swift" + "UniqueDeque/UniqueDeque.swift" + "UniqueDeque/UniqueDeque+Prepend.swift" + "UniqueDeque/UniqueDeque+Append.swift" + "UniqueDeque/UniqueDeque+Removals.swift" + "Deque/_DequeBuffer.swift" + "Deque/Deque+Collection.swift" + "Deque/Deque+CustomReflectable.swift" + "Deque/Deque.swift" + "Deque/Deque+Hashable.swift" + "Deque/_DequeBufferHeader.swift" + "Deque/Deque+Codable.swift" + "Deque/Deque+Testing.swift" + "Deque/Deque._UnsafeHandle.swift" + "Deque/Deque+Descriptions.swift" + "Deque/Deque+Extras.swift" + "Deque/Deque+ExpressibleByArrayLiteral.swift" + "Deque/Deque+Equatable.swift" + "Deque/Deque._Storage.swift" ) diff --git a/Sources/DequeModule/Deque+Codable.swift b/Sources/DequeModule/Deque/Deque+Codable.swift similarity index 100% rename from Sources/DequeModule/Deque+Codable.swift rename to Sources/DequeModule/Deque/Deque+Codable.swift diff --git a/Sources/DequeModule/Deque+Collection.swift b/Sources/DequeModule/Deque/Deque+Collection.swift similarity index 100% rename from Sources/DequeModule/Deque+Collection.swift rename to Sources/DequeModule/Deque/Deque+Collection.swift diff --git a/Sources/DequeModule/Deque+CustomReflectable.swift b/Sources/DequeModule/Deque/Deque+CustomReflectable.swift similarity index 100% rename from Sources/DequeModule/Deque+CustomReflectable.swift rename to Sources/DequeModule/Deque/Deque+CustomReflectable.swift diff --git a/Sources/DequeModule/Deque+Descriptions.swift b/Sources/DequeModule/Deque/Deque+Descriptions.swift similarity index 100% rename from Sources/DequeModule/Deque+Descriptions.swift rename to Sources/DequeModule/Deque/Deque+Descriptions.swift diff --git a/Sources/DequeModule/Deque+Equatable.swift b/Sources/DequeModule/Deque/Deque+Equatable.swift similarity index 100% rename from Sources/DequeModule/Deque+Equatable.swift rename to Sources/DequeModule/Deque/Deque+Equatable.swift diff --git a/Sources/DequeModule/Deque+ExpressibleByArrayLiteral.swift b/Sources/DequeModule/Deque/Deque+ExpressibleByArrayLiteral.swift similarity index 100% rename from Sources/DequeModule/Deque+ExpressibleByArrayLiteral.swift rename to Sources/DequeModule/Deque/Deque+ExpressibleByArrayLiteral.swift diff --git a/Sources/DequeModule/Deque+Extras.swift b/Sources/DequeModule/Deque/Deque+Extras.swift similarity index 100% rename from Sources/DequeModule/Deque+Extras.swift rename to Sources/DequeModule/Deque/Deque+Extras.swift diff --git a/Sources/DequeModule/Deque+Hashable.swift b/Sources/DequeModule/Deque/Deque+Hashable.swift similarity index 100% rename from Sources/DequeModule/Deque+Hashable.swift rename to Sources/DequeModule/Deque/Deque+Hashable.swift diff --git a/Sources/DequeModule/Deque+Testing.swift b/Sources/DequeModule/Deque/Deque+Testing.swift similarity index 100% rename from Sources/DequeModule/Deque+Testing.swift rename to Sources/DequeModule/Deque/Deque+Testing.swift diff --git a/Sources/DequeModule/Deque._Storage.swift b/Sources/DequeModule/Deque/Deque._Storage.swift similarity index 100% rename from Sources/DequeModule/Deque._Storage.swift rename to Sources/DequeModule/Deque/Deque._Storage.swift diff --git a/Sources/DequeModule/Deque._UnsafeHandle.swift b/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift similarity index 100% rename from Sources/DequeModule/Deque._UnsafeHandle.swift rename to Sources/DequeModule/Deque/Deque._UnsafeHandle.swift diff --git a/Sources/DequeModule/Deque.swift b/Sources/DequeModule/Deque/Deque.swift similarity index 100% rename from Sources/DequeModule/Deque.swift rename to Sources/DequeModule/Deque/Deque.swift diff --git a/Sources/DequeModule/_DequeBuffer.swift b/Sources/DequeModule/Deque/_DequeBuffer.swift similarity index 100% rename from Sources/DequeModule/_DequeBuffer.swift rename to Sources/DequeModule/Deque/_DequeBuffer.swift diff --git a/Sources/DequeModule/_DequeBufferHeader.swift b/Sources/DequeModule/Deque/_DequeBufferHeader.swift similarity index 100% rename from Sources/DequeModule/_DequeBufferHeader.swift rename to Sources/DequeModule/Deque/_DequeBufferHeader.swift From 722ed6ae907cee9c412b48b3f403730c7424cde3 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 5 Jan 2026 18:29:31 -0800 Subject: [PATCH 06/75] [RigidDeque] Flesh out append methods --- .../BasicContainers/RigidArray+Append.swift | 7 +- Sources/BasicContainers/RigidArray.swift | 5 +- .../DequeModule/Deque/Deque+Collection.swift | 6 +- Sources/DequeModule/Deque/Deque+Extras.swift | 4 +- .../Deque/Deque._UnsafeHandle.swift | 10 +- .../RigidDeque/RigidDeque+Append.swift | 175 +++++++++++++++--- .../RigidDeque/RigidDeque+Experimental.swift | 42 +++++ .../RigidDeque/RigidDeque+Prepend.swift | 7 +- .../DequeModule/RigidDeque/RigidDeque.swift | 167 ++++++++++++----- .../UniqueDeque/UniqueDeque+Append.swift | 6 +- .../UniqueDeque+Experimental.swift | 36 ++++ .../DequeModule/UniqueDeque/UniqueDeque.swift | 18 +- Sources/DequeModule/_DequeSlot.swift | 2 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 143 +++++++++++++- .../DequeModule/_UnsafeDequeSegments.swift | 33 +++- 15 files changed, 535 insertions(+), 126 deletions(-) create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift diff --git a/Sources/BasicContainers/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray+Append.swift index f1c57ee4..13347432 100644 --- a/Sources/BasicContainers/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray+Append.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -39,7 +39,7 @@ extension RigidArray where Element: ~Copyable { /// then this returns the given item without appending it; otherwise it /// returns nil. /// - /// - Parameter item: The element to append to the collection. + /// - Parameter item: The element to append to the array. /// - Returns: `item` if the array is full; otherwise nil. /// /// - Complexity: O(1) @@ -188,8 +188,7 @@ extension RigidArray where Element: ~Copyable { /// in the source array, then this triggers a runtime error. /// /// - Parameters - /// - items: A fully initialized buffer whose contents to move into - /// the array. + /// - items: A container whose contents to move into this array. /// /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient diff --git a/Sources/BasicContainers/RigidArray.swift b/Sources/BasicContainers/RigidArray.swift index 6d78ed8c..3b7ff6da 100644 --- a/Sources/BasicContainers/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -314,7 +314,8 @@ extension RigidArray where Element: ~Copyable { public var startIndex: Int { 0 } /// The array’s "past the end” position—that is, the position one greater than - /// the last valid subscript argument. This is always equal to array's count. + /// the last valid subscript argument. This is always equal to the array's + /// count. /// /// - Complexity: O(1) @inlinable diff --git a/Sources/DequeModule/Deque/Deque+Collection.swift b/Sources/DequeModule/Deque/Deque+Collection.swift index 8f4fa8b6..3c469485 100644 --- a/Sources/DequeModule/Deque/Deque+Collection.swift +++ b/Sources/DequeModule/Deque/Deque+Collection.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -701,7 +701,7 @@ extension Deque: RangeReplaceableCollection { _storage.update { target in target.uncheckedAppend(next) let gaps = target.availableSegments() - target.count += gaps.initialize(fromPrefixOf: &it) + target.count += gaps.initialize(copyingPrefixOf: &it) } } } @@ -735,7 +735,7 @@ extension Deque: RangeReplaceableCollection { _storage.ensureUnique(minimumCapacity: count + c) _storage.update { target in let gaps = target.availableSegments().prefix(c) - gaps.initialize(from: newElements) + gaps.initialize(copying: newElements) target.count += c } } diff --git a/Sources/DequeModule/Deque/Deque+Extras.swift b/Sources/DequeModule/Deque/Deque+Extras.swift index 850e493f..e4b36ba0 100644 --- a/Sources/DequeModule/Deque/Deque+Extras.swift +++ b/Sources/DequeModule/Deque/Deque+Extras.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -148,7 +148,7 @@ extension Deque { _storage.ensureUnique(minimumCapacity: count + c) _storage.update { target in let gaps = target.availableSegments().suffix(c) - gaps.initialize(from: newElements) + gaps.initialize(copying: newElements) target.count += c target.startSlot = target.slot(target.startSlot, offsetBy: -c) } diff --git a/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift b/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift index c44333af..263e5c40 100644 --- a/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift +++ b/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -392,7 +392,7 @@ extension Deque._UnsafeHandle { assert(newElements.count == range.count) guard !range.isEmpty else { return } let target = mutableSegments(forOffsets: range) - target.assign(from: newElements) + target.reassign(copying: newElements) } } @@ -425,7 +425,7 @@ extension Deque._UnsafeHandle { let c = self.count count += source.count let gap = mutableSegments(forOffsets: c ..< count) - gap.initialize(from: source) + gap.initialize(copying: source) } } @@ -458,7 +458,7 @@ extension Deque._UnsafeHandle { count += source.count let gap = mutableWrappedBuffer(between: newStart, and: oldStart) - gap.initialize(from: source) + gap.initialize(copying: source) } } @@ -487,7 +487,7 @@ extension Deque._UnsafeHandle { assert(newElements.count == newCount) guard newCount > 0 else { return } let gap = openGap(ofSize: newCount, atOffset: offset) - gap.initialize(from: newElements) + gap.initialize(copying: newElements) } @inlinable diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 6bfe93d3..31612034 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -18,12 +18,6 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - @_alwaysEmitIntoClient - @_transparent - internal mutating func uncheckedAppend(_ newElement: consuming Element) { - _handle.uncheckedAppend(newElement) - } - /// Adds an element to the end of the deque. /// /// If the deque does not have sufficient capacity to hold any more elements, @@ -35,8 +29,8 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent public mutating func append(_ newElement: consuming Element) { - precondition(!isFull, "RigidDeque is full") - uncheckedAppend(newElement) + precondition(!isFull, "RigidDeque capacity overflow") + _handle.uncheckedAppend(newElement) } /// Adds an element to the end of the deque, if possible. @@ -45,7 +39,7 @@ extension RigidDeque where Element: ~Copyable { /// then this returns the given item without appending it; otherwise it /// returns nil. /// - /// - Parameter item: The element to append to the collection. + /// - Parameter item: The element to append to the deque. /// - Returns: `item` if the deque is full; otherwise nil. /// /// - Complexity: O(1) @@ -59,6 +53,153 @@ extension RigidDeque where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Append a given number of items to the end of this deque by populating + /// a series of storage regions by successive calls of the specified callback + /// function. + /// + /// If the deque does not have sufficient capacity to store the new items, + /// then this triggers a runtime error. + /// + /// The newly appended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease when the callback fails to fully populate its output span or when if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated. + /// + /// - Parameters + /// - count: The number of items to append to the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is allowed to initialize fewer than `count` items. The deque is + /// appended however many items the callback adds to the output span + /// before it returns (or before it throws an error). + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + public mutating func append( + count: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition(freeCapacity >= count, "RigidDeque capacity overflow") + try _handle.uncheckedAppend(count: count, initializingWith: body) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Moves the elements of a buffer to the end of this deque, leaving the + /// buffer uninitialized. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// buffer, then this triggers a runtime error. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func append( + moving items: UnsafeMutableBufferPointer + ) { + precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") + _handle.uncheckedAppend(moving: items) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Moves the elements of a input span to the end of this deque, leaving the + /// span empty. + /// + /// If the deque does not have sufficient capacity to hold all items in its + /// storage, then this triggers a runtime error. + /// + /// - Parameters + /// - items: An input span whose contents need to be appended to this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout InputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.append(moving: source) + count = 0 + } + } +#endif + + /// Moves the elements of an output span to the end of this deque, leaving the + /// span empty. + /// + /// If the deque does not have sufficient capacity to hold all items in its + /// storage, then this triggers a runtime error. + /// + /// - Parameters + /// - items: An output span whose contents need to be appended to this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout OutputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.append(moving: source) + count = 0 + } + } + + /// Appends the elements of a given deque to the end of this array by moving + /// them between the containers. On return, the input deque becomes empty, but + /// it is not destroyed, and it preserves its original storage capacity. + /// + /// If the target deque does not have sufficient capacity to hold all items + /// in the source deque, then this triggers a runtime error. + /// + /// - Parameters + /// - items: A deque whose items to move to the end of this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout RigidDeque + ) { + // FIXME: Remove this in favor of a generic algorithm over range-replaceable containers + precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") + items._handle.unsafeConsumeElements { source in + self._handle.uncheckedAppend(moving: source) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Appends the elements of a given container to the end of this deque by + /// consuming the source container. + /// + /// If the target deque does not have sufficient capacity to hold all items, + /// then this triggers a runtime error. + /// + /// - Parameters + /// - items: A container whose contents to move into this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func append( + consuming items: consuming RigidDeque + ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers + var items = items + self.append(moving: &items) + } +#endif +} + @available(SwiftStdlib 5.0, *) extension RigidDeque /*where Element: Copyable*/ { /// Copies the elements of a buffer to the end of this deque. @@ -79,7 +220,7 @@ extension RigidDeque /*where Element: Copyable*/ { newElements.count <= freeCapacity, "RigidDeque capacity overflow") guard newElements.count > 0 else { return } - _handle.uncheckedAppend(contentsOf: newElements) + _handle.uncheckedAppend(copying: newElements) } /// Copies the elements of a buffer to the end of this deque. @@ -115,16 +256,6 @@ extension RigidDeque /*where Element: Copyable*/ { } } - @_alwaysEmitIntoClient - @inline(__always) - internal mutating func _append>( - prefixOf items: S - ) -> S.Iterator { - let (it, c) = _handle.availableSegments().initialize(fromSequencePrefix: items) - _handle.count += c - return it - } - /// Copies the elements of a sequence to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the @@ -142,7 +273,7 @@ extension RigidDeque /*where Element: Copyable*/ { } if done != nil { return } - var it = self._append(prefixOf: newElements) + var it = _handle.uncheckedAppend(copyingPrefixOf: newElements) precondition(it.next() == nil, "RigidDeque capacity overflow") } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift new file mode 100644 index 00000000..79237cc1 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +#if false // FIXME +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + @_lifetime(borrow self) + public func borrowElement(at index: Int) -> Ref { + precondition(index >= 0 && index < count, "Index out of bounds") + let slot = _handle.slot(forOffset: index) + return Ref(unsafeAddress: _handle.ptr(at: slot), borrowing: self) + } + + @_alwaysEmitIntoClient + @_transparent + @_lifetime(&self) + public mutating func mutateElement(at index: Int) -> Mut { + precondition(index >= 0 && index < count, "Index out of bounds") + let slot = _handle.slot(forOffset: index) + return Mut(unsafeAddress: _handle.mutablePtr(at: slot), mutating: &self) + } +} +#endif + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 30633fc3..f7be73a7 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -145,12 +145,13 @@ extension RigidDeque /*where Element: Copyable*/ { return } guard done == nil else { return } - + // Add new elements as suffix and check that all elements were copied. let oldEndSlot = _handle.endSlot - var it = self._append(prefixOf: newElements) + var it = _handle.uncheckedAppend(copyingPrefixOf: newElements) precondition(it.next() == nil, "RigidDeque capacity overflow") _handle.rotate(toStartAt: oldEndSlot) + } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index 4f67b278..5c32e10e 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -16,6 +16,8 @@ import ContainersPreview #if compiler(<6.2) +/// A fixed capacity, heap allocated, noncopyable double-ended queue of +/// potentially noncopyable elements. @frozen @available(*, unavailable, message: "RigidDeque requires a Swift 6.2 toolchain") public struct RigidDeque: ~Copyable { @@ -26,7 +28,8 @@ public struct RigidDeque: ~Copyable { #else -/// A fixed-capacity container implementing a double-ended queue. +/// A fixed capacity, heap allocated, noncopyable double-ended queue of +/// potentially noncopyable elements. @available(SwiftStdlib 5.0, *) @frozen @safe @@ -69,14 +72,26 @@ extension RigidDeque where Element: ~Copyable { #endif // COLLECTIONS_INTERNAL_CHECKS } + +//MARK: - Basics + @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - @usableFromInline - internal var description: String { - _handle.description - } + @_alwaysEmitIntoClient + @_transparent + public var capacity: Int { _assumeNonNegative(_handle.capacity) } + + @_alwaysEmitIntoClient + @_transparent + public var freeCapacity: Int { _assumeNonNegative(capacity - count) } + + @_alwaysEmitIntoClient + @_transparent + public var isFull: Bool { count == capacity } } +//MARK: - Span creation + @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @@ -96,43 +111,53 @@ extension RigidDeque where Element: ~Copyable { } } +//MARK: - Container primitives + @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { + /// A type that represents a position in the deque: an integer offset from its + /// logical start position. + /// + /// Valid indices consist of the position of every element and a "past the + /// end” position that’s not valid for use as a subscript argument. public typealias Index = Int - + + /// A Boolean value indicating whether this deque contains no elements. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public var isEmpty: Bool { _handle.count == 0 } - + + /// The number of elements in this deque. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public var count: Int { _handle.count } - + + /// The position of the first element in a nonempty deque. This is always zero. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public var startIndex: Int { 0 } - + + /// The deque’s "past the end” position—that is, the position one greater than + /// the last valid subscript argument. This is always equal to the deque's + /// count. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public var endIndex: Int { _handle.count } - - @_alwaysEmitIntoClient - @_transparent - @_lifetime(borrow self) - public func borrowElement(at index: Int) -> Ref { - precondition(index >= 0 && index < count, "Index out of bounds") - let slot = _handle.slot(forOffset: index) - return Ref(unsafeAddress: _handle.ptr(at: slot), borrowing: self) - } - - @_alwaysEmitIntoClient - @_transparent - @_lifetime(&self) - public mutating func mutateElement(at index: Int) -> Mut { - precondition(index >= 0 && index < count, "Index out of bounds") - let slot = _handle.slot(forOffset: index) - return Mut(unsafeAddress: _handle.mutablePtr(at: slot), mutating: &self) - } + + /// The range of indices that are valid for subscripting this deque. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var indices: Range { unsafe Range(uncheckedBounds: (0, count)) } @_alwaysEmitIntoClient public subscript(position: Int) -> Element { @@ -155,36 +180,84 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - @_alwaysEmitIntoClient - @_transparent - public var capacity: Int { _handle.capacity } - - @_alwaysEmitIntoClient - @_transparent - public var freeCapacity: Int { capacity - count } - - @_alwaysEmitIntoClient - @_transparent - public var isFull: Bool { count == capacity } - - @_alwaysEmitIntoClient - @_transparent - public mutating func resize(to newCapacity: Int) { - _handle.reallocate(capacity: newCapacity) + /// Exchanges the values at the specified indices of the array. + /// + /// Both parameters must be valid indices of the array and not equal to + /// endIndex. Passing the same index as both `i` and `j` has no effect. + /// + /// - Parameter i: The index of the first value to swap. + /// - Parameter j: The index of the second valud to swap. + /// + /// - Complexity: O(1) + @inlinable + public mutating func swapAt(_ i: Int, _ j: Int) { + precondition( + i >= 0 && i < count && j >= 0 && j < count, + "Index out of bounds") + _handle.uncheckedSwapAt(i, j) } } +//MARK: - Resizing + @available(SwiftStdlib 5.0, *) -extension RigidDeque { +extension RigidDeque where Element: ~Copyable { + /// Grow or shrink the capacity of a rigid deque instance without discarding + /// its contents. + /// + /// This operation replaces the deque's storage buffer with a newly allocated + /// buffer of the specified capacity, moving all existing elements + /// to its new storage. The old storage is then deallocated. + /// + /// - Parameter newCapacity: The desired new capacity. `newCapacity` must be + /// greater than or equal to the current count. + /// + /// - Complexity: O(`count`) @_alwaysEmitIntoClient @_transparent - internal func _copy() -> Self { + public mutating func reallocate(capacity newCapacity: Int) { + _handle.reallocate(capacity: newCapacity) + } + + /// Ensure that the deque has capacity to store the specified number of + /// elements, by growing its storage buffer if necessary. + /// + /// If `capacity < n`, then this operation reallocates the rigid deque's + /// storage to grow it; on return, the deque's capacity becomes `n`. + /// Otherwise the deque is left as is. + /// + /// - Complexity: O(`count`) + @inlinable + public mutating func reserveCapacity(_ n: Int) { + guard capacity < n else { return } + reallocate(capacity: n) + } +} + +//MARK: - Copying helpers + +@available(SwiftStdlib 5.0, *) +extension RigidDeque { + /// Copy the contents of this array into a newly allocated rigid deque + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + @_transparent + public func _clone() -> Self { RigidDeque(_handle: _handle.allocateCopy()) } + /// Copy the contents of this deque into a newly allocated rigid deque + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting rigid deque. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) @_alwaysEmitIntoClient @_transparent - internal func _copy(capacity: Int) -> Self { + public func _clone(capacity: Int) -> Self { RigidDeque(_handle: _handle.allocateCopy(capacity: capacity)) } } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift index 47b7fc02..c24662a0 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -31,7 +31,7 @@ extension UniqueDeque where Element: ~Copyable { @_transparent public mutating func append(_ newElement: consuming Element) { _ensureFreeCapacity(1) - _storage.uncheckedAppend(newElement) + _storage._handle.uncheckedAppend(newElement) } } @@ -116,7 +116,7 @@ extension UniqueDeque /*where Element: Copyable*/ { if done != nil { return } _ensureFreeCapacity(newElements.underestimatedCount) - var it = _storage._append(prefixOf: newElements) + var it = _storage._handle.uncheckedAppend(copyingPrefixOf: newElements) while let item = it.next() { _ensureFreeCapacity(1) _storage.append(item) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift new file mode 100644 index 00000000..7d62a203 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +#if false // FIXME + +@_alwaysEmitIntoClient +@_transparent +@_lifetime(borrow self) +public func borrowElement(at index: Int) -> Ref { + _storage.borrowElement(at: index) +} + +@_alwaysEmitIntoClient +@_transparent +@_lifetime(&self) +public mutating func mutateElement(at index: Int) -> Mut { + _storage.mutateElement(at: index) +} + +#endif +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift index c70dc20c..d4bc693c 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -77,20 +77,6 @@ extension UniqueDeque where Element: ~Copyable { @inline(__always) public var indices: Range { unsafe Range(uncheckedBounds: (0, count)) } - @_alwaysEmitIntoClient - @_transparent - @_lifetime(borrow self) - public func borrowElement(at index: Int) -> Ref { - _storage.borrowElement(at: index) - } - - @_alwaysEmitIntoClient - @_transparent - @_lifetime(&self) - public mutating func mutateElement(at index: Int) -> Mut { - _storage.mutateElement(at: index) - } - @_alwaysEmitIntoClient public subscript(position: Int) -> Element { @inline(__always) @@ -131,7 +117,7 @@ extension UniqueDeque where Element: ~Copyable { } let c = Swift.max(minimumCapacity, 7 * _capacity / 4) - _storage.resize(to: c) + _storage.reallocate(capacity: c) } @inlinable diff --git a/Sources/DequeModule/_DequeSlot.swift b/Sources/DequeModule/_DequeSlot.swift index 22365c9a..dd1a54c3 100644 --- a/Sources/DequeModule/_DequeSlot.swift +++ b/Sources/DequeModule/_DequeSlot.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 6b1543b0..7b0d7d6f 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -338,7 +338,9 @@ extension _UnsafeDequeHandle where Element: ~Copyable { internal func segments( forOffsets offsets: Range ) -> _UnsafeDequeSegments { - assert(offsets.lowerBound >= 0 && offsets.upperBound <= count) + // Note: no asserts for bounds checks, as this is used to implement + // appends/prepends + assert(offsets.count <= capacity) guard _buffer.baseAddress != nil else { return .init(._empty) } @@ -439,7 +441,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent internal mutating func reallocate(capacity newCapacity: Int) { - precondition(newCapacity >= count) + precondition(newCapacity >= count, "Capacity overflow") guard newCapacity != capacity else { return } var new = _UnsafeDequeHandle.allocate(capacity: newCapacity) @@ -498,6 +500,18 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +// MARK: Swap + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedSwapAt(_ i: Int, _ j: Int) { + let slot1 = self.slot(forOffset: i) + let slot2 = self.slot(forOffset: j) + self.mutableBuffer.swapAt(slot1.position, slot2.position) + } +} + // MARK: Replacement extension _UnsafeDequeHandle { @@ -516,7 +530,24 @@ extension _UnsafeDequeHandle { assert(newElements.count == range.count) guard !range.isEmpty else { return } let target = mutableSegments(forOffsets: range) - target.assign(from: newElements) + target.reassign(copying: newElements) + } +} + +// MARK: Consumption + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal mutating func unsafeConsumeElements( + with body: (UnsafeMutableBufferPointer) -> Void + ) { + let segments = mutableSegments() + body(segments.first) + if let second = segments.second { + body(second) + } + self.count = 0 } } @@ -537,6 +568,100 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +extension _UnsafeDequeHandle where Element: ~Copyable { + @inlinable + internal mutating func _insertSegment( + _ buffer: UnsafeMutableBufferPointer, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + var span = OutputSpan(buffer: buffer, initializedCount: 0) + defer { + self.count &+= span.finalize(for: buffer) + span = OutputSpan() + } + try body(&span) + } + + /// Append a given number of items to the end of this deque by populating + /// a series of storage regions by successive calls of the specified callback + /// function. + /// + /// This unchecked routine does not verify that the deque has sufficient + /// capacity to store the new items. + /// + /// The newly appended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease when the callback fails to fully populate its output span or when if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated. + /// + /// - Parameters + /// - count: The number of items to append to the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is allowed to initialize fewer than `count` items. The deque is + /// appended however many items the callback adds to the output span + /// before it returns (or before it throws an error). + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + internal mutating func uncheckedAppend( + count: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + let origCount = self.count + let gap = self.mutableSegments(forOffsets: origCount ..< origCount + count) + + try _insertSegment(gap.first, initializingWith: body) + if self.count == origCount + gap.first.count, let second = gap.second { + try _insertSegment(second, initializingWith: body) + } + } + + /// Moves the elements of a buffer to the end of this deque, leaving the + /// buffer uninitialized. + /// + /// This unchecked routine does not verify that the deque has sufficient + /// capacity to store the new items. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + internal mutating func uncheckedAppend( + moving items: UnsafeMutableBufferPointer + ) { + guard items.count > 0 else { return } + + let gap = self.mutableSegments( + forOffsets: self.count ..< self.count + items.count) + + gap.first.moveInitializeAll( + fromContentsOf: items._extracting(first: gap.first.count)) + + if let second = gap.second { + assert(gap.first.count + second.count == items.count) + second.moveInitializeAll( + fromContentsOf: items._extracting(last: second.count)) + } + self.count &+= items.count + } + + @_alwaysEmitIntoClient + @inline(__always) + internal mutating func uncheckedAppend>( + copyingPrefixOf items: S + ) -> S.Iterator { + let (it, c) = self.availableSegments().initialize(fromSequencePrefix: items) + self.count += c + return it + } +} + extension _UnsafeDequeHandle { /// Append the contents of `source` to this buffer. The buffer must have /// enough free capacity to insert the new elements. @@ -545,13 +670,13 @@ extension _UnsafeDequeHandle { /// does it ensure that the storage buffer is uniquely referenced. @_alwaysEmitIntoClient @_transparent - internal mutating func uncheckedAppend(contentsOf source: UnsafeBufferPointer) { + internal mutating func uncheckedAppend(copying source: UnsafeBufferPointer) { assert(count + source.count <= capacity) guard source.count > 0 else { return } let c = self.count count += source.count let gap = mutableSegments(forOffsets: c ..< count) - gap.initialize(from: source) + gap.initialize(copying: source) } } @@ -586,7 +711,7 @@ extension _UnsafeDequeHandle /*where Element: Copyable*/ { count += source.count let gap = mutableSegments(between: newStart, and: oldStart) - gap.initialize(from: source) + gap.initialize(copying: source) } /// Prepend the contents of `source` to this buffer. The buffer must have @@ -608,7 +733,7 @@ extension _UnsafeDequeHandle /*where Element: Copyable*/ { count += sourceCount let gap = mutableSegments(between: newStart, and: oldStart) - gap.initialize(from: source) + gap.initialize(copying: source) } } @@ -965,7 +1090,7 @@ extension _UnsafeDequeHandle { assert(newElements.count == newCount) guard newCount > 0 else { return } let gap = openGap(ofSize: newCount, atOffset: offset) - gap.initialize(from: newElements) + gap.initialize(copying: newElements) } } diff --git a/Sources/DequeModule/_UnsafeDequeSegments.swift b/Sources/DequeModule/_UnsafeDequeSegments.swift index 98bb9985..228c8d91 100644 --- a/Sources/DequeModule/_UnsafeDequeSegments.swift +++ b/Sources/DequeModule/_UnsafeDequeSegments.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -189,7 +189,7 @@ extension _UnsafeMutableDequeSegments { @_alwaysEmitIntoClient @_transparent internal func initialize( - fromPrefixOf iterator: inout I + copyingPrefixOf iterator: inout I ) -> Int where I.Element == Element { var copied = 0 @@ -217,7 +217,7 @@ extension _UnsafeMutableDequeSegments { where S.Element == Element { guard second == nil || first.count >= elements.underestimatedCount else { var it = elements.makeIterator() - let copied = initialize(fromPrefixOf: &it) + let copied = initialize(copyingPrefixOf: &it) return (it, copied) } // Note: Array._copyContents traps when not given enough space, so we @@ -240,9 +240,24 @@ extension _UnsafeMutableDequeSegments { @_alwaysEmitIntoClient @_transparent - internal func initialize( - from elements: __owned C - ) where C.Element == Element { + internal func initialize( + copying elements: UnsafeMutableBufferPointer + ) { + assert(self.count == elements.count) + if let second = second { + let wrap = first.count + first.initializeAll(fromContentsOf: elements._extracting(first: wrap)) + second.initializeAll(fromContentsOf: elements.extracting(wrap...)) + } else { + first.initializeAll(fromContentsOf: elements) + } + } + + @_alwaysEmitIntoClient + @_transparent + internal func initialize( + copying elements: __owned some Collection + ) { assert(self.count == elements.count) if let second = second { let wrap = elements.index(elements.startIndex, offsetBy: first.count) @@ -255,11 +270,11 @@ extension _UnsafeMutableDequeSegments { @_alwaysEmitIntoClient @_transparent - internal func assign( - from elements: C + internal func reassign( + copying elements: C ) where C.Element == Element { assert(elements.count == self.count) deinitialize() - initialize(from: elements) + initialize(copying: elements) } } From 54494e1c98b38501a94f4f439d417ca0497a3076 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 6 Jan 2026 15:14:07 -0800 Subject: [PATCH 07/75] [RigidDeque] Flesh out prepend methods --- .../BasicContainers/RigidArray+Append.swift | 1 + .../RigidArray+Insertions.swift | 1 + Sources/BasicContainers/RigidArray.swift | 1 + .../RigidDeque/RigidDeque+Append.swift | 34 ++- .../RigidDeque/RigidDeque+Prepend.swift | 226 +++++++++++++- .../UniqueDeque/UniqueDeque+Prepend.swift | 2 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 288 ++++++++++++------ .../DequeModule/_UnsafeDequeSegments.swift | 19 +- 8 files changed, 450 insertions(+), 122 deletions(-) diff --git a/Sources/BasicContainers/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray+Append.swift index 13347432..81767ea5 100644 --- a/Sources/BasicContainers/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray+Append.swift @@ -75,6 +75,7 @@ extension RigidArray where Element: ~Copyable { initializingWith body: (inout OutputSpan) throws(E) -> Result ) throws(E) -> Result { // FIXME: This is extremely similar to `edit()`, except it provides a narrower span. + precondition(count >= 0, "Negative count") precondition(freeCapacity >= count, "RigidArray capacity overflow") let buffer = _freeSpace._extracting(first: count) var span = OutputSpan(buffer: buffer, initializedCount: 0) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 669a4fc1..cc47c1f5 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -80,6 +80,7 @@ extension RigidArray where Element: ~Copyable { ) -> Result { // FIXME: This does not allow `body` to throw, to prevent having to move the tail twice. Is that okay? precondition(index >= 0 && index <= self.count, "Index out of bounds") + precondition(count >= 0, "Negative count") precondition(count <= freeCapacity, "RigidArray capacity overflow") let target = unsafe _openGap(at: index, count: count) var span = OutputSpan(buffer: target, initializedCount: 0) diff --git a/Sources/BasicContainers/RigidArray.swift b/Sources/BasicContainers/RigidArray.swift index 3b7ff6da..3982589c 100644 --- a/Sources/BasicContainers/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray.swift @@ -571,6 +571,7 @@ extension RigidArray where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= _count, "Index range out of bounds") + precondition(newCount >= 0, "Negative count") precondition( newCount - subrange.count <= freeCapacity, "RigidArray capacity overflow") diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 31612034..83f5e7d6 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -23,7 +23,7 @@ extension RigidDeque where Element: ~Copyable { /// If the deque does not have sufficient capacity to hold any more elements, /// then this triggers a runtime error. /// - /// - Parameter item: The element to append to the collection. + /// - Parameter item: The element to append to the deque. /// /// - Complexity: O(1) @_alwaysEmitIntoClient @@ -55,19 +55,41 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - /// Append a given number of items to the end of this deque by populating - /// a series of storage regions by successive calls of the specified callback - /// function. + /// Efficiently append a given number of items to the back of this deque by + /// populating a series of storage regions through successive calls of the + /// specified callback function. /// /// If the deque does not have sufficient capacity to store the new items, /// then this triggers a runtime error. /// + /// var buffer = RigidDeque(capacity: 20) + /// buffer.append(999) + /// var i = 0 + /// buffer.append(count: 6) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [999, 0, 1, 2, 3, 4, 5, 6] + /// /// The newly appended items are not guaranteed to form a single contiguous /// storage region. Therefore, the supplied callback may be invoked multiple /// times to initialize each successive chunk of storage. However, invocations /// cease when the callback fails to fully populate its output span or when if /// it throws an error. In such cases, the deque keeps all items that were - /// successfully initialized before the callback terminated. + /// successfully initialized before the callback terminated the append. + /// + /// var buffer = RigidDeque(capacity: 20) + /// buffer.append(999) + /// var i = 0 + /// buffer.append(count: 6) { target in + /// while !target.isFull, i <= 3 { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [999, 0, 1, 2, 3] /// /// - Parameters /// - count: The number of items to append to the deque. @@ -83,6 +105,7 @@ extension RigidDeque where Element: ~Copyable { count: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { + precondition(count >= 0, "Negative count") precondition(freeCapacity >= count, "RigidDeque capacity overflow") try _handle.uncheckedAppend(count: count, initializingWith: body) } @@ -219,7 +242,6 @@ extension RigidDeque /*where Element: Copyable*/ { precondition( newElements.count <= freeCapacity, "RigidDeque capacity overflow") - guard newElements.count > 0 else { return } _handle.uncheckedAppend(copying: newElements) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index f7be73a7..d439edf4 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -18,20 +18,217 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - @_alwaysEmitIntoClient - @_transparent - internal mutating func uncheckedPrepend(_ newElement: consuming Element) { - _handle.uncheckedPrepend(newElement) - } - + /// Adds an element to the front of the deque. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this triggers a runtime error. + /// + /// - Parameter item: The element to prepend to the deque. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public mutating func prepend(_ newElement: consuming Element) { - precondition(!isFull, "RigidDeque is full") - uncheckedPrepend(newElement) + precondition(!isFull, "RigidDeque capacity overflow") + _handle.uncheckedPrepend(newElement) + } + + /// Adds an element to the front of the deque, if possible. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this returns the given item without prepending it; otherwise it + /// returns nil. + /// + /// - Parameter item: The element to prepend to the deque. + /// - Returns: `item` if the deque is full; otherwise nil. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public mutating func pushFirst(_ item: consuming Element) -> Element? { + // FIXME: Remove this in favor of a standard algorithm. + if isFull { return item } + prepend(item) + return nil } } +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Efficiently prepend a given number of items to the front of this deque by + /// populating a series of storage regions through successive calls of the + /// specified callback function. + /// + /// If the deque does not have sufficient capacity to store the new items, + /// then this triggers a runtime error. + /// + /// var buffer = RigidDeque(capacity: 20) + /// buffer.append(999) + /// var i = 0 + /// buffer.prepend(count: 6) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [0, 1, 2, 3, 4, 5, 6, 999] + /// + /// The newly prepended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease when the callback fails to fully populate its output span or when if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// (Partial prepends create a gap in ring buffer storage that needs to be + /// closed by moving newly prepended items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised.) + /// + /// var buffer = RigidDeque(capacity: 20) + /// buffer.append(999) + /// var i = 0 + /// buffer.prepend(count: 6) { target in + /// while !target.isFull, i <= 3 { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [0, 1, 2, 3, 999] + /// + /// - Parameters + /// - count: The number of items to append to the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is allowed to initialize fewer than `count` items. The deque is + /// appended however many items the callback adds to the output span + /// before it returns (or before it throws an error). + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + public mutating func prepend( + count: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition(count >= 0, "Negative count") + precondition(freeCapacity >= count, "RigidDeque capacity overflow") + try _handle.uncheckedPrepend(count: count, initializingWith: body) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Moves the elements of a buffer to the end of this deque, leaving the + /// buffer uninitialized. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// buffer, then this triggers a runtime error. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func prepend( + moving items: UnsafeMutableBufferPointer + ) { + precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") + _handle.uncheckedPrepend(moving: items) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Moves the elements of a input span to the end of this deque, leaving the + /// span empty. + /// + /// If the deque does not have sufficient capacity to hold all items in its + /// storage, then this triggers a runtime error. + /// + /// - Parameters + /// - items: An input span whose contents need to be appended to this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func prepend( + moving items: inout InputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.prepend(moving: source) + count = 0 + } + } +#endif + + /// Moves the elements of an output span to the end of this deque, leaving the + /// span empty. + /// + /// If the deque does not have sufficient capacity to hold all items in its + /// storage, then this triggers a runtime error. + /// + /// - Parameters + /// - items: An output span whose contents need to be appended to this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func prepend( + moving items: inout OutputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.prepend(moving: source) + count = 0 + } + } + + /// Appends the elements of a given deque to the end of this array by moving + /// them between the containers. On return, the input deque becomes empty, but + /// it is not destroyed, and it preserves its original storage capacity. + /// + /// If the target deque does not have sufficient capacity to hold all items + /// in the source deque, then this triggers a runtime error. + /// + /// - Parameters + /// - items: A deque whose items to move to the end of this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func prepend( + moving items: inout RigidDeque + ) { + // FIXME: Remove this in favor of a generic algorithm over range-replaceable containers + precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") + items._handle.unsafeConsumeElements { source in + self._handle.uncheckedAppend(moving: source) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Appends the elements of a given container to the end of this deque by + /// consuming the source container. + /// + /// If the target deque does not have sufficient capacity to hold all items, + /// then this triggers a runtime error. + /// + /// - Parameters + /// - items: A container whose contents to move into this deque. + /// + /// - Complexity: O(`items.count`) + @_alwaysEmitIntoClient + public mutating func prepend( + consuming items: consuming RigidDeque + ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers + var items = items + self.append(moving: &items) + } +#endif +} + + @available(SwiftStdlib 5.0, *) extension RigidDeque /*where Element: Copyable*/ { /// Copies the elements of a buffer to the front of this rigid deque. @@ -52,8 +249,7 @@ extension RigidDeque /*where Element: Copyable*/ { precondition( newElements.count <= freeCapacity, "RigidDeque capacity overflow") - guard newElements.count > 0 else { return } - _handle.uncheckedPrepend(contentsOf: newElements) + _handle.uncheckedPrepend(copying: newElements) } /// Copies the elements of a buffer to the front of this rigid deque. @@ -100,8 +296,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// var numbers = RigidDeque(capacity: 10) /// numbers.append(contentsOf: [1, 2, 3, 4, 5]) /// numbers.prepend(contentsOf: 10...15) - /// print(numbers) - /// // Prints "[10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5]" + /// // `numbers` now contains [10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5] /// /// - Parameter newElements: The elements to prepend to the deque. /// @@ -119,7 +314,7 @@ extension RigidDeque /*where Element: Copyable*/ { let c = newElements.count guard c > 0 else { return } precondition(c <= freeCapacity, "RigidDeque capacity overflow") - _handle.uncheckedPrepend(contentsOf: newElements, count: c) + _handle.uncheckedPrepend(copying: newElements, exactCount: c) } /// Copies the elements of a sequence to the front of the rigid deque. @@ -146,12 +341,13 @@ extension RigidDeque /*where Element: Copyable*/ { } guard done == nil else { return } - // Add new elements as suffix and check that all elements were copied. + // We don't know the exact count of new elements, so we cannot initialize + // them in place. Append them to the end of the deque first, then rotate + // them to their correct location. let oldEndSlot = _handle.endSlot var it = _handle.uncheckedAppend(copyingPrefixOf: newElements) precondition(it.next() == nil, "RigidDeque capacity overflow") _handle.rotate(toStartAt: oldEndSlot) - } } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index 4e493a0d..a91b4b33 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -22,7 +22,7 @@ extension UniqueDeque where Element: ~Copyable { @_transparent public mutating func prepend(_ newElement: consuming Element) { _ensureFreeCapacity(1) - _storage.uncheckedPrepend(newElement) + _storage._handle.uncheckedPrepend(newElement) } } diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 7b0d7d6f..6e0407d9 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -288,7 +288,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle { @discardableResult @_alwaysEmitIntoClient - @_transparent internal mutating func initialize( at start: Slot, from source: UnsafeBufferPointer @@ -303,7 +302,6 @@ extension _UnsafeDequeHandle { extension _UnsafeDequeHandle where Element: ~Copyable { @discardableResult @_alwaysEmitIntoClient - @_transparent internal mutating func moveInitialize( at start: Slot, from source: UnsafeMutableBufferPointer @@ -320,7 +318,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient - @_transparent internal func segments() -> _UnsafeDequeSegments { guard _buffer.baseAddress != nil else { return .init(._empty) @@ -334,7 +331,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } @_alwaysEmitIntoClient - @_transparent internal func segments( forOffsets offsets: Range ) -> _UnsafeDequeSegments { @@ -368,7 +364,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } @_alwaysEmitIntoClient - @_transparent internal mutating func mutableSegments( between start: Slot, and end: Slot @@ -388,7 +383,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient - @_transparent internal mutating func availableSegments() -> _UnsafeMutableDequeSegments { guard _buffer.baseAddress != nil else { return .init(._empty) @@ -407,7 +401,6 @@ extension _UnsafeDequeHandle { /// Copy elements in `handle` into a newly allocated handle without changing its /// capacity or layout. @_alwaysEmitIntoClient - @_transparent internal borrowing func allocateCopy() -> Self { var result: _UnsafeDequeHandle = .allocate(capacity: self.capacity) result.count = self.count @@ -423,7 +416,6 @@ extension _UnsafeDequeHandle { /// Copy elements in `handle` into a newly allocated handle with the specified /// minimum capacity. This operation does not preserve layout. @_alwaysEmitIntoClient - @_transparent internal func allocateCopy(capacity: Int) -> Self { precondition(capacity >= self.count) var result: _UnsafeDequeHandle = .allocate(capacity: capacity) @@ -439,7 +431,6 @@ extension _UnsafeDequeHandle { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient - @_transparent internal mutating func reallocate(capacity newCapacity: Int) { precondition(newCapacity >= count, "Capacity overflow") guard newCapacity != capacity else { return } @@ -460,7 +451,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient - @_transparent internal func slotRange(following offset: inout Int) -> Range { precondition(offset >= 0 && offset <= count, "Index out of bounds") guard _buffer.baseAddress != nil else { @@ -480,7 +470,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } @_alwaysEmitIntoClient - @_transparent internal func slotRange(preceding offset: inout Int) -> Range { precondition(offset >= 0 && offset <= count, "Index out of bounds") guard _buffer.baseAddress != nil else { @@ -521,7 +510,6 @@ extension _UnsafeDequeHandle { /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @_alwaysEmitIntoClient - @_transparent internal mutating func uncheckedReplaceInPlace( inOffsets range: Range, with newElements: C @@ -551,11 +539,11 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } -// MARK: Appending +// MARK: Appending and prepending extension _UnsafeDequeHandle where Element: ~Copyable { - /// Append `element` to this buffer. The buffer must have enough free capacity - /// to insert one new element. + /// Append `element` to the end of this buffer. The buffer must have enough + /// free capacity to insert one new element. /// /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @@ -566,26 +554,70 @@ extension _UnsafeDequeHandle where Element: ~Copyable { mutablePtr(at: endSlot).initialize(to: element) count += 1 } + + /// Prepend `element` to the front of this buffer. The buffer must have enough + /// free capacity to insert one new element. + /// + /// This function does not validate its input arguments in release builds. Nor + /// does it ensure that the storage buffer is uniquely referenced. + @_alwaysEmitIntoClient + @_transparent + internal mutating func uncheckedPrepend(_ element: consuming Element) { + assert(count < capacity) + let slot = self.slot(before: startSlot) + mutablePtr(at: slot).initialize(to: element) + startSlot = slot + count += 1 + } +} + +@available(SwiftStdlib 5.0, *) +extension UnsafeMutableBufferPointer where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal func _initialize( + initializedCount: inout Int, + initializingWith body: (inout OutputSpan) throws(E) -> R + ) throws(E) -> R { + var span = OutputSpan(buffer: self, initializedCount: 0) + defer { + initializedCount &+= span.finalize(for: self) + span = OutputSpan() + } + return try body(&span) + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + internal mutating func _append( + count: Int + ) -> _UnsafeMutableDequeSegments? { + guard count > 0 else { return nil } + let origCount = self.count + self.count &+= count + return self.mutableSegments(forOffsets: origCount ..< origCount + count) + } + + @_alwaysEmitIntoClient + internal mutating func _prepend( + count: Int + ) -> _UnsafeMutableDequeSegments? { + assert(self.count + count <= capacity) + guard count > 0 else { return .init() } + let oldStart = self.startSlot + self.startSlot = self.slot(startSlot, offsetBy: -count) + self.count &+= count + + return self.mutableSegments(between: self.startSlot, and: oldStart) + } } @available(SwiftStdlib 5.0, *) extension _UnsafeDequeHandle where Element: ~Copyable { - @inlinable - internal mutating func _insertSegment( - _ buffer: UnsafeMutableBufferPointer, - initializingWith body: (inout OutputSpan) throws(E) -> Void - ) throws(E) { - var span = OutputSpan(buffer: buffer, initializedCount: 0) - defer { - self.count &+= span.finalize(for: buffer) - span = OutputSpan() - } - try body(&span) - } - /// Append a given number of items to the end of this deque by populating - /// a series of storage regions by successive calls of the specified callback - /// function. + /// a series of storage regions through successive calls of the specified + /// callback function. /// /// This unchecked routine does not verify that the deque has sufficient /// capacity to store the new items. @@ -607,20 +639,89 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient + @_transparent internal mutating func uncheckedAppend( count: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { let origCount = self.count let gap = self.mutableSegments(forOffsets: origCount ..< origCount + count) - - try _insertSegment(gap.first, initializingWith: body) + try gap.first._initialize( + initializedCount: &self.count, initializingWith: body) if self.count == origCount + gap.first.count, let second = gap.second { - try _insertSegment(second, initializingWith: body) + try second._initialize( + initializedCount: &self.count, initializingWith: body) } } - /// Moves the elements of a buffer to the end of this deque, leaving the + /// Prepend a given number of items to the end of this deque by populating + /// a series of storage regions through successive calls of the specified + /// callback function. + /// + /// This unchecked routine does not verify that the deque has sufficient + /// capacity to store the new items. + /// + /// var buffer = RigidDeque(capacity: 20) + /// buffer.append(10) + /// var i = 0 + /// buffer.prepend(count: 10) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + /// + /// The newly prepended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease when the callback fails to fully populate its output span or when if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated. + /// + /// var buffer = RigidDeque(capacity: 20) + /// buffer.append(10) + /// var i = 0 + /// buffer.prepend(count: 10) { target in + /// while !target.isFull, i <= 5 { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [0, 1, 2, 3, 4, 5, 10] + /// + /// - Parameters + /// - count: The number of items to append to the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is allowed to initialize fewer than `count` items. The deque is + /// appended however many items the callback adds to the output span + /// before it returns (or before it throws an error). + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + internal mutating func uncheckedPrepend( + count: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + guard let gap = self._prepend(count: count) else { return } + + var c = 0 + defer { + if c < count { + closeGap(offsets: c ..< count) + } + } + try gap.first._initialize(initializedCount: &c, initializingWith: body) + if c == gap.first.count, let second = gap.second { + try second._initialize(initializedCount: &c, initializingWith: body) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension _UnsafeDequeHandle where Element: ~Copyable { + /// Appends the elements of a buffer to the end of this deque, leaving the /// buffer uninitialized. /// /// This unchecked routine does not verify that the deque has sufficient @@ -635,10 +736,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { internal mutating func uncheckedAppend( moving items: UnsafeMutableBufferPointer ) { - guard items.count > 0 else { return } - - let gap = self.mutableSegments( - forOffsets: self.count ..< self.count + items.count) + guard let gap = _append(count: items.count) else { return } gap.first.moveInitializeAll( fromContentsOf: items._extracting(first: gap.first.count)) @@ -648,17 +746,33 @@ extension _UnsafeDequeHandle where Element: ~Copyable { second.moveInitializeAll( fromContentsOf: items._extracting(last: second.count)) } - self.count &+= items.count } + /// Prepends the elements of a buffer to the front of this deque, leaving the + /// buffer uninitialized. + /// + /// This unchecked routine does not verify that the deque has sufficient + /// capacity to store the new items. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient - @inline(__always) - internal mutating func uncheckedAppend>( - copyingPrefixOf items: S - ) -> S.Iterator { - let (it, c) = self.availableSegments().initialize(fromSequencePrefix: items) - self.count += c - return it + internal mutating func uncheckedPrepend( + moving items: UnsafeMutableBufferPointer + ) { + guard let gap = _prepend(count: items.count) else { return } + + gap.first.moveInitializeAll( + fromContentsOf: items._extracting(first: gap.first.count)) + + if let second = gap.second { + assert(gap.first.count + second.count == items.count) + second.moveInitializeAll( + fromContentsOf: items._extracting(last: second.count)) + } } } @@ -671,46 +785,7 @@ extension _UnsafeDequeHandle { @_alwaysEmitIntoClient @_transparent internal mutating func uncheckedAppend(copying source: UnsafeBufferPointer) { - assert(count + source.count <= capacity) - guard source.count > 0 else { return } - let c = self.count - count += source.count - let gap = mutableSegments(forOffsets: c ..< count) - gap.initialize(copying: source) - } -} - -// MARK: Prepending - -extension _UnsafeDequeHandle where Element: ~Copyable { - @_alwaysEmitIntoClient - @_transparent - internal mutating func uncheckedPrepend(_ element: consuming Element) { - assert(count < capacity) - let slot = self.slot(before: startSlot) - mutablePtr(at: slot).initialize(to: element) - startSlot = slot - count += 1 - } -} - -extension _UnsafeDequeHandle /*where Element: Copyable*/ { - /// Prepend the contents of `source` to this buffer. The buffer must have - /// enough free capacity to insert the new elements. - /// - /// This function does not validate its input arguments in release builds. Nor - /// does it ensure that the storage buffer is uniquely referenced. - @_alwaysEmitIntoClient - @_transparent - internal mutating func uncheckedPrepend(contentsOf source: UnsafeBufferPointer) { - assert(count + source.count <= capacity) - guard source.count > 0 else { return } - let oldStart = startSlot - let newStart = self.slot(startSlot, offsetBy: -source.count) - startSlot = newStart - count += source.count - - let gap = mutableSegments(between: newStart, and: oldStart) + guard let gap = _append(count: source.count) else { return } gap.initialize(copying: source) } @@ -721,22 +796,39 @@ extension _UnsafeDequeHandle /*where Element: Copyable*/ { /// does it ensure that the storage buffer is uniquely referenced. @_alwaysEmitIntoClient @_transparent - internal mutating func uncheckedPrepend( - contentsOf source: some Collection, - count sourceCount: Int - ) { - assert(count + sourceCount <= capacity) - guard sourceCount > 0 else { return } - let oldStart = startSlot - let newStart = self.slot(startSlot, offsetBy: -sourceCount) - startSlot = newStart - count += sourceCount - - let gap = mutableSegments(between: newStart, and: oldStart) + internal mutating func uncheckedPrepend(copying source: UnsafeBufferPointer) { + guard let gap = _prepend(count: source.count) else { return } gap.initialize(copying: source) } } +@available(SwiftStdlib 5.0, *) +extension _UnsafeDequeHandle { + @_alwaysEmitIntoClient + @inline(__always) + internal mutating func uncheckedAppend>( + copyingPrefixOf items: S + ) -> S.Iterator { + // Note: You're supposed to handle contiguous sequences before calling + // this function. You do this by invoking `withContiguousStorageIfAvailable`. + let (it, c) = self.availableSegments().initialize(fromSequencePrefix: items) + self.count += c + return it + } + + @_alwaysEmitIntoClient + @inline(__always) + internal mutating func uncheckedPrepend>( + copying items: C, + exactCount: Int + ) { + // Note: You're supposed to handle contiguous sequences before calling + // this function. You do this by invoking `withContiguousStorageIfAvailable`. + guard let gap = self._prepend(count: exactCount) else { return } + gap.initialize(copying: items) + } +} + // MARK: Opening and Closing Gaps extension _UnsafeDequeHandle where Element: ~Copyable { diff --git a/Sources/DequeModule/_UnsafeDequeSegments.swift b/Sources/DequeModule/_UnsafeDequeSegments.swift index 228c8d91..c5e334a6 100644 --- a/Sources/DequeModule/_UnsafeDequeSegments.swift +++ b/Sources/DequeModule/_UnsafeDequeSegments.swift @@ -80,6 +80,13 @@ internal struct _UnsafeMutableDequeSegments { @usableFromInline internal let second: UnsafeMutableBufferPointer? + @_alwaysEmitIntoClient + @_transparent + internal init() { + self.first = .init(start: nil, count: 0) + self.second = nil + } + @_alwaysEmitIntoClient @_transparent internal init( @@ -241,18 +248,26 @@ extension _UnsafeMutableDequeSegments { @_alwaysEmitIntoClient @_transparent internal func initialize( - copying elements: UnsafeMutableBufferPointer + copying elements: UnsafeBufferPointer ) { assert(self.count == elements.count) if let second = second { let wrap = first.count first.initializeAll(fromContentsOf: elements._extracting(first: wrap)) - second.initializeAll(fromContentsOf: elements.extracting(wrap...)) + second.initializeAll(fromContentsOf: elements._extracting(last: second.count)) } else { first.initializeAll(fromContentsOf: elements) } } + @_alwaysEmitIntoClient + @_transparent + internal func initialize( + copying elements: UnsafeMutableBufferPointer + ) { + self.initialize(copying: UnsafeBufferPointer(elements)) + } + @_alwaysEmitIntoClient @_transparent internal func initialize( From 16aac1913c36c74cc759f1d75170a54d912bb23f Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 6 Jan 2026 15:49:14 -0800 Subject: [PATCH 08/75] [RigidDeque] Clean up initializers --- .../RigidDeque/RigidDeque+Collection.swift | 37 --------- .../RigidDeque/RigidDeque+Initializers.swift | 76 +++++++------------ Sources/DequeModule/_UnsafeDequeHandle.swift | 2 +- 3 files changed, 27 insertions(+), 88 deletions(-) delete mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift deleted file mode 100644 index 9caae9ba..00000000 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Collection.swift +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2025 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 -// -//===----------------------------------------------------------------------===// - -#if !COLLECTIONS_SINGLE_MODULE -import InternalCollectionsUtilities -import ContainersPreview -#endif - -#if compiler(>=6.2) - -@available(SwiftStdlib 5.0, *) -extension RigidDeque { - @inlinable - public func _copyToContiguousArray() -> ContiguousArray { - ContiguousArray(unsafeUninitializedCapacity: count) { target, count in - let segments = _handle.segments() - let c = segments.first.count - target[..) throws -> Void ) rethrows { self.init(_handle: .allocate(capacity: capacity)) - let buffer = _handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) - var span = OutputSpan(buffer: buffer, initializedCount: 0) - defer { - _handle.count = span.finalize(for: buffer) - span = OutputSpan() - } - try initializer(&span) - } - - /// Creates a rigid deque with the specified capacity, then calls the given - /// closure with a buffer covering the deque's uninitialized memory. - /// - /// Inside the closure, set the `initializedCount` parameter to the number of - /// elements that are initialized by the closure. The memory in the range - /// `buffer[0.., inout Int) throws -> Void - ) rethrows { - self.init(_handle: .allocate(capacity: capacity)) - var newCount = 0 - var buffer = _handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) - - defer { - precondition(newCount <= capacity, - "Initialized count set to greater than specified capacity") - let b = _handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) - precondition(buffer.baseAddress == b.baseAddress && buffer.count == b.count, - "Initializer relocated Deque storage") - _handle.count = newCount - } - try initializer(&buffer, &newCount) + try self.append(count: capacity, initializingWith: initializer) } } @@ -108,7 +68,22 @@ extension RigidDeque /*where Element: Copyable*/ { _handle.mutableBuffer.initialize(repeating: repeatedValue) _handle.count = count } +} +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Creates a new rigid deque taking over the storage of the specified + /// unique deque instance, consuming it in the process. + /// + /// - Complexity: O(1) + @inlinable + public init(consuming array: consuming UniqueDeque) { + self = array._storage + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*where Element: Copyable*/ { /// Creates a new deque with the specified capacity, holding a copy /// of the contents of a given sequence. /// @@ -134,9 +109,10 @@ extension RigidDeque /*where Element: Copyable*/ { @_alwaysEmitIntoClient @inline(__always) public init( + capacity: Int? = nil, copying contents: some Collection ) { - self.init(capacity: contents.count) + self.init(capacity: capacity ?? contents.count) self.append(copying: contents) } } diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 6e0407d9..c304ecb2 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -16,7 +16,7 @@ import ContainersPreview @frozen @usableFromInline -internal struct _UnsafeDequeHandle { +internal struct _UnsafeDequeHandle: ~Copyable { @usableFromInline internal typealias Slot = _DequeSlot From 5943e6eb5c3abf52c19c632269b8897b975bee0d Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 7 Jan 2026 17:46:25 -0800 Subject: [PATCH 09/75] [RigidDeque] Flesh out insertions --- Package@swift-6.0.swift | 2 +- .../RigidArray+Insertions.swift | 6 +- .../RigidDeque/RigidDeque+Append.swift | 11 +- .../RigidDeque/RigidDeque+Insertions.swift | 467 +++++++++++++++++- .../RigidDeque/RigidDeque+Prepend.swift | 11 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 46 +- .../UnsafeMutableBufferPointer+Extras.swift | 52 +- 7 files changed, 566 insertions(+), 29 deletions(-) diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index e04dc722..30c7fde3 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -273,7 +273,7 @@ let targets: [CustomTarget] = [ .target( kind: .exported, name: "DequeModule", - dependencies: ["InternalCollectionsUtilities"], + dependencies: ["ContainersPreview", "InternalCollectionsUtilities"], exclude: ["CMakeLists.txt"]), .target( kind: .test, diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index cc47c1f5..65fee312 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -206,6 +206,7 @@ extension RigidArray where Element: ~Copyable { moving items: inout RigidArray, at index: Int ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers insert(count: items.count, at: index) { target in target.withUnsafeMutableBufferPointer { dst, dstCount in items.edit { source in @@ -233,8 +234,7 @@ extension RigidArray where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// - Parameters - /// - items: A fully initialized buffer whose contents to move into - /// the array. + /// - items: The array whose contents to move into `self`. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the array. /// diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 83f5e7d6..4bde551c 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -56,7 +56,7 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { /// Efficiently append a given number of items to the back of this deque by - /// populating a series of storage regions through successive calls of the + /// populating a series of storage regions through repeated calls of the /// specified callback function. /// /// If the deque does not have sufficient capacity to store the new items, @@ -76,7 +76,7 @@ extension RigidDeque where Element: ~Copyable { /// The newly appended items are not guaranteed to form a single contiguous /// storage region. Therefore, the supplied callback may be invoked multiple /// times to initialize each successive chunk of storage. However, invocations - /// cease when the callback fails to fully populate its output span or when if + /// cease when the callback fails to fully populate its output span or if /// it throws an error. In such cases, the deque keeps all items that were /// successfully initialized before the callback terminated the append. /// @@ -94,10 +94,7 @@ extension RigidDeque where Element: ~Copyable { /// - Parameters /// - count: The number of items to append to the deque. /// - body: A callback that gets called at most twice to directly - /// populate newly reserved storage within the deque. The function - /// is allowed to initialize fewer than `count` items. The deque is - /// appended however many items the callback adds to the output span - /// before it returns (or before it throws an error). + /// populate newly reserved storage within the deque. /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient @@ -193,7 +190,7 @@ extension RigidDeque where Element: ~Copyable { ) { // FIXME: Remove this in favor of a generic algorithm over range-replaceable containers precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") - items._handle.unsafeConsumeElements { source in + items._handle.unsafeConsumeAll { source in self._handle.uncheckedAppend(moving: source) } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 018806ed..4a74639b 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -18,14 +18,473 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { + /// Inserts a new element into the deque at the specified position. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this triggers a runtime error. + /// + /// The new element is inserted before the element currently at the specified + /// index. If you pass the deque's `endIndex` as the `index` parameter, then + /// the new element is appended to the container. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new item. + /// + /// - Parameter item: The new element to insert into the array. + /// - Parameter index: The position at which to insert the new element. + /// `index` must be a valid index in the array. + /// + /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @_transparent public mutating func insert(_ newElement: consuming Element, at index: Int) { - precondition(!isFull, "RigidDeque is full") - precondition(index >= 0 && index <= count, - "Can't insert element at invalid index") + precondition(!isFull, "RigidDeque capacity overflow") + precondition(index >= 0 && index <= count, "Index out of bounds") _handle.uncheckedInsert(newElement, at: index) } } +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Inserts a given number of new items into this deque at the specified + /// position, using a callback to directly initialize deque storage by + /// populating an output span. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// var buffer = RigidDeque(capacity: 20) + /// buffer.append([-999, 999]) + /// var i = 0 + /// buffer.insert(count: 3, at: 1) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [-999, 0, 1, 2, 999] + /// + /// The newly prepended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease if the callback fails to fully populate its output span or if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// (Partial prepends create a gap in ring buffer storage that needs to be + /// closed by moving newly prepended items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised.) + /// + /// - Parameters: + /// - count: The number of items to insert into the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. + /// + /// - Complexity: O(`self.count` + `count`) + @inlinable + public mutating func insert( + count: Int, + at index: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + // FIXME: This does not allow `body` to throw, to prevent having to move the tail twice. Is that okay? + precondition(index >= 0 && index <= self.count, "Index out of bounds") + precondition(count >= 0, "Negative count") + precondition(count <= freeCapacity, "RigidDeque capacity overflow") + try _handle.uncheckedInsert(count: count, at: index, initializingWith: body) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Inserts the elements of a fully initialized buffer by moving them into + /// this deque, starting at the specified position. After this operation, + /// the supplied buffer becomes uninitialized. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the array. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func insert( + moving items: UnsafeMutableBufferPointer, + at index: Int + ) { + var remainder = items + insert(count: items.count, at: index) { target in + target.withUnsafeMutableBufferPointer { buffer, count in + buffer.moveInitializeAll( + fromContentsOf: remainder._extracting(first: buffer.count)) + remainder = remainder._extracting(droppingFirst: buffer.count) + count = buffer.count + } + } + assert(remainder.isEmpty) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Moves the elements of an input span into this deque, + /// starting at the specified position, and leaving the span empty. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - items: An input span whose contents to move into + /// the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func insert( + moving items: inout InputSpan, + at index: Int + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.insert(moving: source, at: index) + count = 0 + } + } +#endif + + /// Moves the elements of an output span into this deque, + /// starting at the specified position, and leaving the span empty. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - items: An output span whose contents to move into + /// the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func insert( + moving items: inout OutputSpan, + at index: Int + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.insert(moving: source, at: index) + count = 0 + } + } + + /// Inserts the elements of a given deque into the given position in this + /// deque by moving them between the containers. On return, the input deque + /// becomes empty, but it is not destroyed, and it preserves its original + /// storage capacity. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - items: A deque whose contents to move into `self`. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// + /// - Complexity: O(`count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func insert( + moving items: inout RigidDeque, + at index: Int + ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers + insert(count: items.count, at: index) { target in + target.withUnsafeMutableBufferPointer { dst, dstCount in + var remainder = dst + items._handle.unsafeConsumePrefix(upTo: remainder.count) { src in + let c = remainder._moveInitializePrefix(from: src) + dstCount += c + remainder = remainder._extracting(last: c) + } + assert(remainder.isEmpty) + } + } + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Inserts the elements of a given deque into the given position in this + /// deque by consuming the source container. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - items: The deque whose contents to move into `self`. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// + /// - Complexity: O(`count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func insert( + consuming items: consuming RigidDeque, + at index: Int + ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers + var items = items + self.insert(moving: &items, at: index) + } +#endif +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /* where Element: Copyable */ { + /// Copies the elements of a fully initialized buffer pointer into this + /// deque at the specified position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the array. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the deque. The buffer + /// must be fully initialized. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of `self`. + /// + /// - Complexity: O(`count` + `newElements.count`) + @inlinable + public mutating func insert( + copying newElements: UnsafeBufferPointer, at index: Int + ) { + guard newElements.count > 0 else { return } + self.insert(count: newElements.count, at: index) { target in + target.withUnsafeMutableBufferPointer { buffer, count in + buffer.initializeAll(fromContentsOf: newElements) + count = newElements.count + } + } + } + + /// Copies the elements of a fully initialized buffer pointer into this + /// deque at the specified position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the deque. The buffer + /// must be fully initialized. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of `self`. + /// + /// - Complexity: O(`count` + `newElements.count`) + @inlinable + public mutating func insert( + copying newElements: UnsafeMutableBufferPointer, + at index: Int + ) { + unsafe self.insert(copying: UnsafeBufferPointer(newElements), at: index) + } + + /// Copies the elements of a span into this deque at the specified position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`count` + `newElements.count`) + @inlinable + public mutating func insert( + copying newElements: Span, at index: Int + ) { + unsafe newElements.withUnsafeBufferPointer { + unsafe self.insert(copying: $0, at: index) + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _insertContainer< + C: Container & ~Copyable & ~Escapable + >( + at index: Int, + copying items: borrowing C, + newCount: Int + ) { + insert(count: newCount, at: index) { target in + target.withUnsafeMutableBufferPointer { buffer, count in + let copied = items._copyContents(intoPrefixOf: buffer) + precondition( + copied == newCount, + "Broken Container: count doesn't match contents") + count = newCount + } + } + } +#endif + + @inlinable + internal mutating func _insertCollection( + at index: Int, + copying items: some Collection, + newCount: Int + ) { + let done: Void? = items.withContiguousStorageIfAvailable { buffer in + self.insert(copying: buffer, at: index) + } + if done != nil { return } + + precondition(index >= 0 && index <= count, "Index out of bounds") + precondition(newCount <= freeCapacity, "RigidDeque capacity overflow") + var i = items.startIndex + self._handle.uncheckedInsert(count: newCount, at: index) { target in + target.append(items[i]) + items.formIndex(after: &i) + } + precondition(i == items.endIndex, + "Broken Collection: count doesn't match contents") + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of a container into this deque at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`self.count` + `newElements.count`). + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & ~Copyable & ~Escapable + >( + copying newElements: borrowing C, at index: Int + ) { + _insertContainer( + at: index, copying: newElements, newCount: newElements.count) + } +#endif + + /// Copies the elements of a collection into this deque at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`count` + `newElements.count`) + @inlinable + @inline(__always) + public mutating func insert( + copying newElements: some Collection, at index: Int + ) { + _insertCollection( + at: index, copying: newElements, newCount: newElements.count) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of a container into this deque at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque's `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements preceding or succeeding the specified position are + /// moved to make room for the new items. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & Collection + >( + copying newElements: borrowing C, at index: Int + ) { + _insertContainer( + at: index, copying: newElements, newCount: newElements.count) + } +#endif +} + #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index d439edf4..129116b3 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -56,7 +56,7 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { /// Efficiently prepend a given number of items to the front of this deque by - /// populating a series of storage regions through successive calls of the + /// populating a series of storage regions through repeated calls of the /// specified callback function. /// /// If the deque does not have sufficient capacity to store the new items, @@ -76,7 +76,7 @@ extension RigidDeque where Element: ~Copyable { /// The newly prepended items are not guaranteed to form a single contiguous /// storage region. Therefore, the supplied callback may be invoked multiple /// times to initialize each successive chunk of storage. However, invocations - /// cease when the callback fails to fully populate its output span or when if + /// cease if the callback fails to fully populate its output span or if /// it throws an error. In such cases, the deque keeps all items that were /// successfully initialized before the callback terminated the prepend. /// (Partial prepends create a gap in ring buffer storage that needs to be @@ -98,10 +98,7 @@ extension RigidDeque where Element: ~Copyable { /// - Parameters /// - count: The number of items to append to the deque. /// - body: A callback that gets called at most twice to directly - /// populate newly reserved storage within the deque. The function - /// is allowed to initialize fewer than `count` items. The deque is - /// appended however many items the callback adds to the output span - /// before it returns (or before it throws an error). + /// populate newly reserved storage within the deque. /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient @@ -198,7 +195,7 @@ extension RigidDeque where Element: ~Copyable { ) { // FIXME: Remove this in favor of a generic algorithm over range-replaceable containers precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") - items._handle.unsafeConsumeElements { source in + items._handle.unsafeConsumeAll { source in self._handle.uncheckedAppend(moving: source) } } diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index c304ecb2..01461c98 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -16,6 +16,7 @@ import ContainersPreview @frozen @usableFromInline +@unsafe internal struct _UnsafeDequeHandle: ~Copyable { @usableFromInline internal typealias Slot = _DequeSlot @@ -527,7 +528,7 @@ extension _UnsafeDequeHandle { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent - internal mutating func unsafeConsumeElements( + internal mutating func unsafeConsumeAll( with body: (UnsafeMutableBufferPointer) -> Void ) { let segments = mutableSegments() @@ -537,6 +538,22 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } self.count = 0 } + + @_alwaysEmitIntoClient + @_transparent + internal mutating func unsafeConsumePrefix( + upTo offset: Int, + with body: (UnsafeMutableBufferPointer) -> Void + ) { + assert(offset >= 0 && offset <= count) + let segments = mutableSegments(forOffsets: Range(uncheckedBounds: (0, offset))) + body(segments.first) + if let second = segments.second { + body(second) + } + self.startSlot = self.slot(forOffset: offset) + self.count &-= offset + } } // MARK: Appending and prepending @@ -616,7 +633,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension _UnsafeDequeHandle where Element: ~Copyable { /// Append a given number of items to the end of this deque by populating - /// a series of storage regions through successive calls of the specified + /// a series of storage regions through repeated calls of the specified /// callback function. /// /// This unchecked routine does not verify that the deque has sufficient @@ -655,7 +672,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } /// Prepend a given number of items to the end of this deque by populating - /// a series of storage regions through successive calls of the specified + /// a series of storage regions through repeated calls of the specified /// callback function. /// /// This unchecked routine does not verify that the deque has sufficient @@ -695,7 +712,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is allowed to initialize fewer than `count` items. The deque is - /// appended however many items the callback adds to the output span + /// prepended however many items the callback adds to output span /// before it returns (or before it throws an error). /// /// - Complexity: O(`count`) @@ -717,6 +734,27 @@ extension _UnsafeDequeHandle where Element: ~Copyable { try second._initialize(initializedCount: &c, initializingWith: body) } } + + @_alwaysEmitIntoClient + internal mutating func uncheckedInsert( + count: Int, + at offset: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + guard count > 0 else { return } + let gap = self.openGap(ofSize: count, atOffset: offset) + + var c = 0 + defer { + if c < count { + closeGap(offsets: offset + c ..< offset + count) + } + } + try gap.first._initialize(initializedCount: &c, initializingWith: body) + if c == gap.first.count, let second = gap.second { + try second._initialize(initializedCount: &c, initializingWith: body) + } + } } @available(SwiftStdlib 5.0, *) diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index c47b632e..34d7f5a9 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -31,13 +31,13 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @inline(__always) public func _extracting(unchecked bounds: Range) -> Self { assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, - "Index out of range") + "Index out of range") guard let start = self.baseAddress else { return Self(start: nil, count: 0) } return Self(start: start + bounds.lowerBound, count: bounds.count) } - + /// Returns a buffer pointer containing the initial elements of this buffer, /// up to the specified maximum length. /// @@ -60,7 +60,30 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { let newCount = Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } - + + /// Returns a buffer pointer containing all but the given number of initial + /// elements. + /// + /// If the number of elements to drop exceeds the number of elements in the + /// buffer, the result is an empty buffer. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to drop. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(droppingFirst maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let cut = Swift.min(maxLength, count) + return Self(start: baseAddress?.advanced(by: cut), count: count &- cut) + } + /// Returns a buffer pointer containing the final elements of this buffer, /// up to the given maximum length. /// @@ -83,6 +106,29 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) } + + /// Returns a buffer pointer containing all but the given number of trailing + /// elements. + /// + /// If the number of elements to drop exceeds the number of elements in the + /// buffer, the result is an empty buffer. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to drop. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(droppingLast maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = count &- Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } } extension UnsafeMutableBufferPointer where Element: ~Copyable { From e84db1974d0467e536c77059cfc9deb98e055777 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 8 Jan 2026 13:11:52 -0800 Subject: [PATCH 10/75] [RigidDeque] Update removals --- .../BasicContainers/RigidArray+Removals.swift | 41 +++--- .../RigidDeque/RigidDeque+Insertions.swift | 65 ++++++---- .../RigidDeque/RigidDeque+Removals.swift | 118 +++++++++++++----- 3 files changed, 150 insertions(+), 74 deletions(-) diff --git a/Sources/BasicContainers/RigidArray+Removals.swift b/Sources/BasicContainers/RigidArray+Removals.swift index a1149b90..c0103111 100644 --- a/Sources/BasicContainers/RigidArray+Removals.swift +++ b/Sources/BasicContainers/RigidArray+Removals.swift @@ -18,6 +18,26 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { + /// Removes and returns the element at the specified position. + /// + /// All the elements following the specified position are moved to close the + /// gap. + /// + /// - Parameter i: The position of the element to remove. `index` must be + /// a valid index of the array that is not equal to the end index. + /// - Returns: The removed element. + /// + /// - Complexity: O(`count`) + @inlinable + @discardableResult + public mutating func remove(at index: Int) -> Element { + precondition(index >= 0 && index < _count, "Index out of bounds") + let old = unsafe _storage.moveElement(from: index) + _closeGap(at: index, count: 1) + _count -= 1 + return old + } + /// Removes all elements from the array, preserving its allocated capacity. /// /// - Complexity: O(*n*), where *n* is the original count of the array. @@ -66,26 +86,6 @@ extension RigidArray where Element: ~Copyable { _count &-= k } - /// Removes and returns the element at the specified position. - /// - /// All the elements following the specified position are moved to close the - /// gap. - /// - /// - Parameter i: The position of the element to remove. `index` must be - /// a valid index of the array that is not equal to the end index. - /// - Returns: The removed element. - /// - /// - Complexity: O(`count`) - @inlinable - @discardableResult - public mutating func remove(at index: Int) -> Element { - precondition(index >= 0 && index < _count, "Index out of bounds") - let old = unsafe _storage.moveElement(from: index) - _closeGap(at: index, count: 1) - _count -= 1 - return old - } - /// Removes the specified subrange of elements from the array. /// /// All the elements following the specified subrange are moved to close the @@ -140,6 +140,7 @@ extension RigidArray where Element: ~Copyable { extension RigidArray where Element: ~Copyable { /// Remove all items currently in this array, returning an input span to /// allow them to be consumed in place. + /// /// The input span extends the exclusive mutating access initiated by this /// operation to cover the span's lifetime. Once the span is destroyed, /// the array becomes empty, but it preserves its original storage capacity. diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 4a74639b..2149398d 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -27,8 +27,9 @@ extension RigidDeque where Element: ~Copyable { /// index. If you pass the deque's `endIndex` as the `index` parameter, then /// the new element is appended to the container. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new item. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new item. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// - Parameter item: The new element to insert into the array. /// - Parameter index: The position at which to insert the new element. @@ -50,8 +51,9 @@ extension RigidDeque where Element: ~Copyable { /// position, using a callback to directly initialize deque storage by /// populating an output span. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -106,8 +108,9 @@ extension RigidDeque where Element: ~Copyable { /// this deque, starting at the specified position. After this operation, /// the supplied buffer becomes uninitialized. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -140,8 +143,9 @@ extension RigidDeque where Element: ~Copyable { /// Moves the elements of an input span into this deque, /// starting at the specified position, and leaving the span empty. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -169,8 +173,9 @@ extension RigidDeque where Element: ~Copyable { /// Moves the elements of an output span into this deque, /// starting at the specified position, and leaving the span empty. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -199,8 +204,9 @@ extension RigidDeque where Element: ~Copyable { /// becomes empty, but it is not destroyed, and it preserves its original /// storage capacity. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -237,8 +243,9 @@ extension RigidDeque where Element: ~Copyable { /// Inserts the elements of a given deque into the given position in this /// deque by consuming the source container. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -270,8 +277,9 @@ extension RigidDeque /* where Element: Copyable */ { /// specified index. If you pass the deque’s `endIndex` as the `index` /// parameter, then the new elements are appended to the end of the array. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -303,8 +311,9 @@ extension RigidDeque /* where Element: Copyable */ { /// specified index. If you pass the deque’s `endIndex` as the `index` /// parameter, then the new elements are appended to the end of the deque. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -330,8 +339,9 @@ extension RigidDeque /* where Element: Copyable */ { /// specified index. If you pass the deque’s `endIndex` as the `index` /// parameter, then the new elements are appended to the end of the deque. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -402,8 +412,9 @@ extension RigidDeque /* where Element: Copyable */ { /// specified index. If you pass the deque’s `endIndex` as the `index` /// parameter, then the new elements are appended to the end of the deque. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -433,8 +444,9 @@ extension RigidDeque /* where Element: Copyable */ { /// specified index. If you pass the deque’s `endIndex` as the `index` /// parameter, then the new elements are appended to the end of the deque. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. @@ -462,8 +474,9 @@ extension RigidDeque /* where Element: Copyable */ { /// specified index. If you pass the deque's `endIndex` as the `index` /// parameter, then the new elements are appended to the end of the deque. /// - /// Existing elements preceding or succeeding the specified position are - /// moved to make room for the new items. + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift index 51104a35..ef0efb8a 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -18,70 +18,132 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { + /// Removes and returns the element at the specified position. + /// + /// Existing elements in the deque's storage are moved as needed to close the + /// gap left by the removed item. (The direction of the move depends on the + /// location of the removal, minimizing the cost.) + /// + /// - Parameter i: The position of the element to remove. `index` must be + /// a valid index of the deque that is not equal to the end index. + /// - Returns: The removed element. + /// + /// - Complexity: O(`count`) @discardableResult @_alwaysEmitIntoClient - @_transparent public mutating func remove(at index: Int) -> Element { - precondition(index >= 0 && index < count, - "Can't remove element at invalid index") + precondition(index >= 0 && index < count, "Index out of bounds") return _handle.uncheckedRemove(at: index) } - + + /// Removes all elements from the deque, preserving its allocated capacity. + /// + /// - Complexity: O(`count`) @_alwaysEmitIntoClient - @_transparent - public mutating func removeSubrange(_ bounds: Range) { - precondition(bounds.lowerBound >= 0 && bounds.upperBound <= count, - "Index range out of bounds") - _handle.uncheckedRemove(offsets: bounds) + public mutating func removeAll() { + _handle.uncheckedRemoveAll() } - + + /// Removes and returns the first element of the deque. + /// + /// The deque must not be empty. + /// + /// - Returns: The first element of the original deque. + /// + /// - Complexity: O(1) @discardableResult @_alwaysEmitIntoClient - @_transparent public mutating func removeFirst() -> Element { precondition(!isEmpty, "Cannot remove first element of an empty RigidDeque") return _handle.uncheckedRemoveFirst() } - + + /// Removes and returns the last element of the deque. + /// + /// The deque must not be empty. + /// + /// - Returns: The last element of the original deque. + /// + /// - Complexity: O(1) @discardableResult @_alwaysEmitIntoClient - @_transparent public mutating func removeLast() -> Element { precondition(!isEmpty, "Cannot remove last element of an empty RigidDeque") return _handle.uncheckedRemoveLast() } - + + /// Removes and discards the specified number of elements from the start of + /// the deque. + /// + /// Attempting to remove more elements than exist in the deque + /// triggers a runtime error. + /// + /// - Parameter k: The number of elements to remove from the deque. + /// `k` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// + /// - Complexity: O(`k`) @_alwaysEmitIntoClient - @_transparent - public mutating func removeFirst(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") - _handle.uncheckedRemoveFirst(n) + public mutating func removeFirst(_ k: Int) { + precondition(k >= 0, "Can't remove a negative number of elements") + precondition(k <= count, "Can't remove more elements than there are in a RigidDeque") + _handle.uncheckedRemoveFirst(k) } - + + /// Removes and discards the specified number of elements from the end of the + /// deque. + /// + /// Attempting to remove more elements than exist in the deque + /// triggers a runtime error. + /// + /// - Parameter k: The number of elements to remove from the deque. + /// `k` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// + /// - Complexity: O(`k`) @_alwaysEmitIntoClient - @_transparent public mutating func removeLast(_ n: Int) { precondition(n >= 0, "Can't remove a negative number of elements") precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") _handle.uncheckedRemoveLast(n) } - + + /// Removes the specified subrange of elements from the deque. + /// + /// - Parameter bounds: The subrange to remove. The bounds of the + /// range must be valid indices of the deque. + /// + /// - Complexity: O(`count`) @_alwaysEmitIntoClient - @_transparent - public mutating func removeAll() { - _handle.uncheckedRemoveAll() + public mutating func removeSubrange(_ bounds: Range) { + precondition( + bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Subrange out of bounds") + _handle.uncheckedRemove(offsets: bounds) } +} +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Removes and returns the first element of the deque, if there is one. + /// + /// - Returns: The first element of the original deque if it was not empty; + /// otherwise, `nil`. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient - @_transparent public mutating func popFirst() -> Element? { guard !isEmpty else { return nil } return _handle.uncheckedRemoveFirst() } + /// Removes and returns the last element of the deque, if there is one. + /// + /// - Returns: The last element of the original deque if it was not empty; + /// otherwise, `nil`. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient - @_transparent public mutating func popLast() -> Element? { guard !isEmpty else { return nil } return _handle.uncheckedRemoveLast() From d1d757e42542ebb192e243085cc012219aaeb0d7 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 8 Jan 2026 17:24:16 -0800 Subject: [PATCH 11/75] [RigidDeque] Implement replacement operations --- .../RigidArray+Replacements.swift | 95 +-- .../BorrowIteratorProtocol.swift | 25 + .../RigidDeque/RigidDeque+Insertions.swift | 43 +- .../RigidDeque/RigidDeque+Replacements.swift | 574 ++++++++++++++++++ .../RigidDeque/RigidDeque+Testing.swift | 8 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 115 +++- .../UnsafeBufferPointer+Extras.swift | 47 ++ 7 files changed, 811 insertions(+), 96 deletions(-) create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift diff --git a/Sources/BasicContainers/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray+Replacements.swift index 654cca7d..30ba8e3e 100644 --- a/Sources/BasicContainers/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray+Replacements.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -32,11 +32,11 @@ extension RigidArray where Element: ~Copyable { /// /// If you pass a zero-length range as the `subrange` parameter, then /// this method is equivalent to calling - /// `insert(count: newCount, initializingWith: body)`. + /// `insert(count: newCount, at: subrange.lowerbound, initializingWith: body)`. /// /// Likewise, if you pass a zero for `newCount`, then this method /// removes the elements in the given subrange without any replacement. - /// Calling `removeSubrange(subrange)` is preferred in this case. + /// This case is more directly expressed by `removeSubrange(subrange)`. /// /// - Parameters /// - subrange: The subrange of the array to replace. The bounds of @@ -83,13 +83,13 @@ extension RigidArray where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(moving:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. /// /// Likewise, if you pass a zero-length buffer as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters /// - subrange: The subrange of the array to replace. The bounds of @@ -123,13 +123,13 @@ extension RigidArray where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(moving:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. /// /// Likewise, if you pass a zero-length buffer as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters /// - subrange: The subrange of the array to replace. The bounds of @@ -162,13 +162,13 @@ extension RigidArray where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(moving:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. /// /// Likewise, if you pass a zero-length buffer as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters /// - subrange: The subrange of the array to replace. The bounds of @@ -202,13 +202,13 @@ extension RigidArray where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. /// /// Likewise, if you pass a zero-length buffer as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters /// - subrange: The subrange of the array to replace. The bounds of @@ -221,6 +221,7 @@ extension RigidArray where Element: ~Copyable { _ subrange: Range, moving newElements: inout RigidArray, ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers unsafe newElements._unsafeEdit { buffer, count in let source = buffer._extracting(first: count) unsafe self.replaceSubrange(subrange, moving: source) @@ -244,13 +245,13 @@ extension RigidArray where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(consuming:at:)`. /// /// Likewise, if you pass a zero-length buffer as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters /// - subrange: The subrange of the array to replace. The bounds of @@ -283,13 +284,13 @@ extension RigidArray { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. /// /// Likewise, if you pass a zero-length buffer as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of @@ -321,13 +322,13 @@ extension RigidArray { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. /// /// Likewise, if you pass a zero-length buffer as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of @@ -357,13 +358,13 @@ extension RigidArray { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. /// /// Likewise, if you pass a zero-length span as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of @@ -441,13 +442,13 @@ extension RigidArray { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. /// /// Likewise, if you pass a zero-length container as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of @@ -480,13 +481,13 @@ extension RigidArray { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. /// /// Likewise, if you pass a zero-length collection as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of @@ -517,13 +518,13 @@ extension RigidArray { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling - /// the `insert(copying:at:)` method instead is preferred in this case. + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. /// /// Likewise, if you pass a zero-length container as the `newElements` /// parameter, this method removes the elements in the given subrange - /// without replacement. Calling the `removeSubrange(_:)` method instead is - /// preferred in this case. + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. /// /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of diff --git a/Sources/ContainersPreview/BorrowIteratorProtocol.swift b/Sources/ContainersPreview/BorrowIteratorProtocol.swift index f3452512..ffac1f98 100644 --- a/Sources/ContainersPreview/BorrowIteratorProtocol.swift +++ b/Sources/ContainersPreview/BorrowIteratorProtocol.swift @@ -10,6 +10,11 @@ //===----------------------------------------------------------------------===// #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + @available(SwiftStdlib 5.0, *) public protocol BorrowIteratorProtocol: ~Copyable, ~Escapable { associatedtype Element: ~Copyable /*& ~Escapable*/ @@ -90,6 +95,26 @@ extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { } } +@available(SwiftStdlib 5.0, *) +extension BorrowIteratorProtocol +where Self: ~Copyable & ~Escapable, Element: Copyable +{ + @_lifetime(copy self) + @_lifetime(self: copy self) + @_transparent + public mutating func copyContents(into target: inout OutputSpan) { + target.withUnsafeMutableBufferPointer { dst, dstCount in + var tail = dst._extracting(droppingFirst: dstCount) + while !tail.isEmpty { + let src = nextSpan(maximumCount: tail.count) + if src.isEmpty { break } + tail._initializeAndDropPrefix(copying: src) + dstCount += src.count + } + } + } +} + @available(SwiftStdlib 5.0, *) extension Span: BorrowIteratorProtocol where Element: ~Copyable { @_lifetime(copy self) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 2149398d..3ab94810 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -49,7 +49,7 @@ extension RigidDeque where Element: ~Copyable { extension RigidDeque where Element: ~Copyable { /// Inserts a given number of new items into this deque at the specified /// position, using a callback to directly initialize deque storage by - /// populating an output span. + /// populating a series of output spans. /// /// Existing elements in the deque's storage are moved as needed to make room /// for the new items. (The direction of the move depends on the location of @@ -75,8 +75,8 @@ extension RigidDeque where Element: ~Copyable { /// cease if the callback fails to fully populate its output span or if /// it throws an error. In such cases, the deque keeps all items that were /// successfully initialized before the callback terminated the prepend. - /// (Partial prepends create a gap in ring buffer storage that needs to be - /// closed by moving newly prepended items to their correct positions given + /// (Partial insertions create a gap in ring buffer storage that needs to be + /// closed by moving already inserted items to their correct positions given /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised.) /// @@ -85,7 +85,8 @@ extension RigidDeque where Element: ~Copyable { /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. /// - body: A callback that gets called at most twice to directly - /// populate newly reserved storage within the deque. + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. /// /// - Complexity: O(`self.count` + `count`) @inlinable @@ -127,6 +128,7 @@ extension RigidDeque where Element: ~Copyable { moving items: UnsafeMutableBufferPointer, at index: Int ) { + guard !items.isEmpty else { return } var remainder = items insert(count: items.count, at: index) { target in target.withUnsafeMutableBufferPointer { buffer, count in @@ -296,12 +298,16 @@ extension RigidDeque /* where Element: Copyable */ { copying newElements: UnsafeBufferPointer, at index: Int ) { guard newElements.count > 0 else { return } - self.insert(count: newElements.count, at: index) { target in + var remainder = newElements + insert(count: remainder.count, at: index) { target in target.withUnsafeMutableBufferPointer { buffer, count in - buffer.initializeAll(fromContentsOf: newElements) - count = newElements.count + buffer.initializeAll( + fromContentsOf: remainder._extracting(first: buffer.count)) + remainder = remainder._extracting(droppingFirst: buffer.count) + count = buffer.count } } + assert(remainder.isEmpty) } /// Copies the elements of a fully initialized buffer pointer into this @@ -370,15 +376,14 @@ extension RigidDeque /* where Element: Copyable */ { copying items: borrowing C, newCount: Int ) { + let expectedCount = self.count - subrange.count + newCount + var it = newElements.startBorrowIteration() insert(count: newCount, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in - let copied = items._copyContents(intoPrefixOf: buffer) - precondition( - copied == newCount, - "Broken Container: count doesn't match contents") - count = newCount - } + it.copyContents(into: &target) } + precondition( + it.nextSpan().isEmpty && count == expectedCount, + "Broken Container: count doesn't match contents") } #endif @@ -388,8 +393,8 @@ extension RigidDeque /* where Element: Copyable */ { copying items: some Collection, newCount: Int ) { - let done: Void? = items.withContiguousStorageIfAvailable { buffer in - self.insert(copying: buffer, at: index) + let done: Void? = items.withContiguousStorageIfAvailable { src in + self.insert(copying: src, at: index) } if done != nil { return } @@ -397,8 +402,10 @@ extension RigidDeque /* where Element: Copyable */ { precondition(newCount <= freeCapacity, "RigidDeque capacity overflow") var i = items.startIndex self._handle.uncheckedInsert(count: newCount, at: index) { target in - target.append(items[i]) - items.formIndex(after: &i) + while !target.isFull { + target.append(items[i]) + items.formIndex(after: &i) + } } precondition(i == items.endIndex, "Broken Collection: count doesn't match contents") diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift new file mode 100644 index 00000000..b5352b54 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -0,0 +1,574 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Replaces the specified range of elements by a given count of new items, + /// using a callback to directly initialize deque storage by populating + /// a series of output spans. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting room for the new elements starting at the + /// same location. The number of new elements need not match the number + /// of elements being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, then + /// this method is equivalent to calling + /// `insert(count: newCount, at: subrange.lowerBound, initializingWith: body)`. + /// + /// Likewise, if you pass a zero for `newCount`, then this method + /// removes the elements in the given subrange without any replacement. + /// This case is more directly expressed by `removeSubrange(subrange)`. + /// + /// The newly prepended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease if the callback fails to fully populate its output span or if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// (Partial insertions create a gap in ring buffer storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised.) + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newCount: the number of items to replace the old subrange. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `newCount`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + newCount: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + // FIXME: Should we have a version of this with two closures, to allow custom-consuming the old items? + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= count, + "Subrange out of bounds") + precondition(newCount >= 0, "Negative count") + precondition( + count - subrange.count + newCount <= capacity, + "RigidDeque capacity overflow") + try _handle.uncheckedReplaceSubrange( + subrange, + newCount: newCount, + initializingWith: body) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Replaces the specified range of elements by moving the elements of a + /// fully initialized buffer into their place. On return, the buffer is left + /// in an uninitialized state. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newElements: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving newElements: UnsafeMutableBufferPointer, + ) { + var remainder = newElements + replaceSubrange(subrange, newCount: remainder.count) { target in + target.withUnsafeMutableBufferPointer { buffer, count in + buffer.moveInitializeAll( + fromContentsOf: remainder._extracting(first: buffer.count)) + remainder = remainder._extracting(droppingFirst: buffer.count) + count = buffer.count + } + } + assert(remainder.isEmpty) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by moving the contents of an + /// input span into their place. On return, the span is left empty. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: An input span whose contents are to be moved into the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving items: inout InputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.replaceSubrange(subrange, moving: source) + count = 0 + } + } +#endif + + /// Replaces the specified range of elements by moving the contents of an + /// output span into their place. On return, the span is left empty. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: An output span whose contents are to be moved into the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving items: inout OutputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.replaceSubrange(subrange, moving: source) + count = 0 + } + } + + /// Replaces the specified range of elements by moving the elements of a + /// another deque into their place. On return, the source deque + /// becomes empty, but it is not destroyed, and it preserves its original + /// storage capacity. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newElements: A deque whose contents to move into `self`. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving newElements: inout RigidDeque, + ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers + replaceSubrange(subrange, newCount: newElements.count) { target in + target.withUnsafeMutableBufferPointer { dst, dstCount in + var remainder = dst + newElements._handle.unsafeConsumePrefix(upTo: remainder.count) { src in + let c = remainder._moveInitializePrefix(from: src) + dstCount += c + remainder = remainder._extracting(last: c) + } + assert(remainder.isEmpty) + } + } + } +} + + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by moving the elements of a + /// given deque into their place, consuming it in the process. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(consuming:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newElements: A deque whose contents to move into `self`. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + consuming newElements: consuming RigidDeque, + ) { + // FIXME: Remove this in favor of a generic algorithm over consumable containers + replaceSubrange(subrange, moving: &newElements) + } +#endif +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /* where Element: Copyable */ { + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: UnsafeBufferPointer + ) { + var remainder = newElements + replaceSubrange(subrange, newCount: remainder.count) { target in + target.withUnsafeMutableBufferPointer { dst, dstCount in + dst.initializeAll(fromContentsOf: remainder._extracting(first: dst.count)) + dstCount += dst.count + remainder = remainder._extracting(droppingFirst: dst.count) + } + } + assert(remainder.isEmpty) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: UnsafeMutableBufferPointer + ) { + unsafe self.replaceSubrange( + subrange, + copying: UnsafeBufferPointer(newElements)) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given span. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length span as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: Span + ) { + unsafe newElements.withUnsafeBufferPointer { buffer in + unsafe self.replaceSubrange(subrange, copying: buffer) + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copyingContainer newElements: borrowing C, + newCount: Int + ) { + + let expectedCount = self.count - subrange.count + newCount + var it = newElements.startBorrowIteration() + self.replaceSubrange(subrange, newCount: newCount) { target in + it.copyContents(into: &target) + } + precondition( + it.nextSpan().isEmpty && count == expectedCount, + "Broken Container: count doesn't match contents") + } +#endif + + @inlinable + internal mutating func _replaceSubrange( + _ subrange: Range, + copyingCollection newElements: __owned some Collection, + newCount: Int + ) { + let done: Void? = newElements.withContiguousStorageIfAvailable { src in + precondition( + src.count == newCount, + "Broken Collection: count doesn't match contents") + self.replaceSubrange(subrange, copying: src) + } + if done != nil { return } + + var i = newElements.startIndex + self.replaceSubrange(subrange, newCount: newCount) { target in + while !target.isFull { + target.append(newElements[i]) + newElements.formIndex(after: &i) + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length container as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copying newElements: borrowing C + ) { + _replaceSubrange( + subrange, copyingContainer: newElements, newCount: newElements.count) + } +#endif + + /// Replaces the specified subrange of elements by copying the elements of + /// the given collection. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length collection as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @inlinable + @inline(__always) + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: __owned some Collection + ) { + _replaceSubrange( + subrange, copyingCollection: newElements, newCount: newElements.count) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the deque isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length container as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this deque and + /// *m* is the count of `newElements`. + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & Collection + >( + _ subrange: Range, + copying newElements: C + ) { + _replaceSubrange( + subrange, copyingContainer: newElements, newCount: newElements.count) + } +#endif +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift index a1706ab0..a4db2f82 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift @@ -25,7 +25,7 @@ extension RigidDeque where Element: ~Copyable { /// (Or would hold it after an insertion in case the deque is currently /// empty.) /// - /// This property isn't intended to be used outside of `Deque`'s own test + /// This property isn't intended to be used outside of `DequeModule`'s own test /// target. @_spi(Testing) public var _startSlot: Int { @@ -36,8 +36,10 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque { /// Constructs a deque instance of the specified contents and layout. Exposed - /// as public to allow exhaustive input/output tests for `Deque`'s members. - /// This isn't intended to be used outside of `Deque`'s own test target. + /// as public to allow exhaustive input/output tests for `RigidDeque` members. + /// + /// This initializer isn't intended to be used outside of `DequeModule`'s + /// own test target. @_spi(Testing) public init( _capacity capacity: Int, diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 01461c98..f4975721 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -734,27 +734,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { try second._initialize(initializedCount: &c, initializingWith: body) } } - - @_alwaysEmitIntoClient - internal mutating func uncheckedInsert( - count: Int, - at offset: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Void - ) throws(E) { - guard count > 0 else { return } - let gap = self.openGap(ofSize: count, atOffset: offset) - - var c = 0 - defer { - if c < count { - closeGap(offsets: offset + c ..< offset + count) - } - } - try gap.first._initialize(initializedCount: &c, initializingWith: body) - if c == gap.first.count, let second = gap.second { - try second._initialize(initializedCount: &c, initializingWith: body) - } - } } @available(SwiftStdlib 5.0, *) @@ -887,6 +866,18 @@ extension _UnsafeDequeHandle where Element: ~Copyable { return (slot(source, offsetBy: count), slot(target, offsetBy: count)) } + @_alwaysEmitIntoClient + @_transparent + func isLeftLeaning(_ offset: Int) -> Bool { + offset < count - offset + } + + @_alwaysEmitIntoClient + @_transparent + func isLeftLeaning(_ subrange: Range) -> Bool { + subrange.lowerBound < count - subrange.upperBound + } + /// Slide elements around so that there is a gap of uninitialized slots of /// size `gapSize` starting at `offset`, and return a (potentially wrapped) /// buffer holding the newly inserted slots. @@ -1197,6 +1188,30 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + internal mutating func uncheckedInsert( + count: Int, + at offset: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + guard count > 0 else { return } + let gap = self.openGap(ofSize: count, atOffset: offset) + + var c = 0 + defer { + if c < count { + closeGap(offsets: offset + c ..< offset + count) + } + } + try gap.first._initialize(initializedCount: &c, initializingWith: body) + if c == gap.first.count, let second = gap.second { + try second._initialize(initializedCount: &c, initializingWith: body) + } + } +} + extension _UnsafeDequeHandle { /// Insert all elements from `newElements` into this deque, starting at /// `offset`. @@ -1235,7 +1250,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { closeGap(offsets: Range(uncheckedBounds: (offset, offset + 1))) return result } - + @_alwaysEmitIntoClient @_transparent internal mutating func uncheckedRemoveFirst() -> Element { @@ -1245,7 +1260,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { count -= 1 return result } - + @_alwaysEmitIntoClient @_transparent internal mutating func uncheckedRemoveLast() -> Element { @@ -1255,7 +1270,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { count -= 1 return result } - + @_alwaysEmitIntoClient @_transparent internal mutating func uncheckedRemoveFirst(_ n: Int) { @@ -1266,7 +1281,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { startSlot = slot(startSlot, offsetBy: n) count -= n } - + @_alwaysEmitIntoClient @_transparent internal mutating func uncheckedRemoveLast(_ n: Int) { @@ -1276,7 +1291,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { target.deinitialize() count -= n } - + /// Remove all elements stored in this instance, deinitializing their storage. /// /// This method does not ensure that the storage buffer is uniquely @@ -1290,7 +1305,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { count = 0 startSlot = .zero } - + /// Remove all elements in `bounds`, deinitializing their storage and sliding /// remaining elements to close the resulting gap. /// @@ -1300,9 +1315,53 @@ extension _UnsafeDequeHandle where Element: ~Copyable { @_transparent internal mutating func uncheckedRemove(offsets bounds: Range) { assert(bounds.lowerBound >= 0 && bounds.upperBound <= self.count) - + // Deinitialize elements in `bounds`. mutableSegments(forOffsets: bounds).deinitialize() closeGap(offsets: bounds) } } + +// MARK: Replacement + +@available(SwiftStdlib 5.0, *) +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + internal mutating func uncheckedReplaceSubrange( + _ subrange: Range, + newCount: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + assert( + subrange.lowerBound >= 0 && subrange.upperBound <= count, + "Subrange out of bounds") + assert(newCount >= 0, "Negative count") + let delta = newCount - subrange.count + assert(count + delta <= capacity, "RigidDeque capacity overflow") + self.mutableSegments(forOffsets: subrange).deinitialize() + // Note: we're careful to open/close the gap in a direction that does not + // lead to trying to move slots we deinitialized above. + let left = isLeftLeaning(subrange) + if delta > 0 { + _ = self.openGap( + ofSize: delta, + atOffset: (left ? subrange.lowerBound : subrange.upperBound)) + } else { + self.closeGap( + offsets: (left ? subrange.prefix(-delta) : subrange.suffix(-delta))) + } + let newRange = Range(uncheckedBounds: (subrange.lowerBound, newCount)) + let gap = self.mutableSegments(forOffsets: newRange) + + var c = 0 + defer { + if c < newCount { + closeGap(offsets: newRange.dropFirst(c)) + } + } + try gap.first._initialize(initializedCount: &c, initializingWith: body) + if c == gap.first.count, let second = gap.second { + try second._initialize(initializedCount: &c, initializingWith: body) + } + } +} diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index ba05e636..f1d1aa1a 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -57,6 +57,29 @@ extension UnsafeBufferPointer where Element: ~Copyable { return Self(start: baseAddress, count: newCount) } + /// Returns a buffer pointer containing all but the given number of initial + /// elements. + /// + /// If the number of elements to drop exceeds the number of elements in the + /// buffer, the result is an empty buffer. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to drop. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(droppingFirst maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let cut = Swift.min(maxLength, count) + return Self(start: baseAddress?.advanced(by: cut), count: count &- cut) + } + /// Returns a buffer pointer containing the final elements of this buffer, /// up to the given maximum length. /// @@ -79,4 +102,28 @@ extension UnsafeBufferPointer where Element: ~Copyable { let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) } + + /// Returns a buffer pointer containing all but the given number of trailing + /// elements. + /// + /// If the number of elements to drop exceeds the number of elements in the + /// buffer, the result is an empty buffer. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to drop. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(droppingLast maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = count &- Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } + } From 67abaf5182afdf993bdcf9c652e4c53762dc6336 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 29 Oct 2025 20:10:27 -0700 Subject: [PATCH 12/75] Replace Container with a far less powerful (but more universal) Iterable construct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’m hoping Container will return later. --- Package.swift | 15 +- .../BasicContainers/RigidArray+Append.swift | 12 +- .../RigidArray+Initializers.swift | 51 ++-- .../RigidArray+Insertions.swift | 6 + .../RigidArray+Replacements.swift | 6 + Sources/BasicContainers/RigidArray.swift | 46 ++- .../BasicContainers/UniqueArray+Append.swift | 37 ++- .../UniqueArray+Initializers.swift | 10 +- .../UniqueArray+Insertions.swift | 4 + .../UniqueArray+Replacements.swift | 4 + Sources/BasicContainers/UniqueArray.swift | 8 +- .../BorrowIteratorProtocol.swift | 138 ++++++--- Sources/ContainersPreview/Box.swift | 1 + .../Container+Utilities.swift | 135 --------- Sources/ContainersPreview/Container.swift | 110 ++++--- .../ContainersPreview/FactoryIterator.swift | 62 ++++ .../Iterable+Standard Conformances.swift | 98 ++++++ .../Iterable+Utilities.swift | 279 ++++++++++++++++++ Sources/ContainersPreview/Iterable.swift | 139 +++++++++ Sources/ContainersPreview/Mut.swift | 51 +++- Sources/ContainersPreview/Ref.swift | 39 ++- .../RigidArrayTests.swift | 68 +++-- .../UniqueArrayTests.swift | 62 ++-- .../Assertions+Containers.swift | 44 +-- .../ConformanceCheckers/CheckContainer.swift | 57 ++-- .../MinimalTypes/StaccatoContainer.swift | 2 + 26 files changed, 1071 insertions(+), 413 deletions(-) delete mode 100644 Sources/ContainersPreview/Container+Utilities.swift create mode 100644 Sources/ContainersPreview/FactoryIterator.swift create mode 100644 Sources/ContainersPreview/Iterable+Standard Conformances.swift create mode 100644 Sources/ContainersPreview/Iterable+Utilities.swift create mode 100644 Sources/ContainersPreview/Iterable.swift diff --git a/Package.swift b/Package.swift index 8a1903e5..945deb23 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ import PackageDescription -#if false // FIXME: Disabled while we're debugging a runtime crash (rdar://150240032) +// FIXME: This can sometimes induce a runtime crash (rdar://150240032) let _traits: Set = [ .default( enabledTraits: [ @@ -35,7 +35,6 @@ let _traits: Set = [ types before they ship. """), ] -#endif // This package recognizes the conditional compilation flags listed below. // To use enable them, uncomment the corresponding lines or define them @@ -43,9 +42,9 @@ let _traits: Set = [ // // swift build -Xswiftc -DCOLLECTIONS_INTERNAL_CHECKS var defines: [SwiftSetting] = [ -// .define( -// "COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW", -// .when(traits: ["UnstableContainersPreview"])), + .define( + "COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW", + .when(traits: ["UnstableContainersPreview"])), .define( "COLLECTIONS_UNSTABLE_SORTED_COLLECTIONS", .when(traits: ["UnstableSortedCollections"])), @@ -104,8 +103,8 @@ let extraSettings: [SwiftSetting] = [ .enableExperimentalFeature("Lifetimes"), .enableExperimentalFeature("InoutLifetimeDependence"), .enableExperimentalFeature("SuppressedAssociatedTypes"), -// .enableExperimentalFeature("AddressableParameters"), -// .enableExperimentalFeature("AddressableTypes"), + .enableExperimentalFeature("AddressableParameters"), + .enableExperimentalFeature("AddressableTypes"), // Note: if you touch these, please make sure to also update the similar lists in // CMakeLists.txt and Xcode/Shared.xcconfig. @@ -359,6 +358,6 @@ let _targets: [Target] = targets.map { $0.toTarget() } let package = Package( name: "swift-collections", products: _products, - traits: [], //_traits, + traits: _traits, targets: _targets ) diff --git a/Sources/BasicContainers/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray+Append.swift index f1c57ee4..3f045f74 100644 --- a/Sources/BasicContainers/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray+Append.swift @@ -274,9 +274,9 @@ extension RigidArray { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @inlinable internal mutating func _append< - Source: Container & ~Copyable & ~Escapable + Source: Iterable & ~Copyable & ~Escapable >( - copyingContainer newElements: borrowing Source + copyingIterable newElements: borrowing Source ) { let target = _freeSpace _count += newElements._copyContents(intoPrefixOf: target) @@ -296,11 +296,11 @@ extension RigidArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Container & ~Copyable & ~Escapable + Source: Iterable & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { - _append(copyingContainer: newElements) + _append(copyingIterable: newElements) } #endif @@ -338,9 +338,9 @@ extension RigidArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Container & Sequence + Source: Iterable & Sequence >(copying newElements: Source) { - _append(copyingContainer: newElements) + _append(copyingIterable: newElements) } #endif } diff --git a/Sources/BasicContainers/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray+Initializers.swift index d9d8fc72..3fd7f2e7 100644 --- a/Sources/BasicContainers/RigidArray+Initializers.swift +++ b/Sources/BasicContainers/RigidArray+Initializers.swift @@ -98,15 +98,38 @@ extension RigidArray /*where Element: Copyable*/ { /// The container must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) - public init & ~Copyable & ~Escapable>( - capacity: Int? = nil, + public init & ~Copyable & ~Escapable>( + capacity: Int, copying contents: borrowing Source ) { - self.init(capacity: capacity ?? contents.count) + self.init(capacity: capacity) + self.append(copying: contents) + } + +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Creates a new array with the specified capacity, holding a copy + /// of the contents of a given container. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new array, or nil to allocate + /// just enough capacity to store the contents. + /// - contents: The container whose contents to copy into the new array. + /// The container must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init & Sequence>( + capacity: Int, + copying contents: Source + ) { + self.init(capacity: capacity) self.append(copying: contents) } #endif - + + // FIXME: Add a version that's generic over `Container`, with an optional capacity + /// Creates a new array with the specified capacity, holding a copy /// of the contents of a given collection. /// @@ -124,26 +147,6 @@ extension RigidArray /*where Element: Copyable*/ { self.init(capacity: capacity ?? contents.count) self.append(copying: contents) } - -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Creates a new array with the specified capacity, holding a copy - /// of the contents of a given container. - /// - /// - Parameters: - /// - capacity: The storage capacity of the new array, or nil to allocate - /// just enough capacity to store the contents. - /// - contents: The container whose contents to copy into the new array. - /// The container must not contain more than `capacity` elements. - @_alwaysEmitIntoClient - @inline(__always) - public init & Sequence>( - capacity: Int? = nil, - copying contents: Source - ) { - self.init(capacity: capacity ?? contents.count) - self.append(copying: contents) - } -#endif } // FIXME: Add init(moving:), init(consuming:) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 669a4fc1..856aebd4 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -341,6 +341,7 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. @inlinable internal mutating func _insertContainer< C: Container & ~Copyable & ~Escapable @@ -359,6 +360,7 @@ extension RigidArray { } } } +#endif #endif @inlinable @@ -388,6 +390,7 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -417,6 +420,7 @@ extension RigidArray { _insertContainer( at: index, copying: newElements, newCount: newElements.count) } +#endif #endif /// Copies the elements of a collection into this array at the specified @@ -448,6 +452,7 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -478,6 +483,7 @@ extension RigidArray { at: index, copying: newElements, newCount: newElements.count) } #endif +#endif } #endif diff --git a/Sources/BasicContainers/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray+Replacements.swift index 654cca7d..38717592 100644 --- a/Sources/BasicContainers/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray+Replacements.swift @@ -382,6 +382,7 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. @inlinable internal mutating func _replaceSubrange< C: Container & ~Copyable & ~Escapable @@ -399,6 +400,7 @@ extension RigidArray { } } } +#endif #endif @inlinable @@ -429,6 +431,7 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -466,6 +469,7 @@ extension RigidArray { _replaceSubrange( subrange, copyingContainer: newElements, newCount: newElements.count) } +#endif #endif /// Replaces the specified subrange of elements by copying the elements of @@ -505,6 +509,7 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -544,6 +549,7 @@ extension RigidArray { subrange, copyingContainer: newElements, newCount: newElements.count) } #endif +#endif } #endif diff --git a/Sources/BasicContainers/RigidArray.swift b/Sources/BasicContainers/RigidArray.swift index 6d78ed8c..6c4ab14b 100644 --- a/Sources/BasicContainers/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray.swift @@ -286,13 +286,49 @@ extension RigidArray where Element: ~Copyable { #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension RigidArray: Container where Element: ~Copyable { - public typealias BorrowIterator = Span - +extension RigidArray: Iterable where Element: ~Copyable { + @frozen + public struct BorrowIterator: ~Copyable, ~Escapable, BorrowIteratorProtocol { + @usableFromInline + internal let _span: Span + + @usableFromInline + internal var _offset: Int + + @inlinable + @_lifetime(copy span) + internal init(_span span: Span, offset: Int) { + self._span = span + self._offset = offset + } + + @_lifetime(&self) + @_lifetime(self: copy self) + public mutating func nextSpan(maximumCount: Int) -> Span { + let c = Swift.min(maximumCount, _span.count - _offset) + let end = _offset &+ c + let result = _span.extracting(Range(uncheckedBounds: (_offset, end))) + _offset = end + return result + } + + @_lifetime(self: copy self) + public mutating func skip(by offset: Int) -> Int { + let c = Swift.min(offset, _span.count &- _offset) + _offset += offset + return c + } + } + + @inlinable + public var estimatedCount: EstimatedCount { + .exactly(count) + } + @_alwaysEmitIntoClient @inline(__always) - public func startBorrowIteration() -> Span { - self.span + public func startBorrowIteration() -> BorrowIterator { + .init(_span: self.span, offset: 0) } } #endif diff --git a/Sources/BasicContainers/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray+Append.swift index 7cb3c56d..bb114597 100644 --- a/Sources/BasicContainers/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray+Append.swift @@ -231,11 +231,32 @@ extension UniqueArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Copies the elements of a container to the end of this array. + @inlinable + internal mutating func _append< + Source: Iterable & ~Copyable & ~Escapable + >( + copyingIterable newElements: borrowing Source + ) { + _ensureFreeCapacity(newElements.underestimatedCount) + var it = newElements.startBorrowIteration() + while true { + let span = it.nextSpan() + if span.isEmpty { break } + _ensureFreeCapacity(span.count) + _storage.append(copying: span) + } + } + // FIXME: Add _append(copyingContainer:), forwarding to the same method on RigidArray +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of an iterable to the end of this array. /// /// If the array does not have sufficient capacity to hold enough elements, /// then this reallocates the array's storage to extend its capacity, using - /// a geometric growth rate. + /// a geometric growth rate. If the input sequence does not provide a precise + /// estimate of its count, then the array's storage may need to be resized + /// more than once. /// /// - Parameters /// - newElements: A container whose contents to copy into the array. @@ -245,12 +266,11 @@ extension UniqueArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Container & ~Copyable & ~Escapable + Source: Iterable & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { - _ensureFreeCapacity(newElements.count) - _storage._append(copyingContainer: newElements) + self._append(copyingIterable: newElements) } #endif @@ -259,7 +279,7 @@ extension UniqueArray { /// /// If the array does not have sufficient capacity to hold enough elements, /// then this reallocates the array's storage to extend its capacity, using - /// a geometric growth rate. If the input sequence does not provide a correct + /// a geometric growth rate. If the input sequence does not provide a precise /// estimate of its count, then the array's storage may need to be resized /// more than once. /// @@ -300,10 +320,9 @@ extension UniqueArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Container & Sequence + Source: Iterable & Sequence >(copying newElements: Source) { - _ensureFreeCapacity(newElements.count) - _storage._append(copyingContainer: newElements) + self._append(copyingIterable: newElements) } #endif } diff --git a/Sources/BasicContainers/UniqueArray+Initializers.swift b/Sources/BasicContainers/UniqueArray+Initializers.swift index f0110a85..ee731b61 100644 --- a/Sources/BasicContainers/UniqueArray+Initializers.swift +++ b/Sources/BasicContainers/UniqueArray+Initializers.swift @@ -70,16 +70,16 @@ extension UniqueArray where Element: ~Copyable { extension UniqueArray /*where Element: Copyable*/ { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Creates a new array with the specified initial capacity, holding a copy - /// of the contents of a given container. + /// of the contents of a given iterable. /// /// - Parameters: /// - capacity: The storage capacity of the new array, or nil to allocate /// just enough capacity to store the contents. - /// - contents: The container whose contents to copy into the new array. - /// The container must not contain more than `capacity` elements. + /// - contents: An iterable whose contents to copy into the new array. + /// The iterable must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) - public init & ~Copyable & ~Escapable>( + public init & ~Copyable & ~Escapable>( capacity: Int? = nil, copying contents: borrowing Source ) { @@ -115,7 +115,7 @@ extension UniqueArray /*where Element: Copyable*/ { /// - contents: The container whose contents to copy into the new array. @_alwaysEmitIntoClient @inline(__always) - public init & Sequence>( + public init & Sequence>( capacity: Int? = nil, copying contents: Source ) { diff --git a/Sources/BasicContainers/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray+Insertions.swift index 4e9fbf27..8180b00c 100644 --- a/Sources/BasicContainers/UniqueArray+Insertions.swift +++ b/Sources/BasicContainers/UniqueArray+Insertions.swift @@ -301,6 +301,7 @@ extension UniqueArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -334,6 +335,7 @@ extension UniqueArray { _ensureFreeCapacity(c) _storage._insertContainer(at: index, copying: newElements, newCount: c) } +#endif #endif /// Copies the elements of a collection into this array at the specified @@ -368,6 +370,7 @@ extension UniqueArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -402,6 +405,7 @@ extension UniqueArray { _storage._insertContainer(at: index, copying: newElements, newCount: c) } #endif +#endif } #endif diff --git a/Sources/BasicContainers/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray+Replacements.swift index b52b020d..f2b85f0e 100644 --- a/Sources/BasicContainers/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray+Replacements.swift @@ -378,6 +378,7 @@ extension UniqueArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -420,6 +421,7 @@ extension UniqueArray { _storage._replaceSubrange( subrange, copyingContainer: newElements, newCount: c) } +#endif #endif /// Replaces the specified subrange of elements by copying the elements of @@ -464,6 +466,7 @@ extension UniqueArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: This needs a container with an exact count. /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -507,5 +510,6 @@ extension UniqueArray { subrange, copyingContainer: newElements, newCount: c) } #endif +#endif } #endif diff --git a/Sources/BasicContainers/UniqueArray.swift b/Sources/BasicContainers/UniqueArray.swift index 8bf93ab1..0c3122ad 100644 --- a/Sources/BasicContainers/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray.swift @@ -177,12 +177,16 @@ extension UniqueArray where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension UniqueArray: Container where Element: ~Copyable { +extension UniqueArray: Iterable where Element: ~Copyable { public typealias BorrowIterator = RigidArray.BorrowIterator + public var estimatedCount: ContainersPreview.EstimatedCount { + .exactly(count) + } + @_alwaysEmitIntoClient @inline(__always) - public func startBorrowIteration() -> Span { + public func startBorrowIteration() -> BorrowIterator { self._storage.startBorrowIteration() } } diff --git a/Sources/ContainersPreview/BorrowIteratorProtocol.swift b/Sources/ContainersPreview/BorrowIteratorProtocol.swift index f3452512..b13a0147 100644 --- a/Sources/ContainersPreview/BorrowIteratorProtocol.swift +++ b/Sources/ContainersPreview/BorrowIteratorProtocol.swift @@ -12,17 +12,31 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) public protocol BorrowIteratorProtocol: ~Copyable, ~Escapable { - associatedtype Element: ~Copyable /*& ~Escapable*/ + associatedtype Element: ~Copyable - /// Advance the iterator to the next storage chunk, returning a span over it. + // FIXME: This ought to be a core requirement, but `Ref` is not a thing yet. +// @_lifetime(&self) +// @_lifetime(self: copy self) +// mutating func next() -> Ref? + + /// Advance the iterator, returning an ephemeral span over the elements + /// that are ready to be visited. /// - /// If the iterator has not yet reached the end of the underlying container, - /// then this method returns a non-empty span over the container's storage - /// that begins with the element at the iterator's current position and - /// extends to the end of the contiguous storage chunk that contains that - /// item, but at most `maximumCount` items. On return, the iterator's current - /// position is updated to the slot following the last item in the returned - /// span. + /// If the underlying iterable is a container type, then the returned span + /// typically directly addresses one of its storage buffers. On the other + /// hand, if the underlying iterable materializes its elements on demand, + /// then the returned span addresses some temporary buffer associated with + /// the iterator itself. Consequently, the returned span is tied to this + /// particular invocation of `nextSpan`, and it cannot survive until the next + /// invocation of it. + /// + /// If the iterator has not yet reached the end of the underlying iterable, + /// then this method returns a non-empty span of at most `maximumCount` + /// elements, and updates the iterator's current position to the element + /// following the last item in the returned span (or the end, if there is + /// none). The `maximumCount` argument allows callers to avoid getting more + /// items that they are able to process in one go, simplifying usage, and + /// avoiding materializing more elements than needed. /// /// If the iterator's current position is at the end of the container, then /// this method returns an empty span without updating the position. @@ -39,30 +53,50 @@ public protocol BorrowIteratorProtocol: ~Copyable, ~Escapable { /// } /// /// Note: The spans returned by this method are not guaranteed to be disjunct. - /// Some containers may use the same storage chunk (or parts of a storage - /// chunk) multiple times, for example to repeat their contents. + /// Iterators that materialize elements on demand typically reuse the same + /// buffer over and over again; and even some proper containers may link to a + /// single storage chunk (or parts of a storage chunk) multiple times, for + /// example to repeat their contents. /// /// Note: Repeatedly iterating over the same container is expected to return /// the same items (collected in similarly sized span instances), but the - /// returned spans are not guaranteed to be identical. (For example, this is - /// the case with containers that can store contents within their direct - /// representation. Such containers may not always have a unique address in - /// memory, and so the locations of the spans exposed by this method may vary - /// between different borrows of the same container.) + /// returned spans are not guaranteed to be identical. For example, this is + /// the case with containers that store some of their contents within their + /// direct representation. Such containers may not always have a unique + /// address in memory, and so the locations of the spans exposed by this + /// method may vary between different borrows of the same container.) + @_lifetime(&self) + @_lifetime(self: copy self) + mutating func nextSpan(maximumCount: Int) -> Span + + /// Advance the position of this iterator by the specified offset, or until + /// the end of the underlying iterable. /// - /// - Parameter maximumCount: The maximum count of items the caller is ready - /// to process, or nil if the caller is prepared to accept an arbitrarily - /// large span. If non-nil, the maximum must be greater than zero. - /// - Returns: A span over a piece of contiguous storage in the underlying - /// container. It the iterator is at the end of the container, then - /// this returns an empty span. Otherwise the result will contain at least - /// one element. - @_lifetime(copy self) + /// Returns the number of items that were skipped. If this is less than + /// `maximumOffset`, then the iterable did not have enough elements left to + /// skip the requested number of items. In this case, the iterator's current + /// position is set to the end of the iterable. + /// + /// `maximumOffset` must be nonnegative, unless this is a bidirectional + /// or random-access iterator. @_lifetime(self: copy self) - mutating func nextSpan(maximumCount: Int?) -> Span + mutating func skip(by maximumOffset: Int) -> Int + // FIXME: Add BidirectionalBorrowIteratorProtocol and RandomAccessBorrowIteratorProtocol. + // BidirectionalBorrowIteratorProtocol would need to have a `previousSpan` + // method, which considerably complicates implementation. + // Perhaps these would be better left to as variants of protocol Container, + // which do not need a separate iterator concept. +} + +@available(SwiftStdlib 5.0, *) +extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { + @_lifetime(&self) @_lifetime(self: copy self) - mutating func skip(by offset: Int) -> Int + @_transparent + public mutating func nextSpan() -> Span { + nextSpan(maximumCount: Int.max) + } } @available(SwiftStdlib 5.0, *) @@ -82,24 +116,60 @@ extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { @available(SwiftStdlib 5.0, *) extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { - @_lifetime(copy self) +#if false // FIXME: This doesn't work, but it should? + @_lifetime(&self) @_lifetime(self: copy self) - @_transparent - public mutating func nextSpan() -> Span { - nextSpan(maximumCount: nil) + public mutating func next() -> Ref? { + let span = nextSpan(maximumCount: 1) + guard !span.isEmpty else { return nil } + return Ref(_borrowing: span[unchecked: 0]) } +#endif + + // @_lifetime(&self) + // @_lifetime(self: copy self) + // public mutating func nextSpan(maximumCount: Int) -> Span { + // guard let ref = next() else { return Span() } + // return ref.span // FIXME + // } } @available(SwiftStdlib 5.0, *) extension Span: BorrowIteratorProtocol where Element: ~Copyable { @_lifetime(copy self) @_lifetime(self: copy self) - public mutating func nextSpan(maximumCount: Int?) -> Span { - let c = maximumCount ?? self.count - let result = self.extracting(first: c) - self = self.extracting(droppingFirst: c) + @inlinable + public mutating func nextSpan(maximumCount: Int) -> Span { + let result = self.extracting(first: maximumCount) + self = self.extracting(droppingFirst: maximumCount) return result } } +// FIXME: Decide if we want UnsafeBufferPointer types to be borrow iterators + +#if false // FIXME: Implement this +@available(SwiftStdlib 5.0, *) +extension MutableSpan: BorrowIteratorProtocol where Element: ~Copyable { + @_lifetime(copy self) + @_lifetime(self: copy self) + @inlinable + public mutating func nextSpan(maximumCount: Int) -> Span { + //??? + } +} +#endif + +#if false // FIXME: Implement this +@available(SwiftStdlib 5.0, *) +extension OutputSpan: BorrowIteratorProtocol where Element: ~Copyable { + @_lifetime(copy self) + @_lifetime(self: copy self) + @inlinable + public mutating func nextSpan(maximumCount: Int) -> Span { + //??? + } +} +#endif + #endif diff --git a/Sources/ContainersPreview/Box.swift b/Sources/ContainersPreview/Box.swift index f486879b..64f37693 100644 --- a/Sources/ContainersPreview/Box.swift +++ b/Sources/ContainersPreview/Box.swift @@ -103,6 +103,7 @@ extension Box where T: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Return a borrowing reference to the contents of this box. + @available(SwiftStdlib 5.0, *) @_alwaysEmitIntoClient @_transparent @_lifetime(borrow self) diff --git a/Sources/ContainersPreview/Container+Utilities.swift b/Sources/ContainersPreview/Container+Utilities.swift deleted file mode 100644 index 407594ad..00000000 --- a/Sources/ContainersPreview/Container+Utilities.swift +++ /dev/null @@ -1,135 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2024 - 2025 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 -// -//===----------------------------------------------------------------------===// - -#if !COLLECTIONS_SINGLE_MODULE -import InternalCollectionsUtilities -#endif - -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - -@available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable, Element: Copyable { - @inlinable - package func _copyContents( - intoPrefixOf buffer: UnsafeMutableBufferPointer - ) -> Int { - var target = buffer - var it = self.startBorrowIteration() - while target.count != 0 { - let span = it.nextSpan(maximumCount: target.count) - if span.isEmpty { - return buffer.count - target.count - } - target._initializeAndDropPrefix(copying: span) - } - let test = it.nextSpan() - precondition(test.isEmpty, "Contents do not fit in target buffer") - return buffer.count - } -} - -@available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable { - @inlinable - @discardableResult - internal func _spanwiseZip< - Other: Container & ~Copyable & ~Escapable, - State: ~Copyable, E: Error - >( - state: inout State, - with other: borrowing Other, - by process: (inout State, Span, Span) throws(E) -> Bool - ) throws(E) -> Int { - var it1 = self.startBorrowIteration() - var it2 = other.startBorrowIteration() - var a = it1.nextSpan() - var b = it2.nextSpan() - var offset = 0 // Offset of the start of the current spans - loop: - while true { - if a.isEmpty { - a = it1.nextSpan() - } - if b.isEmpty { - b = it2.nextSpan() - } - if a.isEmpty || b.isEmpty { - return offset - } - - let c = Swift.min(a.count, b.count) - guard try process(&state, a.extracting(first: c), b.extracting(first: c)) else { - return offset - } - a = a.extracting(droppingFirst: c) - b = b.extracting(droppingFirst: c) - offset += c - } - } - - /// Returns a Boolean value indicating whether this container and another - /// container contain equivalent elements in the same order, using the given - /// predicate as the equivalence test. - /// - /// The predicate must form an *equivalence relation* over the elements. That - /// is, for any elements `a`, `b`, and `c`, the following conditions must - /// hold: - /// - /// - `areEquivalent(a, a)` is always `true`. (Reflexivity) - /// - `areEquivalent(a, b)` implies `areEquivalent(b, a)`. (Symmetry) - /// - If `areEquivalent(a, b)` and `areEquivalent(b, c)` are both `true`, then - /// `areEquivalent(a, c)` is also `true`. (Transitivity) - /// - /// - Parameters: - /// - other: A container to compare to this container. - /// - areEquivalent: A predicate that returns `true` if its two arguments - /// are equivalent; otherwise, `false`. - /// - Returns: `true` if this container and `other` contain equivalent items, - /// using `areEquivalent` as the equivalence test; otherwise, `false.` - /// - /// - Complexity: O(*m*), where *m* is the count of the longer of the input containers. - @inlinable - public func borrowingElementsEqual< - E: Error, - Other: Container & ~Copyable & ~Escapable - >( - _ other: borrowing Other, - by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool - ) throws(E) -> Bool { - guard self.count == other.count else { return false } - var result = true - try _spanwiseZip(state: &result, with: other) { state, a, b throws(E) in - assert(a.count == b.count) - for i in a.indices { - guard try areEquivalent(a[i], b[i]) else { - state = false - return false - } - } - return true - } - return result - } -} - -@available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable, Element: Equatable { - @inlinable - public func borrowingElementsEqual< - Other: Container & ~Copyable & ~Escapable - >( - _ other: borrowing Other, - ) -> Bool { - self.borrowingElementsEqual(other, by: ==) - } -} - -#endif diff --git a/Sources/ContainersPreview/Container.swift b/Sources/ContainersPreview/Container.swift index a804e5aa..3856fe76 100644 --- a/Sources/ContainersPreview/Container.swift +++ b/Sources/ContainersPreview/Container.swift @@ -11,77 +11,69 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // Unfortunately this does not work well with Iterable yet. + @available(SwiftStdlib 5.0, *) -public protocol Container: ~Copyable, ~Escapable { - associatedtype Element: ~Copyable /*& ~Escapable*/ - associatedtype BorrowIterator: BorrowIteratorProtocol & ~Copyable & ~Escapable +public struct ContainerIterator< + Base: Container & ~Copyable /*& ~Escapable*/ +>: ~Copyable, ~Escapable { + let _base: Ref + var _position: Base.Index + + @_lifetime(borrow base) + init(_borrowing base: borrowing @_addressable Base, from position: Base.Index) { + self._base = Ref(_borrowing: base) + self._position = position + } +} + +@available(SwiftStdlib 5.0, *) +extension ContainerIterator: BorrowIteratorProtocol where Base: ~Copyable { + public typealias Element = Base.Element + + @_lifetime(&self) + public mutating func nextSpan(maximumCount: Int) -> Span { + let r = _base[].nextSpan(after: &self._position, maximumCount: maximumCount) + return r + } +} + +@available(SwiftStdlib 5.0, *) +public protocol Container: Iterable, ~Copyable, ~Escapable { + associatedtype Index - var isEmpty: Bool { get } var count: Int { get } - + + var startIndex: Index { get } + var endIndex: Index { get } + func index(after index: Index) -> Index + func index(_ index: Index, offsetBy delta: Int) -> Index + // ... + +// subscript(index: Index) -> Element { borrow } + @_lifetime(borrow self) - borrowing func startBorrowIteration() -> BorrowIterator + func nextSpan(after index: inout Index, maximumCount: Int) -> Span } @available(SwiftStdlib 5.0, *) extension Container where Self: ~Copyable & ~Escapable { - /// Implementation demo of what borrowing for-in loops would need to expand into. - @inlinable - public func _borrowingForEach( - _ body: (borrowing Element) throws(E) -> Void - ) throws(E) -> Void { - var it = startBorrowIteration() - while true { - let span = it.nextSpan() - if span.isEmpty { break } - var i = 0 - while i < span.count { - try body(span[unchecked: i]) - i &+= 1 - } - } - } + @_transparent + public var estimatedCount: EstimatedCount { .exactly(count) } } @available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable { - @inlinable - public func borrowingReduce( - into initial: consuming Result, - _ update: (inout Result, borrowing Self.Element) throws(E) -> () - ) throws(E) -> Result { - var result = initial - try self._borrowingForEach { item throws(E) in - try update(&result, item) - } - return result +extension Container +where + Self: ~Copyable /*& ~Escapable*/, + BorrowIterator == ContainerIterator +{ + @_lifetime(borrow self) + public func startBorrowIteration() -> BorrowIterator { + ContainerIterator(_borrowing: self, from: self.startIndex) } - - @inlinable - public func borrowingReduce( - _ initial: consuming Result, - _ next: (consuming Result, borrowing Self.Element) throws(E) -> Result - ) throws(E) -> Result { - var result = initial -#if false // FIXME: missing reinitialization of closure capture 'result' after consume - try self._borrowingForEach { item throws(E) in - result = try next(result, item) - } -#else - var it = startBorrowIteration() - while true { - let span = it.nextSpan() - if span.isEmpty { break } - var i = 0 - while i < span.count { - result = try next(result, span[unchecked: i]) - i &+= 1 - } - } -#endif - return result - } - } #endif + +#endif diff --git a/Sources/ContainersPreview/FactoryIterator.swift b/Sources/ContainersPreview/FactoryIterator.swift new file mode 100644 index 00000000..beedad56 --- /dev/null +++ b/Sources/ContainersPreview/FactoryIterator.swift @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2025 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +public protocol FactoryIterator: ~Copyable, ~Escapable { + associatedtype Element: ~Copyable /* ~Escapable */ + + @_lifetime(target: copy target) + mutating func generate(into target: inout OutputSpan) +} + +//------------------------------------------------------------------------------ + +@available(SwiftStdlib 5.0, *) +public protocol ConsumingIterator: FactoryIterator, ~Copyable, ~Escapable { + @_lifetime(&self) + mutating func nextSpan(maximumCount: Int?) -> InputSpan +} + +@available(SwiftStdlib 5.0, *) +extension ConsumingIterator where Self: ~Copyable & ~Escapable { + @_lifetime(target: copy target) + mutating func generate(into target: inout OutputSpan) { + var remainder = target.count + while true { + var source = self.nextSpan(maximumCount: target.count) + remainder -= source.count + target._append(moving: &source) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension OutputSpan where Element: ~Copyable { + @_lifetime(source: copy source) + mutating func _append(moving source: inout InputSpan) { + self.withUnsafeMutableBufferPointer { target, targetCount in + source.withUnsafeMutableBufferPointer { source, sourceCount in + precondition(sourceCount <= targetCount, "OutputSpan capacity overflow") + target + .extracting(targetCount ..< targetCount + sourceCount) + .moveInitializeAll(fromContentsOf: source._extracting(last: sourceCount)) + } + } + } +} + +#endif diff --git a/Sources/ContainersPreview/Iterable+Standard Conformances.swift b/Sources/ContainersPreview/Iterable+Standard Conformances.swift new file mode 100644 index 00000000..22bc7dbd --- /dev/null +++ b/Sources/ContainersPreview/Iterable+Standard Conformances.swift @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +@available(SwiftStdlib 5.0, *) +extension Span: Iterable where Element: ~Copyable { + // FIXME: This simple definition cannot also be a backward (or bidirectional) + // iterator, nor a random-access iterator. If we want to go in that direction, + // we'll need to rather introduce a type more like `RigidArray.BorrowIterator`. + public typealias BorrowIterator = Self + + @inlinable + public var estimatedCount: EstimatedCount { + .exactly(count) + } + + @_lifetime(copy self) + @inlinable + public func startBorrowIteration() -> Span { + self + } +} + +@available(SwiftStdlib 5.0, *) +extension MutableSpan: Iterable where Element: ~Copyable { + public typealias BorrowIterator = Span.BorrowIterator + + @inlinable + public var estimatedCount: EstimatedCount { + .exactly(count) + } + + @_lifetime(borrow self) + @inlinable + public func startBorrowIteration() -> Span { + self.span + } +} + +@available(SwiftStdlib 5.0, *) +extension OutputSpan: Iterable where Element: ~Copyable { + public typealias BorrowIterator = Span.BorrowIterator + + @inlinable + public var estimatedCount: EstimatedCount { + .exactly(count) + } + + @_lifetime(borrow self) + @inlinable + public func startBorrowIteration() -> Span { + self.span + } +} + +@available(SwiftStdlib 5.0, *) +extension InputSpan: Iterable where Element: ~Copyable { + public typealias BorrowIterator = Span.BorrowIterator + + @inlinable + public var estimatedCount: EstimatedCount { + .exactly(count) + } + + @_lifetime(borrow self) + @inlinable + public func startBorrowIteration() -> Span { + self.span + } +} + +@available(SwiftStdlib 6.2, *) +extension Array: Iterable { + public typealias BorrowIterator = Span.BorrowIterator + + @inlinable + public var estimatedCount: EstimatedCount { + .exactly(count) + } + + @_lifetime(borrow self) + @inlinable + public func startBorrowIteration() -> Span { + self.span + } +} + + +#endif diff --git a/Sources/ContainersPreview/Iterable+Utilities.swift b/Sources/ContainersPreview/Iterable+Utilities.swift new file mode 100644 index 00000000..31a86d5e --- /dev/null +++ b/Sources/ContainersPreview/Iterable+Utilities.swift @@ -0,0 +1,279 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2025 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable, Element: Copyable { + @inlinable + package func _copyContents( + intoPrefixOf buffer: UnsafeMutableBufferPointer + ) -> Int { + var target = buffer + var it = self.startBorrowIteration() + while target.count != 0 { + let span = it.nextSpan(maximumCount: target.count) + if span.isEmpty { + return buffer.count - target.count + } + target._initializeAndDropPrefix(copying: span) + } + let test = it.nextSpan() + precondition(test.isEmpty, "Contents do not fit in target buffer") + return buffer.count + } +} + +#if true +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable { + @inlinable + public func elementsEqual< + Other: Iterable & ~Copyable & ~Escapable + >( + _ other: borrowing Other, + ) -> Bool where Element: Equatable { + switch (self.estimatedCount, other.estimatedCount) { + case let (.exactly(a), .exactly(b)): + guard a == b else { return false } + default: + break + } + var it1 = self.startBorrowIteration() + var it2 = other.startBorrowIteration() + while true { + let a = it1.nextSpan() + var i = 0 + if a.isEmpty { + return it2.nextSpan().isEmpty + } + while i < a.count { + let b = it2.nextSpan(maximumCount: a.count) + if b.isEmpty { + return false + } + precondition(b.count <= a.count - i) + + var j = 0 + while j < b.count { + guard a[unchecked: i] == b[unchecked: j] else { return false } + i &+= 1 + j &+= 1 + } + } + } + } +} + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable { + /// Returns a Boolean value indicating whether this Iterable and another + /// Iterable contain equivalent elements in the same order, using the given + /// predicate as the equivalence test. + /// + /// The predicate must form an *equivalence relation* over the elements. That + /// is, for any elements `a`, `b`, and `c`, the following conditions must + /// hold: + /// + /// - `areEquivalent(a, a)` is always `true`. (Reflexivity) + /// - `areEquivalent(a, b)` implies `areEquivalent(b, a)`. (Symmetry) + /// - If `areEquivalent(a, b)` and `areEquivalent(b, c)` are both `true`, then + /// `areEquivalent(a, c)` is also `true`. (Transitivity) + /// + /// - Parameters: + /// - other: A Iterable to compare to this Iterable. + /// - areEquivalent: A predicate that returns `true` if its two arguments + /// are equivalent; otherwise, `false`. + /// - Returns: `true` if this Iterable and `other` contain equivalent items, + /// using `areEquivalent` as the equivalence test; otherwise, `false.` + /// + /// - Complexity: O(*m*), where *m* is the count of the longer of the input Iterables. + @inlinable + public func elementsEqual< + E: Error, + Other: Iterable & ~Copyable & ~Escapable + >( + _ other: borrowing Other, + by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool + ) throws(E) -> Bool { + switch (self.estimatedCount, other.estimatedCount) { + case let (.exactly(a), .exactly(b)): + guard a == b else { return false } + default: + break + } + var it1 = self.startBorrowIteration() + var it2 = other.startBorrowIteration() + while true { + let a = it1.nextSpan() + var i = 0 + if a.isEmpty { + return it2.nextSpan().isEmpty + } + while i < a.count { + let b = it2.nextSpan(maximumCount: a.count) + if b.isEmpty { + return false + } + precondition(b.count <= a.count - i) + + var j = 0 + while j < b.count { + guard try areEquivalent(a[unchecked: i], b[unchecked: j]) else { + return false + } + i &+= 1 + j &+= 1 + } + } + } + } +} + +#else // rdar://150228920 +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable { + @inlinable + public func elementsEqual< + Other: Iterable & ~Copyable & ~Escapable + >( + _ other: borrowing Other, + ) -> Bool where Element: Equatable { + var it1 = self.startBorrowIteration() + var it2 = other.startBorrowIteration() + var a = Span() + var b = Span() + loop: + while true { + if a.isEmpty { + a = it1.nextSpan() + } + if b.isEmpty { + b = it2.nextSpan() + } + if a.isEmpty || b.isEmpty { + return a.isEmpty && b.isEmpty + } + + let c = Swift.min(a.count, b.count) + var i = 0 + while i < c { + guard a[unchecked: i] == b[unchecked: i] else { return false } + i &+= 1 + } + a = a.extracting(droppingFirst: c) + b = b.extracting(droppingFirst: c) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable { + @inlinable + @discardableResult + internal func _spanwiseZip< + Other: Iterable & ~Copyable & ~Escapable, + State: ~Copyable, E: Error + >( + state: inout State, + with other: borrowing Other, + by process: (inout State, Span, Span) throws(E) -> Bool + ) throws(E) -> Int { + var it1 = self.startBorrowIteration() + var it2 = other.startBorrowIteration() + var a = Span() + var b = Span() + var offset = 0 // Offset of the start of the current spans + loop: + while true { + if a.isEmpty { + a = it1.nextSpan() + } + if b.isEmpty { + b = it2.nextSpan() + } + if a.isEmpty || b.isEmpty { + return offset + } + + let c = Swift.min(a.count, b.count) + guard try process(&state, a.extracting(first: c), b.extracting(first: c)) else { + return offset + } + a = a.extracting(droppingFirst: c) + b = b.extracting(droppingFirst: c) + offset += c + } + } + + /// Returns a Boolean value indicating whether this Iterable and another + /// Iterable contain equivalent elements in the same order, using the given + /// predicate as the equivalence test. + /// + /// The predicate must form an *equivalence relation* over the elements. That + /// is, for any elements `a`, `b`, and `c`, the following conditions must + /// hold: + /// + /// - `areEquivalent(a, a)` is always `true`. (Reflexivity) + /// - `areEquivalent(a, b)` implies `areEquivalent(b, a)`. (Symmetry) + /// - If `areEquivalent(a, b)` and `areEquivalent(b, c)` are both `true`, then + /// `areEquivalent(a, c)` is also `true`. (Transitivity) + /// + /// - Parameters: + /// - other: A Iterable to compare to this Iterable. + /// - areEquivalent: A predicate that returns `true` if its two arguments + /// are equivalent; otherwise, `false`. + /// - Returns: `true` if this Iterable and `other` contain equivalent items, + /// using `areEquivalent` as the equivalence test; otherwise, `false.` + /// + /// - Complexity: O(*m*), where *m* is the count of the longer of the input Iterables. + @inlinable + public func elementsEqual< + E: Error, + Other: Iterable & ~Copyable & ~Escapable + >( + _ other: borrowing Other, + by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool + ) throws(E) -> Bool { + guard self.count == other.count else { return false } + var result = true + try _spanwiseZip(state: &result, with: other) { state, a, b throws(E) in + assert(a.count == b.count) + for i in a.indices { + guard try areEquivalent(a[i], b[i]) else { + state = false + return false + } + } + return true + } + return result + } +} + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable, Element: Equatable { + @inlinable + public func elementsEqual< + Other: Iterable & ~Copyable & ~Escapable + >( + _ other: borrowing Other, + ) -> Bool { + self.elementsEqual(other, by: ==) + } +} +#endif + +#endif diff --git a/Sources/ContainersPreview/Iterable.swift b/Sources/ContainersPreview/Iterable.swift new file mode 100644 index 00000000..d6034139 --- /dev/null +++ b/Sources/ContainersPreview/Iterable.swift @@ -0,0 +1,139 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2025 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +public enum EstimatedCount { + case infinite + case exactly(Int) + case unknown +} + +@available(SwiftStdlib 5.0, *) +public protocol Iterable: ~Copyable, ~Escapable { + associatedtype Element: ~Copyable + associatedtype BorrowIterator: BorrowIteratorProtocol & ~Copyable & ~Escapable + + var isEmpty: Bool { get } + + var estimatedCount: EstimatedCount { get } + + @_lifetime(borrow self) + borrowing func startBorrowIteration() -> BorrowIterator + + func _customContainsEquatableElement( + _ element: borrowing Element + ) -> Bool? +} + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable { + @inlinable + public var underestimatedCount: Int { + switch estimatedCount { + case .infinite: + Int.max + case .exactly(let c): + c + case .unknown: + 0 + } + } + + @inlinable + public func _customContainsEquatableElement(_ element: borrowing Element) -> Bool? { + nil + } +} + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: Sequence { + @inlinable + public func _customContainsEquatableElement(_ element: borrowing Element) -> Bool? { + nil + } +} + +@available(SwiftStdlib 5.0, *) +extension Iterable where Element: Copyable { + // FIXME: How do we expect this to work for ~Copyable elements? + public var first: Element? { + var it = startBorrowIteration() + let span = it.nextSpan(maximumCount: 1) + guard !span.isEmpty else { return nil } + return span[0] + } +} + + + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable { + /// Implementation demo of what borrowing for-in loops would need to expand into. + @inlinable + public func _borrowingForEach( + _ body: (borrowing Element) throws(E) -> Void + ) throws(E) -> Void { + var it = startBorrowIteration() + while true { + let span = it.nextSpan() + if span.isEmpty { break } + var i = 0 + while i < span.count { + try body(span[unchecked: i]) + i &+= 1 + } + } + } +} + +@available(SwiftStdlib 5.0, *) +extension Iterable where Self: ~Copyable & ~Escapable { + @inlinable + public func borrowingReduce( + into initial: consuming Result, + _ update: (inout Result, borrowing Self.Element) throws(E) -> () + ) throws(E) -> Result { + var result = initial + try self._borrowingForEach { item throws(E) in + try update(&result, item) + } + return result + } + + @inlinable + public func borrowingReduce( + _ initial: consuming Result, + _ next: (consuming Result, borrowing Self.Element) throws(E) -> Result + ) throws(E) -> Result { + var result = initial +#if false // FIXME: missing reinitialization of closure capture 'result' after consume + try self._borrowingForEach { item throws(E) in + result = try next(result, item) + } +#else + var it = startBorrowIteration() + while true { + let span = it.nextSpan() + if span.isEmpty { break } + var i = 0 + while i < span.count { + result = try next(result, span[unchecked: i]) + i &+= 1 + } + } +#endif + return result + } + +} + +#endif diff --git a/Sources/ContainersPreview/Mut.swift b/Sources/ContainersPreview/Mut.swift index 983b6314..7451d8ab 100644 --- a/Sources/ContainersPreview/Mut.swift +++ b/Sources/ContainersPreview/Mut.swift @@ -9,20 +9,18 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if compiler(>=6.2) import Builtin -// FIXME: A better name for the generic argument. - /// A safe mutable reference allowing in-place mutation to an exclusive value. /// -/// In order to get an instance of a `Mut`, one must have exclusive access -/// to the instance of `T`. This is achieved through the 'inout' operator, '&'. +/// In order to get an instance of a `Mut`, one must have exclusive access +/// to the instance of `Target`. This is achieved through the 'inout' operator, '&'. @frozen @safe -public struct Mut: ~Copyable, ~Escapable { +public struct Mut: ~Copyable, ~Escapable { @usableFromInline - package let _pointer: UnsafeMutablePointer + package let _pointer: UnsafeMutablePointer /// Initializes an instance of 'Mut' extending the exclusive access of the /// passed instance. @@ -30,8 +28,8 @@ public struct Mut: ~Copyable, ~Escapable { /// - Parameter instance: The desired instance to get a mutable reference to. @_alwaysEmitIntoClient @_transparent - public init(_ instance: inout T) { - unsafe _pointer = UnsafeMutablePointer(Builtin.unprotectedAddressOf(&instance)) + public init(_ instance: inout Target) { + unsafe _pointer = UnsafeMutablePointer(Builtin.unprotectedAddressOf(&instance)) } /// Unsafely initializes an instance of 'Mut' using the given 'unsafeAddress' @@ -39,7 +37,7 @@ public struct Mut: ~Copyable, ~Escapable { /// argument. /// /// - Parameter unsafeAddress: The address to use to mutably reference an - /// instance of type 'T'. + /// instance of type 'Target'. /// - Parameter owner: The owning instance that this 'Mut' instance's /// lifetime is based on. @unsafe @@ -47,7 +45,7 @@ public struct Mut: ~Copyable, ~Escapable { @_transparent @_lifetime(&owner) public init( - unsafeAddress: UnsafeMutablePointer, + unsafeAddress: UnsafeMutablePointer, mutating owner: inout Owner ) { unsafe _pointer = unsafeAddress @@ -58,26 +56,26 @@ public struct Mut: ~Copyable, ~Escapable { /// lifetime is immortal. /// /// - Parameter unsafeImmortalAddress: The address to use to mutably reference - /// an immortal instance of type 'T'. + /// an immortal instance of type 'Target'. @_lifetime(immortal) @unsafe @_alwaysEmitIntoClient @_transparent public init( - unsafeImmortalAddress: UnsafeMutablePointer + unsafeImmortalAddress: UnsafeMutablePointer ) { unsafe _pointer = unsafeImmortalAddress } } -extension Mut where T: ~Copyable { +extension Mut where Target: ~Copyable { /// Dereferences the mutable reference allowing for in-place reads and writes /// to the underlying instance. @_alwaysEmitIntoClient - public subscript() -> T { + public subscript() -> Target { @_transparent unsafeAddress { - unsafe UnsafePointer(_pointer) + unsafe UnsafePointer(_pointer) } @_transparent @@ -87,4 +85,25 @@ extension Mut where T: ~Copyable { } } } + +extension Optional where Wrapped: ~Copyable /* FIXME: ~Escapable */ { + @_lifetime(&self) + public mutating func mutate() -> Mut? { + if self == nil { + return nil + } + let pointer = unsafe UnsafeMutablePointer( + Builtin.unprotectedAddressOf(&self)) + return unsafe Mut(unsafeAddress: pointer, mutating: &self) + } + + @_lifetime(&self) + @_alwaysEmitIntoClient + @_transparent + public mutating func insert(_ value: consuming Wrapped) -> Mut { + self = .some(value) + return mutate()._consumingUnsafelyUnwrap() + } + +} #endif diff --git a/Sources/ContainersPreview/Ref.swift b/Sources/ContainersPreview/Ref.swift index ab7edecc..66f6ec12 100644 --- a/Sources/ContainersPreview/Ref.swift +++ b/Sources/ContainersPreview/Ref.swift @@ -12,17 +12,25 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW import Builtin +@available(SwiftStdlib 5.0, *) @frozen @safe -public struct Ref: Copyable, ~Escapable { +public struct Ref: Copyable, ~Escapable { @usableFromInline - package let _pointer: UnsafePointer + package let _pointer: UnsafePointer -#if compiler(>=6.2) && FIXME @_lifetime(borrow value) @_alwaysEmitIntoClient @_transparent - public init(_ value: borrowing @_addressable T) { + internal init(_borrowing value: borrowing @_addressable Target) { + unsafe _pointer = UnsafePointer(Builtin.unprotectedAddressOfBorrow(value)) + } + +#if compiler(>=6.3) // rdar://161844406 (https://github.com/swiftlang/swift/pull/84748) + @_lifetime(borrow value) + @_alwaysEmitIntoClient + @_transparent + public init(_ value: borrowing @_addressable Target) { unsafe _pointer = UnsafePointer(Builtin.unprotectedAddressOfBorrow(value)) } #endif @@ -31,7 +39,7 @@ public struct Ref: Copyable, ~Escapable { @_alwaysEmitIntoClient @_transparent public init( - unsafeAddress: UnsafePointer, + unsafeAddress: UnsafePointer, borrowing owner: borrowing Owner ) { unsafe _pointer = unsafeAddress @@ -41,18 +49,35 @@ public struct Ref: Copyable, ~Escapable { @_alwaysEmitIntoClient @_transparent public init( - unsafeAddress: UnsafePointer, + unsafeAddress: UnsafePointer, copying owner: borrowing Owner ) { unsafe _pointer = unsafeAddress } @_alwaysEmitIntoClient - public subscript() -> T { + public subscript() -> Target { @_transparent unsafeAddress { unsafe _pointer } } } + +extension Optional where Wrapped: ~Copyable /* FIXME: ~Escapable */ { + @available(SwiftStdlib 5.0, *) + @_lifetime(borrow self) + @_addressableSelf + public func borrow() -> Ref? { + if self == nil { + return nil + } + + let pointer = unsafe UnsafePointer( + Builtin.unprotectedAddressOfBorrow(self) + ) + + return unsafe Ref(unsafeAddress: pointer, borrowing: self) + } +} #endif diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index 622c2f14..3382fe70 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -22,7 +22,7 @@ import BasicContainers #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +public func expectIteratorContents< Element: Equatable, C2: Collection, >( @@ -33,7 +33,7 @@ public func expectContainerContents< file: StaticString = #file, line: UInt = #line ) { - expectContainerContents( + expectIteratorContents( left.span, equalTo: right, message(), trapping: trapping, file: file, line: line) @@ -41,7 +41,7 @@ public func expectContainerContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +public func expectIteratorContents< E1: ~Copyable, C2: Collection, >( @@ -53,7 +53,7 @@ public func expectContainerContents< file: StaticString = #file, line: UInt = #line ) { - expectContainerContents( + expectIteratorContents( left.span, equivalentTo: right, by: areEquivalent, @@ -69,9 +69,9 @@ class RigidArrayTests: CollectionTestCase { let items = tracker.rigidArray(layout: layout) let expected = (0 ..< layout.count).map { tracker.instance(for: $0) } expectEqual(tracker.instances, 2 * layout.count) - expectContainerContents(items, equalTo: expected) + expectIteratorContents(items, equalTo: expected) #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - checkContainer(items, expectedContents: expected) + checkIterable(items, expectedContents: expected) #endif } } @@ -115,7 +115,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.freeCapacity, layout.capacity - layout.count) expectEqual(a.isEmpty, layout.count == 0) expectEqual(a.isFull, layout.count == layout.capacity) - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) @@ -160,6 +160,7 @@ class RigidArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_init_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("spanCounts", in: [ @@ -184,6 +185,7 @@ class RigidArrayTests: CollectionTestCase { } } } +#endif #endif func test_span() { @@ -286,7 +288,7 @@ class RigidArrayTests: CollectionTestCase { a.swapAt(i, layout.count - 1 - i) } let expected = (0 ..< layout.count).reversed() - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count) } } @@ -390,7 +392,7 @@ class RigidArrayTests: CollectionTestCase { errorHandler: { error in expectTrue(error is TestError) } - expectContainerContents( + expectIteratorContents( a, equivalentTo: (0 ..< layout.count).map { -$0 }, by: { $0.payload == $1 }) @@ -415,7 +417,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, newCapacity) expectEqual(tracker.instances, layout.count) - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -439,7 +441,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, Swift.max(layout.capacity, newCapacity)) expectEqual(tracker.instances, layout.count) - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -454,8 +456,8 @@ class RigidArrayTests: CollectionTestCase { expectEqual(b.count, layout.count) expectEqual(b.capacity, layout.count) expectEqual(tracker.instances, layout.count) - expectContainerContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) - expectContainerContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIteratorContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } } @@ -472,8 +474,8 @@ class RigidArrayTests: CollectionTestCase { expectEqual(b.count, layout.count) expectEqual(b.capacity, newCapacity) expectEqual(tracker.instances, layout.count) - expectContainerContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) - expectContainerContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIteratorContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } } @@ -517,7 +519,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(tracker.instances, layout.count) a.removeLast(k) expectEqual(tracker.instances, layout.count - k) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -534,7 +536,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) let old = a.remove(at: i) expectEqual(old.payload, i) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -549,7 +551,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.removeSubrange(range) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -564,7 +566,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.removeAll(where: { $0.payload.isMultiple(of: 2) }) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -581,7 +583,7 @@ class RigidArrayTests: CollectionTestCase { let item = a.popLast() expectEquivalent(item, expectedItem, by: { $0?.payload == $1 }) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -594,7 +596,7 @@ class RigidArrayTests: CollectionTestCase { for i in layout.count ..< layout.capacity { a.append(tracker.instance(for: i)) expectEqual(a.count, i + 1) - expectContainerContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) } expectTrue(a.isFull) expectEqual(tracker.instances, layout.capacity) @@ -629,13 +631,14 @@ class RigidArrayTests: CollectionTestCase { using: { layout.count + $0 }) a.append(copying: b.span) expectTrue(a.isFull) - expectContainerContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_append_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("spanCount", in: 1 ... Swift.max(1, layout.capacity - layout.count)) { spanCount in @@ -648,12 +651,13 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.append(copying: b) expectTrue(a.isFull) - expectContainerContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } } } +#endif #endif func test_insert_at() { @@ -667,7 +671,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.insert(tracker.instance(for: -1), at: i) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + 1) } } @@ -690,7 +694,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.insert(copying: trackedAddition, at: i) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } @@ -715,7 +719,7 @@ class RigidArrayTests: CollectionTestCase { } a.insert(copying: rigidAddition.span, at: i) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } @@ -723,6 +727,7 @@ class RigidArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_insert_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("i", in: 0 ... layout.count) { i in @@ -743,13 +748,14 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [Swift.max(spanCount, 1)]) a.insert(copying: rigidAddition, at: i) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } } } } +#endif #endif func test_replaceSubrange_Collection() { @@ -768,7 +774,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.replaceSubrange(range, copying: trackedAddition) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -789,7 +795,7 @@ class RigidArrayTests: CollectionTestCase { let trackedAddition = RigidArray(copying: addition.map { tracker.instance(for: $0) }) a.replaceSubrange(range, copying: trackedAddition.span) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -798,6 +804,7 @@ class RigidArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_replaceSubrange_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in @@ -814,7 +821,7 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.replaceSubrange(range, copying: trackedAddition) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -823,5 +830,6 @@ class RigidArrayTests: CollectionTestCase { } } #endif +#endif } #endif diff --git a/Tests/BasicContainersTests/UniqueArrayTests.swift b/Tests/BasicContainersTests/UniqueArrayTests.swift index 3eaf7488..9836a702 100644 --- a/Tests/BasicContainersTests/UniqueArrayTests.swift +++ b/Tests/BasicContainersTests/UniqueArrayTests.swift @@ -22,7 +22,7 @@ import BasicContainers #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +public func expectIteratorContents< Element: Equatable, C2: Collection, >( @@ -33,7 +33,7 @@ public func expectContainerContents< file: StaticString = #file, line: UInt = #line ) { - expectContainerContents( + expectIteratorContents( left.span, equalTo: right, message(), trapping: trapping, file: file, line: line) @@ -41,7 +41,7 @@ public func expectContainerContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +public func expectIteratorContents< E1: ~Copyable, C2: Collection, >( @@ -53,7 +53,7 @@ public func expectContainerContents< file: StaticString = #file, line: UInt = #line ) { - expectContainerContents( + expectIteratorContents( left.span, equivalentTo: right, by: areEquivalent, @@ -70,9 +70,9 @@ class UniqueArrayTests: CollectionTestCase { let items = UniqueArray(consuming: tracker.rigidArray(layout: layout)) let expected = (0 ..< layout.count).map { tracker.instance(for: $0) } expectEqual(tracker.instances, 2 * layout.count) - expectContainerContents(items, equalTo: expected) + expectIteratorContents(items, equalTo: expected) #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - checkContainer(items, expectedContents: expected) + checkIterable(items, expectedContents: expected) #endif } } @@ -150,7 +150,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.freeCapacity, layout.capacity - layout.count) expectEqual(a.isEmpty, layout.count == 0) - expectContainerContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } } @@ -189,6 +189,7 @@ class UniqueArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_init_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("spanCounts", in: [ @@ -214,6 +215,7 @@ class UniqueArrayTests: CollectionTestCase { } } } +#endif #endif func test_span() { @@ -316,7 +318,7 @@ class UniqueArrayTests: CollectionTestCase { a.swapAt(i, layout.count - 1 - i) } let expected = (0 ..< layout.count).reversed() - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count) } @@ -394,7 +396,7 @@ class UniqueArrayTests: CollectionTestCase { errorHandler: { error in expectTrue(error is TestError) } - expectContainerContents( + expectIteratorContents( a, equivalentTo: (0 ..< layout.count).map { -$0 }, by: { $0.payload == $1 }) @@ -419,7 +421,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, newCapacity) expectEqual(tracker.instances, layout.count) - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -443,7 +445,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, Swift.max(layout.capacity, newCapacity)) expectEqual(tracker.instances, layout.count) - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -500,7 +502,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(tracker.instances, layout.count) a.removeLast(k) expectEqual(tracker.instances, layout.count - k) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -517,7 +519,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) let old = a.remove(at: i) expectEqual(old.payload, i) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -532,7 +534,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.removeSubrange(range) - expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -547,7 +549,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.removeAll(where: { $0.payload.isMultiple(of: 2) }) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -564,7 +566,7 @@ class UniqueArrayTests: CollectionTestCase { let item = a.popLast() expectEquivalent(item, expectedItem, by: { $0?.payload == $1 }) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -634,7 +636,7 @@ class UniqueArrayTests: CollectionTestCase { for i in layout.count ..< c { a.append(tracker.instance(for: i)) expectEqual(a.count, i + 1) - expectContainerContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) + expectIteratorContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) } expectEqual(tracker.instances, c) } @@ -651,7 +653,7 @@ class UniqueArrayTests: CollectionTestCase { elements: (layout.count ..< c).map { tracker.instance(for: $0) }, underestimatedCount: .half, isContiguous: isContiguous)) - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< c, by: { $0.payload == $1}) expectEqual(tracker.instances, c) } @@ -671,7 +673,7 @@ class UniqueArrayTests: CollectionTestCase { } a.append(copying: b.span) let c = layout.count + additions - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< c, by: { $0.payload == $1 }) expectEqual(tracker.instances, c) } @@ -680,6 +682,7 @@ class UniqueArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_append_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("additions", in: [0, 1, 10, 100]) { additions in @@ -695,7 +698,7 @@ class UniqueArrayTests: CollectionTestCase { contents: RigidArray(copying: addition), spanCounts: [spanCount]) a.append(copying: b) - expectContainerContents( + expectIteratorContents( a, equivalentTo: 0 ..< c, by: { $0.payload == $1 }) expectEqual(tracker.instances, c) } @@ -703,6 +706,7 @@ class UniqueArrayTests: CollectionTestCase { } } } +#endif #endif func test_insert_at() { @@ -715,7 +719,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.insert(tracker.instance(for: -1), at: i) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + 1) } @@ -737,7 +741,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.insert(copying: trackedAddition, at: i) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + c) } @@ -762,7 +766,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.insert(copying: rigidAddition.span, at: i) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + c) } @@ -772,6 +776,7 @@ class UniqueArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_insert_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("i", in: 0 ... layout.count) { i in @@ -793,7 +798,7 @@ class UniqueArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.insert(copying: rigidAddition, at: i) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + c) } @@ -802,6 +807,7 @@ class UniqueArrayTests: CollectionTestCase { } } } +#endif #endif func test_replaceSubrange_copying_Collection() { @@ -817,7 +823,7 @@ class UniqueArrayTests: CollectionTestCase { let trackedAddition = addition.map { tracker.instance(for: $0) } a.replaceSubrange(range, copying: trackedAddition) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } @@ -840,7 +846,7 @@ class UniqueArrayTests: CollectionTestCase { copying: addition.map { tracker.instance(for: $0) }) a.replaceSubrange(range, copying: trackedAddition.span) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } @@ -850,6 +856,7 @@ class UniqueArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update func test_replaceSubrange_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in @@ -867,7 +874,7 @@ class UniqueArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.replaceSubrange(range, copying: trackedAddition) - expectContainerContents( + expectIteratorContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } @@ -877,5 +884,6 @@ class UniqueArrayTests: CollectionTestCase { } } #endif +#endif } #endif diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index e153de16..14f68c7d 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -19,7 +19,7 @@ import ContainersPreview #if compiler(>=6.2) /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +public func expectIteratorContents< Element: Equatable, C2: Collection, >( @@ -58,7 +58,7 @@ public func expectContainerContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +public func expectIteratorContents< E1: ~Copyable, C2: Collection, >( @@ -97,19 +97,19 @@ public func expectContainerContents< #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -public func expectContainersWithEquivalentElements< - C1: Container & ~Copyable & ~Escapable, - C2: Container & ~Copyable & ~Escapable +public func expectIterablesWithEquivalentElements< + I1: Iterable & ~Copyable & ~Escapable, + I2: Iterable & ~Copyable & ~Escapable >( - _ left: borrowing C1, - _ right: borrowing C2, - by areEquivalent: (borrowing C1.Element, borrowing C2.Element) -> Bool, + _ left: borrowing I1, + _ right: borrowing I2, + by areEquivalent: (borrowing I1.Element, borrowing I2.Element) -> Bool, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #file, line: UInt = #line ) { - if left.borrowingElementsEqual(right, by: areEquivalent) { return } + if left.elementsEqual(right, by: areEquivalent) { return } _expectFailure( "Containers do not have equivalent elements", message, trapping: trapping, file: file, line: line) @@ -117,19 +117,19 @@ public func expectContainersWithEquivalentElements< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainersWithEqualElements< +public func expectIterablesWithEqualElements< Element: Equatable, - C1: Container & ~Copyable & ~Escapable, - C2: Container & ~Copyable & ~Escapable, + I1: Iterable & ~Copyable & ~Escapable, + I2: Iterable & ~Copyable & ~Escapable, >( - _ left: borrowing C1, - _ right: borrowing C2, + _ left: borrowing I1, + _ right: borrowing I2, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #file, line: UInt = #line ) { - if left.borrowingElementsEqual(right) { return } + if left.elementsEqual(right) { return } _expectFailure( "Containers do not have equal elements", message, trapping: trapping, file: file, line: line) @@ -137,12 +137,12 @@ public func expectContainersWithEqualElements< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +public func expectIteratorContents< Element: Equatable, - C1: Container & ~Copyable & ~Escapable, + I1: Iterable & ~Copyable & ~Escapable, C2: Collection, >( - _ left: borrowing C1, + _ left: borrowing I1, equalTo right: C2, _ message: @autoclosure () -> String = "", trapping: Bool = false, @@ -179,13 +179,13 @@ public func expectContainerContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< - C1: Container & ~Copyable & ~Escapable, +public func expectIteratorContents< + I1: Iterable & ~Copyable & ~Escapable, C2: Collection, >( - _ left: borrowing C1, + _ left: borrowing I1, equivalentTo right: C2, - by areEquivalent: (borrowing C1.Element, C2.Element) -> Bool, + by areEquivalent: (borrowing I1.Element, C2.Element) -> Bool, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #file, diff --git a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift index 032ec094..a18e6d66 100644 --- a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift +++ b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift @@ -15,17 +15,17 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) @inlinable -public func checkContainer< - C: Container & ~Copyable & ~Escapable, - Expected: Sequence +public func checkIterable< + I: Iterable & ~Copyable & ~Escapable, + Expected: Sequence >( - _ container: borrowing C, + _ iterable: borrowing I, expectedContents: Expected, file: StaticString = #filePath, line: UInt = #line -) where C.Element: Equatable { - checkContainer( - container, +) where I.Element: Equatable { + checkIterable( + iterable, expectedContents: expectedContents, by: ==, file: file, line: line) @@ -33,32 +33,41 @@ public func checkContainer< @available(SwiftStdlib 5.0, *) @inlinable -public func checkContainer< - C: Container & ~Copyable & ~Escapable, - Expected: Sequence +public func checkIterable< + I: Iterable & ~Copyable & ~Escapable, + Expected: Sequence >( - _ container: borrowing C, + _ iterable: borrowing I, expectedContents: Expected, - by areEquivalent: (C.Element, C.Element) -> Bool, + by areEquivalent: (I.Element, I.Element) -> Bool, file: StaticString = #filePath, line: UInt = #line -) where C.Element: Equatable { - let entry = TestContext.current.push("checkContainer", file: file, line: line) +) where I.Element: Equatable { + let entry = TestContext.current.push("checkIterable", file: file, line: line) defer { TestContext.current.pop(entry) } let expectedContents = Array(expectedContents) - expectEqual(container.isEmpty, expectedContents.isEmpty) - let actualCount = container.count - expectEqual(actualCount, expectedContents.count) + + expectEqual(iterable.isEmpty, expectedContents.isEmpty) + + let estimatedCount = iterable.estimatedCount + switch estimatedCount { + case .exactly(let c): + expectEqual(c, expectedContents.count) + case .infinite: + expectFailure() + case .unknown: + break + } // Check that the spans seem plausibly sized and that the indices are monotonic. let spanShapes: [Range] = { var r: [Range] = [] var pos = 0 - var it = container.startBorrowIteration() + var it = iterable.startBorrowIteration() while true { let origPos = pos - let span = it.nextSpan(maximumCount: nil) + let span = it.nextSpan() pos += span.count if span.isEmpty { break @@ -68,16 +77,16 @@ public func checkContainer< return r }() expectEqual( - spanShapes.reduce(into: 0, { $0 += $1.count }), actualCount, + spanShapes.reduce(into: 0, { $0 += $1.count }), expectedContents.count, "Container's count does not match the sum of its spans") // Check that the spans have stable sizes and the expected contents. do { var pos = 0 - var it = container.startBorrowIteration() + var it = iterable.startBorrowIteration() var spanIndex = 0 while true { - let span = it.nextSpan(maximumCount: nil) + let span = it.nextSpan() if span.isEmpty { break } expectEqual( span.count, spanShapes[spanIndex].count, @@ -95,7 +104,7 @@ public func checkContainer< // Check that we can iterate one by one. do { var pos = 0 - var it = container.startBorrowIteration() + var it = iterable.startBorrowIteration() while true { let span = it.nextSpan(maximumCount: 1) if span.isEmpty { break } @@ -111,7 +120,7 @@ public func checkContainer< // Check that we can iterate with huge maximum counts do { var pos = 0 - var it = container.startBorrowIteration() + var it = iterable.startBorrowIteration() var spanIndex = 0 while true { let span = it.nextSpan(maximumCount: Int.max) diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift index b61709f8..068b47f3 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift @@ -17,6 +17,7 @@ import ContainersPreview #endif #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if false // FIXME: Update /// A container type with user-defined contents and storage chunks. /// Useful for testing. @available(SwiftStdlib 5.0, *) @@ -86,3 +87,4 @@ extension StaccatoContainer: Container where Element: ~Copyable { } } #endif +#endif From 33b50fdb766ffc84481648d2f71ce5cb0c5bd54d Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 12 Jan 2026 14:10:25 -0800 Subject: [PATCH 13/75] =?UTF-8?q?FactoryIterator=20=E2=86=92=20Producer,?= =?UTF-8?q?=20ConsumingIterator=20=E2=86=92=20Drain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BorrowIteratorProtocol.swift | 2 +- Sources/ContainersPreview/Container.swift | 2 +- Sources/ContainersPreview/Drain.swift | 50 +++++++++++++++ .../ContainersPreview/FactoryIterator.swift | 62 ------------------- Sources/ContainersPreview/InputSpan.swift | 2 +- Sources/ContainersPreview/Iterable.swift | 2 +- Sources/ContainersPreview/Mut.swift | 2 +- Sources/ContainersPreview/Producer.swift | 22 +++++++ 8 files changed, 77 insertions(+), 67 deletions(-) create mode 100644 Sources/ContainersPreview/Drain.swift delete mode 100644 Sources/ContainersPreview/FactoryIterator.swift create mode 100644 Sources/ContainersPreview/Producer.swift diff --git a/Sources/ContainersPreview/BorrowIteratorProtocol.swift b/Sources/ContainersPreview/BorrowIteratorProtocol.swift index b13a0147..26ed63e2 100644 --- a/Sources/ContainersPreview/BorrowIteratorProtocol.swift +++ b/Sources/ContainersPreview/BorrowIteratorProtocol.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 diff --git a/Sources/ContainersPreview/Container.swift b/Sources/ContainersPreview/Container.swift index 3856fe76..495da94f 100644 --- a/Sources/ContainersPreview/Container.swift +++ b/Sources/ContainersPreview/Container.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 diff --git a/Sources/ContainersPreview/Drain.swift b/Sources/ContainersPreview/Drain.swift new file mode 100644 index 00000000..e3bb4c6d --- /dev/null +++ b/Sources/ContainersPreview/Drain.swift @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +public protocol Drain: Producer, ~Copyable, ~Escapable { + @_lifetime(&self) + mutating func nextSpan(maximumCount: Int?) -> InputSpan +} + +@available(SwiftStdlib 5.0, *) +extension Drain where Self: ~Copyable & ~Escapable { + @_lifetime(target: copy target) + mutating func drain(filling target: inout OutputSpan) { + while target.freeCapacity > 0 { + var source = self.nextSpan(maximumCount: target.freeCapacity) + target._append(moving: &source) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension OutputSpan where Element: ~Copyable { + @_lifetime(source: copy source) + mutating func _append(moving source: inout InputSpan) { + self.withUnsafeMutableBufferPointer { dst, dstCount in + source.withUnsafeMutableBufferPointer { src, srcCount in + precondition(srcCount <= dstCount, "OutputSpan capacity overflow") + dst + .extracting(dstCount ..< dstCount + srcCount) + .moveInitializeAll(fromContentsOf: src._extracting(last: srcCount)) + } + } + } +} + +#endif diff --git a/Sources/ContainersPreview/FactoryIterator.swift b/Sources/ContainersPreview/FactoryIterator.swift deleted file mode 100644 index beedad56..00000000 --- a/Sources/ContainersPreview/FactoryIterator.swift +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2024 - 2025 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 -// -//===----------------------------------------------------------------------===// - -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - -#if !COLLECTIONS_SINGLE_MODULE -import InternalCollectionsUtilities -#endif - -@available(SwiftStdlib 5.0, *) -public protocol FactoryIterator: ~Copyable, ~Escapable { - associatedtype Element: ~Copyable /* ~Escapable */ - - @_lifetime(target: copy target) - mutating func generate(into target: inout OutputSpan) -} - -//------------------------------------------------------------------------------ - -@available(SwiftStdlib 5.0, *) -public protocol ConsumingIterator: FactoryIterator, ~Copyable, ~Escapable { - @_lifetime(&self) - mutating func nextSpan(maximumCount: Int?) -> InputSpan -} - -@available(SwiftStdlib 5.0, *) -extension ConsumingIterator where Self: ~Copyable & ~Escapable { - @_lifetime(target: copy target) - mutating func generate(into target: inout OutputSpan) { - var remainder = target.count - while true { - var source = self.nextSpan(maximumCount: target.count) - remainder -= source.count - target._append(moving: &source) - } - } -} - -@available(SwiftStdlib 5.0, *) -extension OutputSpan where Element: ~Copyable { - @_lifetime(source: copy source) - mutating func _append(moving source: inout InputSpan) { - self.withUnsafeMutableBufferPointer { target, targetCount in - source.withUnsafeMutableBufferPointer { source, sourceCount in - precondition(sourceCount <= targetCount, "OutputSpan capacity overflow") - target - .extracting(targetCount ..< targetCount + sourceCount) - .moveInitializeAll(fromContentsOf: source._extracting(last: sourceCount)) - } - } - } -} - -#endif diff --git a/Sources/ContainersPreview/InputSpan.swift b/Sources/ContainersPreview/InputSpan.swift index 7560041c..e705015f 100644 --- a/Sources/ContainersPreview/InputSpan.swift +++ b/Sources/ContainersPreview/InputSpan.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 diff --git a/Sources/ContainersPreview/Iterable.swift b/Sources/ContainersPreview/Iterable.swift index d6034139..e7306cc7 100644 --- a/Sources/ContainersPreview/Iterable.swift +++ b/Sources/ContainersPreview/Iterable.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 diff --git a/Sources/ContainersPreview/Mut.swift b/Sources/ContainersPreview/Mut.swift index 7451d8ab..310163c1 100644 --- a/Sources/ContainersPreview/Mut.swift +++ b/Sources/ContainersPreview/Mut.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW import Builtin /// A safe mutable reference allowing in-place mutation to an exclusive value. diff --git a/Sources/ContainersPreview/Producer.swift b/Sources/ContainersPreview/Producer.swift new file mode 100644 index 00000000..c63c9ff9 --- /dev/null +++ b/Sources/ContainersPreview/Producer.swift @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +@available(SwiftStdlib 5.0, *) +public protocol Producer: ~Copyable, ~Escapable { + associatedtype Element: ~Copyable /* ~Escapable */ + + @_lifetime(target: copy target) + mutating func generate(into target: inout OutputSpan) +} + +#endif From 7f7089eae6c48afb26b54ddb3ea0eec12828d9a4 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 16 Jan 2026 16:06:27 -0800 Subject: [PATCH 14/75] Update Producer and Drain, fleshing them out a bit --- Sources/ContainersPreview/Drain.swift | 215 +++++++++++++++-- Sources/ContainersPreview/InputSpan.swift | 44 +++- .../ContainersPreview/OutputSpan+Extras.swift | 75 ++++++ Sources/ContainersPreview/Producer.swift | 216 +++++++++++++++++- .../UnsafeBufferPointer+Extras.swift | 11 +- .../UnsafeMutableBufferPointer+Extras.swift | 15 +- 6 files changed, 534 insertions(+), 42 deletions(-) create mode 100644 Sources/ContainersPreview/OutputSpan+Extras.swift diff --git a/Sources/ContainersPreview/Drain.swift b/Sources/ContainersPreview/Drain.swift index e3bb4c6d..943b4385 100644 --- a/Sources/ContainersPreview/Drain.swift +++ b/Sources/ContainersPreview/Drain.swift @@ -11,40 +11,205 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if !COLLECTIONS_SINGLE_MODULE -import InternalCollectionsUtilities -#endif - +/// A type that supplies the values of an in-place consumable sequence through +/// a series of `InputSpan` instances. This iterator-like construct allows +/// directly consuming elements from some container's storage, in bulk, +/// without requiring them to be moved into any temporary buffer. +/// +/// Drains are inherently also producers -- they can produce items by simply +/// moving their consumable contents to the client-supplied series of +/// output spans. @available(SwiftStdlib 5.0, *) -public protocol Drain: Producer, ~Copyable, ~Escapable { +public protocol Drain: Producer, ~Copyable, ~Escapable +where ProducerError == Never +{ + /// Returns the next span of consumable items in the sequence underlying this + /// drain, of at most the specified maximum count. A `maximumCount` of nil + /// indicates no limit, meaning that the client is able to process an + /// arbitrarily large number of elements. + /// + /// Repeatedly calling this method returns, in order, all the elements of the + /// underlying consumable sequence. As soon as the sequence has run out of + /// elements, all subsequent calls return empty spans. + /// + /// While the returned input spans exist, they continue to mutate the drain, + /// extending the exclusive access initiated by the call to + /// `drainNext(maximumCount:)`. To call this (or any other) method again, the + /// returned input span needs to be consumed or otherwise destroyed. + /// + /// Once this method returns, the contents of the resulting input span are + /// already destined for consumption, either gradually by invoking explicit + /// methods such as `InputSpan.popFirst`, or all at once when + /// the input span is destroyed. There is no way to "put items back" into + /// the consumable sequence, other than by moving them into a + /// temporary location and later reinserting them into the underlying + /// construct through some type-specific operations. + /// + /// - Parameter maximumCount: The maximum number of items that the client + /// is prepared to consume, or nil if the client is able to process an + /// arbitrary number of elements. If this is non-nil, then it must be a + /// positive integer. + /// - Returns: An input span of at most the specified maximum count (if any), + /// containing the next elements of the underlying consumable sequence. + /// This method returns an empty span to indicate that it has reached + /// the end of the sequence. @_lifetime(&self) - mutating func nextSpan(maximumCount: Int?) -> InputSpan + @_lifetime(self: copy self) + mutating func drainNext(maximumCount: Int?) -> InputSpan + // TODO: The primary use case does not need this to throw; do we need to allow that? + // Note: making this failable is not entirely straightforward, as there is no + // easy way to signal partial success -- conforming implementations + // would likely need to store errors they encounter midway through a + // chunk and report them at the beginning of the next iteration. + // I take this as an indication that we don't need to do that. + // (Contrast with this `Producer.generate(into:)`; the shape of that method + // allows it to partially populate its client-supplied target and still + // report an error.) + // + // Note: We can also express this with a higher-order shape: + // + // mutating func drainNext( + // _ body: (inout InputSpan) throws(E) -> R + // ) throws(E) -> R + // + // This would allow partial consumption, eliminating the need for + // `maximumCount`, but at the cost of having to deal with closures -- + // it can be tricky to elegantly flow data/control in & out higher-order + // functions. Allowing the function argument to throw also precludes + // the drain itself from throwing, unless they are both required + // to use the same error type, which would be impractical. } @available(SwiftStdlib 5.0, *) extension Drain where Self: ~Copyable & ~Escapable { - @_lifetime(target: copy target) - mutating func drain(filling target: inout OutputSpan) { - while target.freeCapacity > 0 { - var source = self.nextSpan(maximumCount: target.freeCapacity) - target._append(moving: &source) - } + /// Returns the next span of consumable items in the sequence underlying this + /// drain, of an arbitrarily large count. + /// + /// Repeatedly calling this method returns, in order, all the elements of the + /// underlying consumable sequence. As soon as the sequence has run out of + /// elements, all subsequent calls return empty spans. + /// + /// While the returned input spans exist, they continue to mutate the drain, + /// extending the exclusive access initiated by the call to + /// `drain(maximumCount:)`. To call this (or any other) method again, the + /// returned input span needs to be consumed or otherwise destroyed. + /// + /// Once this method returns, the contents of the resulting input span are + /// already destined for consumption, either gradually by invoking explicit + /// methods such as `InputSpan.popFirst`, or all at once when + /// the input span is destroyed. There is no way to "put items back" into + /// the consumable sequence, other than by moving them into a + /// temporary location and later reinserting them into the underlying + /// construct through some type-specific operations. + /// + /// - Returns: An input span containing the next elements of the underlying + /// consumable sequence. This method returns an empty span to indicate + /// that it has reached the end of the sequence. + @_lifetime(&self) + @_lifetime(self: copy self) + @_transparent + mutating func drainNext() -> InputSpan { + drainNext(maximumCount: nil) } -} -@available(SwiftStdlib 5.0, *) -extension OutputSpan where Element: ~Copyable { - @_lifetime(source: copy source) - mutating func _append(moving source: inout InputSpan) { - self.withUnsafeMutableBufferPointer { dst, dstCount in - source.withUnsafeMutableBufferPointer { src, srcCount in - precondition(srcCount <= dstCount, "OutputSpan capacity overflow") - dst - .extracting(dstCount ..< dstCount + srcCount) - .moveInitializeAll(fromContentsOf: src._extracting(last: srcCount)) - } - } + /// Generate the next batch of items into the supplied output span instance, + /// which must have room for at least one new element. + /// + /// Repeatedly calling this method produces, in order, all the elements of the + /// underlying generative sequence. As soon as the sequence has run out of + /// elements, all subsequent calls return false without appending any new + /// items to their target. This method is not guaranteed to fully populate the + /// given output span, but it always appends at least one item until the end + /// of the underlying generative sequence. + /// + /// The ownership of all generated elements is transferred to the caller of + /// this method -- it can arbitrarily store, mutate, consume or discard them + /// as needed, even across invocations of this method, or after the producer + /// is destroyed. + /// + /// The returned Boolean value can be used to easily determine if the + /// method was able to make progress towards filling `target` without hitting + /// the end of the underlying sequence. + /// + /// ### Error handling + /// + /// This method throws an error to indicate a failure while trying to generate + /// the upcoming next item in the sequence. Failure may happen midway through + /// populating `target`, in which case the output span will still gain + /// new items despite the error. (Those items are successfully + /// generated, and do not necessarilly need to be discarded.) + /// + /// This protocol does not specify the meaning of a failure, or the + /// precise state of the iterator after an error is thrown; however, the + /// error must not trigger runtime traps in subsequent attempts at iteration. + /// (After a failure, conforming types may choose to produce new items, or + /// signal the end of the iteration, or throw another error, which may or may + /// not match the first.) + /// + /// Absent of more specific information, generic code should stop + /// iterating, discard the producer and rethrow the error when it encounters + /// a failure. Generic code is encouraged to preserve the items that got + /// successfully produced before the throw (including ones appended by + /// the call that ultimately ended in failure); however, whether this is + /// possible (or desirable) ultimately depends on the specific problem that + /// the algorithm is solving. + /// + /// - Parameter target: An output span ready to take newly generated items. + /// - Returns: A boolean value indicating whether the operation was able to + /// append at least one item to the supplied output span without hitting + /// the end of the underlying sequence. + @_lifetime(target: copy target) + mutating func generate( + into target: inout OutputSpan + ) throws(Never) -> Bool { + var source = self.drainNext(maximumCount: target.freeCapacity) + if source.isEmpty { return false } + target._append(moving: &source) + return true } + + /// Skip at most the given number items in the underlying generative sequence, + /// decreasing it by the number of items successfully skipped. + /// + /// This is equivalent to generating the same number of items then immediately + /// discarding them, except it may avoid the overhead of actually + /// materializing them. + /// + /// As soon as the producer has run out of items, all subsequent calls to + /// this method stop decrementing `remainder` and return false. + /// + /// The default implementation of this method calls `generate(into:)` with + /// a small temporary buffer, immediately discarding all generated items. + /// Conforming types are encouraged to replace this default approach + /// with a more efficient implementation whenever it is possible to do so. + /// + /// ### Error handling + /// + /// This method throws an error to indicate a failure while trying to skip + /// the upcoming next item in the sequence. Failure may happen midway through + /// skipping a batch of items, in which case the `remainder` will still be + /// decremented by the number of elements that were successfully skipped + /// before encountering the problem. + /// + /// - Parameter remainder: The maximum number of items remaining to skip. + /// This method decrements this value by the number of items it + /// successfully skipped before returning. + /// - Returns: A boolean value indicating whether the operation was able to + /// satisfy the request at least partially without hitting the end of the + /// underlying consumable sequence. + @inlinable + @_lifetime(self: copy self) + public mutating func skip( + remainder: inout Int + ) throws(ProducerError) -> Bool { + precondition(remainder >= 0, "Can't skip a negative number of elements") + guard remainder > 0 else { return true } + let span = drainNext(maximumCount: remainder) + let success = span.count > 0 + remainder &-= span.count + return success + } + } #endif diff --git a/Sources/ContainersPreview/InputSpan.swift b/Sources/ContainersPreview/InputSpan.swift index e705015f..70fa8f9c 100644 --- a/Sources/ContainersPreview/InputSpan.swift +++ b/Sources/ContainersPreview/InputSpan.swift @@ -33,7 +33,9 @@ public struct InputSpan: ~Copyable, ~Escapable { deinit { if _count > 0 { let c = _count - unsafe _first().withMemoryRebound(to: Element.self, capacity: _count) { + unsafe _unsafeRawAddressOfSlot(uncheckedOffset: 0).withMemoryRebound( + to: Element.self, capacity: _count + ) { _ = unsafe $0.deinitialize(count: c) } } @@ -59,15 +61,6 @@ extension InputSpan where Element: ~Copyable { unsafe _pointer.unsafelyUnwrapped } - @_alwaysEmitIntoClient - @_transparent - @unsafe - internal func _first() -> UnsafeMutableRawPointer { - // NOTE: `_pointer` must be known to be not-nil. - let offset = (capacity &- _count) &* MemoryLayout.stride - return unsafe _start().advanced(by: offset) - } - @unsafe @_alwaysEmitIntoClient @_transparent @@ -330,7 +323,7 @@ extension InputSpan where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(self: copy self) public mutating func removeFirst() -> Element { - precondition(!isEmpty, "InputSpan underflow") + precondition(_count > 0, "InputSpan underflow") defer { _count &-= 1 } return _unsafeAddressOfElement(unchecked: 0).move() } @@ -351,6 +344,21 @@ extension InputSpan where Element: ~Copyable { } _count &-= k } + + /// Removes and returns the first element of this input span, if it exists. + /// + /// - Returns: The first element of the original span if it wasn't empty; + /// otherwise, `nil`. + /// + /// - Complexity: O(1) + @inlinable + public mutating func popFirst() -> Element? { + guard _count > 0 else { return nil } + let result = unsafe _unsafeAddressOfElement(unchecked: 0).move() + _count &-= 1 + return result + } + /// Remove all this span's elements and return its memory /// to the uninitialized state. @@ -473,4 +481,18 @@ extension InputSpan where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +internal func withTemporaryInputSpan( + of type: Element.Type, + capacity: Int, + _ body: (inout InputSpan) throws(E) -> R +) throws(E) -> R { + try withUnsafeTemporaryAllocation( + of: Element.self, capacity: capacity + ) { buffer throws(E) in + var span = InputSpan(buffer: buffer, initializedCount: 0) + return try body(&span) + } +} + #endif diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/OutputSpan+Extras.swift new file mode 100644 index 00000000..c510bd17 --- /dev/null +++ b/Sources/ContainersPreview/OutputSpan+Extras.swift @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +@_alwaysEmitIntoClient +internal func withTemporaryOutputSpan( + of type: Element.Type, + capacity: Int, + _ body: (inout OutputSpan) throws(E) -> R +) throws(E) -> R { + try withUnsafeTemporaryAllocation( + of: Element.self, capacity: capacity + ) { buffer throws(E) in + var span = OutputSpan(buffer: buffer, initializedCount: 0) + return try body(&span) + } +} + +@available(SwiftStdlib 5.0, *) +extension OutputSpan where Element: ~Copyable { + /// Removes and returns the last element of this output span, if it exists. + /// + /// - Returns: The last element of the original span if it wasn't empty; + /// otherwise, `nil`. + /// + /// - Complexity: O(1) + @inlinable + internal mutating func _popLast() -> Element? { + // FIXME: This needs to be in the stdlib. + withUnsafeMutableBufferPointer { buffer, count in + guard count > 0 else { return nil } + count &-= 1 + return buffer.moveElement(from: count) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension OutputSpan where Element: ~Copyable { + @_lifetime(source: copy source) + @inlinable + internal mutating func _append(moving source: inout InputSpan) { + // FIXME: This needs to be in the stdlib. + self.withUnsafeMutableBufferPointer { dst, dstCount in + source.withUnsafeMutableBufferPointer { src, srcCount in + let dstEnd = dstCount + srcCount + let srcStart = src.count - srcCount + precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") + let srcItems = src._extracting(uncheckedFrom: srcStart, to: src.count) + dst + ._extracting(uncheckedFrom: dstCount, to: dstEnd) + .moveInitializeAll(fromContentsOf: srcItems) + dstCount &+= srcCount + srcCount = 0 + } + } + } +} + + +#endif diff --git a/Sources/ContainersPreview/Producer.swift b/Sources/ContainersPreview/Producer.swift index c63c9ff9..db4c2230 100644 --- a/Sources/ContainersPreview/Producer.swift +++ b/Sources/ContainersPreview/Producer.swift @@ -11,12 +11,224 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +/// A type that supplies the values of a generative sequence by populating +/// a client-supplied series of `OutputSpan` instances. "Generative" sequences +/// transfer the ownership of items they produce to their clients, rather than +/// merely providing borrowing access to them. A `Producer` instance represents +/// an ongoing iteration over such a generative sequence. @available(SwiftStdlib 5.0, *) public protocol Producer: ~Copyable, ~Escapable { - associatedtype Element: ~Copyable /* ~Escapable */ + /// The type of the items that this producer generates. + associatedtype Element: ~Copyable + /// The error that this producer may throw, or `Never` if this producer + /// always succeeds. + associatedtype ProducerError: Error = Never + + /// Generate the next batch of items into the supplied output span instance, + /// which must have room for at least one new element. + /// + /// Repeatedly calling this method produces, in order, all the elements of the + /// underlying generative sequence. As soon as the sequence has run out of + /// elements, all subsequent calls return false without appending any new + /// items to their target. This method is not guaranteed to fully populate the + /// given output span, but it always appends at least one item until the end + /// of the underlying generative sequence. + /// + /// The ownership of all generated elements is transferred to the caller of + /// this method -- it can arbitrarily store, mutate, consume or discard them + /// as needed, even across invocations of this method, or after the producer + /// is destroyed. + /// + /// The returned Boolean value can be used to easily determine if the + /// method was able to make progress towards filling `target` without hitting + /// the end of the underlying sequence. + /// + /// ### Error handling + /// + /// This method throws an error to indicate a failure while trying to generate + /// the upcoming next item in the sequence. Failure may happen midway through + /// populating `target`, in which case the output span will still gain + /// new items despite the error. (Those items are successfully + /// generated, and do not necessarilly need to be discarded.) + /// + /// This protocol does not specify the meaning of a failure, or the + /// precise state of the iterator after an error is thrown; however, the + /// error must not trigger runtime traps in subsequent attempts at iteration. + /// (After a failure, conforming types may choose to produce new items, or + /// signal the end of the iteration, or throw another error, which may or may + /// not match the first.) + /// + /// Absent of more specific information, generic code should stop + /// iterating, discard the producer and rethrow the error when it encounters + /// a failure. Generic code is encouraged to preserve the items that got + /// successfully produced before the throw (including ones appended by + /// the call that ultimately ended in failure); however, whether this is + /// possible (or desirable) ultimately depends on the specific problem that + /// the algorithm is solving. + /// + /// - Parameter target: An output span ready to take newly generated items. + /// - Returns: A boolean value indicating whether the operation was able to + /// append at least one item to the supplied output span without hitting + /// the end of the underlying sequence. @_lifetime(target: copy target) - mutating func generate(into target: inout OutputSpan) + @_lifetime(self: copy self) + mutating func generate( + into target: inout OutputSpan + ) throws(ProducerError) -> Bool + + /// Skip at most the given number items in the underlying generative sequence, + /// decreasing it by the number of items successfully skipped. + /// + /// This is equivalent to generating the same number of items then immediately + /// discarding them, except it may avoid the overhead of actually + /// materializing them. + /// + /// As soon as the producer has run out of items, all subsequent calls to + /// this method stop decrementing `n` and return false. + /// + /// The default implementation of this method calls `generate(into:)` with + /// a small temporary buffer, immediately discarding all generated items. + /// Conforming types are encouraged to replace this default approach + /// with a more efficient implementation whenever it is possible to do so. + /// + /// ### Error handling + /// + /// This method throws an error to indicate a failure while trying to skip + /// the upcoming next item in the sequence. Failure may happen midway through + /// skipping a batch of items, in which case `n` will still be + /// decremented by the number of elements that were successfully skipped + /// before encountering the problem. + /// + /// - Parameter n: The maximum number of items remaining to skip. This + /// must be greater than zero. This method decrements this value by the + /// number of items it successfully skipped before returning. + /// - Returns: A boolean value indicating whether the operation was able to + /// skip at least one item without hitting the end of the underlying + /// sequence. + @_lifetime(self: copy self) + mutating func skip(upTo n: inout Int) throws(ProducerError) -> Bool + + /// Generate and return the next element in the underlying generative + /// sequence. + /// + /// Repeatedly calling this method produces, in order, all the elements of the + /// underlying generative sequence. As soon as the sequence has run out of + /// elements, all subsequent calls return `nil`. + /// + /// The ownership of all generated elements is transferred to the + /// caller of this method -- it can arbitrarily store, mutate, + /// consume or discard them as needed, even across invocations of this method, + /// or after the producer is destroyed. + /// + /// This method throws an error to indicate a failure. This protocol does not + /// specify the meaning of such errors, or the precise state of the + /// iterator after an error is thrown; however, the error must not trigger + /// runtime traps in subsequent attempts at iteration. + /// (Conforming types may choose to produce new items, or signal the end of + /// the iteration, or throw another error, which may or may not match the + /// first.) Absent of more specific information, generic code should stop + /// iterating, discard the producer and rethrow the error when it encounters + /// a failure. + /// + /// The default implementation of this method calls `generate(into:)` with + /// a temporary output span with room for a single item, and returns the + /// resulting contents. This often produces satisfactory results; but the + /// protocol allows conformances to customize this entry point if they believe + /// it to be necessary (for example, if they can take shortcuts that aren't + /// available in the bulk method). Custom implementations of `generateNext()` + /// must produce results that are indistinguishable from the default + /// implementation, but they may exhibit observably different performance + /// metrics. + @_lifetime(self: copy self) + mutating func generateNext() throws(ProducerError) -> Element? +} + +@available(SwiftStdlib 5.0, *) +extension Producer where Self: ~Copyable & ~Escapable { + /// Skip at most the given number items in the underlying generative sequence, + /// decreasing it by the number of items successfully skipped. + /// + /// This is equivalent to generating the same number of items then immediately + /// discarding them, except it may avoid the overhead of actually + /// materializing them. + /// + /// As soon as the producer has run out of items, all subsequent calls to + /// this method stop decrementing `n` and return false. + /// + /// The default implementation of this method calls `generate(into:)` with + /// a small temporary buffer, immediately discarding all generated items. + /// Conforming types are encouraged to replace this default approach + /// with a more efficient implementation whenever it is possible to do so. + /// + /// ### Error handling + /// + /// This method throws an error to indicate a failure while trying to skip + /// the upcoming next item in the sequence. Failure may happen midway through + /// skipping a batch of items, in which case `n` will still be + /// decremented by the number of elements that were successfully skipped + /// before encountering the problem. + /// + /// - Parameter n: The maximum number of items remaining to skip. This + /// must be greater than zero. This method decrements this value by the + /// number of items it successfully skipped before returning. + /// - Returns: A boolean value indicating whether the operation was able to + /// skip at least one item without hitting the end of the underlying + /// sequence. + @_lifetime(self: copy self) + mutating func skip(upTo n: inout Int) throws(ProducerError) -> Bool { + precondition(n > 0, "Can't skip less than 1 item") + let maxBufferSize = 8 + return try withTemporaryOutputSpan( + of: Element.self, capacity: Swift.min(maxBufferSize, n) + ) { span throws(ProducerError) in + defer { n &-= span.count } + return try self.generate(into: &span) + } + } + + /// Generate and return the next element in the underlying generative + /// sequence. + /// + /// Repeatedly calling this method produces, in order, all the elements of the + /// underlying generative sequence. As soon as the sequence has run out of + /// elements, all subsequent calls return `nil`. + /// + /// The ownership of all generated elements is transferred to the + /// caller of this method -- it can arbitrarily store, mutate, + /// consume or discard them as needed, even across invocations of this method, + /// or after the producer is destroyed. + /// + /// This method throws an error to indicate a failure. This protocol does not + /// specify the meaning of such errors, or the precise state of the + /// iterator after an error is thrown; however, the error must not trigger + /// runtime traps in subsequent attempts at iteration. + /// (Conforming types may choose to produce new items, or signal the end of + /// the iteration, or throw another error, which may or may not match the + /// first.) Absent of more specific information, generic code should stop + /// iterating, discard the producer and rethrow the error when it encounters + /// a failure. + /// + /// The default implementation of this method calls `generate(into:)` with + /// a temporary output span with room for a single item, and returns the + /// resulting contents. This often produces satisfactory results; but the + /// protocol allows conformances to customize this entry point if they believe + /// it to be necessary (for example, if they can take shortcuts that aren't + /// available in the bulk method). Custom implementations of `generateNext()` + /// must produce results that are indistinguishable from the default + /// implementation, but they may exhibit observably different performance + /// metrics. + @inlinable + @_lifetime(self: copy self) + public mutating func generateNext() throws(ProducerError) -> Element? { + try withUnsafeTemporaryAllocation( + of: Element.self, capacity: 1 + ) { buffer throws(ProducerError) in + var span = OutputSpan(buffer: buffer, initializedCount: 0) + guard try self.generate(into: &span) else { return nil } + return span.removeLast() + } + } } #endif diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index 5cc4116a..63e3945d 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -28,6 +28,15 @@ extension UnsafeBufferPointer where Element: ~Copyable { } extension UnsafeBufferPointer where Element: ~Copyable { + @_alwaysEmitIntoClient + @unsafe + package func _extracting(uncheckedFrom start: Int, to end: Int) -> Self { + guard let base = self.baseAddress else { + return Self(_empty: ()) + } + return unsafe Self(start: base + start, count: end - start) + } + /// Returns a buffer pointer containing the initial elements of this buffer, /// up to the specified maximum length. /// diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index a9eaadcb..3de17e67 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2026 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 @@ -20,6 +20,15 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { } extension UnsafeMutableBufferPointer where Element: ~Copyable { + @_alwaysEmitIntoClient + @unsafe + package func _extracting(uncheckedFrom start: Int, to end: Int) -> Self { + guard let base = self.baseAddress else { + return Self(_empty: ()) + } + return unsafe Self(start: base + start, count: end - start) + } + /// Returns a buffer pointer containing the initial elements of this buffer, /// up to the specified maximum length. /// @@ -37,7 +46,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) - public func _extracting(first maxLength: Int) -> Self { + package func _extracting(first maxLength: Int) -> Self { precondition(maxLength >= 0, "Can't have a prefix of negative length") let newCount = Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) @@ -60,7 +69,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) - public func _extracting(last maxLength: Int) -> Self { + package func _extracting(last maxLength: Int) -> Self { precondition(maxLength >= 0, "Can't have a suffix of negative length") let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) From a617f5e2b1e7bee60846a2033645f28015990d2b Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 16 Jan 2026 17:32:53 -0800 Subject: [PATCH 15/75] =?UTF-8?q?Don=E2=80=99t=20use=20`@unsafe`/`unsafe`?= =?UTF-8?q?=20in=20code=20that=20needs=20to=20work=20on=206.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnsafeBufferPointer+Extras.swift | 3 +-- .../UnsafeMutableBufferPointer+Extras.swift | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index 63e3945d..0900a5ef 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -29,12 +29,11 @@ extension UnsafeBufferPointer where Element: ~Copyable { extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient - @unsafe package func _extracting(uncheckedFrom start: Int, to end: Int) -> Self { guard let base = self.baseAddress else { return Self(_empty: ()) } - return unsafe Self(start: base + start, count: end - start) + return Self(start: base + start, count: end - start) } /// Returns a buffer pointer containing the initial elements of this buffer, diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index 3de17e67..06c8ab68 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -21,12 +21,11 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient - @unsafe package func _extracting(uncheckedFrom start: Int, to end: Int) -> Self { guard let base = self.baseAddress else { return Self(_empty: ()) } - return unsafe Self(start: base + start, count: end - start) + return Self(start: base + start, count: end - start) } /// Returns a buffer pointer containing the initial elements of this buffer, From 7b5221ea249c2f5ba76b993255592cf5f98fd459 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 20 Jan 2026 10:51:17 -0800 Subject: [PATCH 16/75] RigidDeque: Add Container conformance and allow copying from Containers --- .../BorrowIteratorProtocol.swift | 1 - Sources/ContainersPreview/Container.swift | 319 ++++++++++++++++-- .../RigidDeque/RigidDeque+Append.swift | 58 +++- .../RigidDeque/RigidDeque+Container.swift | 45 ++- .../RigidDeque/RigidDeque+Initializers.swift | 43 +++ .../RigidDeque/RigidDeque+Insertions.swift | 4 +- .../RigidDeque/RigidDeque+Prepend.swift | 58 +++- Sources/DequeModule/_UnsafeDequeHandle.swift | 20 ++ .../RigidArrayTests.swift | 58 ++-- .../UniqueArrayTests.swift | 52 +-- .../DequeTests/RigidDequeTests+Testing.swift | 23 +- Tests/DequeTests/RigidDequeTests+XCTest.swift | 212 ++++-------- .../Assertions+Containers.swift | 8 +- .../AssertionContexts/Assertions.swift | 20 ++ 14 files changed, 657 insertions(+), 264 deletions(-) diff --git a/Sources/ContainersPreview/BorrowIteratorProtocol.swift b/Sources/ContainersPreview/BorrowIteratorProtocol.swift index 3b7a10e9..864de931 100644 --- a/Sources/ContainersPreview/BorrowIteratorProtocol.swift +++ b/Sources/ContainersPreview/BorrowIteratorProtocol.swift @@ -143,7 +143,6 @@ extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable, Element: Copyable { - @_lifetime(copy self) @_lifetime(self: copy self) @_transparent public mutating func copyContents(into target: inout OutputSpan) { diff --git a/Sources/ContainersPreview/Container.swift b/Sources/ContainersPreview/Container.swift index 495da94f..bb851f0b 100644 --- a/Sources/ContainersPreview/Container.swift +++ b/Sources/ContainersPreview/Container.swift @@ -11,13 +11,257 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // Unfortunately this does not work well with Iterable yet. +@available(SwiftStdlib 5.0, *) +public protocol Container: Iterable, ~Copyable, ~Escapable { + associatedtype Index: Comparable + + var count: Int { get } + + var startIndex: Index { get } + var endIndex: Index { get } + func index(after index: Index) -> Index + func formIndex(after index: inout Index) + func index(_ index: Index, offsetBy n: Int) -> Index + func formIndex( + _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index + ) + func distance(from start: Index, to end: Index) -> Int + + /// Return a span over the container's storage that begins with the element at the given index, + /// and extends to the end of the contiguous storage chunk that contains it. On return, the index + /// is updated to address the next item following the end of the returned span. + /// + /// This method can be used to efficiently process the items of a container in bulk, by + /// directly iterating over its piecewise contiguous pieces of storage: + /// + /// var index = items.startIndex + /// while true { + /// let span = items.nextSpan(after: &index) + /// if span.isEmpty { break } + /// // Process items in `span` + /// } + /// + /// Note: The spans returned by this method are not guaranteed to be disjunct. Some containers + /// may use the same storage chunk (or parts of a storage chunk) multiple times, to repeat their + /// contents. + /// + /// Note: Repeated invocations of `nextSpan` on the same container and index are not guaranteed + /// to return identical results. (This is particularly the case with containers that can store + /// contents in their "inline" representation. Such containers may not always have + /// a unique address in memory; the locations of the spans exposed by this method may vary + /// between different borrows of the same container.) + /// + /// - Parameter index: A valid index in the container, including the end index. On return, this + /// index is advanced by the count of the resulting span, to simplify iteration. + /// - Returns: A span over contiguous storage that starts at the given index. If the input index + /// is the end index, then this returns an empty span. Otherwise the result is non-empty, + /// with its first element matching the element at the input index. + @_lifetime(borrow self) + func nextSpan(after index: inout Index, maximumCount: Int) -> Span + + // subscript(index: Index) -> Element { borrow } + + // FIXME: Do we want these as standard requirements this time? + func index(alignedDown index: Index) -> Index + func index(alignedUp index: Index) -> Index +} + +@available(SwiftStdlib 5.0, *) +extension Container where Self: ~Copyable & ~Escapable { + @inlinable + @_lifetime(borrow self) + public func nextSpan(after index: inout Index) -> Span { + nextSpan(after: &index, maximumCount: Int.max) + } + +// @inlinable +// @_lifetime(borrow self) +// public func nextSpan(after index: inout Index, maximumCount: Int) -> Span { +// let original = index +// var span = nextSpan(after: &index) +// if span.count > maximumCount { +// span = span.extracting(first: maximumCount) +// // Index remains within the same span, so offseting it is expected to be quick +// index = self.index(original, offsetBy: maximumCount) +// } +// return span +// } +} + +@available(SwiftStdlib 5.0, *) +extension Container where Self: ~Copyable & ~Escapable { + @inlinable + public func formIndex(after index: inout Index) { + index = self.index(after: index) + } + + @inlinable + public func index(_ index: Index, offsetBy n: Int) -> Index { + _defaultIndex(index, advancedBy: n) + } + + @inlinable + public func formIndex( + _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index + ) { + _defaultFormIndex(&index, advancedBy: &n, limitedBy: limit) + } + + @inlinable + public func distance(from start: Index, to end: Index) -> Int { + _defaultDistance(from: start, to: end) + } + + @inlinable + public func index(alignedDown index: Index) -> Index { index } + + @inlinable + public func index(alignedUp index: Index) -> Index { index } +} + + +@available(SwiftStdlib 5.0, *) +extension Container where Self: ~Copyable & ~Escapable { + @inlinable + public func _defaultDistance(from start: Index, to end: Index) -> Int { + // FIXME: Use binary search here (with nextSpan(after:maximumCount:)) + var start = index(alignedDown: start) + let end = index(alignedDown: end) + if start > end { + return -_defaultDistance(from: end, to: start) + } + var count = 0 + while start != end { + count = count + 1 + formIndex(after: &start) + } + return count + } + + @inlinable + public func _defaultIndex(_ i: Index, advancedBy distance: Int) -> Index { + precondition( + distance >= 0, + "Only BidirectionalContainers can be advanced by a negative amount") + + var i = index(alignedDown: i) + var distance = distance + + #if true // with nextSpan(after:maximumCount:) + while distance > 0 { + let span = self.nextSpan(after: &i, maximumCount: distance) + precondition( + !span.isEmpty, + "Can't advance index beyond the end of the container") + distance &-= span.count + } + return i + #else // without nextSpan(after:maximumCount:) + // FIXME: This implementation can be wasteful for contiguous containers, + // as iterating over spans will overshoot the target immediately. + // Reintroducing `nextSpan(after:maximumCount:)` would help avoid + // having to use a second loop to refine the result, but it would + // complicate conformances. + + // Skip forward until we find the span that contains our target. + while distance > 0 { + var j = i + let span = self.nextSpan(after: &j) + precondition( + !span.isEmpty, + "Can't advance index beyond the end of the container") + guard span.count <= distance else { break } + i = j + distance &-= span.count + } + // Step through to find the precise target. + while distance > 0 { + self.formIndex(after: &i) + distance &-= 1 + } + return i + #endif + } + + @inlinable + public func _defaultFormIndex( + _ i: inout Index, + advancedBy distance: inout Int, + limitedBy limit: Index + ) { + precondition( + distance >= 0, + "Only BidirectionalContainers can be advanced by a negative amount") + + i = index(alignedDown: i) + let limit = index(alignedDown: limit) + if i > limit { + i = self.index(i, offsetBy: distance) + distance = 0 + return + } + +#if true // with nextSpan(after:maximumCount:) + // Skip forward until find our target or overshoot the limit. + while distance > 0, i < limit { + var j = i + let span = self.nextSpan(after: &j, maximumCount: distance) + precondition( + !span.isEmpty, + "Can't advance index beyond the end of the container") + if j > limit { + break + } + i = j + distance &-= span.count + } + // Step through to find the precise target. + // FIXME: Use binary search here + while distance != 0 { + if i == limit { + return + } + formIndex(after: &i) + distance &-= 1 + } +#else // without nextSpan(after:maximumCount:) + // Skip forward until we find the span that contains our target. + while distance > 0 { + var j = i + let span = self.nextSpan(after: &j) + precondition( + !span.isEmpty, + "Can't advance index beyond the end of the container") + guard span.count <= distance, j < limit else { + break + } + i = j + distance &-= span.count + } + // Step through to find the precise target. + while distance != 0 { + if i == limit { + return + } + formIndex(after: &i) + distance &-= 1 + } +#endif + } +} + +@available(SwiftStdlib 5.0, *) +extension Container where Self: ~Copyable & ~Escapable { + @_transparent + public var estimatedCount: EstimatedCount { .exactly(count) } +} + @available(SwiftStdlib 5.0, *) public struct ContainerIterator< - Base: Container & ~Copyable /*& ~Escapable*/ + Base: Container & ~Copyable /*FIXME: & ~Escapable*/ >: ~Copyable, ~Escapable { - let _base: Ref + let _base: Ref // FIXME: This doesn't support nonescapable Bases var _position: Base.Index @_lifetime(borrow base) @@ -28,44 +272,22 @@ public struct ContainerIterator< } @available(SwiftStdlib 5.0, *) -extension ContainerIterator: BorrowIteratorProtocol where Base: ~Copyable { +extension ContainerIterator: BorrowIteratorProtocol +where Base: ~Copyable /*FIXME: & ~Escapable*/ +{ public typealias Element = Base.Element + @_unsafeNonescapableResult // FIXME: we cannot convert from a borrow to an inout dependence! @_lifetime(&self) public mutating func nextSpan(maximumCount: Int) -> Span { - let r = _base[].nextSpan(after: &self._position, maximumCount: maximumCount) - return r + _base[].nextSpan(after: &self._position, maximumCount: maximumCount) } } -@available(SwiftStdlib 5.0, *) -public protocol Container: Iterable, ~Copyable, ~Escapable { - associatedtype Index - - var count: Int { get } - - var startIndex: Index { get } - var endIndex: Index { get } - func index(after index: Index) -> Index - func index(_ index: Index, offsetBy delta: Int) -> Index - // ... - -// subscript(index: Index) -> Element { borrow } - - @_lifetime(borrow self) - func nextSpan(after index: inout Index, maximumCount: Int) -> Span -} - -@available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable { - @_transparent - public var estimatedCount: EstimatedCount { .exactly(count) } -} - @available(SwiftStdlib 5.0, *) extension Container where - Self: ~Copyable /*& ~Escapable*/, + Self: ~Copyable /*FIXME: & ~Escapable*/, BorrowIterator == ContainerIterator { @_lifetime(borrow self) @@ -76,4 +298,39 @@ where #endif +extension Strideable { + @inlinable + package mutating func _advance( + by distance: inout Stride, limitedBy limit: Self + ) { + if distance >= 0 { + guard limit >= self else { + self = self.advanced(by: distance) + distance = 0 + return + } + let d = Swift.min(distance, self.distance(to: limit)) + self = self.advanced(by: d) + distance -= d + } else { + guard limit <= self else { + self = self.advanced(by: distance) + distance = 0 + return + } + let d = Swift.max(distance, self.distance(to: limit)) + self = self.advanced(by: d) + distance -= d + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + public mutating func advance( + by distance: inout Stride, limitedBy limit: Self + ) { + _advance(by: &distance, limitedBy: limit) + } #endif +} + diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 4bde551c..736cbb3c 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -241,7 +241,7 @@ extension RigidDeque /*where Element: Copyable*/ { "RigidDeque capacity overflow") _handle.uncheckedAppend(copying: newElements) } - + /// Copies the elements of a buffer to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the @@ -258,7 +258,7 @@ extension RigidDeque /*where Element: Copyable*/ { ) { unsafe self.append(copying: UnsafeBufferPointer(newElements)) } - + /// Copies the elements of a span to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the @@ -274,7 +274,37 @@ extension RigidDeque /*where Element: Copyable*/ { unsafe self.append(copying: source) } } - + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _appendIterable< + I: Iterable & ~Copyable & ~Escapable + >(copying items: borrowing I) { + var it = items.startBorrowIteration() + while true { + let span = it.nextSpan() + if span.isEmpty { break } + append(copying: span) + } + } + + /// Copies the elements of an iterable to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func append & ~Copyable & ~Escapable>( + copying newElements: borrowing I + ) { + self._appendIterable(copying: newElements) + } +#endif + /// Copies the elements of a sequence to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the @@ -291,10 +321,30 @@ extension RigidDeque /*where Element: Copyable*/ { return } if done != nil { return } - + var it = _handle.uncheckedAppend(copyingPrefixOf: newElements) precondition(it.next() == nil, "RigidDeque capacity overflow") } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of an iterable to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func append< + I: Iterable & Sequence + >( + copying newElements: I + ) { + self._appendIterable(copying: newElements) + } +#endif } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift index 87f739ea..94fce5f8 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift @@ -16,11 +16,11 @@ import ContainersPreview #if compiler(>=6.2) -// MARK: Borrowing @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - public struct BorrowIterator: ~Escapable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + public struct BorrowIterator: ~Escapable, BorrowIteratorProtocol { var currentSegment: Span var nextSegment: Span @@ -38,8 +38,8 @@ extension RigidDeque where Element: ~Copyable { @_lifetime(copy self) @_lifetime(self: copy self) - public mutating func nextSpan(maximumCount: Int? = nil) -> Span { - let max = maximumCount ?? Int.max + public mutating func nextSpan(maximumCount: Int) -> Span { + let max = maximumCount let c = Swift.min(currentSegment.count, max) let result = currentSegment.extracting(first: c) if c == currentSegment.count { @@ -56,6 +56,43 @@ extension RigidDeque where Element: ~Copyable { public borrowing func startBorrowIteration() -> BorrowIterator { BorrowIterator(deque: self) } +#endif +} + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension RigidDeque: Container where Element: ~Copyable {} +#endif + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @inlinable @inline(__always) + public func index(after index: Int) -> Int { index + 1 } + + @inlinable @inline(__always) + public func formIndex(after index: inout Int) { index += 1 } + + @inlinable @inline(__always) + public func index(_ index: Int, offsetBy n: Int) -> Int { + index + n + } + + @inlinable + public func formIndex( + _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index + ) { + index._advance(by: &n, limitedBy: limit) + } + + @_lifetime(borrow self) + public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { + precondition(index >= 0 && index <= count, "Index out of bounds") + let segment = self._handle + .nextSegment(from: index) + ._extracting(first: maximumCount) + index &+= segment.count + return _overrideLifetime(Span(_unsafeElements: segment), borrowing: self) + } } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index dc566683..4d46e7b1 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -84,6 +84,27 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque /*where Element: Copyable*/ { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Creates a new deque with the specified capacity, holding a copy + /// of the contents of a given iterable. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque. + /// - contents: An iterable whose contents to copy into the new deque. + /// The iterable must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init< + I: Iterable & ~Copyable & ~Escapable + >( + capacity: Int, + copying contents: borrowing I + ) { + self.init(capacity: capacity) + self.append(copying: contents) + } +#endif + /// Creates a new deque with the specified capacity, holding a copy /// of the contents of a given sequence. /// @@ -115,6 +136,28 @@ extension RigidDeque /*where Element: Copyable*/ { self.init(capacity: capacity ?? contents.count) self.append(copying: contents) } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Creates a new deque with the specified capacity, holding a copy + /// of the contents of a given iterable. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque. + /// - contents: An iterable whose contents to copy into the new deque. + /// The iterable must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init< + I: Iterable & Sequence + >( + capacity: Int, + copying contents: borrowing I + ) { + self.init(capacity: capacity) + self.append(copying: contents) + } +#endif + } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 3ab94810..2f6a16a0 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -376,8 +376,8 @@ extension RigidDeque /* where Element: Copyable */ { copying items: borrowing C, newCount: Int ) { - let expectedCount = self.count - subrange.count + newCount - var it = newElements.startBorrowIteration() + let expectedCount = self.count + newCount + var it = items.startBorrowIteration() insert(count: newCount, at: index) { target in it.copyContents(into: &target) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 129116b3..2f53c3c9 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -314,6 +314,41 @@ extension RigidDeque /*where Element: Copyable*/ { _handle.uncheckedPrepend(copying: newElements, exactCount: c) } +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _prependIterable< + I: Iterable & ~Copyable & ~Escapable + >(copying items: borrowing I) { + // We don't know the exact count of new elements, so we cannot initialize + // them in place. Append them to the end of the deque first, then rotate + // them to their correct location. + let oldEndSlot = _handle.endSlot + var it = items.startBorrowIteration() + while true { + let span = it.nextSpan() + if span.isEmpty { break } + prepend(copying: span) + } + _handle.rotate(toStartAt: oldEndSlot) + } + + /// Copies the elements of an iterable to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func prepend & ~Copyable & ~Escapable>( + copying newElements: borrowing I + ) { + self._prependIterable(copying: newElements) + } +#endif + /// Copies the elements of a sequence to the front of the rigid deque. /// /// Use this method to prepend the elements of a sequence to the front of this @@ -337,7 +372,7 @@ extension RigidDeque /*where Element: Copyable*/ { return } guard done == nil else { return } - + // We don't know the exact count of new elements, so we cannot initialize // them in place. Append them to the end of the deque first, then rotate // them to their correct location. @@ -346,6 +381,23 @@ extension RigidDeque /*where Element: Copyable*/ { precondition(it.next() == nil, "RigidDeque capacity overflow") _handle.rotate(toStartAt: oldEndSlot) } -} - + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of an iterable to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func prepend & Sequence>( + copying newElements: borrowing I + ) { + self._prependIterable(copying: newElements) + } +#endif +} #endif diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index f4975721..f3e3a117 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -318,6 +318,26 @@ extension _UnsafeDequeHandle where Element: ~Copyable { // MARK: Access to Segments extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + internal func nextSegment( + from startOffset: Int + ) -> UnsafeBufferPointer { + assert(startOffset >= 0 && startOffset <= count) + guard _buffer.baseAddress != nil else { + return .init(._empty) + } + let position = startSlot.position &+ startOffset + if position < capacity { + return UnsafeBufferPointer( + start: ptr(at: Slot(at: position)), + count: Swift.min(count &- startOffset, capacity &- position)) + } + // We're after the wrap + return UnsafeBufferPointer( + start: ptr(at: Slot(at: position &- capacity)), + count: startSlot.position &+ count &- position) + } + @_alwaysEmitIntoClient internal func segments() -> _UnsafeDequeSegments { guard _buffer.baseAddress != nil else { diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index 3382fe70..e8652f2c 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -22,7 +22,7 @@ import BasicContainers #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +internal func expectIterableContents< Element: Equatable, C2: Collection, >( @@ -33,7 +33,7 @@ public func expectIteratorContents< file: StaticString = #file, line: UInt = #line ) { - expectIteratorContents( + expectIterableContents( left.span, equalTo: right, message(), trapping: trapping, file: file, line: line) @@ -41,7 +41,7 @@ public func expectIteratorContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +internal func expectIterableContents< E1: ~Copyable, C2: Collection, >( @@ -53,7 +53,7 @@ public func expectIteratorContents< file: StaticString = #file, line: UInt = #line ) { - expectIteratorContents( + expectIterableContents( left.span, equivalentTo: right, by: areEquivalent, @@ -69,7 +69,7 @@ class RigidArrayTests: CollectionTestCase { let items = tracker.rigidArray(layout: layout) let expected = (0 ..< layout.count).map { tracker.instance(for: $0) } expectEqual(tracker.instances, 2 * layout.count) - expectIteratorContents(items, equalTo: expected) + expectIterableContents(items, equalTo: expected) #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW checkIterable(items, expectedContents: expected) #endif @@ -115,7 +115,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.freeCapacity, layout.capacity - layout.count) expectEqual(a.isEmpty, layout.count == 0) expectEqual(a.isFull, layout.count == layout.capacity) - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) @@ -288,7 +288,7 @@ class RigidArrayTests: CollectionTestCase { a.swapAt(i, layout.count - 1 - i) } let expected = (0 ..< layout.count).reversed() - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count) } } @@ -392,7 +392,7 @@ class RigidArrayTests: CollectionTestCase { errorHandler: { error in expectTrue(error is TestError) } - expectIteratorContents( + expectIterableContents( a, equivalentTo: (0 ..< layout.count).map { -$0 }, by: { $0.payload == $1 }) @@ -417,7 +417,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, newCapacity) expectEqual(tracker.instances, layout.count) - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -441,7 +441,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, Swift.max(layout.capacity, newCapacity)) expectEqual(tracker.instances, layout.count) - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -456,8 +456,8 @@ class RigidArrayTests: CollectionTestCase { expectEqual(b.count, layout.count) expectEqual(b.capacity, layout.count) expectEqual(tracker.instances, layout.count) - expectIteratorContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) - expectIteratorContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } } @@ -474,8 +474,8 @@ class RigidArrayTests: CollectionTestCase { expectEqual(b.count, layout.count) expectEqual(b.capacity, newCapacity) expectEqual(tracker.instances, layout.count) - expectIteratorContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) - expectIteratorContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } } @@ -519,7 +519,7 @@ class RigidArrayTests: CollectionTestCase { expectEqual(tracker.instances, layout.count) a.removeLast(k) expectEqual(tracker.instances, layout.count - k) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -536,7 +536,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) let old = a.remove(at: i) expectEqual(old.payload, i) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -551,7 +551,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.removeSubrange(range) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -566,7 +566,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.removeAll(where: { $0.payload.isMultiple(of: 2) }) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -583,7 +583,7 @@ class RigidArrayTests: CollectionTestCase { let item = a.popLast() expectEquivalent(item, expectedItem, by: { $0?.payload == $1 }) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -596,7 +596,7 @@ class RigidArrayTests: CollectionTestCase { for i in layout.count ..< layout.capacity { a.append(tracker.instance(for: i)) expectEqual(a.count, i + 1) - expectIteratorContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) } expectTrue(a.isFull) expectEqual(tracker.instances, layout.capacity) @@ -631,7 +631,7 @@ class RigidArrayTests: CollectionTestCase { using: { layout.count + $0 }) a.append(copying: b.span) expectTrue(a.isFull) - expectIteratorContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } @@ -651,7 +651,7 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.append(copying: b) expectTrue(a.isFull) - expectIteratorContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } @@ -671,7 +671,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.insert(tracker.instance(for: -1), at: i) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + 1) } } @@ -694,7 +694,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.insert(copying: trackedAddition, at: i) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } @@ -719,7 +719,7 @@ class RigidArrayTests: CollectionTestCase { } a.insert(copying: rigidAddition.span, at: i) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } @@ -748,7 +748,7 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [Swift.max(spanCount, 1)]) a.insert(copying: rigidAddition, at: i) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.capacity) } } @@ -774,7 +774,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.replaceSubrange(range, copying: trackedAddition) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -795,7 +795,7 @@ class RigidArrayTests: CollectionTestCase { let trackedAddition = RigidArray(copying: addition.map { tracker.instance(for: $0) }) a.replaceSubrange(range, copying: trackedAddition.span) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -821,7 +821,7 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.replaceSubrange(range, copying: trackedAddition) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } } diff --git a/Tests/BasicContainersTests/UniqueArrayTests.swift b/Tests/BasicContainersTests/UniqueArrayTests.swift index 9836a702..346472a9 100644 --- a/Tests/BasicContainersTests/UniqueArrayTests.swift +++ b/Tests/BasicContainersTests/UniqueArrayTests.swift @@ -22,7 +22,7 @@ import BasicContainers #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +public func expectIterableContents< Element: Equatable, C2: Collection, >( @@ -33,7 +33,7 @@ public func expectIteratorContents< file: StaticString = #file, line: UInt = #line ) { - expectIteratorContents( + expectIterableContents( left.span, equalTo: right, message(), trapping: trapping, file: file, line: line) @@ -41,7 +41,7 @@ public func expectIteratorContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +public func expectIterableContents< E1: ~Copyable, C2: Collection, >( @@ -53,7 +53,7 @@ public func expectIteratorContents< file: StaticString = #file, line: UInt = #line ) { - expectIteratorContents( + expectIterableContents( left.span, equivalentTo: right, by: areEquivalent, @@ -70,7 +70,7 @@ class UniqueArrayTests: CollectionTestCase { let items = UniqueArray(consuming: tracker.rigidArray(layout: layout)) let expected = (0 ..< layout.count).map { tracker.instance(for: $0) } expectEqual(tracker.instances, 2 * layout.count) - expectIteratorContents(items, equalTo: expected) + expectIterableContents(items, equalTo: expected) #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW checkIterable(items, expectedContents: expected) #endif @@ -150,7 +150,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.freeCapacity, layout.capacity - layout.count) expectEqual(a.isEmpty, layout.count == 0) - expectIteratorContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } } @@ -318,7 +318,7 @@ class UniqueArrayTests: CollectionTestCase { a.swapAt(i, layout.count - 1 - i) } let expected = (0 ..< layout.count).reversed() - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count) } @@ -396,7 +396,7 @@ class UniqueArrayTests: CollectionTestCase { errorHandler: { error in expectTrue(error is TestError) } - expectIteratorContents( + expectIterableContents( a, equivalentTo: (0 ..< layout.count).map { -$0 }, by: { $0.payload == $1 }) @@ -421,7 +421,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, newCapacity) expectEqual(tracker.instances, layout.count) - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -445,7 +445,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.capacity, Swift.max(layout.capacity, newCapacity)) expectEqual(tracker.instances, layout.count) - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) } } @@ -502,7 +502,7 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(tracker.instances, layout.count) a.removeLast(k) expectEqual(tracker.instances, layout.count - k) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -519,7 +519,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) let old = a.remove(at: i) expectEqual(old.payload, i) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -534,7 +534,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.removeSubrange(range) - expectIteratorContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) } } } @@ -549,7 +549,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.removeAll(where: { $0.payload.isMultiple(of: 2) }) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -566,7 +566,7 @@ class UniqueArrayTests: CollectionTestCase { let item = a.popLast() expectEquivalent(item, expectedItem, by: { $0?.payload == $1 }) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) } } @@ -636,7 +636,7 @@ class UniqueArrayTests: CollectionTestCase { for i in layout.count ..< c { a.append(tracker.instance(for: i)) expectEqual(a.count, i + 1) - expectIteratorContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) + expectIterableContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) } expectEqual(tracker.instances, c) } @@ -653,7 +653,7 @@ class UniqueArrayTests: CollectionTestCase { elements: (layout.count ..< c).map { tracker.instance(for: $0) }, underestimatedCount: .half, isContiguous: isContiguous)) - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< c, by: { $0.payload == $1}) expectEqual(tracker.instances, c) } @@ -673,7 +673,7 @@ class UniqueArrayTests: CollectionTestCase { } a.append(copying: b.span) let c = layout.count + additions - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< c, by: { $0.payload == $1 }) expectEqual(tracker.instances, c) } @@ -698,7 +698,7 @@ class UniqueArrayTests: CollectionTestCase { contents: RigidArray(copying: addition), spanCounts: [spanCount]) a.append(copying: b) - expectIteratorContents( + expectIterableContents( a, equivalentTo: 0 ..< c, by: { $0.payload == $1 }) expectEqual(tracker.instances, c) } @@ -719,7 +719,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.insert(tracker.instance(for: -1), at: i) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + 1) } @@ -741,7 +741,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.insert(copying: trackedAddition, at: i) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + c) } @@ -766,7 +766,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.insert(copying: rigidAddition.span, at: i) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + c) } @@ -798,7 +798,7 @@ class UniqueArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.insert(copying: rigidAddition, at: i) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count + c) } @@ -823,7 +823,7 @@ class UniqueArrayTests: CollectionTestCase { let trackedAddition = addition.map { tracker.instance(for: $0) } a.replaceSubrange(range, copying: trackedAddition) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } @@ -846,7 +846,7 @@ class UniqueArrayTests: CollectionTestCase { copying: addition.map { tracker.instance(for: $0) }) a.replaceSubrange(range, copying: trackedAddition.span) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } @@ -874,7 +874,7 @@ class UniqueArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.replaceSubrange(range, copying: trackedAddition) - expectIteratorContents( + expectIterableContents( a, equivalentTo: expected, by: { $0.payload == $1 }) expectEqual(tracker.instances, layout.count - range.count + c) } diff --git a/Tests/DequeTests/RigidDequeTests+Testing.swift b/Tests/DequeTests/RigidDequeTests+Testing.swift index 1ceb653f..d758d211 100644 --- a/Tests/DequeTests/RigidDequeTests+Testing.swift +++ b/Tests/DequeTests/RigidDequeTests+Testing.swift @@ -76,19 +76,6 @@ struct RigidDequeTests_Testing { #expect(deque[2] == 30) } - @Test("Init with unsafe uninitialized capacity") - func initWithUnsafeUninitializedCapacity() { - let deque = RigidDeque(unsafeUninitializedCapacity: 5) { buffer, count in - buffer[0] = 100 - buffer[1] = 200 - count = 2 - } - #expect(deque.count == 2) - #expect(deque.capacity == 5) - #expect(deque[0] == 100) - #expect(deque[1] == 200) - } - // MARK: - Basic Properties @Test("Basic properties") @@ -144,6 +131,7 @@ struct RigidDequeTests_Testing { #expect(deque[1] == 99) } +#if false @Test("Borrow element") func borrowElement() { let deque = RigidDeque(copying: [1, 2, 3]) @@ -158,6 +146,7 @@ struct RigidDequeTests_Testing { mut[] = 99 #expect(deque[1] == 99) } +#endif // MARK: - Append Operations @@ -389,7 +378,8 @@ struct RigidDequeTests_Testing { } // MARK: - Capacity Management - + +#if false @Test("Resize capacity") func resizeCapacity() { var deque = RigidDeque(copying: [1, 2, 3]) @@ -408,6 +398,7 @@ struct RigidDequeTests_Testing { #expect(deque.capacity == 5) #expect(deque.count == 3) } +#endif // MARK: - Edge Cases and Error Conditions @@ -435,6 +426,7 @@ struct RigidDequeTests_Testing { } } + #if false @Test("Resize too small") func resizeTooSmall() async { await #expect(processExitsWith: .failure) { @@ -442,6 +434,7 @@ struct RigidDequeTests_Testing { deque.resize(to: 3) } } + #endif @Test("Invalid index access") func invalidIndexAccess() async { @@ -453,10 +446,12 @@ struct RigidDequeTests_Testing { let deque = RigidDeque(copying: [1, 2, 3]) let _ = deque[3] // Index out of bounds } + #if false await #expect(processExitsWith: .failure) { let deque = RigidDeque(copying: [1, 2, 3]) let _ = deque.borrowElement(at: 5) // Index out of bounds } + #endif } @Test("Remove from empty deque") diff --git a/Tests/DequeTests/RigidDequeTests+XCTest.swift b/Tests/DequeTests/RigidDequeTests+XCTest.swift index f6aa51d9..b60a499b 100644 --- a/Tests/DequeTests/RigidDequeTests+XCTest.swift +++ b/Tests/DequeTests/RigidDequeTests+XCTest.swift @@ -20,7 +20,7 @@ import _CollectionsTestSupport #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +internal func expectIterableContents< Element: Equatable, C2: Collection, >( @@ -28,46 +28,45 @@ public func expectContainerContents< equalTo right: C2, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { - expectContainerContents( + expectIterableContents( left, equivalentTo: right, by: ==, + printer: { "\($0)" }, message(), trapping: trapping, file: file, line: line) } /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectContainerContents< +internal func expectIterableContents< E1: ~Copyable, C2: Collection, >( _ left: borrowing RigidDeque, equivalentTo right: C2, by areEquivalent: (borrowing E1, C2.Element) -> Bool, + printer: (borrowing E1) -> String, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { - var spanIterator = left.startBorrowIteration() - var iteratedCount = 0 -// print("-------\nstarting") - while true { - let span = spanIterator.nextSpan() -// print("Span count: \(span.count)") - - if span.isEmpty { - break - } - expectContainerContents( - span, - equivalentTo: right.dropFirst(iteratedCount).prefix(span.count), + var c = 0 + var j = right.startIndex + for i in 0 ..< left.count { + expectEquivalent( + left[i], + right[j], by: areEquivalent, - message(), trapping: trapping, file: file, line: line) - iteratedCount += span.count + printer: printer, + "offset: \(c) \(message())", + trapping: trapping, + file: file, line: line) + right.formIndex(after: &j) + c += 1 } } #endif @@ -77,142 +76,63 @@ final class RigidDequeTests: CollectionTestCase { // TODO } - func test_copyToContiguousArray() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withLifetimeTracking { tracker in - let data = tracker.rigidDeque(with: layout) - let actual = data.deque._copyToContiguousArray() - expectEqualElements(actual, data.contents) - } - } - } - - func test_unsafeUninitializedInitializer_nothrow() { - withEvery("capacity", in: 0 ..< 100) { cap in - withEvery("count", in: [0, cap / 3, cap / 2, 2 * cap / 3, cap] as Set) { count in - withLifetimeTracking { tracker in - let contents = tracker.instances(for: 0 ..< count) - let d1 = RigidDeque>( - unsafeUninitializedCapacity: cap, - initializingWith: { target, c in - guard target.count > 0 else { - expectNil(target.baseAddress) - return - } - expectNotNil(target.baseAddress) - expectEqual(target.count, cap) - expectEqual(c, 0) - contents.withUnsafeBufferPointer { source in - precondition(source.count <= target.count) - target.baseAddress!.initialize( - from: source.baseAddress!, - count: source.count) - } - c = count - }) - expectContainerContents(d1, equalTo: contents) - } - } - } - } - struct TestError: Error, Equatable { let value: Int init(_ value: Int) { self.value = value } } - func test_unsafeUninitializedInitializer_throw() { - func createDeque(cap: Int, count: Int, contents: [LifetimeTracked.Element>]) throws { - _ = try RigidDeque>( - unsafeUninitializedCapacity: cap, - initializingWith: { target, c in - guard target.count > 0 else { - expectNil(target.baseAddress) - throw TestError(count) - } - expectNotNil(target.baseAddress) - expectEqual(target.count, cap) - expectEqual(c, 0) - contents.withUnsafeBufferPointer { source in - precondition(source.count <= target.count) - target.baseAddress!.initialize( - from: source.baseAddress!, - count: source.count) - } - c = count - throw TestError(count) - }) - } - - func workaroundSR14134(cap: Int, count: Int, tracker: LifetimeTracker) { - // This function works around https://bugs.swift.org/browse/SR-14134 - let contents = tracker.instances(for: 0 ..< count) - expectThrows(try createDeque(cap: cap, count: count, contents: contents)) { error in - expectEqual(error as? TestError, TestError(count)) - } - } - - withEvery("capacity", in: 0 ..< 100) { cap in - withEvery("count", in: [0, cap / 3, cap / 2, 2 * cap / 3, cap] as Set) { count in - withLifetimeTracking { tracker in - workaroundSR14134(cap: cap, count: count, tracker: tracker) - } - } - } - } - func test_popFirst() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) let expected = data.contents[...].popFirst() let actual = data.deque.popFirst() expectEqual(actual, expected) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } func test_popLast() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) let expected = data.contents[...].popLast() let actual = data.deque.popLast() expectEqual(actual, expected) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } func test_prependOne() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) let extra = tracker.instance(for: layout.count) guard !data.deque.isFull else { return } data.contents.insert(extra, at: 0) data.deque.prepend(extra) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } func test_appendOne() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) let extra = tracker.instance(for: layout.count) guard !data.deque.isFull else { return } data.contents.insert(extra, at: data.contents.count) data.deque.append(extra) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } func test_prependManyFromMinimalSequence() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("prependCount", in: 0 ..< 10) { prependCount in withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, prependCount))]) { underestimatedCount in withLifetimeTracking { tracker in @@ -222,7 +142,7 @@ final class RigidDequeTests: CollectionTestCase { data.contents.insert(contentsOf: extras, at: 0) guard extras.count <= data.deque.freeCapacity else { return } data.deque.prepend(copying: sequence) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } @@ -230,7 +150,7 @@ final class RigidDequeTests: CollectionTestCase { } func test_prependManyFromMinimalCollection() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("prependCount", in: 0 ..< 10) { prependCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -239,14 +159,14 @@ final class RigidDequeTests: CollectionTestCase { let minimal = MinimalCollection(extra) data.contents.insert(contentsOf: extra, at: 0) data.deque.prepend(copying: minimal) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } } func test_prependManyFromContiguousArray_asCollection() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("prependCount", in: 0 ..< 10) { prependCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -255,7 +175,7 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= data.deque.freeCapacity else { return } data.contents.insert(contentsOf: extra, at: 0) data.deque.prepend(copying: extra) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } @@ -271,7 +191,7 @@ final class RigidDequeTests: CollectionTestCase { deque.prepend(copying: elements) } - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("prependCount", in: 0 ..< 10) { prependCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -280,7 +200,7 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= data.deque.freeCapacity else { return } data.contents.insert(contentsOf: extra, at: 0) prependSequence(contentsOf: extra, to: &data.deque) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } @@ -288,7 +208,7 @@ final class RigidDequeTests: CollectionTestCase { func test_prependManyFromBridgedArray() { // https://github.com/apple/swift-collections/issues/27 - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("appendCount", in: 0 ..< 10) { appendCount in var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } var deque = RigidDeque(layout: layout, contents: contents) @@ -301,13 +221,13 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= deque.freeCapacity else { return } contents.insert(contentsOf: extra, at: 0) deque.prepend(copying: extra) - expectContainerContents(deque, equivalentTo: contents, by: ==) + expectIterableContents(deque, equivalentTo: contents, by: ==) } } } func test_appendManyFromMinimalSequence() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("appendCount", in: 0 ..< 10) { appendCount in withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, appendCount))]) { underestimatedCount in withLifetimeTracking { tracker in @@ -317,7 +237,7 @@ final class RigidDequeTests: CollectionTestCase { data.contents.append(contentsOf: extras) guard extras.count <= data.deque.freeCapacity else { return } data.deque.append(copying: sequence) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } @@ -325,7 +245,7 @@ final class RigidDequeTests: CollectionTestCase { } func test_appendManyFromMinimalCollection() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("appendCount", in: 0 ..< 10) { appendCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -334,14 +254,14 @@ final class RigidDequeTests: CollectionTestCase { let minimal = MinimalCollection(extra) data.contents.append(contentsOf: extra) data.deque.append(copying: minimal) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } } func test_appendManyFromContiguousArray_asCollection() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("appendCount", in: 0 ..< 10) { appendCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -350,7 +270,7 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= data.deque.freeCapacity else { return } data.contents.append(contentsOf: extra) data.deque.append(copying: extra) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } @@ -366,7 +286,7 @@ final class RigidDequeTests: CollectionTestCase { deque.append(copying: elements) } - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("appendCount", in: 0 ..< 10) { appendCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -375,7 +295,7 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= data.deque.freeCapacity else { return } data.contents.append(contentsOf: extra) appendSequence(contentsOf: extra, to: &data.deque) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } @@ -383,7 +303,7 @@ final class RigidDequeTests: CollectionTestCase { func test_appendManyFromBridgedArray() { // https://github.com/apple/swift-collections/issues/27 - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("appendCount", in: 0 ..< 10) { appendCount in var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } var deque = RigidDeque(layout: layout, contents: contents) @@ -396,13 +316,13 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= deque.freeCapacity else { return } contents.append(contentsOf: extra) deque.append(copying: extra) - expectContainerContents(deque, equivalentTo: contents, by: ==) + expectIterableContents(deque, equivalentTo: contents, by: ==) } } } func test_insertOneElement() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("offset", in: 0 ... layout.count) { offset in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -410,14 +330,14 @@ final class RigidDequeTests: CollectionTestCase { guard !data.deque.isFull else { return } data.contents.insert(extra, at: offset) data.deque.insert(extra, at: offset) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } } // func test_insertFromMinimalCollection() { -// withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in +// withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in // withEvery("offset", in: 0 ... layout.count) { offset in // withEvery("insertCount", in: 0 ..< 10) { insertCount in // withLifetimeTracking { tracker in @@ -426,7 +346,7 @@ final class RigidDequeTests: CollectionTestCase { // let minimal = MinimalCollection(extras) // data.contents.insert(contentsOf: extras, at: offset) // data.deque.insert(contentsOf: minimal, at: offset) -// expectContainerContents(data.deque, equalTo: data.contents) +// expectIterableContents(data.deque, equalTo: data.contents) // } // } // } @@ -434,7 +354,7 @@ final class RigidDequeTests: CollectionTestCase { // } // // func test_insertFromArray() { -// withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in +// withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in // withEvery("offset", in: 0 ... layout.count) { offset in // withEvery("insertCount", in: 0 ..< 10) { insertCount in // withLifetimeTracking { tracker in @@ -442,7 +362,7 @@ final class RigidDequeTests: CollectionTestCase { // let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) // data.contents.insert(contentsOf: extras, at: offset) // data.deque.insert(contentsOf: extras, at: offset) -// expectContainerContents(data.deque, equalTo: data.contents) +// expectIterableContents(data.deque, equalTo: data.contents) // } // } // } @@ -450,88 +370,88 @@ final class RigidDequeTests: CollectionTestCase { // } func test_removeOne() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("offset", in: 0 ..< layout.count) { offset in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) let expected = data.contents.remove(at: offset) let actual = data.deque.remove(at: offset) expectEqual(actual, expected) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } } func test_removeSubrange() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) data.contents.removeSubrange(range) data.deque.removeSubrange(range) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } } func test_removeLast() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in guard layout.count > 0 else { return } withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) let expected = data.contents.removeLast() let actual = data.deque.removeLast() expectEqual(actual, expected) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } func test_removeLast_many() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in guard layout.count > 0 else { return } withEvery("n", in: 0 ... layout.count) { n in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) data.contents.removeLast(n) data.deque.removeLast(n) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } } func test_removeFirst_one() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in guard layout.count > 0 else { return } withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) let expected = data.contents.removeFirst() let actual = data.deque.removeFirst() expectEqual(actual, expected) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } func test_removeFirst_many() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in guard layout.count > 0 else { return } withEvery("n", in: 0 ... layout.count) { n in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) data.contents.removeFirst(n) data.deque.removeFirst(n) - expectContainerContents(data.deque, equalTo: data.contents) + expectIterableContents(data.deque, equalTo: data.contents) } } } } func test_removeAll_keepingCapacity() { - withEveryDeque("deque", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("isShared", in: [false, true]) { isShared in guard layout.count > 0 else { return } var data: RigidTestData> = .init(.init(capacity: 0), []) diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index 14f68c7d..065f24a7 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -19,7 +19,7 @@ import ContainersPreview #if compiler(>=6.2) /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +public func expectIterableContents< Element: Equatable, C2: Collection, >( @@ -58,7 +58,7 @@ public func expectIteratorContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +public func expectIterableContents< E1: ~Copyable, C2: Collection, >( @@ -137,7 +137,7 @@ public func expectIterablesWithEqualElements< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +public func expectIterableContents< Element: Equatable, I1: Iterable & ~Copyable & ~Escapable, C2: Collection, @@ -179,7 +179,7 @@ public func expectIteratorContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) -public func expectIteratorContents< +public func expectIterableContents< I1: Iterable & ~Copyable & ~Escapable, C2: Collection, >( diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift index 403991cc..9ff39da8 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift @@ -158,6 +158,26 @@ public func expectEquivalent( message, trapping: trapping, file: file, line: line) } +// FIXME: Remove when CustomStringConvertible starts supporting +// noncopyable/nonescapable types. +public func expectEquivalent< + A: ~Copyable & ~Escapable, + B +>( + _ left: borrowing A, _ right: borrowing B, + by areEquivalent: (borrowing A, borrowing B) -> Bool, + printer: (borrowing A) -> String, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + if areEquivalent(left, right) { return } + _expectFailure( + "'\(printer(left))' is not equivalent to '\(right)'", + message, trapping: trapping, file: file, line: line) +} + public func expectEquivalent( _ left: A?, _ right: B?, by areEquivalent: (A, B) -> Bool, From cd309d5a1ff01b077fc0fa2e6e70a44ebe3d2f49 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 20 Jan 2026 10:52:06 -0800 Subject: [PATCH 17/75] Speed up testing by default --- Package.swift | 5 ++++- Package@swift-6.0.swift | 3 +++ .../TreeHashedCollections Fixtures.swift | 2 ++ Tests/RopeModuleTests/SampleStrings.swift | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 623b46e4..3c7c5a57 100644 --- a/Package.swift +++ b/Package.swift @@ -79,7 +79,10 @@ var defines: [SwiftSetting] = [ // This removes the distinct modules for each data structure, instead // putting them all directly into the `Collections` module. // Note: This is a source-incompatible variation of the default configuration. -// "COLLECTIONS_SINGLE_MODULE", +// .define("COLLECTIONS_SINGLE_MODULE"), + + // Enables longer, more exhaustive tests. +// .define("COLLECTIONS_LONG_TESTS"), ] let availabilityMacros: KeyValuePairs = [ diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index 30c7fde3..701b2265 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -50,6 +50,9 @@ var defines: [String] = [ // putting them all directly into the `Collections` module. // Note: This is a source-incompatible variation of the default configuration. // "COLLECTIONS_SINGLE_MODULE", + + // Enables longer, more exhaustive tests. +// "COLLECTIONS_LONG_TESTS", ] let availabilityMacros: KeyValuePairs = [ diff --git a/Tests/HashTreeCollectionsTests/TreeHashedCollections Fixtures.swift b/Tests/HashTreeCollectionsTests/TreeHashedCollections Fixtures.swift index c61dc868..e993d291 100644 --- a/Tests/HashTreeCollectionsTests/TreeHashedCollections Fixtures.swift +++ b/Tests/HashTreeCollectionsTests/TreeHashedCollections Fixtures.swift @@ -30,6 +30,7 @@ let testItems: [RawCollider] = { RawCollider(5, "ACAD"), RawCollider(6, "ACAD"), ] +#if COLLECTIONS_LONG_TESTS if MemoryLayout.size == 8 { // Cut testing workload down a bit on 32-bit systems. In practice a 32-bit Int // usually means we're running on a watchOS device (arm64_32), and those are relatively slow @@ -47,6 +48,7 @@ let testItems: [RawCollider] = { RawCollider(12, "ACC"), ] #endif +#endif return testItems }() diff --git a/Tests/RopeModuleTests/SampleStrings.swift b/Tests/RopeModuleTests/SampleStrings.swift index f0da1454..f1e73286 100644 --- a/Tests/RopeModuleTests/SampleStrings.swift +++ b/Tests/RopeModuleTests/SampleStrings.swift @@ -61,6 +61,7 @@ let sampleString: String = { 🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦🇺🇸🇨🇦 """# + #if COLLECTIONS_LONG_TESTS if MemoryLayout.size == 8 { /// Add even more flags and extra long combining sequences. This considerably increases test /// workload. (Not necessarily due to grapheme cluster length, but because test performance is @@ -78,6 +79,7 @@ let sampleString: String = { T̸h̴e̶ ̵p̷o̷w̶e̵r̷f̸u̷l̷ ̵p̴r̷o̷g̶r̷a̸m̸m̶i̸n̴g̴ ̷l̶a̴n̸g̵u̵a̶g̸e̶ ̸t̶h̴a̵t̵ ̶i̷s̶ ̵a̷l̴s̸o̷ ̵e̵a̷s̷y̴ ̵t̵o̷ ̷l̷e̶a̵r̴n̸.̵ """# } + #endif return str }() From 0e52141a6548ddb2780d642b8680fdd412ee3c71 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 20 Jan 2026 11:06:33 -0800 Subject: [PATCH 18/75] withTemporary{Input,Output}Span: Add support for stdlibs before 6.3 --- Sources/ContainersPreview/InputSpan.swift | 2 +- .../ContainersPreview/OutputSpan+Extras.swift | 2 +- .../TemporaryAllocation.swift | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 Sources/ContainersPreview/TemporaryAllocation.swift diff --git a/Sources/ContainersPreview/InputSpan.swift b/Sources/ContainersPreview/InputSpan.swift index 70fa8f9c..fdf5a979 100644 --- a/Sources/ContainersPreview/InputSpan.swift +++ b/Sources/ContainersPreview/InputSpan.swift @@ -487,7 +487,7 @@ internal func withTemporaryInputSpan capacity: Int, _ body: (inout InputSpan) throws(E) -> R ) throws(E) -> R { - try withUnsafeTemporaryAllocation( + try _withUnsafeTemporaryAllocation( of: Element.self, capacity: capacity ) { buffer throws(E) in var span = InputSpan(buffer: buffer, initializedCount: 0) diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/OutputSpan+Extras.swift index c510bd17..8cad92ad 100644 --- a/Sources/ContainersPreview/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/OutputSpan+Extras.swift @@ -22,7 +22,7 @@ internal func withTemporaryOutputSpan) throws(E) -> R ) throws(E) -> R { - try withUnsafeTemporaryAllocation( + try _withUnsafeTemporaryAllocation( of: Element.self, capacity: capacity ) { buffer throws(E) in var span = OutputSpan(buffer: buffer, initializedCount: 0) diff --git a/Sources/ContainersPreview/TemporaryAllocation.swift b/Sources/ContainersPreview/TemporaryAllocation.swift new file mode 100644 index 00000000..6a4a3eb1 --- /dev/null +++ b/Sources/ContainersPreview/TemporaryAllocation.swift @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +/// A polyfill of the typed-throws supporting `withUnsafeTemporaryAllocation` in the 6.3 stdlib. +@_alwaysEmitIntoClient @_transparent +package func _withUnsafeTemporaryAllocation< + T: ~Copyable, R: ~Copyable, + E: Error +>( + of type: T.Type, + capacity: Int, + _ body: (UnsafeMutableBufferPointer) throws(E) -> R +) throws(E) -> R { +#if compiler(>=6.3) + try withUnsafeTemporaryAllocation(of: type, capacity: capacity, body) +#else + let r: Result = withUnsafeTemporaryAllocation( + of: T.self, capacity: capacity + ) { buffer in + return Result(catching: { () throws(E) in try body(buffer) }) + } + return try r.get() +#endif +} + +#endif From fabe5d8c87df14ffb0fa0c97044edc667b294afc Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 20 Jan 2026 17:42:19 -0800 Subject: [PATCH 19/75] RigidArray, UniqueArray, RigidDeque tests: Rework some assertions --- .../RigidArrayTests.swift | 134 ++++++++++++++---- .../UniqueArrayTests.swift | 113 ++++++++++++--- Tests/DequeTests/RigidDequeTests+XCTest.swift | 38 ++++- .../Assertions+Containers.swift | 40 +++++- 4 files changed, 267 insertions(+), 58 deletions(-) diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index e8652f2c..a09c6b33 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -30,7 +30,7 @@ internal func expectIterableContents< equalTo right: C2, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { expectIterableContents( @@ -48,15 +48,17 @@ internal func expectIterableContents< _ left: borrowing RigidArray, equivalentTo right: C2, by areEquivalent: (borrowing E1, C2.Element) -> Bool, + printer: (borrowing E1) -> String, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { expectIterableContents( left.span, equivalentTo: right, by: areEquivalent, + printer: printer, message(), trapping: trapping, file: file, line: line) } #endif @@ -118,7 +120,8 @@ class RigidArrayTests: CollectionTestCase { expectIterableContents( a, equivalentTo: 0 ..< layout.count, - by: { $0.payload == $1 }) + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -288,7 +291,11 @@ class RigidArrayTests: CollectionTestCase { a.swapAt(i, layout.count - 1 - i) } let expected = (0 ..< layout.count).reversed() - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count) } } @@ -395,7 +402,8 @@ class RigidArrayTests: CollectionTestCase { expectIterableContents( a, equivalentTo: (0 ..< layout.count).map { -$0 }, - by: { $0.payload == $1 }) + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count) } } @@ -418,7 +426,10 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.capacity, newCapacity) expectEqual(tracker.instances, layout.count) expectIterableContents( - a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + a, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -442,7 +453,10 @@ class RigidArrayTests: CollectionTestCase { expectEqual(a.capacity, Swift.max(layout.capacity, newCapacity)) expectEqual(tracker.instances, layout.count) expectIterableContents( - a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + a, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -456,8 +470,16 @@ class RigidArrayTests: CollectionTestCase { expectEqual(b.count, layout.count) expectEqual(b.capacity, layout.count) expectEqual(tracker.instances, layout.count) - expectIterableContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) - expectIterableContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + expectIterableContents( + b, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -474,8 +496,16 @@ class RigidArrayTests: CollectionTestCase { expectEqual(b.count, layout.count) expectEqual(b.capacity, newCapacity) expectEqual(tracker.instances, layout.count) - expectIterableContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) - expectIterableContents(b, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + expectIterableContents( + b, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -520,7 +550,10 @@ class RigidArrayTests: CollectionTestCase { a.removeLast(k) expectEqual(tracker.instances, layout.count - k) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -536,7 +569,11 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) let old = a.remove(at: i) expectEqual(old.payload, i) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -551,7 +588,11 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.removeSubrange(range) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -584,7 +625,10 @@ class RigidArrayTests: CollectionTestCase { expectEquivalent(item, expectedItem, by: { $0?.payload == $1 }) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -596,7 +640,11 @@ class RigidArrayTests: CollectionTestCase { for i in layout.count ..< layout.capacity { a.append(tracker.instance(for: i)) expectEqual(a.count, i + 1) - expectIterableContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: 0 ..< i + 1, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } expectTrue(a.isFull) expectEqual(tracker.instances, layout.capacity) @@ -631,7 +679,11 @@ class RigidArrayTests: CollectionTestCase { using: { layout.count + $0 }) a.append(copying: b.span) expectTrue(a.isFull) - expectIterableContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: 0 ..< layout.capacity, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.capacity) } } @@ -651,7 +703,11 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.append(copying: b) expectTrue(a.isFull) - expectIterableContents(a, equivalentTo: 0 ..< layout.capacity, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: 0 ..< layout.capacity, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.capacity) } } @@ -671,7 +727,11 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.insert(tracker.instance(for: -1), at: i) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count + 1) } } @@ -694,7 +754,11 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.insert(copying: trackedAddition, at: i) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.capacity) } } @@ -719,7 +783,11 @@ class RigidArrayTests: CollectionTestCase { } a.insert(copying: rigidAddition.span, at: i) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.capacity) } } @@ -748,7 +816,11 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [Swift.max(spanCount, 1)]) a.insert(copying: rigidAddition, at: i) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.capacity) } } @@ -774,7 +846,11 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) a.replaceSubrange(range, copying: trackedAddition) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -795,7 +871,11 @@ class RigidArrayTests: CollectionTestCase { let trackedAddition = RigidArray(copying: addition.map { tracker.instance(for: $0) }) a.replaceSubrange(range, copying: trackedAddition.span) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -821,7 +901,11 @@ class RigidArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.replaceSubrange(range, copying: trackedAddition) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count - range.count + c) } } diff --git a/Tests/BasicContainersTests/UniqueArrayTests.swift b/Tests/BasicContainersTests/UniqueArrayTests.swift index 346472a9..6ae8d9d8 100644 --- a/Tests/BasicContainersTests/UniqueArrayTests.swift +++ b/Tests/BasicContainersTests/UniqueArrayTests.swift @@ -30,7 +30,7 @@ public func expectIterableContents< equalTo right: C2, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { expectIterableContents( @@ -48,16 +48,21 @@ public func expectIterableContents< _ left: borrowing UniqueArray, equivalentTo right: C2, by areEquivalent: (borrowing E1, C2.Element) -> Bool, + printer: (borrowing E1) -> String, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { expectIterableContents( left.span, equivalentTo: right, by: areEquivalent, - message(), trapping: trapping, file: file, line: line) + printer: printer, + message(), + trapping: trapping, + file: file, + line: line) } #endif @@ -150,7 +155,11 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.count, layout.count) expectEqual(a.freeCapacity, layout.capacity - layout.count) expectEqual(a.isEmpty, layout.count == 0) - expectIterableContents(a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -319,7 +328,10 @@ class UniqueArrayTests: CollectionTestCase { } let expected = (0 ..< layout.count).reversed() expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count) } } @@ -399,7 +411,8 @@ class UniqueArrayTests: CollectionTestCase { expectIterableContents( a, equivalentTo: (0 ..< layout.count).map { -$0 }, - by: { $0.payload == $1 }) + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count) } } @@ -422,7 +435,10 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.capacity, newCapacity) expectEqual(tracker.instances, layout.count) expectIterableContents( - a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + a, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -446,7 +462,10 @@ class UniqueArrayTests: CollectionTestCase { expectEqual(a.capacity, Swift.max(layout.capacity, newCapacity)) expectEqual(tracker.instances, layout.count) expectIterableContents( - a, equivalentTo: 0 ..< layout.count, by: { $0.payload == $1 }) + a, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -503,7 +522,10 @@ class UniqueArrayTests: CollectionTestCase { a.removeLast(k) expectEqual(tracker.instances, layout.count - k) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -519,7 +541,11 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) let old = a.remove(at: i) expectEqual(old.payload, i) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -534,7 +560,11 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) a.removeSubrange(range) - expectIterableContents(a, equivalentTo: expected, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -567,7 +597,10 @@ class UniqueArrayTests: CollectionTestCase { expectEquivalent(item, expectedItem, by: { $0?.payload == $1 }) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } } } @@ -636,7 +669,11 @@ class UniqueArrayTests: CollectionTestCase { for i in layout.count ..< c { a.append(tracker.instance(for: i)) expectEqual(a.count, i + 1) - expectIterableContents(a, equivalentTo: 0 ..< i + 1, by: { $0.payload == $1 }) + expectIterableContents( + a, + equivalentTo: 0 ..< i + 1, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) } expectEqual(tracker.instances, c) } @@ -654,7 +691,10 @@ class UniqueArrayTests: CollectionTestCase { underestimatedCount: .half, isContiguous: isContiguous)) expectIterableContents( - a, equivalentTo: 0 ..< c, by: { $0.payload == $1}) + a, + equivalentTo: 0 ..< c, + by: { $0.payload == $1}, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, c) } } @@ -674,7 +714,10 @@ class UniqueArrayTests: CollectionTestCase { a.append(copying: b.span) let c = layout.count + additions expectIterableContents( - a, equivalentTo: 0 ..< c, by: { $0.payload == $1 }) + a, + equivalentTo: 0 ..< c, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, c) } } @@ -699,7 +742,10 @@ class UniqueArrayTests: CollectionTestCase { spanCounts: [spanCount]) a.append(copying: b) expectIterableContents( - a, equivalentTo: 0 ..< c, by: { $0.payload == $1 }) + a, + equivalentTo: 0 ..< c, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, c) } } @@ -720,7 +766,10 @@ class UniqueArrayTests: CollectionTestCase { a.insert(tracker.instance(for: -1), at: i) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count + 1) } } @@ -742,7 +791,10 @@ class UniqueArrayTests: CollectionTestCase { a.insert(copying: trackedAddition, at: i) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count + c) } } @@ -767,7 +819,10 @@ class UniqueArrayTests: CollectionTestCase { a.insert(copying: rigidAddition.span, at: i) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count + c) } } @@ -799,7 +854,10 @@ class UniqueArrayTests: CollectionTestCase { a.insert(copying: rigidAddition, at: i) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count + c) } } @@ -824,7 +882,10 @@ class UniqueArrayTests: CollectionTestCase { a.replaceSubrange(range, copying: trackedAddition) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -847,7 +908,10 @@ class UniqueArrayTests: CollectionTestCase { a.replaceSubrange(range, copying: trackedAddition.span) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count - range.count + c) } } @@ -875,7 +939,10 @@ class UniqueArrayTests: CollectionTestCase { a.replaceSubrange(range, copying: trackedAddition) expectIterableContents( - a, equivalentTo: expected, by: { $0.payload == $1 }) + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) expectEqual(tracker.instances, layout.count - range.count + c) } } diff --git a/Tests/DequeTests/RigidDequeTests+XCTest.swift b/Tests/DequeTests/RigidDequeTests+XCTest.swift index b60a499b..4401f7e9 100644 --- a/Tests/DequeTests/RigidDequeTests+XCTest.swift +++ b/Tests/DequeTests/RigidDequeTests+XCTest.swift @@ -35,10 +35,33 @@ internal func expectIterableContents< left, equivalentTo: right, by: ==, - printer: { "\($0)" }, message(), trapping: trapping, file: file, line: line) } +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +internal func expectIterableContents< + E1, + C2: Collection, +>( + _ left: borrowing RigidDeque, + equivalentTo right: C2, + by areEquivalent: (borrowing E1, C2.Element) -> Bool, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + expectIterableContents( + left, + equivalentTo: right, + by: areEquivalent, + printer: { "\($0)" }, + message(), + file: file, + line: line) +} + /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) internal func expectIterableContents< @@ -69,6 +92,7 @@ internal func expectIterableContents< c += 1 } } + #endif final class RigidDequeTests: CollectionTestCase { @@ -221,7 +245,11 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= deque.freeCapacity else { return } contents.insert(contentsOf: extra, at: 0) deque.prepend(copying: extra) - expectIterableContents(deque, equivalentTo: contents, by: ==) + expectIterableContents( + deque, + equivalentTo: contents, + by: ==, + printer: { "\($0)" }) } } } @@ -316,7 +344,11 @@ final class RigidDequeTests: CollectionTestCase { guard extra.count <= deque.freeCapacity else { return } contents.append(contentsOf: extra) deque.append(copying: extra) - expectIterableContents(deque, equivalentTo: contents, by: ==) + expectIterableContents( + deque, + equivalentTo: contents, + by: ==, + printer: { "\($0)" }) } } } diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index 065f24a7..372dca21 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -27,7 +27,7 @@ public func expectIterableContents< equalTo right: C2, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { var i = 0 @@ -59,7 +59,7 @@ public func expectIterableContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) public func expectIterableContents< - E1: ~Copyable, + E1, C2: Collection, >( _ left: borrowing Span, @@ -67,7 +67,32 @@ public func expectIterableContents< by areEquivalent: (borrowing E1, C2.Element) -> Bool, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, + line: UInt = #line +) { + expectIterableContents( + left, + equivalentTo: right, + by: areEquivalent, + printer: { "\($0)" }, + message(), + trapping: trapping, + file: file, line: line) +} + +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +public func expectIterableContents< + E1: ~Copyable, + C2: Collection, +>( + _ left: borrowing Span, + equivalentTo right: C2, + by areEquivalent: (borrowing E1, C2.Element) -> Bool, + printer: (borrowing E1) -> String, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, line: UInt = #line ) { var i = 0 @@ -106,7 +131,7 @@ public func expectIterablesWithEquivalentElements< by areEquivalent: (borrowing I1.Element, borrowing I2.Element) -> Bool, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { if left.elementsEqual(right, by: areEquivalent) { return } @@ -126,7 +151,7 @@ public func expectIterablesWithEqualElements< _ right: borrowing I2, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { if left.elementsEqual(right) { return } @@ -146,7 +171,7 @@ public func expectIterableContents< equalTo right: C2, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { var it1 = left.startBorrowIteration() @@ -186,9 +211,10 @@ public func expectIterableContents< _ left: borrowing I1, equivalentTo right: C2, by areEquivalent: (borrowing I1.Element, C2.Element) -> Bool, + printer: (borrowing I1.Element) -> String, _ message: @autoclosure () -> String = "", trapping: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { var it1 = left.startBorrowIteration() From e4aba4c1c90e95bfaaed00a04cf0977f6e51d398 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Sun, 25 Jan 2026 10:53:47 -0800 Subject: [PATCH 20/75] =?UTF-8?q?Iterable=20=E2=86=92=20BorrowingSequence,?= =?UTF-8?q?=20BorrowIterator=20=E2=86=92=20BorrowingIterator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicContainers/RigidArray+Append.swift | 20 +++--- .../RigidArray+Initializers.swift | 6 +- Sources/BasicContainers/RigidArray.swift | 6 +- .../BasicContainers/UniqueArray+Append.swift | 18 +++--- .../UniqueArray+Initializers.swift | 12 ++-- Sources/BasicContainers/UniqueArray.swift | 10 +-- Sources/ContainersPreview/CMakeLists.txt | 2 +- .../{ => Extensions}/OutputSpan+Extras.swift | 38 ++++++++++- .../TemporaryAllocation.swift | 0 .../BorrowIteratorProtocol.swift | 34 +++++----- .../{ => Protocols}/Container.swift | 12 ++-- .../{ => Protocols}/Drain.swift | 18 +++--- .../Iterable+Standard Conformances.swift | 32 +++++----- .../{ => Protocols}/Iterable+Utilities.swift | 64 +++++++++---------- .../{ => Protocols}/Iterable.swift | 22 +++---- .../{ => Protocols}/Producer.swift | 34 ++++++++++ .../{Ref.swift => Types/Borrow.swift} | 8 +-- .../ContainersPreview/{ => Types}/Box.swift | 12 ++-- .../{Mut.swift => Types/Inout.swift} | 28 +++++--- .../{ => Types}/InputSpan.swift | 40 +++++++++--- .../{ => Types}/Shared.swift | 0 .../Assertions+Containers.swift | 34 +++++----- .../ConformanceCheckers/CheckContainer.swift | 16 ++--- .../MinimalTypes/StaccatoContainer.swift | 8 +-- 24 files changed, 287 insertions(+), 187 deletions(-) rename Sources/ContainersPreview/{ => Extensions}/OutputSpan+Extras.swift (63%) rename Sources/ContainersPreview/{ => Extensions}/TemporaryAllocation.swift (100%) rename Sources/ContainersPreview/{ => Protocols}/BorrowIteratorProtocol.swift (85%) rename Sources/ContainersPreview/{ => Protocols}/Container.swift (96%) rename Sources/ContainersPreview/{ => Protocols}/Drain.swift (96%) rename Sources/ContainersPreview/{ => Protocols}/Iterable+Standard Conformances.swift (63%) rename Sources/ContainersPreview/{ => Protocols}/Iterable+Utilities.swift (78%) rename Sources/ContainersPreview/{ => Protocols}/Iterable.swift (82%) rename Sources/ContainersPreview/{ => Protocols}/Producer.swift (89%) rename Sources/ContainersPreview/{Ref.swift => Types/Borrow.swift} (88%) rename Sources/ContainersPreview/{ => Types}/Box.swift (91%) rename Sources/ContainersPreview/{Mut.swift => Types/Inout.swift} (79%) rename Sources/ContainersPreview/{ => Types}/InputSpan.swift (93%) rename Sources/ContainersPreview/{ => Types}/Shared.swift (100%) diff --git a/Sources/BasicContainers/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray+Append.swift index aa5c6d13..43805a6b 100644 --- a/Sources/BasicContainers/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray+Append.swift @@ -274,9 +274,9 @@ extension RigidArray { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @inlinable internal mutating func _append< - Source: Iterable & ~Copyable & ~Escapable + Source: BorrowingSequence & ~Copyable & ~Escapable >( - copyingIterable newElements: borrowing Source + copying newElements: borrowing Source ) { let target = _freeSpace _count += newElements._copyContents(intoPrefixOf: target) @@ -284,10 +284,10 @@ extension RigidArray { #endif #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Copies the elements of a container to the end of this array. + /// Copies the elements of a borrowing sequence to the end of this array. /// /// If the array does not have sufficient capacity to hold all items in the - /// source iterable, then this triggers a runtime error. + /// source sequence, then this triggers a runtime error. /// /// - Parameters /// - newElements: A container whose contents to copy into the array. @@ -296,11 +296,11 @@ extension RigidArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Iterable & ~Copyable & ~Escapable + Source: BorrowingSequence & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { - _append(copyingIterable: newElements) + _append(copying: newElements) } #endif @@ -326,10 +326,10 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Copies the elements of a container to the end of this array. + /// Copies the elements of a borrowing sequence to the end of this array. /// /// If the array does not have sufficient capacity to hold all items in the - /// source iterable, then this triggers a runtime error. + /// source sequence, then this triggers a runtime error. /// /// - Parameters /// - newElements: The new elements to copy into the array. @@ -338,9 +338,9 @@ extension RigidArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Iterable & Sequence + Source: BorrowingSequence & Sequence >(copying newElements: Source) { - _append(copyingIterable: newElements) + _append(copying: newElements) } #endif } diff --git a/Sources/BasicContainers/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray+Initializers.swift index 3fd7f2e7..bd88514a 100644 --- a/Sources/BasicContainers/RigidArray+Initializers.swift +++ b/Sources/BasicContainers/RigidArray+Initializers.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -98,7 +98,7 @@ extension RigidArray /*where Element: Copyable*/ { /// The container must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) - public init & ~Copyable & ~Escapable>( + public init & ~Copyable & ~Escapable>( capacity: Int, copying contents: borrowing Source ) { @@ -119,7 +119,7 @@ extension RigidArray /*where Element: Copyable*/ { /// The container must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) - public init & Sequence>( + public init & Sequence>( capacity: Int, copying contents: Source ) { diff --git a/Sources/BasicContainers/RigidArray.swift b/Sources/BasicContainers/RigidArray.swift index e661a306..e636cad6 100644 --- a/Sources/BasicContainers/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray.swift @@ -286,9 +286,9 @@ extension RigidArray where Element: ~Copyable { #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension RigidArray: Iterable where Element: ~Copyable { +extension RigidArray: BorrowingSequence where Element: ~Copyable { @frozen - public struct BorrowIterator: ~Copyable, ~Escapable, BorrowIteratorProtocol { + public struct BorrowingIterator: ~Copyable, ~Escapable, BorrowingIteratorProtocol { @usableFromInline internal let _span: Span @@ -327,7 +327,7 @@ extension RigidArray: Iterable where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) - public func startBorrowIteration() -> BorrowIterator { + public func makeBorrowingIterator() -> BorrowingIterator { .init(_span: self.span, offset: 0) } } diff --git a/Sources/BasicContainers/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray+Append.swift index bb114597..6843b9ab 100644 --- a/Sources/BasicContainers/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray+Append.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -233,12 +233,12 @@ extension UniqueArray { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @inlinable internal mutating func _append< - Source: Iterable & ~Copyable & ~Escapable + Source: BorrowingSequence & ~Copyable & ~Escapable >( - copyingIterable newElements: borrowing Source + copying newElements: borrowing Source ) { _ensureFreeCapacity(newElements.underestimatedCount) - var it = newElements.startBorrowIteration() + var it = newElements.makeBorrowingIterator() while true { let span = it.nextSpan() if span.isEmpty { break } @@ -250,7 +250,7 @@ extension UniqueArray { #endif #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Copies the elements of an iterable to the end of this array. + /// Copies the elements of a borrowing sequence to the end of this array. /// /// If the array does not have sufficient capacity to hold enough elements, /// then this reallocates the array's storage to extend its capacity, using @@ -266,11 +266,11 @@ extension UniqueArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Iterable & ~Copyable & ~Escapable + Source: BorrowingSequence & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { - self._append(copyingIterable: newElements) + self._append(copying: newElements) } #endif @@ -320,9 +320,9 @@ extension UniqueArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: Iterable & Sequence + Source: BorrowingSequence & Sequence >(copying newElements: Source) { - self._append(copyingIterable: newElements) + self._append(copying: newElements) } #endif } diff --git a/Sources/BasicContainers/UniqueArray+Initializers.swift b/Sources/BasicContainers/UniqueArray+Initializers.swift index ee731b61..950cbb82 100644 --- a/Sources/BasicContainers/UniqueArray+Initializers.swift +++ b/Sources/BasicContainers/UniqueArray+Initializers.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -70,16 +70,16 @@ extension UniqueArray where Element: ~Copyable { extension UniqueArray /*where Element: Copyable*/ { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Creates a new array with the specified initial capacity, holding a copy - /// of the contents of a given iterable. + /// of the contents of a given borrowing sequence. /// /// - Parameters: /// - capacity: The storage capacity of the new array, or nil to allocate /// just enough capacity to store the contents. - /// - contents: An iterable whose contents to copy into the new array. - /// The iterable must not contain more than `capacity` elements. + /// - contents: A sequence whose contents to copy into the new array. + /// The sequence must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) - public init & ~Copyable & ~Escapable>( + public init & ~Copyable & ~Escapable>( capacity: Int? = nil, copying contents: borrowing Source ) { @@ -115,7 +115,7 @@ extension UniqueArray /*where Element: Copyable*/ { /// - contents: The container whose contents to copy into the new array. @_alwaysEmitIntoClient @inline(__always) - public init & Sequence>( + public init & Sequence>( capacity: Int? = nil, copying contents: Source ) { diff --git a/Sources/BasicContainers/UniqueArray.swift b/Sources/BasicContainers/UniqueArray.swift index 0c3122ad..a1ff802b 100644 --- a/Sources/BasicContainers/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -177,8 +177,8 @@ extension UniqueArray where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension UniqueArray: Iterable where Element: ~Copyable { - public typealias BorrowIterator = RigidArray.BorrowIterator +extension UniqueArray: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = RigidArray.BorrowingIterator public var estimatedCount: ContainersPreview.EstimatedCount { .exactly(count) @@ -186,8 +186,8 @@ extension UniqueArray: Iterable where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) - public func startBorrowIteration() -> BorrowIterator { - self._storage.startBorrowIteration() + public func makeBorrowingIterator() -> BorrowingIterator { + self._storage.makeBorrowingIterator() } } #endif diff --git a/Sources/ContainersPreview/CMakeLists.txt b/Sources/ContainersPreview/CMakeLists.txt index d24327e6..a7f43d1d 100644 --- a/Sources/ContainersPreview/CMakeLists.txt +++ b/Sources/ContainersPreview/CMakeLists.txt @@ -23,7 +23,7 @@ else() endif() target_sources(${module_name} PRIVATE - "BorrowIteratorProtocol.swift" + "BorrowingIteratorProtocol.swift" "Box.swift" "Container.swift" "Container+Utilities.swift" diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift similarity index 63% rename from Sources/ContainersPreview/OutputSpan+Extras.swift rename to Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift index 8cad92ad..df6c849e 100644 --- a/Sources/ContainersPreview/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift @@ -53,7 +53,7 @@ extension OutputSpan where Element: ~Copyable { extension OutputSpan where Element: ~Copyable { @_lifetime(source: copy source) @inlinable - internal mutating func _append(moving source: inout InputSpan) { + package mutating func _append(moving source: inout InputSpan) { // FIXME: This needs to be in the stdlib. self.withUnsafeMutableBufferPointer { dst, dstCount in source.withUnsafeMutableBufferPointer { src, srcCount in @@ -69,6 +69,42 @@ extension OutputSpan where Element: ~Copyable { } } } + + @_lifetime(source: copy source) + @inlinable + package mutating func _append(moving source: inout OutputSpan) { + // FIXME: This needs to be in the stdlib. + self.withUnsafeMutableBufferPointer { dst, dstCount in + source.withUnsafeMutableBufferPointer { src, srcCount in + let dstEnd = dstCount + srcCount + precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") + let srcItems = src._extracting(uncheckedFrom: 0, to: srcCount) + dst + ._extracting(uncheckedFrom: dstCount, to: dstEnd) + .moveInitializeAll(fromContentsOf: srcItems) + dstCount &+= srcCount + srcCount = 0 + } + } + } +} + +@available(SwiftStdlib 5.0, *) +extension OutputSpan /* where Element: Copyable */ { + @inlinable + package mutating func _append(copying source: borrowing Span) { + // FIXME: This needs to be in the stdlib. + self.withUnsafeMutableBufferPointer { dst, dstCount in + source.withUnsafeBufferPointer { src in + let dstEnd = dstCount + src.count + precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") + dst + ._extracting(uncheckedFrom: dstCount, to: dstEnd) + .initializeAll(fromContentsOf: src) + dstCount &+= src.count + } + } + } } diff --git a/Sources/ContainersPreview/TemporaryAllocation.swift b/Sources/ContainersPreview/Extensions/TemporaryAllocation.swift similarity index 100% rename from Sources/ContainersPreview/TemporaryAllocation.swift rename to Sources/ContainersPreview/Extensions/TemporaryAllocation.swift diff --git a/Sources/ContainersPreview/BorrowIteratorProtocol.swift b/Sources/ContainersPreview/Protocols/BorrowIteratorProtocol.swift similarity index 85% rename from Sources/ContainersPreview/BorrowIteratorProtocol.swift rename to Sources/ContainersPreview/Protocols/BorrowIteratorProtocol.swift index 864de931..d0f4894b 100644 --- a/Sources/ContainersPreview/BorrowIteratorProtocol.swift +++ b/Sources/ContainersPreview/Protocols/BorrowIteratorProtocol.swift @@ -16,7 +16,7 @@ import InternalCollectionsUtilities #endif @available(SwiftStdlib 5.0, *) -public protocol BorrowIteratorProtocol: ~Copyable, ~Escapable { +public protocol BorrowingIteratorProtocol: ~Copyable, ~Escapable { associatedtype Element: ~Copyable // FIXME: This ought to be a core requirement, but `Ref` is not a thing yet. @@ -27,15 +27,15 @@ public protocol BorrowIteratorProtocol: ~Copyable, ~Escapable { /// Advance the iterator, returning an ephemeral span over the elements /// that are ready to be visited. /// - /// If the underlying iterable is a container type, then the returned span + /// If the underlying sequence is a container type, then the returned span /// typically directly addresses one of its storage buffers. On the other - /// hand, if the underlying iterable materializes its elements on demand, + /// hand, if the underlying sequence materializes its elements on demand, /// then the returned span addresses some temporary buffer associated with /// the iterator itself. Consequently, the returned span is tied to this /// particular invocation of `nextSpan`, and it cannot survive until the next /// invocation of it. /// - /// If the iterator has not yet reached the end of the underlying iterable, + /// If the iterator has not yet reached the end of the underlying sequence, /// then this method returns a non-empty span of at most `maximumCount` /// elements, and updates the iterator's current position to the element /// following the last item in the returned span (or the end, if there is @@ -50,7 +50,7 @@ public protocol BorrowIteratorProtocol: ~Copyable, ~Escapable { /// in bulk, by directly iterating over its piecewise contiguous pieces of /// storage: /// - /// var it = items.startBorrowIteration() + /// var it = items.makeBorrowingIterator() /// while true { /// let span = it.nextSpan(after: &index) /// if span.isEmpty { break } @@ -75,27 +75,27 @@ public protocol BorrowIteratorProtocol: ~Copyable, ~Escapable { mutating func nextSpan(maximumCount: Int) -> Span /// Advance the position of this iterator by the specified offset, or until - /// the end of the underlying iterable. + /// the end of the underlying sequence. /// /// Returns the number of items that were skipped. If this is less than - /// `maximumOffset`, then the iterable did not have enough elements left to + /// `maximumOffset`, then the sequence did not have enough elements left to /// skip the requested number of items. In this case, the iterator's current - /// position is set to the end of the iterable. + /// position is set to the end of the sequence. /// /// `maximumOffset` must be nonnegative, unless this is a bidirectional /// or random-access iterator. @_lifetime(self: copy self) mutating func skip(by maximumOffset: Int) -> Int - // FIXME: Add BidirectionalBorrowIteratorProtocol and RandomAccessBorrowIteratorProtocol. - // BidirectionalBorrowIteratorProtocol would need to have a `previousSpan` + // FIXME: Add BidirectionalBorrowingIteratorProtocol and RandomAccessBorrowingIteratorProtocol. + // BidirectionalBorrowingIteratorProtocol would need to have a `previousSpan` // method, which considerably complicates implementation. // Perhaps these would be better left to as variants of protocol Container, // which do not need a separate iterator concept. } @available(SwiftStdlib 5.0, *) -extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { @_lifetime(&self) @_lifetime(self: copy self) @_transparent @@ -105,7 +105,7 @@ extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { @_lifetime(self: copy self) @inlinable public mutating func skip(by offset: Int) -> Int { @@ -120,7 +120,7 @@ extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { #if false // FIXME: This doesn't work, but it should? @_lifetime(&self) @_lifetime(self: copy self) @@ -140,7 +140,7 @@ extension BorrowIteratorProtocol where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension BorrowIteratorProtocol +extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable, Element: Copyable { @_lifetime(self: copy self) @@ -159,7 +159,7 @@ where Self: ~Copyable & ~Escapable, Element: Copyable } @available(SwiftStdlib 5.0, *) -extension Span: BorrowIteratorProtocol where Element: ~Copyable { +extension Span: BorrowingIteratorProtocol where Element: ~Copyable { @_lifetime(copy self) @_lifetime(self: copy self) @inlinable @@ -174,7 +174,7 @@ extension Span: BorrowIteratorProtocol where Element: ~Copyable { #if false // FIXME: Implement this @available(SwiftStdlib 5.0, *) -extension MutableSpan: BorrowIteratorProtocol where Element: ~Copyable { +extension MutableSpan: BorrowingIteratorProtocol where Element: ~Copyable { @_lifetime(copy self) @_lifetime(self: copy self) @inlinable @@ -186,7 +186,7 @@ extension MutableSpan: BorrowIteratorProtocol where Element: ~Copyable { #if false // FIXME: Implement this @available(SwiftStdlib 5.0, *) -extension OutputSpan: BorrowIteratorProtocol where Element: ~Copyable { +extension OutputSpan: BorrowingIteratorProtocol where Element: ~Copyable { @_lifetime(copy self) @_lifetime(self: copy self) @inlinable diff --git a/Sources/ContainersPreview/Container.swift b/Sources/ContainersPreview/Protocols/Container.swift similarity index 96% rename from Sources/ContainersPreview/Container.swift rename to Sources/ContainersPreview/Protocols/Container.swift index bb851f0b..ff635855 100644 --- a/Sources/ContainersPreview/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container.swift @@ -12,7 +12,7 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -public protocol Container: Iterable, ~Copyable, ~Escapable { +public protocol Container: BorrowingSequence, ~Copyable, ~Escapable { associatedtype Index: Comparable var count: Int { get } @@ -261,18 +261,18 @@ extension Container where Self: ~Copyable & ~Escapable { public struct ContainerIterator< Base: Container & ~Copyable /*FIXME: & ~Escapable*/ >: ~Copyable, ~Escapable { - let _base: Ref // FIXME: This doesn't support nonescapable Bases + let _base: Borrow // FIXME: This doesn't support nonescapable Bases var _position: Base.Index @_lifetime(borrow base) init(_borrowing base: borrowing @_addressable Base, from position: Base.Index) { - self._base = Ref(_borrowing: base) + self._base = Borrow(_borrowing: base) self._position = position } } @available(SwiftStdlib 5.0, *) -extension ContainerIterator: BorrowIteratorProtocol +extension ContainerIterator: BorrowingIteratorProtocol where Base: ~Copyable /*FIXME: & ~Escapable*/ { public typealias Element = Base.Element @@ -288,10 +288,10 @@ where Base: ~Copyable /*FIXME: & ~Escapable*/ extension Container where Self: ~Copyable /*FIXME: & ~Escapable*/, - BorrowIterator == ContainerIterator + BorrowingIterator == ContainerIterator { @_lifetime(borrow self) - public func startBorrowIteration() -> BorrowIterator { + public func makeBorrowingIterator() -> BorrowingIterator { ContainerIterator(_borrowing: self, from: self.startIndex) } } diff --git a/Sources/ContainersPreview/Drain.swift b/Sources/ContainersPreview/Protocols/Drain.swift similarity index 96% rename from Sources/ContainersPreview/Drain.swift rename to Sources/ContainersPreview/Protocols/Drain.swift index 943b4385..60a6d7a9 100644 --- a/Sources/ContainersPreview/Drain.swift +++ b/Sources/ContainersPreview/Protocols/Drain.swift @@ -55,7 +55,7 @@ where ProducerError == Never /// the end of the sequence. @_lifetime(&self) @_lifetime(self: copy self) - mutating func drainNext(maximumCount: Int?) -> InputSpan + mutating func drainNext(maximumCount: Int) -> InputSpan // TODO: The primary use case does not need this to throw; do we need to allow that? // Note: making this failable is not entirely straightforward, as there is no // easy way to signal partial success -- conforming implementations @@ -109,7 +109,7 @@ extension Drain where Self: ~Copyable & ~Escapable { @_lifetime(self: copy self) @_transparent mutating func drainNext() -> InputSpan { - drainNext(maximumCount: nil) + drainNext(maximumCount: Int.max) } /// Generate the next batch of items into the supplied output span instance, @@ -158,8 +158,9 @@ extension Drain where Self: ~Copyable & ~Escapable { /// - Returns: A boolean value indicating whether the operation was able to /// append at least one item to the supplied output span without hitting /// the end of the underlying sequence. + @inlinable @_lifetime(target: copy target) - mutating func generate( + public mutating func generate( into target: inout OutputSpan ) throws(Never) -> Bool { var source = self.drainNext(maximumCount: target.freeCapacity) @@ -200,16 +201,15 @@ extension Drain where Self: ~Copyable & ~Escapable { @inlinable @_lifetime(self: copy self) public mutating func skip( - remainder: inout Int + upTo n: inout Int ) throws(ProducerError) -> Bool { - precondition(remainder >= 0, "Can't skip a negative number of elements") - guard remainder > 0 else { return true } - let span = drainNext(maximumCount: remainder) + precondition(n >= 0, "Can't skip a negative number of elements") + guard n > 0 else { return true } + let span = drainNext(maximumCount: n) let success = span.count > 0 - remainder &-= span.count + n &-= span.count return success } - } #endif diff --git a/Sources/ContainersPreview/Iterable+Standard Conformances.swift b/Sources/ContainersPreview/Protocols/Iterable+Standard Conformances.swift similarity index 63% rename from Sources/ContainersPreview/Iterable+Standard Conformances.swift rename to Sources/ContainersPreview/Protocols/Iterable+Standard Conformances.swift index 22bc7dbd..0131f8ec 100644 --- a/Sources/ContainersPreview/Iterable+Standard Conformances.swift +++ b/Sources/ContainersPreview/Protocols/Iterable+Standard Conformances.swift @@ -12,11 +12,11 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Span: Iterable where Element: ~Copyable { +extension Span: BorrowingSequence where Element: ~Copyable { // FIXME: This simple definition cannot also be a backward (or bidirectional) // iterator, nor a random-access iterator. If we want to go in that direction, - // we'll need to rather introduce a type more like `RigidArray.BorrowIterator`. - public typealias BorrowIterator = Self + // we'll need to rather introduce a type more like `RigidArray.BorrowingIterator`. + public typealias BorrowingIterator = Self @inlinable public var estimatedCount: EstimatedCount { @@ -25,14 +25,14 @@ extension Span: Iterable where Element: ~Copyable { @_lifetime(copy self) @inlinable - public func startBorrowIteration() -> Span { + public func makeBorrowingIterator() -> Span { self } } @available(SwiftStdlib 5.0, *) -extension MutableSpan: Iterable where Element: ~Copyable { - public typealias BorrowIterator = Span.BorrowIterator +extension MutableSpan: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = Span.BorrowingIterator @inlinable public var estimatedCount: EstimatedCount { @@ -41,14 +41,14 @@ extension MutableSpan: Iterable where Element: ~Copyable { @_lifetime(borrow self) @inlinable - public func startBorrowIteration() -> Span { + public func makeBorrowingIterator() -> Span { self.span } } @available(SwiftStdlib 5.0, *) -extension OutputSpan: Iterable where Element: ~Copyable { - public typealias BorrowIterator = Span.BorrowIterator +extension OutputSpan: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = Span.BorrowingIterator @inlinable public var estimatedCount: EstimatedCount { @@ -57,14 +57,14 @@ extension OutputSpan: Iterable where Element: ~Copyable { @_lifetime(borrow self) @inlinable - public func startBorrowIteration() -> Span { + public func makeBorrowingIterator() -> Span { self.span } } @available(SwiftStdlib 5.0, *) -extension InputSpan: Iterable where Element: ~Copyable { - public typealias BorrowIterator = Span.BorrowIterator +extension InputSpan: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = Span.BorrowingIterator @inlinable public var estimatedCount: EstimatedCount { @@ -73,14 +73,14 @@ extension InputSpan: Iterable where Element: ~Copyable { @_lifetime(borrow self) @inlinable - public func startBorrowIteration() -> Span { + public func makeBorrowingIterator() -> Span { self.span } } @available(SwiftStdlib 6.2, *) -extension Array: Iterable { - public typealias BorrowIterator = Span.BorrowIterator +extension Array: BorrowingSequence { + public typealias BorrowingIterator = Span.BorrowingIterator @inlinable public var estimatedCount: EstimatedCount { @@ -89,7 +89,7 @@ extension Array: Iterable { @_lifetime(borrow self) @inlinable - public func startBorrowIteration() -> Span { + public func makeBorrowingIterator() -> Span { self.span } } diff --git a/Sources/ContainersPreview/Iterable+Utilities.swift b/Sources/ContainersPreview/Protocols/Iterable+Utilities.swift similarity index 78% rename from Sources/ContainersPreview/Iterable+Utilities.swift rename to Sources/ContainersPreview/Protocols/Iterable+Utilities.swift index 31a86d5e..4032273b 100644 --- a/Sources/ContainersPreview/Iterable+Utilities.swift +++ b/Sources/ContainersPreview/Protocols/Iterable+Utilities.swift @@ -16,13 +16,13 @@ import InternalCollectionsUtilities #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable, Element: Copyable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: Copyable { @inlinable package func _copyContents( intoPrefixOf buffer: UnsafeMutableBufferPointer ) -> Int { var target = buffer - var it = self.startBorrowIteration() + var it = self.makeBorrowingIterator() while target.count != 0 { let span = it.nextSpan(maximumCount: target.count) if span.isEmpty { @@ -38,10 +38,10 @@ extension Iterable where Self: ~Copyable & ~Escapable, Element: Copyable { #if true @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable { @inlinable public func elementsEqual< - Other: Iterable & ~Copyable & ~Escapable + Other: BorrowingSequence & ~Copyable & ~Escapable >( _ other: borrowing Other, ) -> Bool where Element: Equatable { @@ -51,8 +51,8 @@ extension Iterable where Self: ~Copyable & ~Escapable { default: break } - var it1 = self.startBorrowIteration() - var it2 = other.startBorrowIteration() + var it1 = self.makeBorrowingIterator() + var it2 = other.makeBorrowingIterator() while true { let a = it1.nextSpan() var i = 0 @@ -78,10 +78,10 @@ extension Iterable where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable { - /// Returns a Boolean value indicating whether this Iterable and another - /// Iterable contain equivalent elements in the same order, using the given - /// predicate as the equivalence test. +extension BorrowingSequence where Self: ~Copyable & ~Escapable { + /// Returns a Boolean value indicating whether two borrowing sequences contain + /// equivalent elements in the same order, using the given predicate as the + /// equivalence test. /// /// The predicate must form an *equivalence relation* over the elements. That /// is, for any elements `a`, `b`, and `c`, the following conditions must @@ -93,17 +93,17 @@ extension Iterable where Self: ~Copyable & ~Escapable { /// `areEquivalent(a, c)` is also `true`. (Transitivity) /// /// - Parameters: - /// - other: A Iterable to compare to this Iterable. + /// - other: A BorrowingSequence to compare to this BorrowingSequence. /// - areEquivalent: A predicate that returns `true` if its two arguments /// are equivalent; otherwise, `false`. - /// - Returns: `true` if this Iterable and `other` contain equivalent items, + /// - Returns: `true` if this BorrowingSequence and `other` contain equivalent items, /// using `areEquivalent` as the equivalence test; otherwise, `false.` /// - /// - Complexity: O(*m*), where *m* is the count of the longer of the input Iterables. + /// - Complexity: O(*m*), where *m* is the count of the longer of the input sequences. @inlinable public func elementsEqual< E: Error, - Other: Iterable & ~Copyable & ~Escapable + Other: BorrowingSequence & ~Copyable & ~Escapable >( _ other: borrowing Other, by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool @@ -114,8 +114,8 @@ extension Iterable where Self: ~Copyable & ~Escapable { default: break } - var it1 = self.startBorrowIteration() - var it2 = other.startBorrowIteration() + var it1 = self.makeBorrowingIterator() + var it2 = other.makeBorrowingIterator() while true { let a = it1.nextSpan() var i = 0 @@ -144,15 +144,15 @@ extension Iterable where Self: ~Copyable & ~Escapable { #else // rdar://150228920 @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable { @inlinable public func elementsEqual< - Other: Iterable & ~Copyable & ~Escapable + Other: BorrowingSequence & ~Copyable & ~Escapable >( _ other: borrowing Other, ) -> Bool where Element: Equatable { - var it1 = self.startBorrowIteration() - var it2 = other.startBorrowIteration() + var it1 = self.makeBorrowingIterator() + var it2 = other.makeBorrowingIterator() var a = Span() var b = Span() loop: @@ -180,19 +180,19 @@ extension Iterable where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable { @inlinable @discardableResult internal func _spanwiseZip< - Other: Iterable & ~Copyable & ~Escapable, + Other: BorrowingSequence & ~Copyable & ~Escapable, State: ~Copyable, E: Error >( state: inout State, with other: borrowing Other, by process: (inout State, Span, Span) throws(E) -> Bool ) throws(E) -> Int { - var it1 = self.startBorrowIteration() - var it2 = other.startBorrowIteration() + var it1 = self.makeBorrowingIterator() + var it2 = other.makeBorrowingIterator() var a = Span() var b = Span() var offset = 0 // Offset of the start of the current spans @@ -218,8 +218,8 @@ extension Iterable where Self: ~Copyable & ~Escapable { } } - /// Returns a Boolean value indicating whether this Iterable and another - /// Iterable contain equivalent elements in the same order, using the given + /// Returns a Boolean value indicating whether this BorrowingSequence and another + /// BorrowingSequence contain equivalent elements in the same order, using the given /// predicate as the equivalence test. /// /// The predicate must form an *equivalence relation* over the elements. That @@ -232,17 +232,17 @@ extension Iterable where Self: ~Copyable & ~Escapable { /// `areEquivalent(a, c)` is also `true`. (Transitivity) /// /// - Parameters: - /// - other: A Iterable to compare to this Iterable. + /// - other: A BorrowingSequence to compare to this BorrowingSequence. /// - areEquivalent: A predicate that returns `true` if its two arguments /// are equivalent; otherwise, `false`. - /// - Returns: `true` if this Iterable and `other` contain equivalent items, + /// - Returns: `true` if this BorrowingSequence and `other` contain equivalent items, /// using `areEquivalent` as the equivalence test; otherwise, `false.` /// - /// - Complexity: O(*m*), where *m* is the count of the longer of the input Iterables. + /// - Complexity: O(*m*), where *m* is the count of the longer of the input sequences. @inlinable public func elementsEqual< E: Error, - Other: Iterable & ~Copyable & ~Escapable + Other: BorrowingSequence & ~Copyable & ~Escapable >( _ other: borrowing Other, by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool @@ -264,10 +264,10 @@ extension Iterable where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable, Element: Equatable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: Equatable { @inlinable public func elementsEqual< - Other: Iterable & ~Copyable & ~Escapable + Other: BorrowingSequence & ~Copyable & ~Escapable >( _ other: borrowing Other, ) -> Bool { diff --git a/Sources/ContainersPreview/Iterable.swift b/Sources/ContainersPreview/Protocols/Iterable.swift similarity index 82% rename from Sources/ContainersPreview/Iterable.swift rename to Sources/ContainersPreview/Protocols/Iterable.swift index e7306cc7..19ece213 100644 --- a/Sources/ContainersPreview/Iterable.swift +++ b/Sources/ContainersPreview/Protocols/Iterable.swift @@ -18,16 +18,16 @@ public enum EstimatedCount { } @available(SwiftStdlib 5.0, *) -public protocol Iterable: ~Copyable, ~Escapable { +public protocol BorrowingSequence: ~Copyable, ~Escapable { associatedtype Element: ~Copyable - associatedtype BorrowIterator: BorrowIteratorProtocol & ~Copyable & ~Escapable + associatedtype BorrowingIterator: BorrowingIteratorProtocol & ~Copyable & ~Escapable var isEmpty: Bool { get } var estimatedCount: EstimatedCount { get } @_lifetime(borrow self) - borrowing func startBorrowIteration() -> BorrowIterator + borrowing func makeBorrowingIterator() -> BorrowingIterator func _customContainsEquatableElement( _ element: borrowing Element @@ -35,7 +35,7 @@ public protocol Iterable: ~Copyable, ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable { @inlinable public var underestimatedCount: Int { switch estimatedCount { @@ -55,7 +55,7 @@ extension Iterable where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Iterable where Self: Sequence { +extension BorrowingSequence where Self: Sequence { @inlinable public func _customContainsEquatableElement(_ element: borrowing Element) -> Bool? { nil @@ -63,10 +63,10 @@ extension Iterable where Self: Sequence { } @available(SwiftStdlib 5.0, *) -extension Iterable where Element: Copyable { +extension BorrowingSequence where Element: Copyable { // FIXME: How do we expect this to work for ~Copyable elements? public var first: Element? { - var it = startBorrowIteration() + var it = makeBorrowingIterator() let span = it.nextSpan(maximumCount: 1) guard !span.isEmpty else { return nil } return span[0] @@ -76,13 +76,13 @@ extension Iterable where Element: Copyable { @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable { /// Implementation demo of what borrowing for-in loops would need to expand into. @inlinable public func _borrowingForEach( _ body: (borrowing Element) throws(E) -> Void ) throws(E) -> Void { - var it = startBorrowIteration() + var it = makeBorrowingIterator() while true { let span = it.nextSpan() if span.isEmpty { break } @@ -96,7 +96,7 @@ extension Iterable where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Iterable where Self: ~Copyable & ~Escapable { +extension BorrowingSequence where Self: ~Copyable & ~Escapable { @inlinable public func borrowingReduce( into initial: consuming Result, @@ -120,7 +120,7 @@ extension Iterable where Self: ~Copyable & ~Escapable { result = try next(result, item) } #else - var it = startBorrowIteration() + var it = makeBorrowingIterator() while true { let span = it.nextSpan() if span.isEmpty { break } diff --git a/Sources/ContainersPreview/Producer.swift b/Sources/ContainersPreview/Protocols/Producer.swift similarity index 89% rename from Sources/ContainersPreview/Producer.swift rename to Sources/ContainersPreview/Protocols/Producer.swift index db4c2230..5ce8ce54 100644 --- a/Sources/ContainersPreview/Producer.swift +++ b/Sources/ContainersPreview/Protocols/Producer.swift @@ -25,6 +25,13 @@ public protocol Producer: ~Copyable, ~Escapable { /// always succeeds. associatedtype ProducerError: Error = Never + /// A value less than or equal to the number of remaining items that this + /// producer is able to generate until it reaches its end. + /// + /// The default implementation returns 0. If you provide your own + /// implementation, make sure to compute the value nondestructively. + var underestimatedCount: Int { get } + /// Generate the next batch of items into the supplied output span instance, /// which must have room for at least one new element. /// @@ -44,6 +51,11 @@ public protocol Producer: ~Copyable, ~Escapable { /// method was able to make progress towards filling `target` without hitting /// the end of the underlying sequence. /// + /// If `target` is a full span, this method is allowed to unconditionally + /// return true. Passing an empty span is not a reliable way to test if the + /// producer has reached its end. (Some producers may only be able to detect + /// that they are finished while trying to generate the next item.) + /// /// ### Error handling /// /// This method throws an error to indicate a failure while trying to generate @@ -73,6 +85,7 @@ public protocol Producer: ~Copyable, ~Escapable { /// the end of the underlying sequence. @_lifetime(target: copy target) @_lifetime(self: copy self) + @discardableResult mutating func generate( into target: inout OutputSpan ) throws(ProducerError) -> Bool @@ -146,6 +159,14 @@ public protocol Producer: ~Copyable, ~Escapable { @available(SwiftStdlib 5.0, *) extension Producer where Self: ~Copyable & ~Escapable { + /// A value less than or equal to the number of remaining items that this + /// producer is able to generate until it reaches its end. + /// + /// The default implementation returns 0. If you provide your own + /// implementation, make sure to compute the value nondestructively. + @inline(__always) + public var underestimatedCount: Int { 0 } + /// Skip at most the given number items in the underlying generative sequence, /// decreasing it by the number of items successfully skipped. /// @@ -231,4 +252,17 @@ extension Producer where Self: ~Copyable & ~Escapable { } } +@available(SwiftStdlib 5.0, *) +extension Producer where Self: ~Copyable & ~Escapable { + /// Returns true if the producer has no more elements, consuming it in + /// the process. This is implemented by checking if it is possible to + /// skip one item. + /// + /// This is useful in preconditions. + public consuming func _isAtEnd() throws(ProducerError) -> Bool { + var c = 1 + return try !skip(upTo: &c) + } +} + #endif diff --git a/Sources/ContainersPreview/Ref.swift b/Sources/ContainersPreview/Types/Borrow.swift similarity index 88% rename from Sources/ContainersPreview/Ref.swift rename to Sources/ContainersPreview/Types/Borrow.swift index e3bfc786..f909262b 100644 --- a/Sources/ContainersPreview/Ref.swift +++ b/Sources/ContainersPreview/Types/Borrow.swift @@ -9,13 +9,13 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW import Builtin @available(SwiftStdlib 5.0, *) @frozen @safe -public struct Ref: Copyable, ~Escapable { +public struct Borrow: Copyable, ~Escapable { @usableFromInline package let _pointer: UnsafePointer @@ -68,7 +68,7 @@ extension Optional where Wrapped: ~Copyable /* FIXME: ~Escapable */ { @available(SwiftStdlib 5.0, *) @_lifetime(borrow self) @_addressableSelf - public func borrow() -> Ref? { + public func borrow() -> Borrow? { if self == nil { return nil } @@ -77,7 +77,7 @@ extension Optional where Wrapped: ~Copyable /* FIXME: ~Escapable */ { Builtin.unprotectedAddressOfBorrow(self) ) - return unsafe Ref(unsafeAddress: pointer, borrowing: self) + return unsafe Borrow(unsafeAddress: pointer, borrowing: self) } } #endif diff --git a/Sources/ContainersPreview/Box.swift b/Sources/ContainersPreview/Types/Box.swift similarity index 91% rename from Sources/ContainersPreview/Box.swift rename to Sources/ContainersPreview/Types/Box.swift index 64f37693..a3099914 100644 --- a/Sources/ContainersPreview/Box.swift +++ b/Sources/ContainersPreview/Types/Box.swift @@ -94,8 +94,8 @@ extension Box where T: ~Copyable { @_alwaysEmitIntoClient @_transparent @_lifetime(immortal) - public consuming func leak() -> Mut { - let result = unsafe Mut(unsafeImmortalAddress: _pointer) + public consuming func leak() -> Inout { + let result = unsafe Inout(unsafeImmortalAddress: _pointer) discard self return result } @@ -107,8 +107,8 @@ extension Box where T: ~Copyable { @_alwaysEmitIntoClient @_transparent @_lifetime(borrow self) - public func borrow() -> Ref { - unsafe Ref(unsafeAddress: UnsafePointer(_pointer), borrowing: self) + public func borrow() -> Borrow { + unsafe Borrow(unsafeAddress: UnsafePointer(_pointer), borrowing: self) } #endif @@ -117,8 +117,8 @@ extension Box where T: ~Copyable { @_alwaysEmitIntoClient @_transparent @_lifetime(&self) - public mutating func mutate() -> Mut { - unsafe Mut(unsafeAddress: _pointer, mutating: &self) + public mutating func mutate() -> Inout { + unsafe Inout(unsafeAddress: _pointer, mutating: &self) } #endif } diff --git a/Sources/ContainersPreview/Mut.swift b/Sources/ContainersPreview/Types/Inout.swift similarity index 79% rename from Sources/ContainersPreview/Mut.swift rename to Sources/ContainersPreview/Types/Inout.swift index fcc57f87..a7526630 100644 --- a/Sources/ContainersPreview/Mut.swift +++ b/Sources/ContainersPreview/Types/Inout.swift @@ -2,23 +2,23 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW import Builtin /// A safe mutable reference allowing in-place mutation to an exclusive value. /// -/// In order to get an instance of a `Mut`, one must have exclusive access +/// In order to get an instance of a `Inout`, one must have exclusive access /// to the instance of `Target`. This is achieved through the 'inout' operator, '&'. @frozen @safe -public struct Mut: ~Copyable, ~Escapable { +public struct Inout: ~Copyable, ~Escapable { @usableFromInline package let _pointer: UnsafeMutablePointer @@ -68,7 +68,7 @@ public struct Mut: ~Copyable, ~Escapa } } -extension Mut where Target: ~Copyable { +extension Inout where Target: ~Copyable { /// Dereferences the mutable reference allowing for in-place reads and writes /// to the underlying instance. @_alwaysEmitIntoClient @@ -79,28 +79,38 @@ extension Mut where Target: ~Copyable { } @_transparent - @_lifetime(self: copy self) unsafeMutableAddress { unsafe _pointer } } } + +extension Inout where Target: ~Copyable { + package func _withUnsafeTarget( + _ body: (inout Target) throws(E) -> R + ) throws(E) -> R { + try body(&_pointer.pointee) + } +} + + extension Optional where Wrapped: ~Copyable /* FIXME: ~Escapable */ { @_lifetime(&self) - public mutating func mutate() -> Mut? { + @_alwaysEmitIntoClient + public mutating func mutate() -> Inout? { if self == nil { return nil } let pointer = unsafe UnsafeMutablePointer( Builtin.unprotectedAddressOf(&self)) - return unsafe Mut(unsafeAddress: pointer, mutating: &self) + return unsafe Inout(unsafeAddress: pointer, mutating: &self) } @_lifetime(&self) @_alwaysEmitIntoClient @_transparent - public mutating func insert(_ value: consuming Wrapped) -> Mut { + public mutating func insert(_ value: consuming Wrapped) -> Inout { self = .some(value) return mutate()._consumingUnsafelyUnwrap() } diff --git a/Sources/ContainersPreview/InputSpan.swift b/Sources/ContainersPreview/Types/InputSpan.swift similarity index 93% rename from Sources/ContainersPreview/InputSpan.swift rename to Sources/ContainersPreview/Types/InputSpan.swift index fdf5a979..9eeaebed 100644 --- a/Sources/ContainersPreview/InputSpan.swift +++ b/Sources/ContainersPreview/Types/InputSpan.swift @@ -75,10 +75,10 @@ extension InputSpan where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent internal func _unsafeAddressOfElement( - unchecked index: Index + uncheckedOffset offset: Index ) -> UnsafeMutablePointer { _unsafeRawAddressOfSlot( - uncheckedOffset: index + uncheckedOffset: offset ).assumingMemoryBound(to: Element.self) } } @@ -244,13 +244,13 @@ extension InputSpan where Element: ~Copyable { public subscript(_ index: Index) -> Element { unsafeAddress { precondition(indices.contains(index), "Index out of bounds") - return unsafe UnsafePointer(_unsafeAddressOfElement(unchecked: index)) + return unsafe UnsafePointer(_unsafeAddressOfElement(uncheckedOffset: index)) } @_lifetime(self: copy self) unsafeMutableAddress { precondition(indices.contains(index), "Index out of bounds") - return unsafe _unsafeAddressOfElement(unchecked: index) + return unsafe _unsafeAddressOfElement(uncheckedOffset: index) } } @@ -265,11 +265,11 @@ extension InputSpan where Element: ~Copyable { @_alwaysEmitIntoClient public subscript(unchecked index: Index) -> Element { unsafeAddress { - unsafe UnsafePointer(_unsafeAddressOfElement(unchecked: index)) + unsafe UnsafePointer(_unsafeAddressOfElement(uncheckedOffset: index)) } @_lifetime(self: copy self) unsafeMutableAddress { - unsafe _unsafeAddressOfElement(unchecked: index) + unsafe _unsafeAddressOfElement(uncheckedOffset: index) } } @@ -296,8 +296,8 @@ extension InputSpan where Element: ~Copyable { @_lifetime(self: copy self) public mutating func swapAt(unchecked i: Index, unchecked j: Index) { guard i != j else { return } - let pi = unsafe _unsafeAddressOfElement(unchecked: i) - let pj = unsafe _unsafeAddressOfElement(unchecked: j) + let pi = unsafe _unsafeAddressOfElement(uncheckedOffset: i) + let pj = unsafe _unsafeAddressOfElement(uncheckedOffset: j) let temporary = unsafe pi.move() unsafe pi.initialize(to: pj.move()) unsafe pj.initialize(to: consume temporary) @@ -325,7 +325,7 @@ extension InputSpan where Element: ~Copyable { public mutating func removeFirst() -> Element { precondition(_count > 0, "InputSpan underflow") defer { _count &-= 1 } - return _unsafeAddressOfElement(unchecked: 0).move() + return _unsafeAddressOfElement(uncheckedOffset: 0).move() } /// Remove the last N elements of this span, returning the memory they occupy @@ -354,7 +354,7 @@ extension InputSpan where Element: ~Copyable { @inlinable public mutating func popFirst() -> Element? { guard _count > 0 else { return nil } - let result = unsafe _unsafeAddressOfElement(unchecked: 0).move() + let result = unsafe _unsafeAddressOfElement(uncheckedOffset: 0).move() _count &-= 1 return result } @@ -481,6 +481,26 @@ extension InputSpan where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +extension InputSpan where Element: ~Copyable { + @_alwaysEmitIntoClient + @_lifetime(&self) + public mutating func consumePrefix(upTo n: Int) -> InputSpan { + precondition(n >= 0, "Cannot consume a negative number of elements") + let c = Swift.min(n, self.count) + + let buffer = unsafe _unsafeRawAddressOfSlot( + uncheckedOffset: 0 + ).withMemoryRebound(to: Element.self, capacity: c) { start in + UnsafeMutableBufferPointer(start: start, count: c) + } + _count -= c + return _overrideLifetime( + InputSpan(buffer: buffer, initializedCount: c), + mutating: &self) + } +} + @available(SwiftStdlib 5.0, *) internal func withTemporaryInputSpan( of type: Element.Type, diff --git a/Sources/ContainersPreview/Shared.swift b/Sources/ContainersPreview/Types/Shared.swift similarity index 100% rename from Sources/ContainersPreview/Shared.swift rename to Sources/ContainersPreview/Types/Shared.swift diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index 372dca21..47741132 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -123,12 +123,12 @@ public func expectIterableContents< #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) public func expectIterablesWithEquivalentElements< - I1: Iterable & ~Copyable & ~Escapable, - I2: Iterable & ~Copyable & ~Escapable + I1: BorrowingSequence & ~Copyable & ~Escapable, + I2: BorrowingSequence & ~Copyable & ~Escapable >( - _ left: borrowing I1, - _ right: borrowing I2, - by areEquivalent: (borrowing I1.Element, borrowing I2.Element) -> Bool, + _ left: borrowing S1, + _ right: borrowing S2, + by areEquivalent: (borrowing S1.Element, borrowing S2.Element) -> Bool, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #filePath, @@ -144,11 +144,11 @@ public func expectIterablesWithEquivalentElements< @available(SwiftStdlib 5.0, *) public func expectIterablesWithEqualElements< Element: Equatable, - I1: Iterable & ~Copyable & ~Escapable, - I2: Iterable & ~Copyable & ~Escapable, + I1: BorrowingSequence & ~Copyable & ~Escapable, + I2: BorrowingSequence & ~Copyable & ~Escapable, >( - _ left: borrowing I1, - _ right: borrowing I2, + _ left: borrowing S1, + _ right: borrowing S2, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #filePath, @@ -164,17 +164,17 @@ public func expectIterablesWithEqualElements< @available(SwiftStdlib 5.0, *) public func expectIterableContents< Element: Equatable, - I1: Iterable & ~Copyable & ~Escapable, + I1: BorrowingSequence & ~Copyable & ~Escapable, C2: Collection, >( - _ left: borrowing I1, + _ left: borrowing S1, equalTo right: C2, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line ) { - var it1 = left.startBorrowIteration() + var it1 = left.makeBorrowingIterator() var it2 = right.makeIterator() while true { let span = it1.nextSpan() @@ -205,19 +205,19 @@ public func expectIterableContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) public func expectIterableContents< - I1: Iterable & ~Copyable & ~Escapable, + I1: BorrowingSequence & ~Copyable & ~Escapable, C2: Collection, >( - _ left: borrowing I1, + _ left: borrowing S1, equivalentTo right: C2, - by areEquivalent: (borrowing I1.Element, C2.Element) -> Bool, - printer: (borrowing I1.Element) -> String, + by areEquivalent: (borrowing S1.Element, C2.Element) -> Bool, + printer: (borrowing S1.Element) -> String, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line ) { - var it1 = left.startBorrowIteration() + var it1 = left.makeBorrowingIterator() var it2 = right.makeIterator() var offset = 0 while true { diff --git a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift index a18e6d66..4280134f 100644 --- a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift +++ b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift @@ -16,10 +16,10 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) @inlinable public func checkIterable< - I: Iterable & ~Copyable & ~Escapable, + S: BorrowingSequence & ~Copyable & ~Escapable, Expected: Sequence >( - _ iterable: borrowing I, + _ iterable: borrowing S, expectedContents: Expected, file: StaticString = #filePath, line: UInt = #line @@ -34,10 +34,10 @@ public func checkIterable< @available(SwiftStdlib 5.0, *) @inlinable public func checkIterable< - I: Iterable & ~Copyable & ~Escapable, + S: BorrowingSequence & ~Copyable & ~Escapable, Expected: Sequence >( - _ iterable: borrowing I, + _ iterable: borrowing S, expectedContents: Expected, by areEquivalent: (I.Element, I.Element) -> Bool, file: StaticString = #filePath, @@ -64,7 +64,7 @@ public func checkIterable< let spanShapes: [Range] = { var r: [Range] = [] var pos = 0 - var it = iterable.startBorrowIteration() + var it = iterable.makeBorrowingIterator() while true { let origPos = pos let span = it.nextSpan() @@ -83,7 +83,7 @@ public func checkIterable< // Check that the spans have stable sizes and the expected contents. do { var pos = 0 - var it = iterable.startBorrowIteration() + var it = iterable.makeBorrowingIterator() var spanIndex = 0 while true { let span = it.nextSpan() @@ -104,7 +104,7 @@ public func checkIterable< // Check that we can iterate one by one. do { var pos = 0 - var it = iterable.startBorrowIteration() + var it = iterable.makeBorrowingIterator() while true { let span = it.nextSpan(maximumCount: 1) if span.isEmpty { break } @@ -120,7 +120,7 @@ public func checkIterable< // Check that we can iterate with huge maximum counts do { var pos = 0 - var it = iterable.startBorrowIteration() + var it = iterable.makeBorrowingIterator() var spanIndex = 0 while true { let span = it.nextSpan(maximumCount: Int.max) diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift index 068b47f3..6e220149 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift @@ -36,7 +36,7 @@ public struct StaccatoContainer: ~Copyable { } @available(SwiftStdlib 5.0, *) -public struct _StaccatoBorrowIterator: BorrowIteratorProtocol, ~Escapable { +public struct _StaccatoBorrowingIterator: BorrowingIteratorProtocol, ~Escapable { internal let _contents: Span internal let _spanCounts: [Int] internal let _modulus: Int @@ -78,12 +78,12 @@ public struct _StaccatoBorrowIterator: BorrowIteratorProtoco @available(SwiftStdlib 5.0, *) extension StaccatoContainer: Container where Element: ~Copyable { - public typealias BorrowIterator = _StaccatoBorrowIterator // FIXME rdar://150240032 + public typealias BorrowingIterator = _StaccatoBorrowingIterator // FIXME rdar://150240032 public var isEmpty: Bool { _contents.isEmpty } public var count: Int { _contents.count } - public func startBorrowIteration() -> BorrowIterator { - BorrowIterator(contents: _contents.span, spanCounts: _spanCounts) + public func makeBorrowingIterator() -> BorrowingIterator { + BorrowingIterator(contents: _contents.span, spanCounts: _spanCounts) } } #endif From 70a36c2c47520e111d706320d7697b8e692e41c0 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Sun, 25 Jan 2026 10:56:11 -0800 Subject: [PATCH 21/75] RigidDeque: Another iterative design pass on deque operations - Adopt and embrace Drain and Producer to simplify moving data in and out of deques. - Fully generalized core range replacement primitive using higher-order functions based around InputSpan and OutputSpan --- ....swift => BorrowingIteratorProtocol.swift} | 0 ...owingSequence+Standard Conformances.swift} | 51 +++ ...wift => BorrowingSequence+Utilities.swift} | 0 ...Iterable.swift => BorrowingSequence.swift} | 0 .../Protocols/Producer.swift | 5 +- Sources/DequeModule/Deque/Deque+Testing.swift | 14 +- .../RigidDeque/RigidDeque+Append.swift | 150 ++++---- .../RigidDeque/RigidDeque+Consumption.swift | 147 +++++++ .../RigidDeque/RigidDeque+Container.swift | 49 ++- .../RigidDeque/RigidDeque+Initializers.swift | 86 +++-- .../RigidDeque/RigidDeque+Insertions.swift | 130 +++---- .../RigidDeque/RigidDeque+Prepend.swift | 359 ++++++++++++------ .../RigidDeque/RigidDeque+Replacements.swift | 206 +++++----- .../RigidDeque/RigidDeque+Testing.swift | 10 +- .../DequeModule/RigidDeque/RigidDeque.swift | 27 +- .../DequeModule/UniqueDeque/UniqueDeque.swift | 2 +- Sources/DequeModule/_DequeSlot.swift | 8 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 88 +++-- .../UnsafeBufferPointer+Extras.swift | 25 +- .../UnsafeMutableBufferPointer+Extras.swift | 23 ++ .../{RefTests.swift => BorrowTests.swift} | 4 +- .../{MutTests.swift => InoutTests.swift} | 6 +- .../Assertions+Containers.swift | 12 +- .../AssertionContexts/Assertions.swift | 6 +- .../ConformanceCheckers/CheckContainer.swift | 10 +- .../MinimalTypes/CustomProducer.swift | 46 +++ 26 files changed, 986 insertions(+), 478 deletions(-) rename Sources/ContainersPreview/Protocols/{BorrowIteratorProtocol.swift => BorrowingIteratorProtocol.swift} (100%) rename Sources/ContainersPreview/Protocols/{Iterable+Standard Conformances.swift => BorrowingSequence+Standard Conformances.swift} (68%) rename Sources/ContainersPreview/Protocols/{Iterable+Utilities.swift => BorrowingSequence+Utilities.swift} (100%) rename Sources/ContainersPreview/Protocols/{Iterable.swift => BorrowingSequence.swift} (100%) create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift rename Tests/ContainersTests/{RefTests.swift => BorrowTests.swift} (86%) rename Tests/ContainersTests/{MutTests.swift => InoutTests.swift} (85%) create mode 100644 Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift diff --git a/Sources/ContainersPreview/Protocols/BorrowIteratorProtocol.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift similarity index 100% rename from Sources/ContainersPreview/Protocols/BorrowIteratorProtocol.swift rename to Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift diff --git a/Sources/ContainersPreview/Protocols/Iterable+Standard Conformances.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift similarity index 68% rename from Sources/ContainersPreview/Protocols/Iterable+Standard Conformances.swift rename to Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift index 0131f8ec..52a1162b 100644 --- a/Sources/ContainersPreview/Protocols/Iterable+Standard Conformances.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift @@ -94,5 +94,56 @@ extension Array: BorrowingSequence { } } +@available(SwiftStdlib 6.2, *) +extension Range: BorrowingSequence +where Bound: Strideable, Bound.Stride: SignedInteger +{ + public typealias Element = Bound + + @frozen + public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable { + @usableFromInline + internal var _current: InlineArray<1, Bound> + + @usableFromInline + internal var _end: Bound + + @usableFromInline + internal var _first: Bool + + @inlinable + internal init(_ base: Range) { + self._current = .init(repeating: base.lowerBound) + self._end = base.upperBound + self._first = true + } + @inlinable + @_lifetime(&self) + public mutating func nextSpan(maximumCount: Int) -> Span { + guard _current[0] < _end else { return .init() } + if _first { + _first = false + } else { + _current[0] = _current[0].advanced(by: 1) + } + return _current.span + } + } + + @inlinable + public var estimatedCount: EstimatedCount { + if let count = Int(exactly: lowerBound.distance(to: upperBound)) { + return .exactly(count) + } + return .unknown + } + + public func makeBorrowingIterator() -> BorrowingIterator { + BorrowingIterator(self) + } + + + +} #endif diff --git a/Sources/ContainersPreview/Protocols/Iterable+Utilities.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift similarity index 100% rename from Sources/ContainersPreview/Protocols/Iterable+Utilities.swift rename to Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift diff --git a/Sources/ContainersPreview/Protocols/Iterable.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift similarity index 100% rename from Sources/ContainersPreview/Protocols/Iterable.swift rename to Sources/ContainersPreview/Protocols/BorrowingSequence.swift diff --git a/Sources/ContainersPreview/Protocols/Producer.swift b/Sources/ContainersPreview/Protocols/Producer.swift index 5ce8ce54..c80ef53d 100644 --- a/Sources/ContainersPreview/Protocols/Producer.swift +++ b/Sources/ContainersPreview/Protocols/Producer.swift @@ -164,6 +164,7 @@ extension Producer where Self: ~Copyable & ~Escapable { /// /// The default implementation returns 0. If you provide your own /// implementation, make sure to compute the value nondestructively. + @inlinable @inline(__always) public var underestimatedCount: Int { 0 } @@ -196,8 +197,9 @@ extension Producer where Self: ~Copyable & ~Escapable { /// - Returns: A boolean value indicating whether the operation was able to /// skip at least one item without hitting the end of the underlying /// sequence. + @inlinable @_lifetime(self: copy self) - mutating func skip(upTo n: inout Int) throws(ProducerError) -> Bool { + public mutating func skip(upTo n: inout Int) throws(ProducerError) -> Bool { precondition(n > 0, "Can't skip less than 1 item") let maxBufferSize = 8 return try withTemporaryOutputSpan( @@ -259,6 +261,7 @@ extension Producer where Self: ~Copyable & ~Escapable { /// skip one item. /// /// This is useful in preconditions. + @inlinable public consuming func _isAtEnd() throws(ProducerError) -> Bool { var c = 1 return try !skip(upTo: &c) diff --git a/Sources/DequeModule/Deque/Deque+Testing.swift b/Sources/DequeModule/Deque/Deque+Testing.swift index 0136886b..a101b001 100644 --- a/Sources/DequeModule/Deque/Deque+Testing.swift +++ b/Sources/DequeModule/Deque/Deque+Testing.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -36,8 +36,8 @@ extension Deque { /// /// This property isn't intended to be used outside of `Deque`'s own test /// target. - @_spi(Testing) - public var _capacity: Int { + @usableFromInline + package var _capacity: Int { _storage.capacity } @@ -47,16 +47,16 @@ extension Deque { /// /// This property isn't intended to be used outside of `Deque`'s own test /// target. - @_spi(Testing) - public var _startSlot: Int { + @usableFromInline + package var _startSlot: Int { _storage.startSlot.position } /// Constructs a deque instance of the specified contents and layout. Exposed /// as public to allow exhaustive input/output tests for `Deque`'s members. /// This isn't intended to be used outside of `Deque`'s own test target. - @_spi(Testing) - public init( + @usableFromInline + package init( _capacity capacity: Int, startSlot: Int, contents: some Sequence diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 736cbb3c..3f396bc1 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -27,7 +27,7 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(1) @_alwaysEmitIntoClient - @_transparent + @inline(__always) public mutating func append(_ newElement: consuming Element) { precondition(!isFull, "RigidDeque capacity overflow") _handle.uncheckedAppend(newElement) @@ -44,7 +44,7 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(1) @_alwaysEmitIntoClient - @_transparent + @inline(__always) public mutating func pushLast(_ item: consuming Element) -> Element? { // FIXME: Remove this in favor of a standard algorithm. if isFull { return item } @@ -59,13 +59,13 @@ extension RigidDeque where Element: ~Copyable { /// populating a series of storage regions through repeated calls of the /// specified callback function. /// - /// If the deque does not have sufficient capacity to store the new items, - /// then this triggers a runtime error. + /// If the capacity of the deque isn't sufficient to accommodate the specified + /// number of new elements, then this method triggers a runtime error. /// /// var buffer = RigidDeque(capacity: 20) /// buffer.append(999) /// var i = 0 - /// buffer.append(count: 6) { target in + /// buffer.append(maximumCount: 6) { target in /// while !target.isFull { /// target.append(i) /// i += 1 @@ -83,7 +83,7 @@ extension RigidDeque where Element: ~Copyable { /// var buffer = RigidDeque(capacity: 20) /// buffer.append(999) /// var i = 0 - /// buffer.append(count: 6) { target in + /// buffer.append(maximumCount: 6) { target in /// while !target.isFull, i <= 3 { /// target.append(i) /// i += 1 @@ -92,19 +92,21 @@ extension RigidDeque where Element: ~Copyable { /// // `buffer` now contains [999, 0, 1, 2, 3] /// /// - Parameters - /// - count: The number of items to append to the deque. + /// - maximumCount: The maximum number of items to append to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. /// - /// - Complexity: O(`count`) + /// - Complexity: O(`maximumCount`) in addition to the complexity of the callback + /// invocations. @_alwaysEmitIntoClient + @inline(__always) public mutating func append( - count: Int, + maximumCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition(count >= 0, "Negative count") - precondition(freeCapacity >= count, "RigidDeque capacity overflow") - try _handle.uncheckedAppend(count: count, initializingWith: body) + precondition(freeCapacity >= maximumCount, "RigidDeque capacity overflow") + try _handle.uncheckedAppend(capacity: maximumCount, initializingWith: body) } } @@ -128,10 +130,10 @@ extension RigidDeque where Element: ~Copyable { precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") _handle.uncheckedAppend(moving: items) } - + #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Moves the elements of a input span to the end of this deque, leaving the - /// span empty. + /// Moves the elements of an input span by appending them to the end of + /// this deque, leaving the span empty. /// /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. @@ -151,9 +153,9 @@ extension RigidDeque where Element: ~Copyable { } } #endif - - /// Moves the elements of an output span to the end of this deque, leaving the - /// span empty. + + /// Moves the elements of an output span by appending them to the end of + /// this deque, leaving the span empty. /// /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. @@ -172,57 +174,68 @@ extension RigidDeque where Element: ~Copyable { count = 0 } } - - /// Appends the elements of a given deque to the end of this array by moving - /// them between the containers. On return, the input deque becomes empty, but - /// it is not destroyed, and it preserves its original storage capacity. + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Appends at most `maximumCount` items generated by a producer to the end of + /// this deque. /// - /// If the target deque does not have sufficient capacity to hold all items - /// in the source deque, then this triggers a runtime error. + /// If the target deque does not have sufficient capacity to hold the + /// specified number of new items, then this triggers a runtime error. + /// + /// This operation appends as many items as the producer can generate before + /// either reaching its end (or throwing an error), or filling the specified + /// capacity. This operation only consumes the first `maximumCount` items in the + /// producer; if the producer has more, then they remain available after this + /// method returns. /// /// - Parameters - /// - items: A deque whose items to move to the end of this deque. + /// - maximumCount: The maximum number of items to append to the deque. + /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`items.count`) + /// - Complexity: O(*n*), where *n* is the number of items @_alwaysEmitIntoClient - public mutating func append( - moving items: inout RigidDeque - ) { - // FIXME: Remove this in favor of a generic algorithm over range-replaceable containers - precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") - items._handle.unsafeConsumeAll { source in - self._handle.uncheckedAppend(moving: source) + public mutating func append< + P: Producer & ~Copyable & ~Escapable + >( + maximumCount: Int, + from producer: inout P + ) throws(P.ProducerError) { + try self.append( + maximumCount: maximumCount + ) { target throws(P.ProducerError) in + try producer.generate(into: &target) } } -} - -@available(SwiftStdlib 5.0, *) -extension RigidDeque where Element: ~Copyable { +#endif + #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Appends the elements of a given container to the end of this deque by - /// consuming the source container. - /// - /// If the target deque does not have sufficient capacity to hold all items, - /// then this triggers a runtime error. + /// Appends items generated by a producer to the end of this deque until + /// the deque becomes full or until the producer reaches its end or fails. /// /// - Parameters - /// - items: A container whose contents to move into this deque. + /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`items.count`) + /// - Complexity: O(*n*), where *n* is the number of items appended. @_alwaysEmitIntoClient - public mutating func append( - consuming items: consuming RigidDeque - ) { - // FIXME: Remove this in favor of a generic algorithm over consumable containers - var items = items - self.append(moving: &items) + public mutating func append< + P: Producer & ~Copyable & ~Escapable + >( + from producer: inout P + ) throws(P.ProducerError) { + try self.append( + maximumCount: freeCapacity + ) { target throws(P.ProducerError) in + try producer.generate(into: &target) + } } #endif + } @available(SwiftStdlib 5.0, *) extension RigidDeque /*where Element: Copyable*/ { - /// Copies the elements of a buffer to the end of this deque. + /// Copies the elements of a buffer and append them to the end of this + /// deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. @@ -242,7 +255,8 @@ extension RigidDeque /*where Element: Copyable*/ { _handle.uncheckedAppend(copying: newElements) } - /// Copies the elements of a buffer to the end of this deque. + /// Copies the elements of a buffer and append them to the end of this + /// deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. @@ -259,7 +273,7 @@ extension RigidDeque /*where Element: Copyable*/ { unsafe self.append(copying: UnsafeBufferPointer(newElements)) } - /// Copies the elements of a span to the end of this deque. + /// Copies the elements of a span and append them to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// span, then this triggers a runtime error. @@ -276,19 +290,20 @@ extension RigidDeque /*where Element: Copyable*/ { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - @inlinable - internal mutating func _appendIterable< - I: Iterable & ~Copyable & ~Escapable - >(copying items: borrowing I) { - var it = items.startBorrowIteration() + @_alwaysEmitIntoClient + internal mutating func _append< + S: BorrowingSequence & ~Copyable & ~Escapable + >(copying items: borrowing S) { + var it = items.makeBorrowingIterator() while true { let span = it.nextSpan() if span.isEmpty { break } - append(copying: span) + self.append(copying: span) } } - /// Copies the elements of an iterable to the end of this deque. + /// Copies the elements of a borrowing sequence and append them to the end of + /// this deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. @@ -298,14 +313,15 @@ extension RigidDeque /*where Element: Copyable*/ { /// /// - Complexity: O(*m*), where *m* is the length of `newElements`. @_alwaysEmitIntoClient - public mutating func append & ~Copyable & ~Escapable>( - copying newElements: borrowing I + public mutating func append & ~Copyable & ~Escapable>( + copying newElements: borrowing S ) { - self._appendIterable(copying: newElements) + self._append(copying: newElements) } #endif - /// Copies the elements of a sequence to the end of this deque. + /// Append the elements of a sequence to the end of this deque by copying + /// them. /// /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. @@ -327,7 +343,7 @@ extension RigidDeque /*where Element: Copyable*/ { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Copies the elements of an iterable to the end of this deque. + /// Copies the elements of a borrowing sequence to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. @@ -338,11 +354,11 @@ extension RigidDeque /*where Element: Copyable*/ { /// - Complexity: O(*m*), where *m* is the length of `newElements`. @_alwaysEmitIntoClient public mutating func append< - I: Iterable & Sequence + S: BorrowingSequence & Sequence >( - copying newElements: I + copying newElements: S ) { - self._appendIterable(copying: newElements) + self._append(copying: newElements) } #endif } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift new file mode 100644 index 00000000..06f0e70b --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift @@ -0,0 +1,147 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consume( + _ subrange: Range, + consumingWith consumer: (inout InputSpan) -> Void + ) { + let segments = self._handle.mutableSegments(forOffsets: subrange) + + var span = InputSpan(buffer: segments.first, initializedCount: segments.first.count) + consumer(&span) + _ = consume span + + if let second = segments.second { + var span = InputSpan(buffer: second, initializedCount: second.count) + consumer(&span) + } + } + + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consume>( + _ subrange: R, + consumingWith consumer: (inout InputSpan) -> Void + ) { + consume(subrange.relative(to: indices), consumingWith: consumer) + } + + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consumeAll( + consumingWith consumer: (inout InputSpan) -> Void + ) { + consume(indices, consumingWith: consumer) + } +#endif +} + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consume(_ subrange: Range) -> SubrangeConsumer { + SubrangeConsumer(_base: &self, offsetRange: subrange) + } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consume>( + _ subrange: R + ) -> SubrangeConsumer { + consume(subrange.relative(to: indices)) + } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consumeAll() -> SubrangeConsumer { + consume(indices) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + @frozen + public struct SubrangeConsumer: ~Copyable, ~Escapable { + @usableFromInline + internal var _base: Inout + + @usableFromInline + internal var _offsetRange: Range + + @usableFromInline + internal var _buffer1: UnsafeMutableBufferPointer + + @usableFromInline + internal var _buffer2: UnsafeMutableBufferPointer + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&_base) + internal init(_base: inout RigidDeque, offsetRange: Range) { + let segments = _base._handle.mutableSegments(forOffsets: offsetRange) + self._buffer1 = segments.first + self._buffer2 = segments.second ?? .init(start: nil, count: 0) + self._base = Inout(&_base) + self._offsetRange = offsetRange + } + + @inlinable + deinit { + self._buffer1.deinitialize() + self._buffer2.deinitialize() + // FIXME: This needs to be written as + // self._base[]._handle.closeGap(offsets: self._offsetRange) + // but unfortunately we cannot mutate self in deinit yet. + // Inout's dereferencing operation is necessarily declared mutating + // to avoid exclusivity violations. + self._base._pointer.pointee._handle.closeGap(offsets: self._offsetRange) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque.SubrangeConsumer: Drain { + @inlinable + @_lifetime(&self) + @_lifetime(self: copy self) + public mutating func drainNext(maximumCount: Int) -> InputSpan { + if _buffer1.isEmpty { + if _buffer2.isEmpty { + return .init() + } + swap(&_buffer1, &_buffer2) + } + let buffer = _buffer1._trim(first: maximumCount) + return _overrideLifetime( + InputSpan(buffer: buffer, initializedCount: buffer.count), + mutating: &self) + } +} +#endif + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift index 94fce5f8..bff57969 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -20,41 +20,48 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - public struct BorrowIterator: ~Escapable, BorrowIteratorProtocol { - var currentSegment: Span - var nextSegment: Span + @frozen + public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol { + @usableFromInline + internal var _currentSegment: Span + @usableFromInline + internal var _nextSegment: Span + + @_alwaysEmitIntoClient @_lifetime(borrow deque) internal init(deque: borrowing RigidDeque, iteratedCount: Int = 0) { let segments = deque._handle.segments() - self.currentSegment = _overrideLifetime( + self._currentSegment = _overrideLifetime( Span(_unsafeElements: segments.first), borrowing: deque) - self.nextSegment = _overrideLifetime( + self._nextSegment = _overrideLifetime( Span( _unsafeElements: segments.second ?? UnsafeBufferPointer(start: nil, count: 0)), borrowing: deque) } + @_alwaysEmitIntoClient @_lifetime(copy self) @_lifetime(self: copy self) public mutating func nextSpan(maximumCount: Int) -> Span { - let max = maximumCount - let c = Swift.min(currentSegment.count, max) - let result = currentSegment.extracting(first: c) - if c == currentSegment.count { - currentSegment = nextSegment - nextSegment = Span() + let c = Swift.min(_currentSegment.count, maximumCount) + // FIXME: Define and use Span._trim(first:) + let result = _currentSegment.extracting(first: c) + if c == _currentSegment.count { + _currentSegment = _nextSegment + _nextSegment = Span() } else { - currentSegment = currentSegment.extracting(droppingFirst: c) + _currentSegment = _currentSegment.extracting(droppingFirst: c) } return result } } + @_alwaysEmitIntoClient @_lifetime(borrow self) - public borrowing func startBorrowIteration() -> BorrowIterator { - BorrowIterator(deque: self) + public borrowing func makeBorrowingIterator() -> BorrowingIterator { + BorrowingIterator(deque: self) } #endif } @@ -66,24 +73,28 @@ extension RigidDeque: Container where Element: ~Copyable {} @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - @inlinable @inline(__always) + @_alwaysEmitIntoClient + @inline(__always) public func index(after index: Int) -> Int { index + 1 } - @inlinable @inline(__always) + @_alwaysEmitIntoClient + @inline(__always) public func formIndex(after index: inout Int) { index += 1 } - @inlinable @inline(__always) + @_alwaysEmitIntoClient + @inline(__always) public func index(_ index: Int, offsetBy n: Int) -> Int { index + n } - @inlinable + @_alwaysEmitIntoClient public func formIndex( _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index ) { index._advance(by: &n, limitedBy: limit) } + @_alwaysEmitIntoClient @_lifetime(borrow self) public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index 4d46e7b1..a32848e1 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -20,7 +20,6 @@ import ContainersPreview extension RigidDeque where Element: ~Copyable { /// Creates an empty rigid deque with the specified capacity. @_alwaysEmitIntoClient - @_transparent public init(capacity: Int) { self.init(_handle: .allocate(capacity: capacity)) } @@ -42,16 +41,57 @@ extension RigidDeque where Element: ~Copyable { /// - initializer: A closure that initializes the elements of the new deque. /// - Parameter outputSpan: An `OutputSpan` allowing initialization of the /// deque's initial elements. - @inlinable - public init( + @inlinable @inline(__always) + public init( capacity: Int, - initializingWith initializer: (inout OutputSpan) throws -> Void - ) rethrows { + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) { self.init(_handle: .allocate(capacity: capacity)) - try self.append(count: capacity, initializingWith: initializer) + try self.append(maximumCount: capacity, initializingWith: initializer) } } +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { + /// Creates a new rigid deque taking over the storage of the specified + /// unique deque instance, consuming it in the process. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public init(consuming deque: consuming UniqueDeque) { + self = deque._storage + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Creates a new rigid deque of the specified capacity, populating it with + /// items generated by a given producer. + /// + /// The deque is appended as many items as possible before the producer + /// reaches its end. No more than `capacity` elements are retrieved from the + /// producer. + /// + /// If the producer throws an error during this initializer, then all + /// previously produced items are discarded and the initializer rethrows the + /// error. + /// + /// - Parameters + /// - producer: A producer that generates the items to append to the new + /// deque. + /// + /// - Complexity: O(`capacity`) + public init & ~Copyable & ~Escapable>( + capacity: Int, from producer: inout P + ) throws(P.ProducerError) { + self.init(capacity: capacity) + try self.append(from: &producer) + } +#endif +} + @available(SwiftStdlib 5.0, *) extension RigidDeque /*where Element: Copyable*/ { /// Creates a new deque containing the specified number of a single, @@ -63,6 +103,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// `repeating` parameter. `count` must be zero or greater. /// /// - Complexity: O(`count`) + @inlinable public init(repeating repeatedValue: Element, count: Int) { self.init(capacity: count) _handle.mutableBuffer.initialize(repeating: repeatedValue) @@ -70,35 +111,24 @@ extension RigidDeque /*where Element: Copyable*/ { } } -@available(SwiftStdlib 5.0, *) -extension RigidDeque where Element: ~Copyable { - /// Creates a new rigid deque taking over the storage of the specified - /// unique deque instance, consuming it in the process. - /// - /// - Complexity: O(1) - @inlinable - public init(consuming array: consuming UniqueDeque) { - self = array._storage - } -} @available(SwiftStdlib 5.0, *) extension RigidDeque /*where Element: Copyable*/ { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Creates a new deque with the specified capacity, holding a copy - /// of the contents of a given iterable. + /// of the contents of a given borrowing sequence. /// /// - Parameters: /// - capacity: The storage capacity of the new deque. - /// - contents: An iterable whose contents to copy into the new deque. - /// The iterable must not contain more than `capacity` elements. + /// - contents: A sequence whose contents to copy into the new deque. + /// The sequence must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) public init< - I: Iterable & ~Copyable & ~Escapable + S: BorrowingSequence & ~Copyable & ~Escapable >( capacity: Int, - copying contents: borrowing I + copying contents: borrowing S ) { self.init(capacity: capacity) self.append(copying: contents) @@ -139,19 +169,19 @@ extension RigidDeque /*where Element: Copyable*/ { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Creates a new deque with the specified capacity, holding a copy - /// of the contents of a given iterable. + /// of the contents of a given sequence. /// /// - Parameters: /// - capacity: The storage capacity of the new deque. - /// - contents: An iterable whose contents to copy into the new deque. - /// The iterable must not contain more than `capacity` elements. + /// - contents: A sequence whose contents to copy into the new deque. + /// The sequence must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) public init< - I: Iterable & Sequence + S: BorrowingSequence & Sequence >( capacity: Int, - copying contents: borrowing I + copying contents: borrowing S ) { self.init(capacity: capacity) self.append(copying: contents) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 2f6a16a0..1457d04d 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -37,7 +37,7 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient - @_transparent + @inline(__always) public mutating func insert(_ newElement: consuming Element, at index: Int) { precondition(!isFull, "RigidDeque capacity overflow") precondition(index >= 0 && index <= count, "Index out of bounds") @@ -55,13 +55,13 @@ extension RigidDeque where Element: ~Copyable { /// for the new items. (The direction of the move depends on the location of /// the insertion, minimizing the cost.) /// - /// If the capacity of the array isn't sufficient to accommodate the new - /// elements, then this method triggers a runtime error. + /// If the capacity of the deque isn't sufficient to accommodate the specified + /// number of new elements, then this method triggers a runtime error. /// /// var buffer = RigidDeque(capacity: 20) /// buffer.append([-999, 999]) /// var i = 0 - /// buffer.insert(count: 3, at: 1) { target in + /// buffer.insert(capacity: 3, at: 1) { target in /// while !target.isFull { /// target.append(i) /// i += 1 @@ -69,37 +69,39 @@ extension RigidDeque where Element: ~Copyable { /// } /// // `buffer` now contains [-999, 0, 1, 2, 999] /// - /// The newly prepended items are not guaranteed to form a single contiguous + /// The newly inserted items are not guaranteed to form a single contiguous /// storage region. Therefore, the supplied callback may be invoked multiple /// times to initialize each successive chunk of storage. However, invocations /// cease if the callback fails to fully populate its output span or if /// it throws an error. In such cases, the deque keeps all items that were /// successfully initialized before the callback terminated the prepend. - /// (Partial insertions create a gap in ring buffer storage that needs to be + /// + /// Partial insertions create a gap in ring buffer storage that needs to be /// closed by moving already inserted items to their correct positions given /// the adjusted count. This adds some overhead compared to adding exactly as - /// many items as promised.) + /// many items as promised. /// /// - Parameters: - /// - count: The number of items to insert into the deque. + /// - maximumCount: The maximum number of items to insert into the deque. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. /// - /// - Complexity: O(`self.count` + `count`) - @inlinable + /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity + /// of the callback invocations. + @_alwaysEmitIntoClient + @inline(__always) public mutating func insert( - count: Int, + maximumCount: Int, at index: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { - // FIXME: This does not allow `body` to throw, to prevent having to move the tail twice. Is that okay? precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(count >= 0, "Negative count") - precondition(count <= freeCapacity, "RigidDeque capacity overflow") - try _handle.uncheckedInsert(count: count, at: index, initializingWith: body) + precondition(capacity >= 0, "Cannot insert a negative number of items") + precondition(capacity <= freeCapacity, "RigidDeque capacity overflow") + try _handle.uncheckedInsert(capacity: capacity, at: index, initializingWith: body) } } @@ -130,11 +132,10 @@ extension RigidDeque where Element: ~Copyable { ) { guard !items.isEmpty else { return } var remainder = items - insert(count: items.count, at: index) { target in + insert(maximumCount: items.count, at: index) { target in target.withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( - fromContentsOf: remainder._extracting(first: buffer.count)) - remainder = remainder._extracting(droppingFirst: buffer.count) + fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count } } @@ -201,73 +202,48 @@ extension RigidDeque where Element: ~Copyable { } } - /// Inserts the elements of a given deque into the given position in this - /// deque by moving them between the containers. On return, the input deque - /// becomes empty, but it is not destroyed, and it preserves its original - /// storage capacity. +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Inserts at most `capacity` items generated by a producer into this deque, + /// starting at the given index. /// /// Existing elements in the deque's storage are moved as needed to make room /// for the new items. (The direction of the move depends on the location of /// the insertion, minimizing the cost.) /// - /// If the capacity of the deque isn't sufficient to accommodate the new - /// elements, then this method triggers a runtime error. + /// If the target deque does not have sufficient capacity to hold the + /// specified number of new items, then this triggers a runtime error. /// - /// - Parameters - /// - items: A deque whose contents to move into `self`. + /// This operation inserts as many items as the producer can generate before + /// either reaching `capacity`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `capacity` items left in + /// its underlying sequence, then extra items remain available after this + /// method returns. + /// + /// If the operation inserts fewer than `capacity` items, then it results in + /// a gap in ring buffer storage that needs to be closed by moving some + /// items to their correct positions given the adjusted count. This adds some + /// overhead compared to adding exactly as many items as promised. + /// + /// - Parameters: + /// - capacity: The maximum number of items to insert into the deque. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. + /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`count` + `items.count`) + /// - Complexity: O(`self.count` + `capacity`) @_alwaysEmitIntoClient - public mutating func insert( - moving items: inout RigidDeque, + public mutating func insert< + P: Producer & ~Copyable & ~Escapable + >( + maximumCount: Int, + from producer: inout P, at index: Int - ) { - // FIXME: Remove this in favor of a generic algorithm over consumable containers - insert(count: items.count, at: index) { target in - target.withUnsafeMutableBufferPointer { dst, dstCount in - var remainder = dst - items._handle.unsafeConsumePrefix(upTo: remainder.count) { src in - let c = remainder._moveInitializePrefix(from: src) - dstCount += c - remainder = remainder._extracting(last: c) - } - assert(remainder.isEmpty) - } + ) throws(P.ProducerError) { + try insert(maximumCount: maximumCount, at: index) { target throws(P.ProducerError) in + try producer.generate(into: &target) } } -} - -@available(SwiftStdlib 5.0, *) -extension RigidDeque where Element: ~Copyable { -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Inserts the elements of a given deque into the given position in this - /// deque by consuming the source container. - /// - /// Existing elements in the deque's storage are moved as needed to make room - /// for the new items. (The direction of the move depends on the location of - /// the insertion, minimizing the cost.) - /// - /// If the capacity of the deque isn't sufficient to accommodate the new - /// elements, then this method triggers a runtime error. - /// - /// - Parameters - /// - items: The deque whose contents to move into `self`. - /// - index: The position at which to insert the new items. - /// `index` must be a valid index in the deque. - /// - /// - Complexity: O(`count` + `items.count`) - @_alwaysEmitIntoClient - public mutating func insert( - consuming items: consuming RigidDeque, - at index: Int - ) { - // FIXME: Remove this in favor of a generic algorithm over consumable containers - var items = items - self.insert(moving: &items, at: index) - } -#endif + #endif } @available(SwiftStdlib 5.0, *) @@ -299,7 +275,7 @@ extension RigidDeque /* where Element: Copyable */ { ) { guard newElements.count > 0 else { return } var remainder = newElements - insert(count: remainder.count, at: index) { target in + insert(maximumCount: remainder.count, at: index) { target in target.withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( fromContentsOf: remainder._extracting(first: buffer.count)) @@ -377,8 +353,8 @@ extension RigidDeque /* where Element: Copyable */ { newCount: Int ) { let expectedCount = self.count + newCount - var it = items.startBorrowIteration() - insert(count: newCount, at: index) { target in + var it = items.makeBorrowingIterator() + insert(maximumCount: newCount, at: index) { target in it.copyContents(into: &target) } precondition( @@ -398,10 +374,8 @@ extension RigidDeque /* where Element: Copyable */ { } if done != nil { return } - precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(newCount <= freeCapacity, "RigidDeque capacity overflow") var i = items.startIndex - self._handle.uncheckedInsert(count: newCount, at: index) { target in + self.insert(maximumCount: newCount, at: index) { target in while !target.isFull { target.append(items[i]) items.formIndex(after: &i) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 2f53c3c9..88604923 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -46,7 +46,7 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent public mutating func pushFirst(_ item: consuming Element) -> Element? { - // FIXME: Remove this in favor of a standard algorithm. + // FIXME: Remove this in favor of a standard algorithm. (Or not -- prependable containers may not be worth a protocol) if isFull { return item } prepend(item) return nil @@ -59,8 +59,8 @@ extension RigidDeque where Element: ~Copyable { /// populating a series of storage regions through repeated calls of the /// specified callback function. /// - /// If the deque does not have sufficient capacity to store the new items, - /// then this triggers a runtime error. + /// If the capacity of the deque isn't sufficient to accommodate the specified + /// number of new elements, then this method triggers a runtime error. /// /// var buffer = RigidDeque(capacity: 20) /// buffer.append(999) @@ -79,10 +79,11 @@ extension RigidDeque where Element: ~Copyable { /// cease if the callback fails to fully populate its output span or if /// it throws an error. In such cases, the deque keeps all items that were /// successfully initialized before the callback terminated the prepend. - /// (Partial prepends create a gap in ring buffer storage that needs to be - /// closed by moving newly prepended items to their correct positions given + /// + /// Note: Partial prepends create a gap in ring buffer storage that needs to + /// be closed by moving newly prepended items to their correct positions given /// the adjusted count. This adds some overhead compared to adding exactly as - /// many items as promised.) + /// many items as promised. /// /// var buffer = RigidDeque(capacity: 20) /// buffer.append(999) @@ -96,25 +97,26 @@ extension RigidDeque where Element: ~Copyable { /// // `buffer` now contains [0, 1, 2, 3, 999] /// /// - Parameters - /// - count: The number of items to append to the deque. + /// - maximumCount: The maximum number of items to prepend to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. /// - /// - Complexity: O(`count`) + /// - Complexity: O(`maximumCount`) in addition to the complexity of the callback + /// invocations. @_alwaysEmitIntoClient public mutating func prepend( - count: Int, + maximumCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition(count >= 0, "Negative count") - precondition(freeCapacity >= count, "RigidDeque capacity overflow") - try _handle.uncheckedPrepend(count: count, initializingWith: body) + precondition(maximumCount >= 0, "Negative count") + precondition(freeCapacity >= maximumCount, "RigidDeque capacity overflow") + try _handle.uncheckedPrepend(count: maximumCount, initializingWith: body) } } @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - /// Moves the elements of a buffer to the end of this deque, leaving the + /// Moves the elements of a buffer to the front of this deque, leaving the /// buffer uninitialized. /// /// If the deque does not have sufficient capacity to hold all items in the @@ -133,16 +135,16 @@ extension RigidDeque where Element: ~Copyable { precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") _handle.uncheckedPrepend(moving: items) } - + #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Moves the elements of a input span to the end of this deque, leaving the - /// span empty. + /// Moves the elements of an input span by prepending them to the front of + /// this deque, leaving the span empty. /// /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// /// - Parameters - /// - items: An input span whose contents need to be appended to this deque. + /// - items: An input span whose contents need to be prepended to this deque. /// /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient @@ -156,15 +158,15 @@ extension RigidDeque where Element: ~Copyable { } } #endif - - /// Moves the elements of an output span to the end of this deque, leaving the - /// span empty. + + /// Moves the elements of an output span by prepending them to the front of + /// this deque, leaving the span empty. /// /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// /// - Parameters - /// - items: An output span whose contents need to be appended to this deque. + /// - items: An output span whose contents need to be prepended to this deque. /// /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient @@ -177,58 +179,81 @@ extension RigidDeque where Element: ~Copyable { count = 0 } } - - /// Appends the elements of a given deque to the end of this array by moving - /// them between the containers. On return, the input deque becomes empty, but - /// it is not destroyed, and it preserves its original storage capacity. + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Prepends at most `maximumCount` items generated by a producer to the front of + /// this deque. /// - /// If the target deque does not have sufficient capacity to hold all items - /// in the source deque, then this triggers a runtime error. + /// If the target deque does not have sufficient capacity to hold the + /// specified number of new items, then this triggers a runtime error. + /// + /// This operation prepends as many items as the producer can generate before + /// either reaching its end (or throwing an error), or filling the specified + /// capacity. This operation only consumes the first `maximumCount` items in the + /// producer; if the producer has more, then they remain available after this + /// method returns. + /// + /// Note: Partial prepends create a gap in ring buffer storage that needs to + /// be closed by moving newly prepended items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. /// /// - Parameters - /// - items: A deque whose items to move to the end of this deque. + /// - maximumCount: The maximum number of items to append to the deque. + /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`items.count`) + /// - Complexity: O(`capacity`) @_alwaysEmitIntoClient - public mutating func prepend( - moving items: inout RigidDeque - ) { - // FIXME: Remove this in favor of a generic algorithm over range-replaceable containers - precondition(items.count <= freeCapacity, "RigidDeque capacity overflow") - items._handle.unsafeConsumeAll { source in - self._handle.uncheckedAppend(moving: source) + public mutating func prepend< + P: Producer & ~Copyable & ~Escapable + >( + maximumCount: Int, + from producer: inout P + ) throws(P.ProducerError) { + try self.prepend( + maximumCount: maximumCount + ) { target throws(P.ProducerError) in + try producer.generate(into: &target) } } -} - -@available(SwiftStdlib 5.0, *) -extension RigidDeque where Element: ~Copyable { +#endif + #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Appends the elements of a given container to the end of this deque by - /// consuming the source container. + /// Prepends items generated by a producer to the front of this deque until + /// the deque becomes full or until the producer reaches its end (or fails). /// - /// If the target deque does not have sufficient capacity to hold all items, - /// then this triggers a runtime error. + /// The items are prepended so that the first generated item will be the first + /// item in the resulting deque, with the rest following in order of + /// generation. This generally requires the prepended items to be moved in + /// place at the end of the operation, as their precise number isn't known + /// in advance. If you do know the precise number you intend to prepend, + /// it is preferable to call the `prepend(capacity:from:)` method, as it + /// is able to eliminate this overhead (leading to a constant factor + /// performance improvement). /// /// - Parameters - /// - items: A container whose contents to move into this deque. + /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`items.count`) + /// - Complexity: O(*n*), where *n* is the number of items appended. @_alwaysEmitIntoClient - public mutating func prepend( - consuming items: consuming RigidDeque - ) { - // FIXME: Remove this in favor of a generic algorithm over consumable containers - var items = items - self.append(moving: &items) + public mutating func prepend< + P: Producer & ~Copyable & ~Escapable + >( + from producer: inout P + ) throws(P.ProducerError) { + try self.prepend( + maximumCount: freeCapacity + ) { target throws(P.ProducerError) in + try producer.generate(into: &target) + } } #endif } - @available(SwiftStdlib 5.0, *) extension RigidDeque /*where Element: Copyable*/ { - /// Copies the elements of a buffer to the front of this rigid deque. + /// Copies the elements of a buffer and prepend them to the front of this + /// rigid deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. @@ -249,7 +274,8 @@ extension RigidDeque /*where Element: Copyable*/ { _handle.uncheckedPrepend(copying: newElements) } - /// Copies the elements of a buffer to the front of this rigid deque. + /// Copies the elements of a buffer and prepend them to the front of this + /// deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. @@ -267,7 +293,7 @@ extension RigidDeque /*where Element: Copyable*/ { unsafe self.prepend(copying: UnsafeBufferPointer(newElements)) } - /// Copies the elements of a span to the front of this rigid deque. + /// Copy the elements of a span and prepend them to the front of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// span, then this triggers a runtime error. @@ -284,15 +310,124 @@ extension RigidDeque /*where Element: Copyable*/ { } } - /// Copies the elements of a collection to the front of the rigid deque. +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _prepend< + S: BorrowingSequence & ~Copyable & ~Escapable + >(copying items: borrowing S) { + // We don't know the exact count of new elements, so we cannot initialize + // them in place. Append them to the end of the deque first, then rotate + // them to their correct location. + // + // FIXME: If we get a BorrowingSequence.estimatedCount with an exact case, + // then we should use that when possible to copy items to their final + // location in a single pass. + let oldEndSlot = _handle.endSlot + self._append(copying: items) // Not a typo! + _handle.rotate(toStartAt: oldEndSlot) + } + + @inlinable + internal mutating func _prepend< + S: BorrowingSequence & ~Copyable & ~Escapable + >( + copying items: borrowing S, + exactCount: Int + ) { + var it = items.makeBorrowingIterator() + self.prepend(maximumCount: exactCount) { target in + let span = it.nextSpan(maximumCount: target.freeCapacity) + target._append(copying: span) + } + } + + /// Copies the elements of a borrowing sequence and prepend them to the front + /// of this deque. /// - /// Use this method to prepend the elements of a collection to the front of - /// this deque. This example prepends the elements of a `Range` instance + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// As borrowing sequences do not necessarily provide an exact count, this + /// operation works by first appending the items, then finalizing the + /// prepend by rotating them in place as a postprocessing step. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func prepend & ~Copyable & ~Escapable>( + copying newElements: borrowing S + ) { + self._prepend(copying: newElements) + } + + /// Copies the elements of a container and prepends them to the front + /// of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// container, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(`newElements.count`) + @_alwaysEmitIntoClient + public mutating func prepend & ~Copyable & ~Escapable>( + copying newElements: borrowing C + ) { + self._prepend(copying: newElements, exactCount: newElements.count) + } +#endif + + /// Prepend the elements of a sequence to the front of this deque by copying + /// them. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// This example prepends the elements of a `Range` instance /// to a rigid deque of integers. /// /// var numbers = RigidDeque(capacity: 10) - /// numbers.append(contentsOf: [1, 2, 3, 4, 5]) - /// numbers.prepend(contentsOf: 10...15) + /// numbers.append(copying: [1, 2, 3, 4, 5]) + /// numbers.prepend(copying: 10...15) + /// // `numbers` now contains [10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5] + /// + /// As borrowing sequences do not necessarily provide an exact count, this + /// operation works by first appending the items, then finalizing the + /// prepend by rotating them in place as a postprocessing step. + /// + /// - Parameter newElements: The elements to prepend to the deque. + /// + /// - Complexity: O(`newElements.count`) + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying newElements: some Sequence + ) { + let done: Void? = newElements.withContiguousStorageIfAvailable { source in + unsafe self.prepend(copying: source) + return + } + guard done == nil else { return } + let oldEndSlot = _handle.endSlot + self.append(copying: newElements) // Not a typo! + _handle.rotate(toStartAt: oldEndSlot) + } + + /// Prepend the elements of a collection to the front of this deque by copying + /// them. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// This example prepends the elements of a `Range` instance + /// to a rigid deque of integers. + /// + /// var numbers = RigidDeque(capacity: 10) + /// numbers.append(copying: [1, 2, 3, 4, 5]) + /// numbers.prepend(copying: 10...15) /// // `numbers` now contains [10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5] /// /// - Parameter newElements: The elements to prepend to the deque. @@ -315,24 +450,7 @@ extension RigidDeque /*where Element: Copyable*/ { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - @inlinable - internal mutating func _prependIterable< - I: Iterable & ~Copyable & ~Escapable - >(copying items: borrowing I) { - // We don't know the exact count of new elements, so we cannot initialize - // them in place. Append them to the end of the deque first, then rotate - // them to their correct location. - let oldEndSlot = _handle.endSlot - var it = items.startBorrowIteration() - while true { - let span = it.nextSpan() - if span.isEmpty { break } - prepend(copying: span) - } - _handle.rotate(toStartAt: oldEndSlot) - } - - /// Copies the elements of an iterable to the end of this deque. + /// Copies the elements of a borrowing sequence to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. @@ -342,48 +460,13 @@ extension RigidDeque /*where Element: Copyable*/ { /// /// - Complexity: O(*m*), where *m* is the length of `newElements`. @_alwaysEmitIntoClient - public mutating func prepend & ~Copyable & ~Escapable>( - copying newElements: borrowing I + public mutating func prepend & Sequence>( + copying newElements: borrowing S ) { - self._prependIterable(copying: newElements) + self._prepend(copying: newElements) } -#endif - - /// Copies the elements of a sequence to the front of the rigid deque. - /// - /// Use this method to prepend the elements of a sequence to the front of this - /// deque. This example prepends the elements of a `Range` instance to a - /// rigid deque of integers. - /// - /// var numbers = RigidDeque(capacity: 10) - /// numbers.append(contentsOf: [1, 2, 3, 4, 5]) - /// numbers.prepend(contentsOf: 10...15) - /// print(numbers) - /// // Prints "[10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5]" - /// - /// - Parameter newElements: The elements to prepend to the deque. - /// - /// - Complexity: O(`newElements.count`) - @inlinable - @_alwaysEmitIntoClient - public mutating func prepend(copying newElements: some Sequence) { - let done: Void? = newElements.withContiguousStorageIfAvailable { source in - unsafe self.prepend(copying: source) - return - } - guard done == nil else { return } - - // We don't know the exact count of new elements, so we cannot initialize - // them in place. Append them to the end of the deque first, then rotate - // them to their correct location. - let oldEndSlot = _handle.endSlot - var it = _handle.uncheckedAppend(copyingPrefixOf: newElements) - precondition(it.next() == nil, "RigidDeque capacity overflow") - _handle.rotate(toStartAt: oldEndSlot) - } - -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Copies the elements of an iterable to the end of this deque. + + /// Copies the elements of a borrowing sequence to the end of this deque. /// /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. @@ -393,10 +476,42 @@ extension RigidDeque /*where Element: Copyable*/ { /// /// - Complexity: O(*m*), where *m* is the length of `newElements`. @_alwaysEmitIntoClient - public mutating func prepend & Sequence>( - copying newElements: borrowing I + public mutating func prepend & Collection>( + copying newElements: borrowing S ) { - self._prependIterable(copying: newElements) + self._prepend(copying: newElements, exactCount: newElements.count) + } + + /// Copies the elements of a container to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func prepend & Sequence>( + copying newElements: borrowing C + ) { + self._prepend(copying: newElements, exactCount: newElements.count) + } + + /// Copies the elements of a container to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + public mutating func prepend & Collection>( + copying newElements: borrowing C + ) { + self._prepend(copying: newElements, exactCount: newElements.count) } #endif } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index b5352b54..c42a25f5 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -32,7 +32,7 @@ extension RigidDeque where Element: ~Copyable { /// /// If you pass a zero-length range as the `subrange` parameter, then /// this method is equivalent to calling - /// `insert(count: newCount, at: subrange.lowerBound, initializingWith: body)`. + /// `insert(maximumCount: newCount, at: subrange.lowerBound, initializingWith: body)`. /// /// Likewise, if you pass a zero for `newCount`, then this method /// removes the elements in the given subrange without any replacement. @@ -44,16 +44,17 @@ extension RigidDeque where Element: ~Copyable { /// cease if the callback fails to fully populate its output span or if /// it throws an error. In such cases, the deque keeps all items that were /// successfully initialized before the callback terminated the prepend. - /// (Partial insertions create a gap in ring buffer storage that needs to be + /// + /// Partial insertions create a gap in ring buffer storage that needs to be /// closed by moving newly inserted items to their correct positions given /// the adjusted count. This adds some overhead compared to adding exactly as - /// many items as promised.) + /// many items as promised. /// /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newCount: the number of items to replace the old subrange. - /// - body: A callback that gets called at most twice to directly + /// - maximumCount: the maximum number of items to replace the old subrange. + /// - initializer: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. /// @@ -61,22 +62,91 @@ extension RigidDeque where Element: ~Copyable { @inlinable public mutating func replaceSubrange( _ subrange: Range, - newCount: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Void + maximumCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - // FIXME: Should we have a version of this with two closures, to allow custom-consuming the old items? precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(newCount >= 0, "Negative count") + precondition(maximumCount >= 0, "Can't insert a negative number of items") precondition( - count - subrange.count + newCount <= capacity, + count - subrange.count + maximumCount <= capacity, "RigidDeque capacity overflow") try _handle.uncheckedReplaceSubrange( subrange, - newCount: newCount, - initializingWith: body) + newCount: capacity, + initializingWith: initializer) } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by a given count of new items, + /// using callbacks to consume old items, and to then insert new ones. + /// + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// This method has the same overall effect as calling + /// + /// try deque.consume(subrange, consumingWith: consumer) + /// try deque.insert(maximumCount: maximumCount, at: subrange.lowerBound, initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the deque twice. + /// + /// If the capacity of the deque isn't sufficient to accommodate the specified + /// number of new elements, then this method triggers a runtime error. + /// + /// The removed and newly inserted items are not guaranteed to form a single + /// contiguous storage region. Therefore, the supplied callbacks may be + /// invoked multiple times to consume, then initialize successive chunks of + /// storage. Calls to `consumer` do not get interleaved with calls to + /// `initializer`: no new item is inserted until every replaced item has been + /// consumed. + /// + /// The `initializer` callback is not required to fully populate its + /// output span, and it is allowed to throw an error. In such cases, the + /// deque keeps all items that were successfully initialized before the + /// callback terminated. + /// + /// Partial insertions create a gap in ring buffer storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - maximumCount: the maximum number of items to replace the old subrange. + /// - consumer: A callback that gets called at most twice to consume + /// the elements to be removed directly from the deque's storage. The + /// function is always called with a non-empty input span. + /// - initializer: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity + /// of the callback invocations. + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + maximumCount: Int, + consumingWith consumer: (inout InputSpan) -> Void, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= count, + "Subrange out of bounds") + precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition( + count - subrange.count + maximumCount <= capacity, + "RigidDeque capacity overflow") + try _handle.uncheckedReplaceSubrange( + subrange, + newCount: capacity, + consumingWith: consumer, + initializingWith: initializer) + } +#endif } @available(SwiftStdlib 5.0, *) @@ -115,11 +185,10 @@ extension RigidDeque where Element: ~Copyable { moving newElements: UnsafeMutableBufferPointer, ) { var remainder = newElements - replaceSubrange(subrange, newCount: remainder.count) { target in + replaceSubrange(subrange, maximumCount: remainder.count) { target in target.withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( - fromContentsOf: remainder._extracting(first: buffer.count)) - remainder = remainder._extracting(droppingFirst: buffer.count) + fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count } } @@ -204,60 +273,9 @@ extension RigidDeque where Element: ~Copyable { } } - /// Replaces the specified range of elements by moving the elements of a - /// another deque into their place. On return, the source deque - /// becomes empty, but it is not destroyed, and it preserves its original - /// storage capacity. - /// - /// This method has the effect of removing the specified range of elements - /// from the deque and inserting the new elements starting at the same - /// location. The number of new elements need not match the number of elements - /// being removed. - /// - /// If the capacity of the deque isn't sufficient to accommodate the new - /// elements, then this method triggers a runtime error. - /// - /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case - /// is more directly expressed by calling `insert(moving:at:)`. - /// - /// Likewise, if you pass a zero-length buffer as the `newElements` - /// parameter, this method removes the elements in the given subrange - /// without replacement. This case is more directly expressed by calling - /// `removeSubrange`. - /// - /// - Parameters - /// - subrange: The subrange of the deque to replace. The bounds of - /// the range must be valid indices in the deque. - /// - newElements: A deque whose contents to move into `self`. - /// - /// - Complexity: O(`self.count` + `newElements.count`) - @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, - moving newElements: inout RigidDeque, - ) { - // FIXME: Remove this in favor of a generic algorithm over consumable containers - replaceSubrange(subrange, newCount: newElements.count) { target in - target.withUnsafeMutableBufferPointer { dst, dstCount in - var remainder = dst - newElements._handle.unsafeConsumePrefix(upTo: remainder.count) { src in - let c = remainder._moveInitializePrefix(from: src) - dstCount += c - remainder = remainder._extracting(last: c) - } - assert(remainder.isEmpty) - } - } - } -} - - -@available(SwiftStdlib 5.0, *) -extension RigidDeque where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Replaces the specified range of elements by moving the elements of a - /// given deque into their place, consuming it in the process. + /// Replaces the specified range of elements by at most `capacity` items + /// generated by a producer. /// /// This method has the effect of removing the specified range of elements /// from the deque and inserting the new elements starting at the same @@ -268,27 +286,42 @@ extension RigidDeque where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case - /// is more directly expressed by calling `insert(consuming:at:)`. + /// inserts the items generated by `producer` at `subrange.lowerBound`. This + /// case is more directly expressed by calling `insert(moving:at:)`. /// - /// Likewise, if you pass a zero-length buffer as the `newElements` - /// parameter, this method removes the elements in the given subrange - /// without replacement. This case is more directly expressed by calling - /// `removeSubrange`. + /// Likewise, if the given producer is empty, then this method removes the + /// elements in the given subrange without replacement. This case is more + /// directly expressed by calling `removeSubrange`. + /// + /// This operation inserts as many items as the producer can generate before + /// either reaching `capacity`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `capacity` items left in + /// its underlying sequence, then extra items remain available after this + /// method returns. + /// + /// If the operation inserts fewer than `capacity` items, then it results in + /// a gap in ring buffer storage that needs to be closed by moving some + /// items to their correct positions given the adjusted count. This adds some + /// overhead compared to adding exactly as many items as promised. /// /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newElements: A deque whose contents to move into `self`. + /// - capacity: The maximum number of items to insert into the deque. + /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `capacity`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( + public mutating func replaceSubrange< + P: Producer & ~Copyable & ~Escapable + >( _ subrange: Range, - consuming newElements: consuming RigidDeque, - ) { - // FIXME: Remove this in favor of a generic algorithm over consumable containers - replaceSubrange(subrange, moving: &newElements) + maximumCount: Int, + from producer: inout P + ) throws(P.ProducerError) { + try replaceSubrange(subrange, maximumCount: maximumCount) { target throws(P.ProducerError) in + try producer.generate(into: &target) + } } #endif } @@ -327,11 +360,10 @@ extension RigidDeque /* where Element: Copyable */ { copying newElements: UnsafeBufferPointer ) { var remainder = newElements - replaceSubrange(subrange, newCount: remainder.count) { target in + replaceSubrange(subrange, maximumCount: remainder.count) { target in target.withUnsafeMutableBufferPointer { dst, dstCount in - dst.initializeAll(fromContentsOf: remainder._extracting(first: dst.count)) + dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count - remainder = remainder._extracting(droppingFirst: dst.count) } } assert(remainder.isEmpty) @@ -420,8 +452,8 @@ extension RigidDeque /* where Element: Copyable */ { ) { let expectedCount = self.count - subrange.count + newCount - var it = newElements.startBorrowIteration() - self.replaceSubrange(subrange, newCount: newCount) { target in + var it = newElements.makeBorrowingIterator() + self.replaceSubrange(subrange, maximumCount: newCount) { target in it.copyContents(into: &target) } precondition( @@ -445,7 +477,7 @@ extension RigidDeque /* where Element: Copyable */ { if done != nil { return } var i = newElements.startIndex - self.replaceSubrange(subrange, newCount: newCount) { target in + self.replaceSubrange(subrange, maximumCount: newCount) { target in while !target.isFull { target.append(newElements[i]) newElements.formIndex(after: &i) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift index a4db2f82..cd6a0d12 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Testing.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -27,8 +27,8 @@ extension RigidDeque where Element: ~Copyable { /// /// This property isn't intended to be used outside of `DequeModule`'s own test /// target. - @_spi(Testing) - public var _startSlot: Int { + @usableFromInline + package var _startSlot: Int { _handle.startSlot.position } } @@ -40,8 +40,8 @@ extension RigidDeque { /// /// This initializer isn't intended to be used outside of `DequeModule`'s /// own test target. - @_spi(Testing) - public init( + @usableFromInline + package init( _capacity capacity: Int, startSlot: Int, copying contents: some Sequence diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index 5c32e10e..ef516dba 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -38,22 +38,27 @@ public struct RigidDeque: ~Copyable { internal typealias _Slot = _DequeSlot @usableFromInline - internal typealias _UnsafeHandle = _UnsafeDequeHandle + package typealias _UnsafeHandle = _UnsafeDequeHandle @usableFromInline - internal var _handle: _UnsafeHandle + package var _handle: _UnsafeHandle @_alwaysEmitIntoClient - @_transparent - internal init(_handle: consuming _UnsafeHandle) { + @inline(__always) + package init(_handle: consuming _UnsafeHandle) { self._handle = _handle } - @_alwaysEmitIntoClient - @_transparent + @inlinable + @inline(__always) deinit { _handle.dispose() } + + @inlinable @inline(__always) + internal mutating func _takeHandle() -> _UnsafeHandle { + exchange(&_handle, with: .allocate(capacity: 0)) + } } @available(SwiftStdlib 5.0, *) @@ -83,7 +88,7 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent - public var freeCapacity: Int { _assumeNonNegative(capacity - count) } + public var freeCapacity: Int { _assumeNonNegative(capacity &- count) } @_alwaysEmitIntoClient @_transparent @@ -119,7 +124,7 @@ extension RigidDeque where Element: ~Copyable { /// logical start position. /// /// Valid indices consist of the position of every element and a "past the - /// end” position that’s not valid for use as a subscript argument. + /// end" position that’s not valid for use as a subscript argument. public typealias Index = Int /// A Boolean value indicating whether this deque contains no elements. @@ -161,6 +166,7 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient public subscript(position: Int) -> Element { + // FIXME: Replace with borrow/mutate accessors @inline(__always) @_transparent unsafeAddress { @@ -214,7 +220,6 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient - @_transparent public mutating func reallocate(capacity newCapacity: Int) { _handle.reallocate(capacity: newCapacity) } @@ -238,12 +243,11 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque { - /// Copy the contents of this array into a newly allocated rigid deque + /// Copy the contents of this deque into a newly allocated rigid deque /// instance with just enough capacity to hold all its elements. /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient - @_transparent public func _clone() -> Self { RigidDeque(_handle: _handle.allocateCopy()) } @@ -256,7 +260,6 @@ extension RigidDeque { /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient - @_transparent public func _clone(capacity: Int) -> Self { RigidDeque(_handle: _handle.allocateCopy(capacity: capacity)) } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift index d4bc693c..e9da7ca8 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -31,7 +31,7 @@ public struct UniqueDeque: ~Copyable { @safe public struct UniqueDeque: ~Copyable { @usableFromInline - internal var _storage: RigidDeque + package var _storage: RigidDeque } @available(SwiftStdlib 5.0, *) diff --git a/Sources/DequeModule/_DequeSlot.swift b/Sources/DequeModule/_DequeSlot.swift index dd1a54c3..0a584477 100644 --- a/Sources/DequeModule/_DequeSlot.swift +++ b/Sources/DequeModule/_DequeSlot.swift @@ -11,7 +11,7 @@ @usableFromInline @frozen -internal struct _DequeSlot { +package struct _DequeSlot { @usableFromInline internal var position: Int @@ -44,7 +44,7 @@ extension _DequeSlot { extension _DequeSlot: CustomStringConvertible { @usableFromInline - internal var description: String { + package var description: String { "@\(position)" } } @@ -52,7 +52,7 @@ extension _DequeSlot: CustomStringConvertible { extension _DequeSlot: Equatable { @_alwaysEmitIntoClient @_transparent - static func ==(left: Self, right: Self) -> Bool { + package static func ==(left: Self, right: Self) -> Bool { left.position == right.position } } @@ -60,7 +60,7 @@ extension _DequeSlot: Equatable { extension _DequeSlot: Comparable { @_alwaysEmitIntoClient @_transparent - static func <(left: Self, right: Self) -> Bool { + package static func <(left: Self, right: Self) -> Bool { left.position < right.position } } diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index f3e3a117..612b28c3 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -17,18 +17,18 @@ import ContainersPreview @frozen @usableFromInline @unsafe -internal struct _UnsafeDequeHandle: ~Copyable { +package struct _UnsafeDequeHandle: ~Copyable { @usableFromInline - internal typealias Slot = _DequeSlot + package typealias Slot = _DequeSlot @usableFromInline - internal var _buffer: UnsafeMutableBufferPointer + package var _buffer: UnsafeMutableBufferPointer @usableFromInline - internal var count: Int + package var count: Int @usableFromInline - internal var startSlot: Slot + package var startSlot: Slot @_alwaysEmitIntoClient @_transparent @@ -667,22 +667,21 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// successfully initialized before the callback terminated. /// /// - Parameters - /// - count: The number of items to append to the deque. + /// - capacity: The maximum number of items to append to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is allowed to initialize fewer than `count` items. The deque is /// appended however many items the callback adds to the output span /// before it returns (or before it throws an error). /// - /// - Complexity: O(`count`) + /// - Complexity: O(`capacity`) @_alwaysEmitIntoClient - @_transparent internal mutating func uncheckedAppend( - count: Int, + capacity: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { let origCount = self.count - let gap = self.mutableSegments(forOffsets: origCount ..< origCount + count) + let gap = self.mutableSegments(forOffsets: origCount ..< origCount + capacity) try gap.first._initialize( initializedCount: &self.count, initializingWith: body) if self.count == origCount + gap.first.count, let second = gap.second { @@ -1212,17 +1211,17 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient internal mutating func uncheckedInsert( - count: Int, + capacity: Int, at offset: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { - guard count > 0 else { return } - let gap = self.openGap(ofSize: count, atOffset: offset) + guard capacity > 0 else { return } + let gap = self.openGap(ofSize: capacity, atOffset: offset) var c = 0 defer { - if c < count { - closeGap(offsets: offset + c ..< offset + count) + if c < capacity { + closeGap(offsets: offset + c ..< offset + capacity) } } try gap.first._initialize(initializedCount: &c, initializingWith: body) @@ -1347,20 +1346,14 @@ extension _UnsafeDequeHandle where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient - internal mutating func uncheckedReplaceSubrange( + internal mutating func _insertAfterReplace( _ subrange: Range, newCount: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Void + initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - assert( - subrange.lowerBound >= 0 && subrange.upperBound <= count, - "Subrange out of bounds") - assert(newCount >= 0, "Negative count") - let delta = newCount - subrange.count - assert(count + delta <= capacity, "RigidDeque capacity overflow") - self.mutableSegments(forOffsets: subrange).deinitialize() // Note: we're careful to open/close the gap in a direction that does not // lead to trying to move slots we deinitialized above. + let delta = newCount - subrange.count let left = isLeftLeaning(subrange) if delta > 0 { _ = self.openGap( @@ -1379,9 +1372,52 @@ extension _UnsafeDequeHandle where Element: ~Copyable { closeGap(offsets: newRange.dropFirst(c)) } } - try gap.first._initialize(initializedCount: &c, initializingWith: body) + try gap.first._initialize(initializedCount: &c, initializingWith: initializer) if c == gap.first.count, let second = gap.second { - try second._initialize(initializedCount: &c, initializingWith: body) + try second._initialize(initializedCount: &c, initializingWith: initializer) } } + + @_alwaysEmitIntoClient + internal mutating func uncheckedReplaceSubrange( + _ subrange: Range, + newCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + assert( + subrange.lowerBound >= 0 && subrange.upperBound <= count, + "Subrange out of bounds") + assert(newCount >= 0, "Negative count") + assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") + self.mutableSegments(forOffsets: subrange).deinitialize() + try _insertAfterReplace(subrange, newCount: newCount, initializingWith: initializer) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @_alwaysEmitIntoClient + internal mutating func uncheckedReplaceSubrange( + _ subrange: Range, + newCount: Int, + consumingWith consumer: (inout InputSpan) -> Void, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + assert( + subrange.lowerBound >= 0 && subrange.upperBound <= count, + "Subrange out of bounds") + assert(newCount >= 0, "Negative count") + assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") + do { + let removed = self.mutableSegments(forOffsets: subrange) + var span = InputSpan( + buffer: removed.first, + initializedCount: removed.first.count) + consumer(&span) + if let second = removed.second { + span = InputSpan(buffer: second, initializedCount: second.count) + consumer(&span) + } + } + try _insertAfterReplace(subrange, newCount: newCount, initializingWith: initializer) + } +#endif } diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index 8dcf782a..849dbb98 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -82,7 +82,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) - public func _extracting(droppingFirst maxLength: Int) -> Self { + package func _extracting(droppingFirst maxLength: Int) -> Self { precondition(maxLength >= 0, "Can't have a prefix of negative length") let cut = Swift.min(maxLength, count) return Self(start: baseAddress?.advanced(by: cut), count: count &- cut) @@ -128,10 +128,31 @@ extension UnsafeBufferPointer where Element: ~Copyable { /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) - public func _extracting(droppingLast maxLength: Int) -> Self { + package func _extracting(droppingLast maxLength: Int) -> Self { precondition(maxLength >= 0, "Can't have a prefix of negative length") let newCount = count &- Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } } + +extension UnsafeBufferPointer where Element: ~Copyable { + @_alwaysEmitIntoClient + package mutating func _trim(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let cut = Swift.min(maxLength, count) + guard cut > 0 else { return .init(start: nil, count: 0) } + let oldStart = baseAddress.unsafelyUnwrapped + self = Self(start: oldStart + cut, count: count - cut) + return Self(start: baseAddress, count: cut) + } + + @_alwaysEmitIntoClient + package mutating func _trim(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let cut = Swift.min(maxLength, count) + guard cut > 0 else { return .init(start: nil, count: 0) } + self = .init(start: baseAddress, count: count &- cut) + return Self(start: baseAddress.unsafelyUnwrapped + (count &- cut), count: cut) + } +} diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index 62d40561..6c974ebc 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -138,6 +138,29 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { } } +extension UnsafeMutableBufferPointer where Element: ~Copyable { + @_alwaysEmitIntoClient + @inline(__always) + package mutating func _trim(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let cut = Swift.min(maxLength, count) + guard cut > 0 else { return .init(start: nil, count: 0) } + let oldStart = baseAddress.unsafelyUnwrapped + self = Self(start: oldStart + cut, count: count - cut) + return Self(start: baseAddress, count: cut) + } + + @_alwaysEmitIntoClient + @inline(__always) + package mutating func _trim(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let cut = Swift.min(maxLength, count) + guard cut > 0 else { return .init(start: nil, count: 0) } + self = .init(start: baseAddress, count: count &- cut) + return Self(start: baseAddress.unsafelyUnwrapped + (count &- cut), count: cut) + } +} + extension UnsafeMutableBufferPointer where Element: ~Copyable { @inlinable package func _moveInitializePrefix( diff --git a/Tests/ContainersTests/RefTests.swift b/Tests/ContainersTests/BorrowTests.swift similarity index 86% rename from Tests/ContainersTests/RefTests.swift rename to Tests/ContainersTests/BorrowTests.swift index c23ed74d..7052c467 100644 --- a/Tests/ContainersTests/RefTests.swift +++ b/Tests/ContainersTests/BorrowTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2026 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 @@ -14,7 +14,7 @@ import XCTest import ContainersPreview import Synchronization -final class RefTests: XCTestCase { +final class BorrowTests: XCTestCase { @available(SwiftStdlib 5.0, *) func test_basic() { let x: Atomic? = Atomic(0) diff --git a/Tests/ContainersTests/MutTests.swift b/Tests/ContainersTests/InoutTests.swift similarity index 85% rename from Tests/ContainersTests/MutTests.swift rename to Tests/ContainersTests/InoutTests.swift index a31b204d..9e379ef3 100644 --- a/Tests/ContainersTests/MutTests.swift +++ b/Tests/ContainersTests/InoutTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2024 - 2026 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 @@ -18,10 +18,10 @@ import ContainersPreview #endif #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -final class MutTests: XCTestCase { +final class InoutTests: XCTestCase { func test_basic() { var x = 0 - var y = Mut(&x) + var y = Inout(&x) var v = y[] XCTAssertEqual(v, 0) diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index 47741132..dd34ac07 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -123,8 +123,8 @@ public func expectIterableContents< #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) public func expectIterablesWithEquivalentElements< - I1: BorrowingSequence & ~Copyable & ~Escapable, - I2: BorrowingSequence & ~Copyable & ~Escapable + S1: BorrowingSequence & ~Copyable & ~Escapable, + S2: BorrowingSequence & ~Copyable & ~Escapable >( _ left: borrowing S1, _ right: borrowing S2, @@ -144,8 +144,8 @@ public func expectIterablesWithEquivalentElements< @available(SwiftStdlib 5.0, *) public func expectIterablesWithEqualElements< Element: Equatable, - I1: BorrowingSequence & ~Copyable & ~Escapable, - I2: BorrowingSequence & ~Copyable & ~Escapable, + S1: BorrowingSequence & ~Copyable & ~Escapable, + S2: BorrowingSequence & ~Copyable & ~Escapable, >( _ left: borrowing S1, _ right: borrowing S2, @@ -164,7 +164,7 @@ public func expectIterablesWithEqualElements< @available(SwiftStdlib 5.0, *) public func expectIterableContents< Element: Equatable, - I1: BorrowingSequence & ~Copyable & ~Escapable, + S1: BorrowingSequence & ~Copyable & ~Escapable, C2: Collection, >( _ left: borrowing S1, @@ -205,7 +205,7 @@ public func expectIterableContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) public func expectIterableContents< - I1: BorrowingSequence & ~Copyable & ~Escapable, + S1: BorrowingSequence & ~Copyable & ~Escapable, C2: Collection, >( _ left: borrowing S1, diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift index 9ff39da8..a1c0de77 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift @@ -424,13 +424,13 @@ public func expectThrows( } } -public func expectThrows( +public func expectThrows( _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line, - body: () throws -> T, - errorHandler: (Error) -> Void = { _ in } + body: () throws(E) -> T, + errorHandler: (E) -> Void = { _ in } ) { do { let result = try body() diff --git a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift index 4280134f..c2920bad 100644 --- a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift +++ b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift @@ -17,13 +17,13 @@ import ContainersPreview @inlinable public func checkIterable< S: BorrowingSequence & ~Copyable & ~Escapable, - Expected: Sequence + Expected: Sequence >( _ iterable: borrowing S, expectedContents: Expected, file: StaticString = #filePath, line: UInt = #line -) where I.Element: Equatable { +) where S.Element: Equatable { checkIterable( iterable, expectedContents: expectedContents, @@ -35,14 +35,14 @@ public func checkIterable< @inlinable public func checkIterable< S: BorrowingSequence & ~Copyable & ~Escapable, - Expected: Sequence + Expected: Sequence >( _ iterable: borrowing S, expectedContents: Expected, - by areEquivalent: (I.Element, I.Element) -> Bool, + by areEquivalent: (S.Element, S.Element) -> Bool, file: StaticString = #filePath, line: UInt = #line -) where I.Element: Equatable { +) where S.Element: Equatable { let entry = TestContext.current.push("checkIterable", file: file, line: line) defer { TestContext.current.pop(entry) } diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift new file mode 100644 index 00000000..5f8c34a9 --- /dev/null +++ b/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +package struct CustomProducer: ~Copyable { + package let underestimatedCount: Int + package let generator: () throws(ProducerError) -> Element? + + package init( + underestimatedCount: Int = 0, + generatingWith generator: borrowing @escaping () throws(ProducerError) -> Element? + ) { + self.underestimatedCount = underestimatedCount + self.generator = copy generator + } +} + +@available(SwiftStdlib 5.0, *) +extension CustomProducer: Producer where Element: ~Copyable { + package mutating func generate( + into target: inout OutputSpan + ) throws(ProducerError) -> Bool { + while !target.isFull { + guard let next = try generator() else { return false } + target.append(next) + } + return true + } +} + +#endif From 29b31e5e0d3ca3d85bc1c546aeb16ad2f510c6f3 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Sun, 25 Jan 2026 16:34:10 -0800 Subject: [PATCH 22/75] RigidDeque: Add test coverage; fix issues --- ...rowingSequence+Standard Conformances.swift | 77 +- .../RigidDeque/RigidDeque+Append.swift | 35 +- .../RigidDeque/RigidDeque+Initializers.swift | 23 +- .../RigidDeque/RigidDeque+Prepend.swift | 48 +- .../DequeModule/RigidDeque/RigidDeque.swift | 29 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 33 +- Tests/DequeTests/DequeInternals.swift | 3 +- Tests/DequeTests/RigidDequeCrashTests.swift | 182 +++ .../DequeTests/RigidDequeTests+Testing.swift | 538 -------- Tests/DequeTests/RigidDequeTests+XCTest.swift | 501 ------- Tests/DequeTests/RigidDequeTests.swift | 1223 +++++++++++++++++ .../Assertions+Containers.swift | 96 ++ .../MinimalTypes/CustomProducer.swift | 2 +- .../Utilities/LifetimeTrackedStruct.swift | 46 +- .../Utilities/LifetimeTracker.swift | 20 + 15 files changed, 1693 insertions(+), 1163 deletions(-) create mode 100644 Tests/DequeTests/RigidDequeCrashTests.swift delete mode 100644 Tests/DequeTests/RigidDequeTests+Testing.swift delete mode 100644 Tests/DequeTests/RigidDequeTests+XCTest.swift create mode 100644 Tests/DequeTests/RigidDequeTests.swift diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift index 52a1162b..d43216c7 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift @@ -99,7 +99,7 @@ extension Range: BorrowingSequence where Bound: Strideable, Bound.Stride: SignedInteger { public typealias Element = Bound - + @frozen public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable { @usableFromInline @@ -107,29 +107,31 @@ where Bound: Strideable, Bound.Stride: SignedInteger @usableFromInline internal var _end: Bound - + @usableFromInline - internal var _first: Bool - + internal var _progress: Bool + @inlinable internal init(_ base: Range) { self._current = .init(repeating: base.lowerBound) self._end = base.upperBound - self._first = true + self._progress = false } @inlinable @_lifetime(&self) public mutating func nextSpan(maximumCount: Int) -> Span { - guard _current[0] < _end else { return .init() } - if _first { - _first = false - } else { + if _progress { _current[0] = _current[0].advanced(by: 1) } + guard _current[0] < _end else { + _progress = false + return .init() + } + _progress = true return _current.span } } - + @inlinable public var estimatedCount: EstimatedCount { if let count = Int(exactly: lowerBound.distance(to: upperBound)) { @@ -137,13 +139,64 @@ where Bound: Strideable, Bound.Stride: SignedInteger } return .unknown } - + + @inlinable public func makeBorrowingIterator() -> BorrowingIterator { BorrowingIterator(self) } +} - +@available(SwiftStdlib 6.2, *) +extension ClosedRange: BorrowingSequence +where Bound: Strideable, Bound.Stride: SignedInteger +{ + public typealias Element = Bound + @frozen + public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable { + @usableFromInline + internal var _current: InlineArray<1, Bound> + + @usableFromInline + internal var _last: Bound + + @usableFromInline + internal var _progress: Bool + + @inlinable + internal init(_ base: ClosedRange) { + self._current = .init(repeating: base.lowerBound) + self._last = base.upperBound + self._progress = false + } + @inlinable + @_lifetime(&self) + public mutating func nextSpan(maximumCount: Int) -> Span { + if _progress { + _current[0] = _current[0].advanced(by: 1) + } + guard _current[0] <= _last else { + _progress = false + return .init() + } + _progress = true + return _current.span + } + } + + @inlinable + public var estimatedCount: EstimatedCount { + guard let distance = Int(exactly: lowerBound.distance(to: upperBound)) + else { return .unknown } + let advanced = distance.addingReportingOverflow(1) + guard !advanced.overflow else { return .unknown } + return .exactly(advanced.partialValue) + } + + @inlinable + public func makeBorrowingIterator() -> BorrowingIterator { + BorrowingIterator(self) + } } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 3f396bc1..0c7bd8c3 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -104,9 +104,10 @@ extension RigidDeque where Element: ~Copyable { maximumCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition(count >= 0, "Negative count") + precondition(maximumCount >= 0, "Cannot append a negative number of items") + guard maximumCount > 0 else { return } precondition(freeCapacity >= maximumCount, "RigidDeque capacity overflow") - try _handle.uncheckedAppend(capacity: maximumCount, initializingWith: body) + try _handle.uncheckedAppend(maximumCount: maximumCount, initializingWith: body) } } @@ -189,7 +190,8 @@ extension RigidDeque where Element: ~Copyable { /// method returns. /// /// - Parameters - /// - maximumCount: The maximum number of items to append to the deque. + /// - maximumCount: The maximum number of items to append to the deque, or + /// nil to use all available capacity. /// - producer: A producer that generates the items to append. /// /// - Complexity: O(*n*), where *n* is the number of items @@ -197,39 +199,16 @@ extension RigidDeque where Element: ~Copyable { public mutating func append< P: Producer & ~Copyable & ~Escapable >( - maximumCount: Int, + maximumCount: Int? = nil, from producer: inout P ) throws(P.ProducerError) { try self.append( - maximumCount: maximumCount + maximumCount: maximumCount ?? self.freeCapacity ) { target throws(P.ProducerError) in try producer.generate(into: &target) } } #endif - -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Appends items generated by a producer to the end of this deque until - /// the deque becomes full or until the producer reaches its end or fails. - /// - /// - Parameters - /// - producer: A producer that generates the items to append. - /// - /// - Complexity: O(*n*), where *n* is the number of items appended. - @_alwaysEmitIntoClient - public mutating func append< - P: Producer & ~Copyable & ~Escapable - >( - from producer: inout P - ) throws(P.ProducerError) { - try self.append( - maximumCount: freeCapacity - ) { target throws(P.ProducerError) in - try producer.generate(into: &target) - } - } -#endif - } @available(SwiftStdlib 5.0, *) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index a32848e1..59537579 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -131,7 +131,7 @@ extension RigidDeque /*where Element: Copyable*/ { copying contents: borrowing S ) { self.init(capacity: capacity) - self.append(copying: contents) + self._append(copying: contents) } #endif @@ -184,7 +184,26 @@ extension RigidDeque /*where Element: Copyable*/ { copying contents: borrowing S ) { self.init(capacity: capacity) - self.append(copying: contents) + self._append(copying: contents) + } + + /// Creates a new deque with the specified capacity, holding a copy + /// of the contents of a given sequence. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque. + /// - contents: A sequence whose contents to copy into the new deque. + /// The sequence must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init< + S: BorrowingSequence & Collection + >( + capacity: Int, + copying contents: borrowing S + ) { + self.init(capacity: capacity) + self._append(copying: contents) } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 88604923..0888480f 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -108,9 +108,9 @@ extension RigidDeque where Element: ~Copyable { maximumCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition(maximumCount >= 0, "Negative count") + precondition(maximumCount >= 0, "Cannot prepend a negative number of items") precondition(freeCapacity >= maximumCount, "RigidDeque capacity overflow") - try _handle.uncheckedPrepend(count: maximumCount, initializingWith: body) + try _handle.uncheckedPrepend(maximumCount: maximumCount, initializingWith: body) } } @@ -199,50 +199,22 @@ extension RigidDeque where Element: ~Copyable { /// many items as promised. /// /// - Parameters - /// - maximumCount: The maximum number of items to append to the deque. - /// - producer: A producer that generates the items to append. + /// - maximumCount: The maximum number of items to prepend to the deque, or + /// nil to use all available capacity. + + /// - producer: A producer that generates the items to prepend. /// - /// - Complexity: O(`capacity`) + /// - Complexity: O(`maximumCount ?? self.freeCapacity`) @_alwaysEmitIntoClient + @inline(__always) public mutating func prepend< P: Producer & ~Copyable & ~Escapable >( - maximumCount: Int, + maximumCount: Int? = nil, from producer: inout P ) throws(P.ProducerError) { try self.prepend( - maximumCount: maximumCount - ) { target throws(P.ProducerError) in - try producer.generate(into: &target) - } - } -#endif - -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Prepends items generated by a producer to the front of this deque until - /// the deque becomes full or until the producer reaches its end (or fails). - /// - /// The items are prepended so that the first generated item will be the first - /// item in the resulting deque, with the rest following in order of - /// generation. This generally requires the prepended items to be moved in - /// place at the end of the operation, as their precise number isn't known - /// in advance. If you do know the precise number you intend to prepend, - /// it is preferable to call the `prepend(capacity:from:)` method, as it - /// is able to eliminate this overhead (leading to a constant factor - /// performance improvement). - /// - /// - Parameters - /// - producer: A producer that generates the items to append. - /// - /// - Complexity: O(*n*), where *n* is the number of items appended. - @_alwaysEmitIntoClient - public mutating func prepend< - P: Producer & ~Copyable & ~Escapable - >( - from producer: inout P - ) throws(P.ProducerError) { - try self.prepend( - maximumCount: freeCapacity + maximumCount: maximumCount ?? freeCapacity ) { target throws(P.ProducerError) in try producer.generate(into: &target) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index ef516dba..dd223be5 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -56,7 +56,7 @@ public struct RigidDeque: ~Copyable { } @inlinable @inline(__always) - internal mutating func _takeHandle() -> _UnsafeHandle { + package mutating func _takeHandle() -> _UnsafeHandle { exchange(&_handle, with: .allocate(capacity: 0)) } } @@ -68,12 +68,12 @@ extension RigidDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} extension RigidDeque where Element: ~Copyable { #if COLLECTIONS_INTERNAL_CHECKS @usableFromInline @inline(never) @_effects(releasenone) - internal func _checkInvariants() { + package func _checkInvariants() { _handle._checkInvariants() } #else - @inlinable @inline(__always) - internal func _checkInvariants() {} + @_transparent + package func _checkInvariants() {} #endif // COLLECTIONS_INTERNAL_CHECKS } @@ -95,27 +95,6 @@ extension RigidDeque where Element: ~Copyable { public var isFull: Bool { count == capacity } } -//MARK: - Span creation - -@available(SwiftStdlib 5.0, *) -extension RigidDeque where Element: ~Copyable { - @_alwaysEmitIntoClient - @_transparent - @_lifetime(borrow self) - internal func _span(over slots: Range<_DequeSlot>) -> Span { - let span = Span(_unsafeElements: _handle.buffer(for: slots)) - return _overrideLifetime(span, borrowing: self) - } - - @_alwaysEmitIntoClient - @_transparent - @_lifetime(&self) - internal mutating func _mutableSpan(over slots: Range<_DequeSlot>) -> MutableSpan { - let span = MutableSpan(_unsafeElements: _handle.mutableBuffer(for: slots)) - return _overrideLifetime(span, mutating: &self) - } -} - //MARK: - Container primitives @available(SwiftStdlib 5.0, *) diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 612b28c3..6906f334 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -343,12 +343,12 @@ extension _UnsafeDequeHandle where Element: ~Copyable { guard _buffer.baseAddress != nil else { return .init(._empty) } - let wrap = capacity - startSlot.position + let wrap = capacity &- startSlot.position if count <= wrap { return .init(start: ptr(at: startSlot), count: count) } return .init(first: ptr(at: startSlot), count: wrap, - second: ptr(at: .zero), count: count - wrap) + second: ptr(at: .zero), count: count &- wrap) } @_alwaysEmitIntoClient @@ -361,13 +361,14 @@ extension _UnsafeDequeHandle where Element: ~Copyable { guard _buffer.baseAddress != nil else { return .init(._empty) } - let lower = slot(forOffset: offsets.lowerBound) - let upper = slot(forOffset: offsets.upperBound) - if offsets.count == 0 || lower < upper { - return .init(start: ptr(at: lower), count: offsets.count) + let start = slot(forOffset: offsets.lowerBound) + let wrap = capacity &- start.position + if offsets.count <= wrap { + return .init(start: ptr(at: start), count: offsets.count) } - return .init(first: ptr(at: lower), count: capacity - lower.position, - second: ptr(at: .zero), count: upper.position) + return .init( + first: ptr(at: start), count: capacity &- start.position, + second: ptr(at: .zero), count: offsets.count &- wrap) } @_alwaysEmitIntoClient @@ -677,14 +678,14 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// - Complexity: O(`capacity`) @_alwaysEmitIntoClient internal mutating func uncheckedAppend( - capacity: Int, + maximumCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { - let origCount = self.count - let gap = self.mutableSegments(forOffsets: origCount ..< origCount + capacity) + let gap = self.mutableSegments(forOffsets: count ..< count + maximumCount) + let c = self.count &+ gap.first.count try gap.first._initialize( initializedCount: &self.count, initializingWith: body) - if self.count == origCount + gap.first.count, let second = gap.second { + if self.count == c, let second = gap.second { try second._initialize( initializedCount: &self.count, initializingWith: body) } @@ -737,15 +738,15 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// - Complexity: O(`count`) @_alwaysEmitIntoClient internal mutating func uncheckedPrepend( - count: Int, + maximumCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { - guard let gap = self._prepend(count: count) else { return } + guard let gap = self._prepend(count: maximumCount) else { return } var c = 0 defer { - if c < count { - closeGap(offsets: c ..< count) + if c < maximumCount { + closeGap(offsets: c ..< maximumCount) } } try gap.first._initialize(initializedCount: &c, initializingWith: body) diff --git a/Tests/DequeTests/DequeInternals.swift b/Tests/DequeTests/DequeInternals.swift index 67798119..848d1dba 100644 --- a/Tests/DequeTests/DequeInternals.swift +++ b/Tests/DequeTests/DequeInternals.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -39,6 +39,7 @@ internal struct DequeLayout: Hashable, CustomStringConvertible { self.startValue = startValue } + var freeCapacity: Int { capacity - count } var valueRange: Range { startValue ..< startValue + count } var description: String { diff --git a/Tests/DequeTests/RigidDequeCrashTests.swift b/Tests/DequeTests/RigidDequeCrashTests.swift new file mode 100644 index 00000000..208cbdca --- /dev/null +++ b/Tests/DequeTests/RigidDequeCrashTests.swift @@ -0,0 +1,182 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 - 2026 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 +// +//===----------------------------------------------------------------------===// + +import Testing +#if COLLECTIONS_SINGLE_MODULE +import Collections +#else +import DequeModule +import ContainersPreview +#endif + +#if compiler(>=6.2) +@Suite("RigidDeque Crash Tests") +struct RigidDequeCrashTests { + + // MARK: - Capacity Management + +#if false + @Test("Resize capacity") + func resizeCapacity() { + var deque = RigidDeque(copying: [1, 2, 3]) + #expect(deque.capacity == 3) + + // Increase capacity + deque.resize(to: 10) + #expect(deque.capacity == 10) + #expect(deque.count == 3) + #expect(deque[0] == 1) + #expect(deque[1] == 2) + #expect(deque[2] == 3) + + // Decrease capacity (but still fits existing elements) + deque.resize(to: 5) + #expect(deque.capacity == 5) + #expect(deque.count == 3) + } +#endif + + // MARK: - Edge Cases and Error Conditions + + @Test("Append to full deque fails") + func appendToFullDequeFails() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 2) + deque.append(1) + deque.append(2) + + #expect(deque.isFull == true) + deque.append(3) // Traps with "RigidDeque is full" + } + } + + @Test("Prepend to full deque fails") + func prependToFullDequeFails() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 2) + deque.append(1) + deque.append(2) + + #expect(deque.isFull == true) + deque.prepend(0) // Traps with "RigidDeque is full" + } + } + + #if false + @Test("Resize too small") + func resizeTooSmall() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(repeating: 0, count: 5) + deque.resize(to: 3) + } + } + #endif + + @Test("Invalid index access") + func invalidIndexAccess() async { + await #expect(processExitsWith: .failure) { + let deque = RigidDeque(copying: [1, 2, 3]) + let _ = deque[-1] // Index out of bounds + } + await #expect(processExitsWith: .failure) { + let deque = RigidDeque(copying: [1, 2, 3]) + let _ = deque[3] // Index out of bounds + } + #if false + await #expect(processExitsWith: .failure) { + let deque = RigidDeque(copying: [1, 2, 3]) + let _ = deque.borrowElement(at: 5) // Index out of bounds + } + #endif + } + + @Test("Remove from empty deque") + func removeFromEmptyDeque() async { + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 5) + deque.removeFirst() // Can't remove first element of an empty RigidDeque + } + await #expect(processExitsWith: .failure) { + var deque = RigidDeque(capacity: 5) + deque.removeLast() // Can't remove last element of an empty RigidDeque + } + } + + // MARK: - Mixed Operations + + @Test("Mixed append and prepend operations") + func mixedAppendPrependOperations() { + var deque = RigidDeque(capacity: 10) + + deque.append(5) + deque.prepend(4) + deque.append(6) + deque.prepend(3) + + #expect(deque.count == 4) + #expect(deque[0] == 3) + #expect(deque[1] == 4) + #expect(deque[2] == 5) + #expect(deque[3] == 6) + } + + @Test("Complex operations sequence") + func complexOperationsSequence() { + var deque = RigidDeque(capacity: 20) + + // Initial setup + deque.append(copying: [10, 20, 30]) + deque.prepend(copying: [5, 7]) + #expect(deque.count == 5) + + // Remove some elements + deque.removeFirst() + deque.removeLast() + #expect(deque.count == 3) + #expect(deque[0] == 7) + #expect(deque[1] == 10) + #expect(deque[2] == 20) + } + + // MARK: - Type Safety Tests (Non-Copyable) + + @Test("Non-copyable element type") + func nonCopyableElementType() { + struct NonCopyable: ~Copyable { + let id: Int + init(_ id: Int) { self.id = id } + } + + var deque = RigidDeque(capacity: 5) + deque.append(NonCopyable(1)) + deque.append(NonCopyable(2)) + + #expect(deque.count == 2) + #expect(deque[0].id == 1) + #expect(deque[1].id == 2) + + let removed = deque.removeFirst() + #expect(removed.id == 1) + #expect(deque.count == 1) + } +} + +#else +// RigidDeque requires Swift 6.2+ compiler +@Suite("RigidDeque Tests") +struct RigidDequeTests { + @Test("Compiler version check") + func compilerVersionCheck() { + // This test suite requires Swift 6.2+ for RigidDeque availability + #expect(true, "RigidDeque requires Swift 6.2+ compiler") + } +} +#endif diff --git a/Tests/DequeTests/RigidDequeTests+Testing.swift b/Tests/DequeTests/RigidDequeTests+Testing.swift deleted file mode 100644 index d758d211..00000000 --- a/Tests/DequeTests/RigidDequeTests+Testing.swift +++ /dev/null @@ -1,538 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2025 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 -// -//===----------------------------------------------------------------------===// - -import Testing -#if COLLECTIONS_SINGLE_MODULE -import Collections -#else -import DequeModule -import ContainersPreview -#endif - -#if compiler(>=6.2) -@Suite("RigidDeque Tests") -struct RigidDequeTests_Testing { - // MARK: - Initializers - - @Test("Init with capacity") - func initWithCapacity() { - let deque = RigidDeque(capacity: 5) - #expect(deque.capacity == 5) - #expect(deque.count == 0) - #expect(deque.freeCapacity == 5) - } - - @Test("Init repeating value") - func initRepeatingValue() { - let deque = RigidDeque(repeating: 42, count: 3) - #expect(deque.count == 3) - #expect(deque.capacity == 3) - #expect(deque[0] == 42) - #expect(deque[1] == 42) - #expect(deque[2] == 42) - } - - @Test("Init copying sequence") - func initCopyingSequence() { - let source = [1, 2, 3, 4, 5] - let deque = RigidDeque(capacity: 10, copying: source) - #expect(deque.count == 5) - #expect(deque.capacity == 10) - for i in 0..<5 { - #expect(deque[i] == source[i]) - } - } - - @Test("Init copying collection") - func initCopyingCollection() { - let source = [1, 2, 3, 4, 5] - let deque = RigidDeque(copying: source) - #expect(deque.count == 5) - #expect(deque.capacity == 5) - for i in 0..<5 { - #expect(deque[i] == source[i]) - } - } - - @Test("Init with initializing closure") - func initWithInitializingClosure() { - let deque = RigidDeque(capacity: 5) { span in - span.append(10) - span.append(20) - span.append(30) - } - #expect(deque.count == 3) - #expect(deque.capacity == 5) - #expect(deque[0] == 10) - #expect(deque[1] == 20) - #expect(deque[2] == 30) - } - - // MARK: - Basic Properties - - @Test("Basic properties") - func basicProperties() { - var deque = RigidDeque(capacity: 10) - - // Empty deque - #expect(deque.isEmpty == true) - #expect(deque.isFull == false) - #expect(deque.count == 0) - #expect(deque.capacity == 10) - #expect(deque.freeCapacity == 10) - #expect(deque.startIndex == 0) - #expect(deque.endIndex == 0) - - // Add some elements - deque.append(1) - deque.append(2) - deque.append(3) - - #expect(deque.isEmpty == false) - #expect(deque.isFull == false) - #expect(deque.count == 3) - #expect(deque.capacity == 10) - #expect(deque.freeCapacity == 7) - #expect(deque.startIndex == 0) - #expect(deque.endIndex == 3) - - // Fill to capacity - for i in 4...10 { - deque.append(i) - } - - #expect(deque.isEmpty == false) - #expect(deque.isFull == true) - #expect(deque.count == 10) - #expect(deque.freeCapacity == 0) - } - - // MARK: - Element Access - - @Test("Subscript access") - func subscriptAccess() { - var deque = RigidDeque(copying: [10, 20, 30, 40, 50]) - - // Read access - #expect(deque[0] == 10) - #expect(deque[2] == 30) - #expect(deque[4] == 50) - - // Write access - deque[1] = 99 - #expect(deque[1] == 99) - } - -#if false - @Test("Borrow element") - func borrowElement() { - let deque = RigidDeque(copying: [1, 2, 3]) - let ref = deque.borrowElement(at: 1) - #expect(ref[] == 2) - } - - @Test("Mutate element") - func mutateElement() { - var deque = RigidDeque(copying: [1, 2, 3]) - var mut = deque.mutateElement(at: 1) - mut[] = 99 - #expect(deque[1] == 99) - } -#endif - - // MARK: - Append Operations - - @Test("Append single element") - func appendSingleElement() { - var deque = RigidDeque(capacity: 5) - - deque.append(10) - #expect(deque.count == 1) - #expect(deque[0] == 10) - - deque.append(20) - #expect(deque.count == 2) - #expect(deque[1] == 20) - } - - @Test("PushLast returns element when full") - func pushLastReturnsBehavior() { - var deque = RigidDeque(capacity: 2) - deque.append(1) - deque.append(2) - - let result = deque.pushLast(99) - #expect(result == 99) // Should return the item when full - #expect(deque.count == 2) // Count unchanged - - // When not full, should return nil - let result2 = deque.pushLast(3) // This should fail since deque is full - #expect(result2 == 3) - } - - @Test("Append copying buffer") - func appendCopyingBuffer() { - var deque = RigidDeque(capacity: 10) - let buffer = [1, 2, 3, 4, 5] - - buffer.withUnsafeBufferPointer { ptr in - deque.append(copying: ptr) - } - - #expect(deque.count == 5) - for i in 0..<5 { - #expect(deque[i] == buffer[i]) - } - } - - @Test("Append copying sequence") - func appendCopyingSequence() { - var deque = RigidDeque(capacity: 10) - let source = [1, 2, 3, 4] - - deque.append(copying: source) - - #expect(deque.count == 4) - for i in 0..<4 { - #expect(deque[i] == source[i]) - } - } - - // MARK: - Prepend Operations - - @Test("Prepend single element") - func prependSingleElement() { - var deque = RigidDeque(capacity: 5) - - deque.prepend(10) - #expect(deque.count == 1) - #expect(deque[0] == 10) - - deque.prepend(20) - #expect(deque.count == 2) - #expect(deque[0] == 20) - #expect(deque[1] == 10) - } - - @Test("Prepend copying buffer") - func prependCopyingBuffer() { - var deque = RigidDeque(capacity: 10) - deque.append(5) - - let buffer = [1, 2, 3, 4] - buffer.withUnsafeBufferPointer { ptr in - deque.prepend(copying: ptr) - } - - #expect(deque.count == 5) - #expect(deque[0] == 1) - #expect(deque[1] == 2) - #expect(deque[2] == 3) - #expect(deque[3] == 4) - #expect(deque[4] == 5) - } - - @Test("Prepend copying collection") - func prependCopyingCollection() { - var deque = RigidDeque(capacity: 10) - deque.append(copying: [5, 6]) - - deque.prepend(copying: [1, 2, 3, 4]) - - #expect(deque.count == 6) - #expect(deque[0] == 1) - #expect(deque[1] == 2) - #expect(deque[2] == 3) - #expect(deque[3] == 4) - #expect(deque[4] == 5) - #expect(deque[5] == 6) - } - - @Test("Prepend copying sequence") - func prependCopyingSequence() { - do { - var deque = RigidDeque(capacity: 10) - deque.append(100) - - let seq = stride(from: 10, through: 30, by: 10) - deque.prepend(copying: seq) - - #expect(deque.count == 4) - #expect(deque[0] == 10) - #expect(deque[1] == 20) - #expect(deque[2] == 30) - #expect(deque[3] == 100) - } - - do { - var deque = RigidDeque(repeating: 100, count: 10) - deque.removeFirst(9) - - let seq = stride(from: 10, through: 30, by: 10) - deque.prepend(copying: seq) - - #expect(deque.count == 4) - #expect(deque[0] == 10) - #expect(deque[1] == 20) - #expect(deque[2] == 30) - #expect(deque[3] == 100) - } - } - - // MARK: - Removal Operations - - @Test("Remove at index") - func removeAtIndex() { - var deque = RigidDeque(copying: [10, 20, 30, 40, 50]) - - let removed = deque.remove(at: 2) - #expect(removed == 30) - #expect(deque.count == 4) - #expect(deque[0] == 10) - #expect(deque[1] == 20) - #expect(deque[2] == 40) - #expect(deque[3] == 50) - } - - @Test("Remove subrange") - func removeSubrange() { - var deque = RigidDeque(copying: [1, 2, 3, 4, 5, 6]) - - deque.removeSubrange(1..<4) - #expect(deque.count == 3) - #expect(deque[0] == 1) - #expect(deque[1] == 5) - #expect(deque[2] == 6) - } - - @Test("RemoveFirst operations") - func removeFirstOperations() { - var deque = RigidDeque(copying: [1, 2, 3, 4, 5]) - - // Remove single first - let first = deque.removeFirst() - #expect(first == 1) - #expect(deque.count == 4) - #expect(deque[0] == 2) - - // Remove multiple first - deque.removeFirst(2) - #expect(deque.count == 2) - #expect(deque[0] == 4) - #expect(deque[1] == 5) - } - - @Test("RemoveLast operations") - func removeLastOperations() { - var deque = RigidDeque(copying: [1, 2, 3, 4, 5]) - - // Remove single last - let last = deque.removeLast() - #expect(last == 5) - #expect(deque.count == 4) - #expect(deque[3] == 4) - - // Remove multiple last - deque.removeLast(2) - #expect(deque.count == 2) - #expect(deque[0] == 1) - #expect(deque[1] == 2) - } - - @Test("PopFirst and PopLast") - func popOperations() { - var deque = RigidDeque(copying: [10, 20]) - - // Pop when not empty - let first = deque.popFirst() - #expect(first == 10) - #expect(deque.count == 1) - - let last = deque.popLast() - #expect(last == 20) - #expect(deque.count == 0) - - // Pop when empty - let emptyFirst = deque.popFirst() - let emptyLast = deque.popLast() - #expect(emptyFirst == nil) - #expect(emptyLast == nil) - } - - @Test("Remove all") - func removeAll() { - var deque = RigidDeque(copying: [1, 2, 3, 4, 5]) - - deque.removeAll() - #expect(deque.isEmpty == true) - #expect(deque.count == 0) - #expect(deque.capacity == 5) // Capacity should remain unchanged - } - - // MARK: - Capacity Management - -#if false - @Test("Resize capacity") - func resizeCapacity() { - var deque = RigidDeque(copying: [1, 2, 3]) - #expect(deque.capacity == 3) - - // Increase capacity - deque.resize(to: 10) - #expect(deque.capacity == 10) - #expect(deque.count == 3) - #expect(deque[0] == 1) - #expect(deque[1] == 2) - #expect(deque[2] == 3) - - // Decrease capacity (but still fits existing elements) - deque.resize(to: 5) - #expect(deque.capacity == 5) - #expect(deque.count == 3) - } -#endif - - // MARK: - Edge Cases and Error Conditions - - @Test("Append to full deque fails") - func appendToFullDequeFails() async { - await #expect(processExitsWith: .failure) { - var deque = RigidDeque(capacity: 2) - deque.append(1) - deque.append(2) - - #expect(deque.isFull == true) - deque.append(3) // Traps with "RigidDeque is full" - } - } - - @Test("Prepend to full deque fails") - func prependToFullDequeFails() async { - await #expect(processExitsWith: .failure) { - var deque = RigidDeque(capacity: 2) - deque.append(1) - deque.append(2) - - #expect(deque.isFull == true) - deque.prepend(0) // Traps with "RigidDeque is full" - } - } - - #if false - @Test("Resize too small") - func resizeTooSmall() async { - await #expect(processExitsWith: .failure) { - var deque = RigidDeque(repeating: 0, count: 5) - deque.resize(to: 3) - } - } - #endif - - @Test("Invalid index access") - func invalidIndexAccess() async { - await #expect(processExitsWith: .failure) { - let deque = RigidDeque(copying: [1, 2, 3]) - let _ = deque[-1] // Index out of bounds - } - await #expect(processExitsWith: .failure) { - let deque = RigidDeque(copying: [1, 2, 3]) - let _ = deque[3] // Index out of bounds - } - #if false - await #expect(processExitsWith: .failure) { - let deque = RigidDeque(copying: [1, 2, 3]) - let _ = deque.borrowElement(at: 5) // Index out of bounds - } - #endif - } - - @Test("Remove from empty deque") - func removeFromEmptyDeque() async { - await #expect(processExitsWith: .failure) { - var deque = RigidDeque(capacity: 5) - deque.removeFirst() // Can't remove first element of an empty RigidDeque - } - await #expect(processExitsWith: .failure) { - var deque = RigidDeque(capacity: 5) - deque.removeLast() // Can't remove last element of an empty RigidDeque - } - } - - // MARK: - Mixed Operations - - @Test("Mixed append and prepend operations") - func mixedAppendPrependOperations() { - var deque = RigidDeque(capacity: 10) - - deque.append(5) - deque.prepend(4) - deque.append(6) - deque.prepend(3) - - #expect(deque.count == 4) - #expect(deque[0] == 3) - #expect(deque[1] == 4) - #expect(deque[2] == 5) - #expect(deque[3] == 6) - } - - @Test("Complex operations sequence") - func complexOperationsSequence() { - var deque = RigidDeque(capacity: 20) - - // Initial setup - deque.append(copying: [10, 20, 30]) - deque.prepend(copying: [5, 7]) - #expect(deque.count == 5) - - // Remove some elements - deque.removeFirst() - deque.removeLast() - #expect(deque.count == 3) - #expect(deque[0] == 7) - #expect(deque[1] == 10) - #expect(deque[2] == 20) - } - - // MARK: - Type Safety Tests (Non-Copyable) - - @Test("Non-copyable element type") - func nonCopyableElementType() { - struct NonCopyable: ~Copyable { - let id: Int - init(_ id: Int) { self.id = id } - } - - var deque = RigidDeque(capacity: 5) - deque.append(NonCopyable(1)) - deque.append(NonCopyable(2)) - - #expect(deque.count == 2) - #expect(deque[0].id == 1) - #expect(deque[1].id == 2) - - let removed = deque.removeFirst() - #expect(removed.id == 1) - #expect(deque.count == 1) - } -} - -#else -// RigidDeque requires Swift 6.2+ compiler -@Suite("RigidDeque Tests") -struct RigidDequeTests { - @Test("Compiler version check") - func compilerVersionCheck() { - // This test suite requires Swift 6.2+ for RigidDeque availability - #expect(true, "RigidDeque requires Swift 6.2+ compiler") - } -} -#endif diff --git a/Tests/DequeTests/RigidDequeTests+XCTest.swift b/Tests/DequeTests/RigidDequeTests+XCTest.swift deleted file mode 100644 index 4401f7e9..00000000 --- a/Tests/DequeTests/RigidDequeTests+XCTest.swift +++ /dev/null @@ -1,501 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2025 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 -// -//===----------------------------------------------------------------------===// - -import XCTest -#if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections -#else -import _CollectionsTestSupport -@_spi(Testing) import DequeModule -#endif - -#if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -/// Check if `left` and `right` contain equal elements in the same order. -@available(SwiftStdlib 5.0, *) -internal func expectIterableContents< - Element: Equatable, - C2: Collection, ->( - _ left: borrowing RigidDeque, - equalTo right: C2, - _ message: @autoclosure () -> String = "", - trapping: Bool = false, - file: StaticString = #filePath, - line: UInt = #line -) { - expectIterableContents( - left, - equivalentTo: right, - by: ==, - message(), trapping: trapping, file: file, line: line) -} - -/// Check if `left` and `right` contain equal elements in the same order. -@available(SwiftStdlib 5.0, *) -internal func expectIterableContents< - E1, - C2: Collection, ->( - _ left: borrowing RigidDeque, - equivalentTo right: C2, - by areEquivalent: (borrowing E1, C2.Element) -> Bool, - _ message: @autoclosure () -> String = "", - trapping: Bool = false, - file: StaticString = #filePath, - line: UInt = #line -) { - expectIterableContents( - left, - equivalentTo: right, - by: areEquivalent, - printer: { "\($0)" }, - message(), - file: file, - line: line) -} - -/// Check if `left` and `right` contain equal elements in the same order. -@available(SwiftStdlib 5.0, *) -internal func expectIterableContents< - E1: ~Copyable, - C2: Collection, ->( - _ left: borrowing RigidDeque, - equivalentTo right: C2, - by areEquivalent: (borrowing E1, C2.Element) -> Bool, - printer: (borrowing E1) -> String, - _ message: @autoclosure () -> String = "", - trapping: Bool = false, - file: StaticString = #filePath, - line: UInt = #line -) { - var c = 0 - var j = right.startIndex - for i in 0 ..< left.count { - expectEquivalent( - left[i], - right[j], - by: areEquivalent, - printer: printer, - "offset: \(c) \(message())", - trapping: trapping, - file: file, line: line) - right.formIndex(after: &j) - c += 1 - } -} - -#endif - -final class RigidDequeTests: CollectionTestCase { - func test_testingSPIs() { - // TODO - } - - struct TestError: Error, Equatable { - let value: Int - init(_ value: Int) { self.value = value } - } - - func test_popFirst() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let expected = data.contents[...].popFirst() - let actual = data.deque.popFirst() - expectEqual(actual, expected) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - - func test_popLast() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let expected = data.contents[...].popLast() - let actual = data.deque.popLast() - expectEqual(actual, expected) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - - func test_prependOne() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extra = tracker.instance(for: layout.count) - guard !data.deque.isFull else { return } - data.contents.insert(extra, at: 0) - data.deque.prepend(extra) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - - func test_appendOne() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extra = tracker.instance(for: layout.count) - guard !data.deque.isFull else { return } - data.contents.insert(extra, at: data.contents.count) - data.deque.append(extra) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - - func test_prependManyFromMinimalSequence() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in - withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, prependCount))]) { underestimatedCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) - let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) - data.contents.insert(contentsOf: extras, at: 0) - guard extras.count <= data.deque.freeCapacity else { return } - data.deque.prepend(copying: sequence) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - } - - func test_prependManyFromMinimalCollection() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extra = tracker.instances(for: layout.count ..< layout.count + prependCount) - guard extra.count <= data.deque.freeCapacity else { return } - let minimal = MinimalCollection(extra) - data.contents.insert(contentsOf: extra, at: 0) - data.deque.prepend(copying: minimal) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_prependManyFromContiguousArray_asCollection() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + prependCount - let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } - data.contents.insert(contentsOf: extra, at: 0) - data.deque.prepend(copying: extra) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_prependManyFromContiguousArray_asSequence() { - // This calls the Sequence-based `Deque.prepend` overload, even if - // `elements` happens to be of a Collection type. - func prependSequence( - contentsOf elements: S, - to deque: inout RigidDeque - ) { - deque.prepend(copying: elements) - } - - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + prependCount - let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } - data.contents.insert(contentsOf: extra, at: 0) - prependSequence(contentsOf: extra, to: &data.deque) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_prependManyFromBridgedArray() { - // https://github.com/apple/swift-collections/issues/27 - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in - var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } - var deque = RigidDeque(layout: layout, contents: contents) - guard appendCount <= deque.freeCapacity else { return } - let extra: [NSObject] = (0 ..< appendCount) - .map { _ in NSObject() } - .withUnsafeBufferPointer { buffer in - NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] - } - guard extra.count <= deque.freeCapacity else { return } - contents.insert(contentsOf: extra, at: 0) - deque.prepend(copying: extra) - expectIterableContents( - deque, - equivalentTo: contents, - by: ==, - printer: { "\($0)" }) - } - } - } - - func test_appendManyFromMinimalSequence() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in - withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, appendCount))]) { underestimatedCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extras = tracker.instances(for: layout.count ..< layout.count + appendCount) - let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) - data.contents.append(contentsOf: extras) - guard extras.count <= data.deque.freeCapacity else { return } - data.deque.append(copying: sequence) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - } - - func test_appendManyFromMinimalCollection() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extra = tracker.instances(for: layout.count ..< layout.count + appendCount) - guard extra.count <= data.deque.freeCapacity else { return } - let minimal = MinimalCollection(extra) - data.contents.append(contentsOf: extra) - data.deque.append(copying: minimal) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_appendManyFromContiguousArray_asCollection() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + appendCount - let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } - data.contents.append(contentsOf: extra) - data.deque.append(copying: extra) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_appendManyFromContiguousArray_asSequence() { - // This calls the Sequence-based `Deque.append` overload, even if - // `elements` happens to be of a Collection type. - func appendSequence( - contentsOf elements: S, - to deque: inout RigidDeque - ) { - deque.append(copying: elements) - } - - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + appendCount - let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } - data.contents.append(contentsOf: extra) - appendSequence(contentsOf: extra, to: &data.deque) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_appendManyFromBridgedArray() { - // https://github.com/apple/swift-collections/issues/27 - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in - var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } - var deque = RigidDeque(layout: layout, contents: contents) - guard appendCount <= deque.freeCapacity else { return } - let extra: [NSObject] = (0 ..< appendCount) - .map { _ in NSObject() } - .withUnsafeBufferPointer { buffer in - NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] - } - guard extra.count <= deque.freeCapacity else { return } - contents.append(contentsOf: extra) - deque.append(copying: extra) - expectIterableContents( - deque, - equivalentTo: contents, - by: ==, - printer: { "\($0)" }) - } - } - } - - func test_insertOneElement() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("offset", in: 0 ... layout.count) { offset in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let extra = tracker.instance(for: layout.count) - guard !data.deque.isFull else { return } - data.contents.insert(extra, at: offset) - data.deque.insert(extra, at: offset) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - -// func test_insertFromMinimalCollection() { -// withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in -// withEvery("offset", in: 0 ... layout.count) { offset in -// withEvery("insertCount", in: 0 ..< 10) { insertCount in -// withLifetimeTracking { tracker in -// var data = tracker.rigidDeque(with: layout) -// let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) -// let minimal = MinimalCollection(extras) -// data.contents.insert(contentsOf: extras, at: offset) -// data.deque.insert(contentsOf: minimal, at: offset) -// expectIterableContents(data.deque, equalTo: data.contents) -// } -// } -// } -// } -// } -// -// func test_insertFromArray() { -// withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in -// withEvery("offset", in: 0 ... layout.count) { offset in -// withEvery("insertCount", in: 0 ..< 10) { insertCount in -// withLifetimeTracking { tracker in -// var data = tracker.rigidDeque(with: layout) -// let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) -// data.contents.insert(contentsOf: extras, at: offset) -// data.deque.insert(contentsOf: extras, at: offset) -// expectIterableContents(data.deque, equalTo: data.contents) -// } -// } -// } -// } -// } - - func test_removeOne() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("offset", in: 0 ..< layout.count) { offset in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let expected = data.contents.remove(at: offset) - let actual = data.deque.remove(at: offset) - expectEqual(actual, expected) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_removeSubrange() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEveryRange("range", in: 0 ..< layout.count) { range in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - data.contents.removeSubrange(range) - data.deque.removeSubrange(range) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_removeLast() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - guard layout.count > 0 else { return } - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let expected = data.contents.removeLast() - let actual = data.deque.removeLast() - expectEqual(actual, expected) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - - func test_removeLast_many() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - guard layout.count > 0 else { return } - withEvery("n", in: 0 ... layout.count) { n in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - data.contents.removeLast(n) - data.deque.removeLast(n) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_removeFirst_one() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - guard layout.count > 0 else { return } - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - let expected = data.contents.removeFirst() - let actual = data.deque.removeFirst() - expectEqual(actual, expected) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - - func test_removeFirst_many() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - guard layout.count > 0 else { return } - withEvery("n", in: 0 ... layout.count) { n in - withLifetimeTracking { tracker in - var data = tracker.rigidDeque(with: layout) - data.contents.removeFirst(n) - data.deque.removeFirst(n) - expectIterableContents(data.deque, equalTo: data.contents) - } - } - } - } - - func test_removeAll_keepingCapacity() { - withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("isShared", in: [false, true]) { isShared in - guard layout.count > 0 else { return } - var data: RigidTestData> = .init(.init(capacity: 0), []) - withLifetimeTracking { tracker in - data = tracker.rigidDeque(with: layout) - data.contents.removeAll(keepingCapacity: true) - data.deque.removeAll() - expectEqual(data.deque.count, 0) - expectEqual(data.deque.capacity, layout.capacity) - } // All elements must be deinitialized at this point. - withExtendedLifetime(data.deque) {} - } - } - } -} diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests.swift new file mode 100644 index 00000000..5b176738 --- /dev/null +++ b/Tests/DequeTests/RigidDequeTests.swift @@ -0,0 +1,1223 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 - 2026 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 +// +//===----------------------------------------------------------------------===// + +import XCTest +#if COLLECTIONS_SINGLE_MODULE +@_spi(Testing) import Collections +#else +import _CollectionsTestSupport +import DequeModule +import BasicContainers +import ContainersPreview +#endif + +#if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +internal func expectIterableContents< + Element: Equatable, + C2: Collection, +>( + _ left: borrowing RigidDeque, + equalTo right: C2, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + expectIterableContents( + left, + equivalentTo: right, + by: ==, + message(), trapping: trapping, file: file, line: line) +} + +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +internal func expectIterableContents< + E1, + C2: Collection, +>( + _ left: borrowing RigidDeque, + equivalentTo right: C2, + by areEquivalent: (borrowing E1, C2.Element) -> Bool, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + expectIterableContents( + left, + equivalentTo: right, + by: areEquivalent, + printer: { "\($0)" }, + message(), + file: file, + line: line) +} + +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +internal func expectIterableContents< + E1: ~Copyable, + C2: Collection, +>( + _ left: borrowing RigidDeque, + equivalentTo right: C2, + by areEquivalent: (borrowing E1, C2.Element) -> Bool, + printer: (borrowing E1) -> String, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + var c = 0 + var j = right.startIndex + for i in 0 ..< left.count { + expectEquivalent( + left[i], + right[j], + by: areEquivalent, + printer: printer, + "offset: \(c) \(message())", + trapping: trapping, + file: file, line: line) + right.formIndex(after: &j) + c += 1 + } +} + +#endif + +final class RigidDequeTests: CollectionTestCase { + struct TestError: Error, Equatable { + let value: Int + init(_ value: Int) { self.value = value } + } + + func test_testingSPIs() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + let data = tracker.rigidDeque(with: layout) + expectEqual(data.deque._startSlot, layout.startSlot) + expectEqual(data.deque.capacity, layout.capacity) + expectEqual(data.deque.count, layout.count) + expectEqual(data.deque.freeCapacity, layout.capacity - layout.count) + for i in 0 ..< layout.count { + expectEqual(data.deque[i], data.contents[i]) + } + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + + func test_basicProperties() { + var deque = RigidDeque(capacity: 10) + + // Empty deque + expectEqual(deque.isEmpty, true) + expectEqual(deque.isFull, false) + expectEqual(deque.count, 0) + expectEqual(deque.capacity, 10) + expectEqual(deque.freeCapacity, 10) + expectEqual(deque.startIndex, 0) + expectEqual(deque.endIndex, 0) + expectEqual(deque.indices, 0 ..< 0) + + // Add some elements + deque.append(1) + deque.append(2) + deque.append(3) + + expectEqual(deque.isEmpty, false) + expectEqual(deque.isFull, false) + expectEqual(deque.count, 3) + expectEqual(deque.capacity, 10) + expectEqual(deque.freeCapacity, 7) + expectEqual(deque.startIndex, 0) + expectEqual(deque.endIndex, 3) + expectEqual(deque.indices, 0 ..< 3) + + // Fill to capacity + for i in 4...10 { + deque.append(i) + } + + expectEqual(deque.isEmpty, false) + expectEqual(deque.isFull, true) + expectEqual(deque.count, 10) + expectEqual(deque.freeCapacity, 0) + expectEqual(deque.indices, 0 ..< 10) + } + + func test_subscriptBorrow() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + let data = tracker.rigidDeque(with: layout) + withEvery("i", in: 0 ..< layout.count) { i in + expectEqual(data.deque[i], data.contents[i]) + } + } + } + } + + func test_subscriptMutate() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("i", in: 0 ..< layout.count) { i in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let new = tracker.instance(for: 100) + data.deque[i] = new + data.contents[i] = new + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_swapAt() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + withEvery("i", in: 0 ..< layout.count) { i in + withEvery("j", in: 0 ..< layout.count) { j in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.deque.swapAt(i, j) + data.contents.swapAt(i, j) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } + + func test_reallocate() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery( + "newCapacity", + in: [layout.capacity, layout.count, 2 * layout.capacity] as Set + ) { newCapacity in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.deque.reallocate(capacity: newCapacity) + + expectEqual(data.deque.capacity, newCapacity) + expectEqual(data.deque.count, layout.count) + expectEqual(tracker.instances, layout.count) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_reserveCapacity() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery( + "newCapacity", + in: [layout.capacity, layout.count, 2 * layout.capacity] as Set + ) { newCapacity in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.deque.reserveCapacity(newCapacity) + + expectEqual(data.deque.capacity, Swift.max(layout.capacity, newCapacity)) + expectEqual(data.deque.count, layout.count) + expectEqual(tracker.instances, layout.count) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_initWithCapacity() { + withEvery("capacity", in: [0, 1, 2, 3, 5, 10]) { capacity in + let deque = RigidDeque(capacity: capacity) + expectEqual(deque.capacity, capacity) + expectEqual(deque.count, 0) + expectEqual(deque.freeCapacity, capacity) + if capacity == 0 { + expectNil(deque._handle._buffer.baseAddress) // No allocations + } + } + } + + func test_initEmpty() { + let deque = RigidDeque() + expectEqual(deque.capacity, 0) + expectEqual(deque.count, 0) + expectEqual(deque.freeCapacity, 0) + expectNil(deque._handle._buffer.baseAddress) // No allocations + } + + func test_initWithClosure_Full() { + withEvery("capacity", in: 0 ..< 10) { capacity in + withLifetimeTracking { tracker in + let deque = RigidDeque(capacity: capacity) { span in + for i in 0 ..< capacity { + span.append(tracker.structInstance(for: i)) + } + } + expectEqual(deque.count, capacity) + expectEqual(deque.capacity, capacity) + withEvery("i", in: 0 ..< capacity) { i in + expectEqual(deque[i].payload, i) + } + + expectEqual(tracker.instances, capacity) + _ = consume deque + expectEqual(tracker.instances, 0) + } + } + } + + func test_initWithClosure_Partial() { + withEvery("capacity", in: 0 ..< 10) { capacity in + withEvery("count", in: [0, capacity / 2, max(capacity - 1, 0)] as Set) { count in + withLifetimeTracking { tracker in + let deque = RigidDeque(capacity: capacity) { span in + for i in 0 ..< count { + span.append(tracker.structInstance(for: i)) + } + } + expectEqual(deque.count, count) + expectEqual(deque.capacity, capacity) + withEvery("i", in: 0 ..< count) { i in + expectEqual(deque[i].payload, i) + } + + expectEqual(tracker.instances, count) + _ = consume deque + expectEqual(tracker.instances, 0) + } + } + } + } + + func test_initWithClosure_Failing() { + withEvery("capacity", in: 1 ..< 10 as Range) { capacity -> Void in + withEvery("count", in: [0, capacity / 2, max(capacity - 1, 0)] as Set) { count -> Void in + withLifetimeTracking { tracker -> Void in + expectThrows { () throws(TestError) -> Void in + let deque = try RigidDeque>( + capacity: capacity + ) { span throws(TestError) -> Void in + for i in 0 ..< count { + span.append(tracker.structInstance(for: i)) + } + expectEqual(tracker.instances, count) + throw TestError(42) + } + expectEqual(deque.count, count) + } + errorHandler: { error in + expectEqual(error.value, 42) + } + } + } + } + } + + func test_init_consumingUniqueDeque() { + withLifetimeTracking { tracker in + let ud = UniqueDeque(copying: tracker.instances(for: 0 ..< 10)) + expectEqual(ud.count, 10) + expectEqual(tracker.instances, 10) + let buffer = ud._storage._handle._buffer + expectNotNil(buffer.baseAddress) + + let rd = RigidDeque(consuming: ud) + expectEqual(rd.count, 10) + expectEqual(tracker.instances, 10) + expectEqual(rd._handle._buffer.baseAddress, buffer.baseAddress) + + _ = consume rd + expectEqual(tracker.instances, 0) + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_initFromProducer() { + withEvery("count", in: 0 ..< 10) { count in + withEvery("capacity", in: [count / 2, count, 2 * count] as Set) { capacity in + withLifetimeTracking { tracker in + var invocations = 0 + var producer = CustomProducer, Never> { + if invocations >= count { + return nil + } + defer { invocations += 1 } + return tracker.structInstance(for: invocations) + } + + let c = min(count, capacity) + let deque = RigidDeque(capacity: capacity, from: &producer) + expectEqual(invocations, c) + expectEqual(deque.count, c) + expectEqual(tracker.instances, c) + expectEqual(invocations, c) + + for i in 0 ..< c { + expectEqual(deque[i].payload, i) + } + } + } + } + } + + func test_initFromThrowingProducer() { + withEvery("count", in: 0 ..< 10) { (count: Int) in + withLifetimeTracking { tracker in + var invocations = 0 + var producer = CustomProducer, TestError> + { () throws(TestError) in + if invocations >= count { + throw TestError(42) + } + defer { invocations += 1 } + return tracker.structInstance(for: invocations) + } + + expectThrows { () throws(TestError) in + let _ = try RigidDeque(capacity: count + 10, from: &producer) + } + errorHandler: { error in + expectEqual(error.value, 42) + } + expectEqual(invocations, count) + } + } + } +#endif + + func test_initRepeatingValue() { + withEvery("c", in: 0 ..< 10) { c in + withLifetimeTracking { tracker in + let deque = RigidDeque(repeating: LifetimeTracked(42, for: tracker), count: c) + expectEqual(deque.count, c) + expectEqual(deque.capacity, c) + withEvery("i", in: 0 ..< c) { i in + expectEqual(deque[i].payload, 42) + } + expectEqual(tracker.instances, c == 0 ? 0 : 1) + _ = consume deque + expectEqual(tracker.instances, 0) + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_initCopyingBorrowingSequence() { + withEvery("c", in: 0 ..< 10) { c in + withEvery("capacity", in: [c, c + 1]) { capacity in + withLifetimeTracking { tracker in + let values = RigidArray(copying: tracker.instances(for: 0 ..< c)) + let deque = RigidDeque(capacity: capacity, copying: values) + + expectEqual(deque.count, c) + expectEqual(deque.capacity, capacity) + expectIterablePayloads(deque, equalTo: 0 ..< c) + + expectEqual(tracker.instances, c) + _ = consume values + expectEqual(tracker.instances, c) + _ = consume deque + expectEqual(tracker.instances, 0) + } + } + } + } +#endif + + func test_initCopyingSequence() { + withEvery("c", in: 0 ..< 10) { c in + withEvery("capacity", in: [c, c + 1]) { capacity in + withLifetimeTracking { tracker in + let values = tracker.instances(for: 0 ..< c) + let contents = MinimalSequence( + elements: values, + underestimatedCount: .value(0)) + + let deque = RigidDeque(capacity: capacity, copying: contents) + + expectEqual(deque.count, c) + expectEqual(deque.capacity, capacity) + expectIterableContents(deque, equalTo: values) + + expectEqual(tracker.instances, c) + _ = consume values + _ = consume contents + expectEqual(tracker.instances, c) + _ = consume deque + expectEqual(tracker.instances, 0) + } + } + } + } + + func test_initCopyingCollection() { + withEvery("c", in: 0 ..< 10) { c in + withEvery("capacity", in: [c, c + 1]) { capacity in + withLifetimeTracking { tracker in + let values = tracker.instances(for: 0 ..< c) + let contents = MinimalCollection(values) + + let deque = RigidDeque(capacity: capacity, copying: contents) + + expectEqual(deque.count, c) + expectEqual(deque.capacity, capacity) + expectIterableContents(deque, equalTo: values) + + expectEqual(tracker.instances, c) + _ = consume values + _ = consume contents + expectEqual(tracker.instances, c) + _ = consume deque + expectEqual(tracker.instances, 0) + } + } + } + } + + func test_initCopyingRange_classic() { + // With a deployment target <6.2, this tests the Collection initializer + withEvery("c", in: 0 ..< 10) { c in + withEvery("capacity", in: [c, c + 1]) { capacity in + let deque = RigidDeque(capacity: capacity, copying: 0 ..< c) + + expectEqual(deque.count, c) + expectEqual(deque.capacity, capacity) + expectIterableContents(deque, equalTo: 0 ..< c) + } + } + } + + @available(SwiftStdlib 6.2, *) + func test_initCopyingRange_modern() { + // With a deployment target >=6.2, this tests the BorrowingSequence initializer + withEvery("c", in: 0 ..< 10) { c in + withEvery("capacity", in: [c, c + 1]) { capacity in + let deque = RigidDeque(capacity: capacity, copying: 0 ..< c) + + expectEqual(deque.count, c) + expectEqual(deque.capacity, capacity) + expectIterableContents(deque, equalTo: 0 ..< c) + } + } + } + + func test_popFirst() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents[...].popFirst() + let actual = data.deque.popFirst() + expectEqual(actual, expected) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + + func test_popLast() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents[...].popLast() + let actual = data.deque.popLast() + expectEqual(actual, expected) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + + func test_prependOne() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + guard !data.deque.isFull else { return } + data.contents.insert(extra, at: 0) + data.deque.prepend(extra) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + + func test_appendOne() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + guard !data.deque.isFull else { return } + data.contents.insert(extra, at: data.contents.count) + data.deque.append(extra) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + + func test_pushFirst() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + + let result = data.deque.pushFirst(extra) + + if layout.count == layout.capacity { + expectEqual(result, extra) + expectIterableContents(data.deque, equalTo: data.contents) + } else { + data.contents.insert(extra, at: 0) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_pushLast() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + + let result = data.deque.pushLast(extra) + + if layout.count == layout.capacity { + expectEqual(result, extra) + expectIterableContents(data.deque, equalTo: data.contents) + } else { + data.contents.insert(extra, at: data.contents.count) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prepend_initializingWith_full() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< layout.freeCapacity) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + + data.contents.insert(contentsOf: extras, at: 0) + + var i = 0 + data.deque.prepend(maximumCount: prependCount) { target in + while !target.isFull { + target.append(extras[i]) + i += 1 + } + } + + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_append_initializingWith_full() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< layout.freeCapacity) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + + data.contents.append(contentsOf: extras) + + var i = 0 + data.deque.append(maximumCount: prependCount) { target in + while !target.isFull { + target.append(extras[i]) + i += 1 + } + } + + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prepend_initializingWith_partial() { + withEveryDeque("layout", ofCapacities: [1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< layout.freeCapacity) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + + data.contents.insert(contentsOf: extras, at: 0) + + var i = 0 + data.deque.prepend(maximumCount: layout.freeCapacity) { target in + while !target.isFull, i < prependCount { + target.append(extras[i]) + i += 1 + } + } + expectEqual(i, extras.count) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_append_initializingWith_partial() { + withEveryDeque("layout", ofCapacities: [1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< layout.freeCapacity) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + + data.contents.append(contentsOf: extras) + + var i = 0 + data.deque.append(maximumCount: layout.freeCapacity) { target in + while !target.isFull, i < prependCount { + target.append(extras[i]) + i += 1 + } + } + expectEqual(i, extras.count) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prepend_initializingWith_failing() { + withEveryDeque("layout", ofCapacities: [1, 2, 3, 5, 10]) { layout in + if layout.freeCapacity == 0 { return } + withEvery("prependCount", in: 0 ..< layout.freeCapacity) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + + data.contents.insert(contentsOf: extras, at: 0) + + expectThrows { () throws(TestError) in + var i = 0 + try data.deque.prepend( + maximumCount: layout.freeCapacity + ) { target throws(TestError) in + while !target.isFull, i < prependCount { + target.append(extras[i]) + i += 1 + } + if i == prependCount { + throw TestError(42) + } + } + } + errorHandler: { error in + expectEqual(error.value, 42) + } + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + + func test_append_initializingWith_failing() { + withEveryDeque("layout", ofCapacities: [1, 2, 3, 5, 10]) { layout in + if layout.freeCapacity == 0 { return } + withEvery("prependCount", in: 0 ..< layout.freeCapacity) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + + data.contents.append(contentsOf: extras) + + expectThrows { () throws(TestError) in + var i = 0 + try data.deque.append( + maximumCount: layout.freeCapacity + ) { target throws(TestError) in + while !target.isFull, i < prependCount { + target.append(extras[i]) + i += 1 + } + if i == prependCount { + throw TestError(42) + } + } + } + errorHandler: { error in + expectEqual(error.value, 42) + } + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_prepend_fromProducer_full() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + withEvery("producerSize", in: 0 ..< 6) { producerSize in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + var extras = tracker.instances(for: 0 ..< producerSize) + + data.contents.insert(contentsOf: extras.prefix(layout.freeCapacity), at: 0) + + var producer = CustomProducer, Never> { + guard !extras.isEmpty else { return nil } + return extras.removeFirst() + } + + data.deque.prepend(from: &producer) + expectEqual(extras.count, max(0, producerSize - layout.freeCapacity)) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_append_fromProducer() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + withEvery("producerSize", in: 0 ..< 6) { producerSize in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + var extras = tracker.instances(for: 0 ..< producerSize) + + data.contents.append(contentsOf: extras.prefix(layout.freeCapacity)) + + var producer = CustomProducer, Never> { + guard !extras.isEmpty else { return nil } + return extras.removeFirst() + } + + data.deque.append(from: &producer) + expectEqual(extras.count, max(0, producerSize - layout.freeCapacity)) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_prepend_fromProducer_failing() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + guard layout.freeCapacity > 0 else { return } + withEvery("producerSize", in: 0 ..< layout.freeCapacity - 1) { producerSize in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + var extras = tracker.instances(for: 0 ..< producerSize) + + data.contents.insert(contentsOf: extras, at: 0) + + var producer = CustomProducer, TestError> { () throws(TestError) in + guard !extras.isEmpty else { throw TestError(23) } + return extras.removeFirst() + } + + expectThrows { () throws(TestError) in + try data.deque.prepend(from: &producer) + } + errorHandler: { error in + expectEqual(error.value, 23) + } + expectEqual(extras.count, 0) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_append_fromProducer_failing() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + guard layout.freeCapacity > 0 else { return } + withEvery("producerSize", in: 0 ..< layout.freeCapacity - 1) { producerSize in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + var extras = tracker.instances(for: 0 ..< producerSize) + + data.contents.append(contentsOf: extras) + + var producer = CustomProducer, TestError> { () throws(TestError) in + guard !extras.isEmpty else { throw TestError(23) } + return extras.removeFirst() + } + + expectThrows { () throws(TestError) in + try data.deque.append(from: &producer) + } + errorHandler: { error in + expectEqual(error.value, 23) + } + expectEqual(extras.count, 0) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } +#endif + + func test_prependManyFromMinimalSequence() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, prependCount))]) { underestimatedCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) + data.contents.insert(contentsOf: extras, at: 0) + guard extras.count <= data.deque.freeCapacity else { return } + data.deque.prepend(copying: sequence) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } + + func test_appendManyFromMinimalSequence() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, appendCount))]) { underestimatedCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extras = tracker.instances(for: layout.count ..< layout.count + appendCount) + let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) + data.contents.append(contentsOf: extras) + guard extras.count <= data.deque.freeCapacity else { return } + data.deque.append(copying: sequence) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } + + func test_prependManyFromMinimalCollection() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instances(for: layout.count ..< layout.count + prependCount) + guard extra.count <= data.deque.freeCapacity else { return } + let minimal = MinimalCollection(extra) + data.contents.insert(contentsOf: extra, at: 0) + data.deque.prepend(copying: minimal) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_appendManyFromMinimalCollection() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instances(for: layout.count ..< layout.count + appendCount) + guard extra.count <= data.deque.freeCapacity else { return } + let minimal = MinimalCollection(extra) + data.contents.append(contentsOf: extra) + data.deque.append(copying: minimal) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prependManyFromContiguousArray_asCollection() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + prependCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.insert(contentsOf: extra, at: 0) + data.deque.prepend(copying: extra) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_appendManyFromContiguousArray_asCollection() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + appendCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.append(contentsOf: extra) + data.deque.append(copying: extra) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prependManyFromContiguousArray_asSequence() { + // This calls the Sequence-based `Deque.prepend` overload, even if + // `elements` happens to be of a Collection type. + func prependSequence( + contentsOf elements: S, + to deque: inout RigidDeque + ) { + deque.prepend(copying: elements) + } + + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("prependCount", in: 0 ..< 10) { prependCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + prependCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.insert(contentsOf: extra, at: 0) + prependSequence(contentsOf: extra, to: &data.deque) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_appendManyFromContiguousArray_asSequence() { + // This calls the Sequence-based `Deque.append` overload, even if + // `elements` happens to be of a Collection type. + func appendSequence( + contentsOf elements: S, + to deque: inout RigidDeque + ) { + deque.append(copying: elements) + } + + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extraRange = layout.count ..< layout.count + appendCount + let extra = ContiguousArray(tracker.instances(for: extraRange)) + guard extra.count <= data.deque.freeCapacity else { return } + data.contents.append(contentsOf: extra) + appendSequence(contentsOf: extra, to: &data.deque) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_prependManyFromBridgedArray() { + // https://github.com/apple/swift-collections/issues/27 + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } + var deque = RigidDeque(layout: layout, contents: contents) + guard appendCount <= deque.freeCapacity else { return } + let extra: [NSObject] = (0 ..< appendCount) + .map { _ in NSObject() } + .withUnsafeBufferPointer { buffer in + NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] + } + guard extra.count <= deque.freeCapacity else { return } + contents.insert(contentsOf: extra, at: 0) + deque.prepend(copying: extra) + expectIterableContents( + deque, + equivalentTo: contents, + by: ==, + printer: { "\($0)" }) + } + } + } + + func test_appendManyFromBridgedArray() { + // https://github.com/apple/swift-collections/issues/27 + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("appendCount", in: 0 ..< 10) { appendCount in + var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } + var deque = RigidDeque(layout: layout, contents: contents) + guard appendCount <= deque.freeCapacity else { return } + let extra: [NSObject] = (0 ..< appendCount) + .map { _ in NSObject() } + .withUnsafeBufferPointer { buffer in + NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] + } + guard extra.count <= deque.freeCapacity else { return } + contents.append(contentsOf: extra) + deque.append(copying: extra) + expectIterableContents( + deque, + equivalentTo: contents, + by: ==, + printer: { "\($0)" }) + } + } + } + + func test_insertOneElement() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("offset", in: 0 ... layout.count) { offset in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extra = tracker.instance(for: layout.count) + guard !data.deque.isFull else { return } + data.contents.insert(extra, at: offset) + data.deque.insert(extra, at: offset) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + // func test_insertFromMinimalCollection() { + // withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + // withEvery("offset", in: 0 ... layout.count) { offset in + // withEvery("insertCount", in: 0 ..< 10) { insertCount in + // withLifetimeTracking { tracker in + // var data = tracker.rigidDeque(with: layout) + // let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) + // let minimal = MinimalCollection(extras) + // data.contents.insert(contentsOf: extras, at: offset) + // data.deque.insert(contentsOf: minimal, at: offset) + // expectIterableContents(data.deque, equalTo: data.contents) + // } + // } + // } + // } + // } + // + // func test_insertFromArray() { + // withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + // withEvery("offset", in: 0 ... layout.count) { offset in + // withEvery("insertCount", in: 0 ..< 10) { insertCount in + // withLifetimeTracking { tracker in + // var data = tracker.rigidDeque(with: layout) + // let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) + // data.contents.insert(contentsOf: extras, at: offset) + // data.deque.insert(contentsOf: extras, at: offset) + // expectIterableContents(data.deque, equalTo: data.contents) + // } + // } + // } + // } + // } + + func test_removeOne() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("offset", in: 0 ..< layout.count) { offset in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents.remove(at: offset) + let actual = data.deque.remove(at: offset) + expectEqual(actual, expected) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeSubrange() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEveryRange("range", in: 0 ..< layout.count) { range in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.contents.removeSubrange(range) + data.deque.removeSubrange(range) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeLast() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents.removeLast() + let actual = data.deque.removeLast() + expectEqual(actual, expected) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + + func test_removeLast_many() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withEvery("n", in: 0 ... layout.count) { n in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.contents.removeLast(n) + data.deque.removeLast(n) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeFirst_one() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let expected = data.contents.removeFirst() + let actual = data.deque.removeFirst() + expectEqual(actual, expected) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + + func test_removeFirst_many() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + guard layout.count > 0 else { return } + withEvery("n", in: 0 ... layout.count) { n in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + data.contents.removeFirst(n) + data.deque.removeFirst(n) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_removeAll_keepingCapacity() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("isShared", in: [false, true]) { isShared in + guard layout.count > 0 else { return } + var data: RigidTestData> = .init(.init(capacity: 0), []) + withLifetimeTracking { tracker in + data = tracker.rigidDeque(with: layout) + data.contents.removeAll(keepingCapacity: true) + data.deque.removeAll() + expectEqual(data.deque.count, 0) + expectEqual(data.deque.capacity, layout.capacity) + } // All elements must be deinitialized at this point. + withExtendedLifetime(data.deque) {} + } + } + } +} diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index dd34ac07..a556cd1a 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -120,6 +120,102 @@ public func expectIterableContents< } } +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +/// Check if `left` contains lifetime tracked instances whose payloads equal +/// the elements in `right`. +@available(SwiftStdlib 5.0, *) +public func expectIterablePayloads< + Payload: Equatable, + E1: BorrowingSequence> & ~Copyable & ~Escapable, + C2: Collection, +>( + _ left: borrowing E1, + equalTo right: C2, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + var it1 = left.makeBorrowingIterator() + var it2 = right.makeIterator() + var i = 0 + while true { + let next1 = it1.nextSpan(maximumCount: 1) + let next2 = it2.next() + switch (next1.isEmpty, next2) { + case (true, nil): + return + case (true, _?): + _expectFailure( + "Borrowing sequence is shorter than expected", + message, trapping: trapping, file: file, line: line) + return + case (false, nil): + _expectFailure( + "Borrowing sequence is longer than expected", + message, trapping: trapping, file: file, line: line) + return + case (false, let b?): + let a = next1[0].payload + guard a == b else { + _expectFailure( + "Element at offset \(i) '\(a)' is not equal to '\(b)'", + message, trapping: trapping, file: file, line: line) + return + } + } + i += 1 + } +} + +/// Check if `left` contains lifetime tracked instances whose payloads equal +/// the elements in `right`. +@available(SwiftStdlib 5.0, *) +public func expectIterablePayloads< + Payload: Equatable, + E1: BorrowingSequence> & ~Copyable & ~Escapable, + C2: Collection, +>( + _ left: borrowing E1, + equalTo right: C2, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + var it1 = left.makeBorrowingIterator() + var it2 = right.makeIterator() + var i = 0 + while true { + let next1 = it1.nextSpan(maximumCount: 1) + let next2 = it2.next() + switch (next1.isEmpty, next2) { + case (true, nil): + return + case (true, _?): + _expectFailure( + "Borrowing sequence is shorter than expected", + message, trapping: trapping, file: file, line: line) + return + case (false, nil): + _expectFailure( + "Borrowing sequence is longer than expected", + message, trapping: trapping, file: file, line: line) + return + case (false, let b?): + let a = next1[0].payload + guard a == b else { + _expectFailure( + "Element at offset \(i) '\(a)' is not equal to '\(b)'", + message, trapping: trapping, file: file, line: line) + return + } + } + i += 1 + } +} +#endif + #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) public func expectIterablesWithEquivalentElements< diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift index 5f8c34a9..419a2b88 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift @@ -14,7 +14,7 @@ import InternalCollectionsUtilities import ContainersPreview #endif -#if compiler(>=6.2) +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) package struct CustomProducer: ~Copyable { diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift index b1b32aae..10af31f9 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -36,9 +36,53 @@ public struct LifetimeTrackedStruct: ~Copyable { self.payload = payload } + public init(copying payload: Payload, for tracker: LifetimeTracker) + where Payload: Copyable + { + tracker.instances += 1 + tracker._nextSerialNumber += 1 + self.tracker = tracker + self.serialNumber = tracker._nextSerialNumber + self.payload = payload + } + deinit { precondition(serialNumber != 0, "Double deinit") tracker.instances -= 1 + // Can't mutate in deinit yet + // serialNumber = -serialNumber + } +} + +extension LifetimeTrackedStruct: TestPrintable where Payload: TestPrintable & ~Copyable { + public var testDescription: String { + return "\(payload.testDescription)" + } +} + +extension LifetimeTrackedStruct/*: Equatable*/ where Payload: Equatable /*& ~Copyable*/ { + public static func == (left: borrowing Self, right: borrowing Self) -> Bool { + return left.payload == right.payload + } +} + +extension LifetimeTrackedStruct/*: Hashable*/ where Payload: Hashable /*& ~Copyable*/ { + public func _rawHashValue(seed: Int) -> Int { + payload._rawHashValue(seed: seed) + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(payload) + } + + public var hashValue: Int { + payload.hashValue + } +} + +extension LifetimeTrackedStruct/*: Comparable*/ where Payload: Comparable /*& ~Copyable*/ { + public static func < (left: borrowing Self, right: borrowing Self) -> Bool { + return left.payload < right.payload } } diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift index a938d3c2..028325f7 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift @@ -10,6 +10,12 @@ // //===----------------------------------------------------------------------===// +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +import BasicContainers +#endif + /// Tracks the life times of `LifetimeTracked` instances, providing a method /// to validate checkpoints where no instances should exist. /// @@ -47,6 +53,20 @@ public class LifetimeTracker { return items.map { LifetimeTracked($0, for: self) } } + @available(SwiftStdlib 5.0, *) + public func structInstances( + count: Int, + generator: (Int) -> Element + ) -> RigidArray> { + var i = 0 + return RigidArray>(capacity: count) { span in + while i < count, !span.isFull { + span.append(LifetimeTrackedStruct(copying: generator(i), for: self)) + i += 1 + } + } + } + public func instances( for items: S, by transform: (S.Element) -> T ) -> [LifetimeTracked] { From fdaf3fe24c72ac54998e4d2361aaa5d9fedd12b5 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 10:22:59 -0800 Subject: [PATCH 23/75] [RigidArray, HashTrees] Mark deinitializers inlinable --- Sources/BasicContainers/RigidArray.swift | 1 + Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/BasicContainers/RigidArray.swift b/Sources/BasicContainers/RigidArray.swift index 6c4ab14b..3278bde0 100644 --- a/Sources/BasicContainers/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray.swift @@ -86,6 +86,7 @@ public struct RigidArray: ~Copyable { @usableFromInline internal var _count: Int + @_alwaysEmitIntoClient deinit { unsafe _storage.extracting(0 ..< _count).deinitialize() unsafe _storage.deallocate() diff --git a/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift b/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift index 0ce0ec3c..1f6375d0 100644 --- a/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift +++ b/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift @@ -42,6 +42,7 @@ extension _HashNode { @usableFromInline internal typealias UnsafeHandle = _HashNode.UnsafeHandle + @inlinable deinit { UnsafeHandle.update(self) { handle in handle.children.deinitialize() From 76fa120c276c62e20bef1a66e9b56e42ec9ca154 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 00:14:51 -0800 Subject: [PATCH 24/75] More RigidDeque testing --- .../Protocols/BorrowingIteratorProtocol.swift | 4 +- .../RigidDeque/RigidDeque+Append.swift | 34 +- .../RigidDeque/RigidDeque+Container.swift | 22 +- .../RigidDeque/RigidDeque+Experimental.swift | 8 +- .../RigidDeque/RigidDeque+Initializers.swift | 26 +- .../RigidDeque/RigidDeque+Insertions.swift | 86 ++--- .../RigidDeque/RigidDeque+Prepend.swift | 104 +++--- .../RigidDeque/RigidDeque+Replacements.swift | 118 +++---- .../DequeModule/RigidDeque/RigidDeque.swift | 20 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 35 +- .../Span+Extras.swift | 39 +++ Tests/DequeTests/DequeInternals.swift | 24 +- Tests/DequeTests/RigidDequeCrashTests.swift | 101 ------ Tests/DequeTests/RigidDequeTests.swift | 328 +++++++++++++----- .../Utilities/LifetimeTracked.swift | 4 +- .../Utilities/LifetimeTrackedStruct.swift | 12 +- .../Utilities/LifetimeTracker.swift | 10 +- 17 files changed, 557 insertions(+), 418 deletions(-) create mode 100644 Sources/InternalCollectionsUtilities/Span+Extras.swift diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift index d0f4894b..651937d9 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift @@ -164,9 +164,7 @@ extension Span: BorrowingIteratorProtocol where Element: ~Copyable { @_lifetime(self: copy self) @inlinable public mutating func nextSpan(maximumCount: Int) -> Span { - let result = self.extracting(first: maximumCount) - self = self.extracting(droppingFirst: maximumCount) - return result + _trim(first: maximumCount) } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 0c7bd8c3..49b8485a 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -220,18 +220,18 @@ extension RigidDeque /*where Element: Copyable*/ { /// buffer, then this triggers a runtime error. /// /// - Parameters - /// - newElements: A fully initialized buffer whose contents to copy into + /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient public mutating func append( - copying newElements: UnsafeBufferPointer + copying items: UnsafeBufferPointer ) { precondition( - newElements.count <= freeCapacity, + items.count <= freeCapacity, "RigidDeque capacity overflow") - _handle.uncheckedAppend(copying: newElements) + _handle.uncheckedAppend(copying: items) } /// Copies the elements of a buffer and append them to the end of this @@ -241,15 +241,15 @@ extension RigidDeque /*where Element: Copyable*/ { /// buffer, then this triggers a runtime error. /// /// - Parameters - /// - newElements: A fully initialized buffer whose contents to copy into + /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient public mutating func append( - copying newElements: UnsafeMutableBufferPointer + copying items: UnsafeMutableBufferPointer ) { - unsafe self.append(copying: UnsafeBufferPointer(newElements)) + unsafe self.append(copying: UnsafeBufferPointer(items)) } /// Copies the elements of a span and append them to the end of this deque. @@ -258,12 +258,12 @@ extension RigidDeque /*where Element: Copyable*/ { /// span, then this triggers a runtime error. /// /// - Parameters - /// - newElements: A span whose contents to copy into the deque. + /// - items: A span whose contents to copy into the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient - public mutating func append(copying newElements: Span) { - unsafe newElements.withUnsafeBufferPointer { source in + public mutating func append(copying items: Span) { + unsafe items.withUnsafeBufferPointer { source in unsafe self.append(copying: source) } } @@ -328,16 +328,16 @@ extension RigidDeque /*where Element: Copyable*/ { /// sequence, then this triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(*m*), where *m* is the length of `newElements`. + /// - Complexity: O(*m*), where *m* is the length of `items`. @_alwaysEmitIntoClient public mutating func append< S: BorrowingSequence & Sequence >( - copying newElements: S + copying items: S ) { - self._append(copying: newElements) + self._append(copying: items) } #endif } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift index bff57969..7a61bd8e 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift @@ -29,30 +29,26 @@ extension RigidDeque where Element: ~Copyable { internal var _nextSegment: Span @_alwaysEmitIntoClient - @_lifetime(borrow deque) - internal init(deque: borrowing RigidDeque, iteratedCount: Int = 0) { - let segments = deque._handle.segments() + @_lifetime(borrow _deque) + internal init(_deque: borrowing RigidDeque) { + let segments = _deque._handle.segments() self._currentSegment = _overrideLifetime( Span(_unsafeElements: segments.first), - borrowing: deque) + borrowing: _deque) self._nextSegment = _overrideLifetime( Span( - _unsafeElements: segments.second ?? UnsafeBufferPointer(start: nil, count: 0)), - borrowing: deque) + _unsafeElements: segments.second ?? UnsafeBufferPointer._empty), + borrowing: _deque) } @_alwaysEmitIntoClient @_lifetime(copy self) @_lifetime(self: copy self) public mutating func nextSpan(maximumCount: Int) -> Span { - let c = Swift.min(_currentSegment.count, maximumCount) - // FIXME: Define and use Span._trim(first:) - let result = _currentSegment.extracting(first: c) - if c == _currentSegment.count { + let result = _currentSegment._trim(first: maximumCount) + if _currentSegment.isEmpty { _currentSegment = _nextSegment _nextSegment = Span() - } else { - _currentSegment = _currentSegment.extracting(droppingFirst: c) } return result } @@ -61,7 +57,7 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) public borrowing func makeBorrowingIterator() -> BorrowingIterator { - BorrowingIterator(deque: self) + BorrowingIterator(_deque: self) } #endif } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift index 79237cc1..cea19d9d 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift @@ -22,19 +22,19 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent @_lifetime(borrow self) - public func borrowElement(at index: Int) -> Ref { + public func borrowElement(at index: Int) -> Borrow { precondition(index >= 0 && index < count, "Index out of bounds") let slot = _handle.slot(forOffset: index) - return Ref(unsafeAddress: _handle.ptr(at: slot), borrowing: self) + return Borrow(unsafeAddress: _handle.ptr(at: slot), borrowing: self) } @_alwaysEmitIntoClient @_transparent @_lifetime(&self) - public mutating func mutateElement(at index: Int) -> Mut { + public mutating func mutateElement(at index: Int) -> Inout { precondition(index >= 0 && index < count, "Index out of bounds") let slot = _handle.slot(forOffset: index) - return Mut(unsafeAddress: _handle.mutablePtr(at: slot), mutating: &self) + return Inout(unsafeAddress: _handle.mutablePtr(at: slot), mutating: &self) } } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index 59537579..c6e34f97 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -18,12 +18,6 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - /// Creates an empty rigid deque with the specified capacity. - @_alwaysEmitIntoClient - public init(capacity: Int) { - self.init(_handle: .allocate(capacity: capacity)) - } - /// Initializes a new rigid deque with zero capacity and no elements. /// /// - Complexity: O(1) @@ -32,6 +26,12 @@ extension RigidDeque where Element: ~Copyable { self.init(_handle: .allocate(capacity: 0)) } + /// Creates an empty rigid deque with the specified capacity. + @_alwaysEmitIntoClient + public init(capacity: Int) { + self.init(_handle: .allocate(capacity: capacity)) + } + /// Creates a rigid deque with the specified capacity, then calls the given /// closure with an output span covering the deque's uninitialized memory. /// @@ -188,21 +188,23 @@ extension RigidDeque /*where Element: Copyable*/ { } /// Creates a new deque with the specified capacity, holding a copy - /// of the contents of a given sequence. + /// of the contents of a given collection. /// /// - Parameters: - /// - capacity: The storage capacity of the new deque. - /// - contents: A sequence whose contents to copy into the new deque. + /// - capacity: The storage capacity of the new deque, or nil to copy all + /// items. If specified, the capacity must be greater + /// than or equal to the count of the collection. + /// - contents: A collection whose contents to copy into the new deque. /// The sequence must not contain more than `capacity` elements. @_alwaysEmitIntoClient @inline(__always) public init< S: BorrowingSequence & Collection >( - capacity: Int, - copying contents: borrowing S + capacity: Int? = nil, + copying contents: S ) { - self.init(capacity: capacity) + self.init(capacity: capacity ?? contents.count) self._append(copying: contents) } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 1457d04d..21eb8b8c 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -31,17 +31,17 @@ extension RigidDeque where Element: ~Copyable { /// for the new item. (The direction of the move depends on the location of /// the insertion, minimizing the cost.) /// - /// - Parameter item: The new element to insert into the array. + /// - Parameter item: The new element to insert into the deque. /// - Parameter index: The position at which to insert the new element. - /// `index` must be a valid index in the array. + /// `index` must be a valid index in the deque. /// /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @inline(__always) - public mutating func insert(_ newElement: consuming Element, at index: Int) { + public mutating func insert(_ item: consuming Element, at index: Int) { precondition(!isFull, "RigidDeque capacity overflow") precondition(index >= 0 && index <= count, "Index out of bounds") - _handle.uncheckedInsert(newElement, at: index) + _handle.uncheckedInsert(item, at: index) } } @@ -99,9 +99,10 @@ extension RigidDeque where Element: ~Copyable { initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(capacity >= 0, "Cannot insert a negative number of items") - precondition(capacity <= freeCapacity, "RigidDeque capacity overflow") - try _handle.uncheckedInsert(capacity: capacity, at: index, initializingWith: body) + precondition(maximumCount >= 0, "Cannot insert a negative number of items") + precondition(maximumCount <= freeCapacity, "RigidDeque capacity overflow") + try _handle.uncheckedInsert( + maximumCount: maximumCount, at: index, initializingWith: body) } } @@ -172,7 +173,7 @@ extension RigidDeque where Element: ~Copyable { } } #endif - + /// Moves the elements of an output span into this deque, /// starting at the specified position, and leaving the span empty. /// @@ -201,10 +202,13 @@ extension RigidDeque where Element: ~Copyable { count = 0 } } +} +@available(SwiftStdlib 5.0, *) +extension RigidDeque where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Inserts at most `capacity` items generated by a producer into this deque, - /// starting at the given index. + /// Inserts at most `maximumCount` items generated by a producer into this + /// deque, starting at the given index. /// /// Existing elements in the deque's storage are moved as needed to make room /// for the new items. (The direction of the move depends on the location of @@ -214,23 +218,23 @@ extension RigidDeque where Element: ~Copyable { /// specified number of new items, then this triggers a runtime error. /// /// This operation inserts as many items as the producer can generate before - /// either reaching `capacity`, or the producer hitting its end, or - /// throwing an error. If the producer has more than `capacity` items left in - /// its underlying sequence, then extra items remain available after this - /// method returns. + /// either reaching `maximumCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `maximumCount` items + /// left in its underlying sequence, then extra items remain available after + /// this method returns. /// - /// If the operation inserts fewer than `capacity` items, then it results in - /// a gap in ring buffer storage that needs to be closed by moving some + /// If the operation inserts fewer than `maximumCount` items, then it results + /// in a gap in ring buffer storage that needs to be closed by moving some /// items to their correct positions given the adjusted count. This adds some /// overhead compared to adding exactly as many items as promised. /// /// - Parameters: - /// - capacity: The maximum number of items to insert into the deque. + /// - maximumCount: The maximum number of items to insert into the deque. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`self.count` + `capacity`) + /// - Complexity: O(`self.count` + `maximumCount`) @_alwaysEmitIntoClient public mutating func insert< P: Producer & ~Copyable & ~Escapable @@ -240,7 +244,9 @@ extension RigidDeque where Element: ~Copyable { at index: Int ) throws(P.ProducerError) { try insert(maximumCount: maximumCount, at: index) { target throws(P.ProducerError) in - try producer.generate(into: &target) + while !target.isFull, try producer.generate(into: &target) { + // Do nothing + } } } #endif @@ -263,7 +269,7 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to insert into the deque. The buffer + /// - items: The new elements to insert into the deque. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be /// a valid index of `self`. @@ -271,10 +277,10 @@ extension RigidDeque /* where Element: Copyable */ { /// - Complexity: O(`count` + `newElements.count`) @inlinable public mutating func insert( - copying newElements: UnsafeBufferPointer, at index: Int + copying items: UnsafeBufferPointer, at index: Int ) { - guard newElements.count > 0 else { return } - var remainder = newElements + guard items.count > 0 else { return } + var remainder = items insert(maximumCount: remainder.count, at: index) { target in target.withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( @@ -301,7 +307,7 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to insert into the deque. The buffer + /// - items: The new elements to insert into the deque. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be /// a valid index of `self`. @@ -309,10 +315,10 @@ extension RigidDeque /* where Element: Copyable */ { /// - Complexity: O(`count` + `newElements.count`) @inlinable public mutating func insert( - copying newElements: UnsafeMutableBufferPointer, + copying items: UnsafeMutableBufferPointer, at index: Int ) { - unsafe self.insert(copying: UnsafeBufferPointer(newElements), at: index) + unsafe self.insert(copying: UnsafeBufferPointer(items), at: index) } /// Copies the elements of a span into this deque at the specified position. @@ -329,16 +335,16 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to insert into the deque. + /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. /// - /// - Complexity: O(`count` + `newElements.count`) + /// - Complexity: O(`count` + `items.count`) @inlinable public mutating func insert( - copying newElements: Span, at index: Int + copying items: Span, at index: Int ) { - unsafe newElements.withUnsafeBufferPointer { + unsafe items.withUnsafeBufferPointer { unsafe self.insert(copying: $0, at: index) } } @@ -405,16 +411,16 @@ extension RigidDeque /* where Element: Copyable */ { /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. /// - /// - Complexity: O(`self.count` + `newElements.count`). + /// - Complexity: O(`self.count` + `items.count`). @_alwaysEmitIntoClient @inline(__always) public mutating func insert< C: Container & ~Copyable & ~Escapable >( - copying newElements: borrowing C, at index: Int + copying items: borrowing C, at index: Int ) { _insertContainer( - at: index, copying: newElements, newCount: newElements.count) + at: index, copying: items, newCount: items.count) } #endif @@ -433,7 +439,7 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to insert into the deque. + /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. /// @@ -441,10 +447,10 @@ extension RigidDeque /* where Element: Copyable */ { @inlinable @inline(__always) public mutating func insert( - copying newElements: some Collection, at index: Int + copying items: some Collection, at index: Int ) { _insertCollection( - at: index, copying: newElements, newCount: newElements.count) + at: index, copying: items, newCount: items.count) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @@ -463,20 +469,20 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to insert into the deque. + /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient @inline(__always) public mutating func insert< C: Container & Collection >( - copying newElements: borrowing C, at index: Int + copying items: borrowing C, at index: Int ) { _insertContainer( - at: index, copying: newElements, newCount: newElements.count) + at: index, copying: items, newCount: items.count) } #endif } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 0888480f..02cd6ad1 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -231,19 +231,19 @@ extension RigidDeque /*where Element: Copyable*/ { /// buffer, then this triggers a runtime error. /// /// - Parameters - /// - newElements: A fully initialized buffer whose contents to copy into + /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @inlinable @_alwaysEmitIntoClient public mutating func prepend( - copying newElements: UnsafeBufferPointer + copying items: UnsafeBufferPointer ) { precondition( - newElements.count <= freeCapacity, + items.count <= freeCapacity, "RigidDeque capacity overflow") - _handle.uncheckedPrepend(copying: newElements) + _handle.uncheckedPrepend(copying: items) } /// Copies the elements of a buffer and prepend them to the front of this @@ -253,16 +253,16 @@ extension RigidDeque /*where Element: Copyable*/ { /// buffer, then this triggers a runtime error. /// /// - Parameters - /// - newElements: A fully initialized buffer whose contents to copy into + /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @inlinable @_alwaysEmitIntoClient public mutating func prepend( - copying newElements: UnsafeMutableBufferPointer + copying items: UnsafeMutableBufferPointer ) { - unsafe self.prepend(copying: UnsafeBufferPointer(newElements)) + unsafe self.prepend(copying: UnsafeBufferPointer(items)) } /// Copy the elements of a span and prepend them to the front of this deque. @@ -271,13 +271,13 @@ extension RigidDeque /*where Element: Copyable*/ { /// span, then this triggers a runtime error. /// /// - Parameters - /// - newElements: A span whose contents to copy into the deque. + /// - items: A span whose contents to copy into the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @inlinable @_alwaysEmitIntoClient - public mutating func prepend(copying newElements: Span) { - unsafe newElements.withUnsafeBufferPointer { source in + public mutating func prepend(copying items: Span) { + unsafe items.withUnsafeBufferPointer { source in unsafe self.prepend(copying: source) } } @@ -294,9 +294,9 @@ extension RigidDeque /*where Element: Copyable*/ { // FIXME: If we get a BorrowingSequence.estimatedCount with an exact case, // then we should use that when possible to copy items to their final // location in a single pass. - let oldEndSlot = _handle.endSlot + let oldCount = self.count self._append(copying: items) // Not a typo! - _handle.rotate(toStartAt: oldEndSlot) + _handle.rotate(toStartAtOffset: oldCount) } @inlinable @@ -324,14 +324,14 @@ extension RigidDeque /*where Element: Copyable*/ { /// prepend by rotating them in place as a postprocessing step. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(*m*), where *m* is the length of `newElements`. + /// - Complexity: O(*m*), where *m* is the length of `items`. @_alwaysEmitIntoClient public mutating func prepend & ~Copyable & ~Escapable>( - copying newElements: borrowing S + copying items: borrowing S ) { - self._prepend(copying: newElements) + self._prepend(copying: items) } /// Copies the elements of a container and prepends them to the front @@ -341,14 +341,14 @@ extension RigidDeque /*where Element: Copyable*/ { /// container, then this triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @_alwaysEmitIntoClient public mutating func prepend & ~Copyable & ~Escapable>( - copying newElements: borrowing C + copying items: borrowing C ) { - self._prepend(copying: newElements, exactCount: newElements.count) + self._prepend(copying: items, exactCount: items.count) } #endif @@ -370,22 +370,22 @@ extension RigidDeque /*where Element: Copyable*/ { /// operation works by first appending the items, then finalizing the /// prepend by rotating them in place as a postprocessing step. /// - /// - Parameter newElements: The elements to prepend to the deque. + /// - Parameter items: The elements to prepend to the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @inlinable @_alwaysEmitIntoClient public mutating func prepend( - copying newElements: some Sequence + copying items: some Sequence ) { - let done: Void? = newElements.withContiguousStorageIfAvailable { source in + let done: Void? = items.withContiguousStorageIfAvailable { source in unsafe self.prepend(copying: source) return } guard done == nil else { return } - let oldEndSlot = _handle.endSlot - self.append(copying: newElements) // Not a typo! - _handle.rotate(toStartAt: oldEndSlot) + let oldCount = self.count + self.append(copying: items) // Not a typo! + _handle.rotate(toStartAtOffset: oldCount) } /// Prepend the elements of a collection to the front of this deque by copying @@ -402,23 +402,23 @@ extension RigidDeque /*where Element: Copyable*/ { /// numbers.prepend(copying: 10...15) /// // `numbers` now contains [10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5] /// - /// - Parameter newElements: The elements to prepend to the deque. + /// - Parameter items: The elements to prepend to the deque. /// - /// - Complexity: O(`newElements.count`) + /// - Complexity: O(`items.count`) @inlinable @_alwaysEmitIntoClient public mutating func prepend( - copying newElements: some Collection + copying items: some Collection ) { - let done: Void? = newElements.withContiguousStorageIfAvailable { source in + let done: Void? = items.withContiguousStorageIfAvailable { source in unsafe self.prepend(copying: source) return } guard done == nil else { return } - let c = newElements.count + let c = items.count guard c > 0 else { return } precondition(c <= freeCapacity, "RigidDeque capacity overflow") - _handle.uncheckedPrepend(copying: newElements, exactCount: c) + _handle.uncheckedPrepend(copying: items, exactCount: c) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @@ -428,14 +428,14 @@ extension RigidDeque /*where Element: Copyable*/ { /// sequence, then this triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(*m*), where *m* is the length of `newElements`. + /// - Complexity: O(*m*), where *m* is the length of `items`. @_alwaysEmitIntoClient public mutating func prepend & Sequence>( - copying newElements: borrowing S + copying items: borrowing S ) { - self._prepend(copying: newElements) + self._prepend(copying: items) } /// Copies the elements of a borrowing sequence to the end of this deque. @@ -444,14 +444,14 @@ extension RigidDeque /*where Element: Copyable*/ { /// sequence, then this triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(*m*), where *m* is the length of `newElements`. + /// - Complexity: O(*m*), where *m* is the length of `items`. @_alwaysEmitIntoClient public mutating func prepend & Collection>( - copying newElements: borrowing S + copying items: borrowing S ) { - self._prepend(copying: newElements, exactCount: newElements.count) + self._prepend(copying: items, exactCount: items.count) } /// Copies the elements of a container to the end of this deque. @@ -460,14 +460,14 @@ extension RigidDeque /*where Element: Copyable*/ { /// sequence, then this triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(*m*), where *m* is the length of `newElements`. + /// - Complexity: O(*m*), where *m* is the length of `items`. @_alwaysEmitIntoClient public mutating func prepend & Sequence>( - copying newElements: borrowing C + copying items: borrowing C ) { - self._prepend(copying: newElements, exactCount: newElements.count) + self._prepend(copying: items, exactCount: items.count) } /// Copies the elements of a container to the end of this deque. @@ -476,14 +476,14 @@ extension RigidDeque /*where Element: Copyable*/ { /// sequence, then this triggers a runtime error. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(*m*), where *m* is the length of `newElements`. + /// - Complexity: O(*m*), where *m* is the length of `items`. @_alwaysEmitIntoClient public mutating func prepend & Collection>( - copying newElements: borrowing C + copying items: borrowing C ) { - self._prepend(copying: newElements, exactCount: newElements.count) + self._prepend(copying: items, exactCount: items.count) } #endif } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index c42a25f5..f8e2978a 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -164,10 +164,10 @@ extension RigidDeque where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(moving:at:)`. /// - /// Likewise, if you pass a zero-length buffer as the `newElements` + /// Likewise, if you pass a zero-length buffer as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -175,16 +175,16 @@ extension RigidDeque where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newElements: A fully initialized buffer whose contents to move into + /// - items: A fully initialized buffer whose contents to move into /// the deque. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient public mutating func replaceSubrange( _ subrange: Range, - moving newElements: UnsafeMutableBufferPointer, + moving items: UnsafeMutableBufferPointer, ) { - var remainder = newElements + var remainder = items replaceSubrange(subrange, maximumCount: remainder.count) { target in target.withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( @@ -208,10 +208,10 @@ extension RigidDeque where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(moving:at:)`. /// - /// Likewise, if you pass a zero-length buffer as the `newElements` + /// Likewise, if you pass a zero-length buffer as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -247,10 +247,10 @@ extension RigidDeque where Element: ~Copyable { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(moving:at:)`. /// - /// Likewise, if you pass a zero-length buffer as the `newElements` + /// Likewise, if you pass a zero-length buffer as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -274,7 +274,7 @@ extension RigidDeque where Element: ~Copyable { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Replaces the specified range of elements by at most `capacity` items + /// Replaces the specified range of elements by at most `maximumCount` items /// generated by a producer. /// /// This method has the effect of removing the specified range of elements @@ -294,12 +294,12 @@ extension RigidDeque where Element: ~Copyable { /// directly expressed by calling `removeSubrange`. /// /// This operation inserts as many items as the producer can generate before - /// either reaching `capacity`, or the producer hitting its end, or - /// throwing an error. If the producer has more than `capacity` items left in + /// either reaching `maximumCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `maximumCount` items left in /// its underlying sequence, then extra items remain available after this /// method returns. /// - /// If the operation inserts fewer than `capacity` items, then it results in + /// If the operation inserts fewer than `maximumCount` items, then it results in /// a gap in ring buffer storage that needs to be closed by moving some /// items to their correct positions given the adjusted count. This adds some /// overhead compared to adding exactly as many items as promised. @@ -307,10 +307,10 @@ extension RigidDeque where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - capacity: The maximum number of items to insert into the deque. + /// - maximumCount: The maximum number of items to insert into the deque. /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`self.count` + `capacity`) + /// - Complexity: O(`self.count` + `maximumCount`) @_alwaysEmitIntoClient public mutating func replaceSubrange< P: Producer & ~Copyable & ~Escapable @@ -340,10 +340,10 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(copying:at:)`. /// - /// Likewise, if you pass a zero-length buffer as the `newElements` + /// Likewise, if you pass a zero-length buffer as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -351,15 +351,15 @@ extension RigidDeque /* where Element: Copyable */ { /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newElements: The new elements to copy into the collection. + /// - items: The new elements to copy into the collection. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `items.count`) @inlinable public mutating func replaceSubrange( _ subrange: Range, - copying newElements: UnsafeBufferPointer + copying items: UnsafeBufferPointer ) { - var remainder = newElements + var remainder = items replaceSubrange(subrange, maximumCount: remainder.count) { target in target.withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) @@ -381,10 +381,10 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(copying:at:)`. /// - /// Likewise, if you pass a zero-length buffer as the `newElements` + /// Likewise, if you pass a zero-length buffer as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -392,17 +392,17 @@ extension RigidDeque /* where Element: Copyable */ { /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newElements: The new elements to copy into the collection. + /// - items: The new elements to copy into the collection. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `items.count`) @inlinable public mutating func replaceSubrange( _ subrange: Range, - copying newElements: UnsafeMutableBufferPointer + copying items: UnsafeMutableBufferPointer ) { unsafe self.replaceSubrange( subrange, - copying: UnsafeBufferPointer(newElements)) + copying: UnsafeBufferPointer(items)) } /// Replaces the specified subrange of elements by copying the elements of @@ -417,10 +417,10 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(copying:at:)`. /// - /// Likewise, if you pass a zero-length span as the `newElements` + /// Likewise, if you pass a zero-length span as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -428,15 +428,15 @@ extension RigidDeque /* where Element: Copyable */ { /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newElements: The new elements to copy into the collection. + /// - items: The new elements to copy into the collection. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `items.count`) @inlinable public mutating func replaceSubrange( _ subrange: Range, - copying newElements: Span + copying items: Span ) { - unsafe newElements.withUnsafeBufferPointer { buffer in + unsafe items.withUnsafeBufferPointer { buffer in unsafe self.replaceSubrange(subrange, copying: buffer) } } @@ -447,12 +447,12 @@ extension RigidDeque /* where Element: Copyable */ { C: Container & ~Copyable & ~Escapable >( _ subrange: Range, - copyingContainer newElements: borrowing C, + copyingContainer items: borrowing C, newCount: Int ) { let expectedCount = self.count - subrange.count + newCount - var it = newElements.makeBorrowingIterator() + var it = items.makeBorrowingIterator() self.replaceSubrange(subrange, maximumCount: newCount) { target in it.copyContents(into: &target) } @@ -465,10 +465,10 @@ extension RigidDeque /* where Element: Copyable */ { @inlinable internal mutating func _replaceSubrange( _ subrange: Range, - copyingCollection newElements: __owned some Collection, + copyingCollection items: __owned some Collection, newCount: Int ) { - let done: Void? = newElements.withContiguousStorageIfAvailable { src in + let done: Void? = items.withContiguousStorageIfAvailable { src in precondition( src.count == newCount, "Broken Collection: count doesn't match contents") @@ -476,11 +476,11 @@ extension RigidDeque /* where Element: Copyable */ { } if done != nil { return } - var i = newElements.startIndex + var i = items.startIndex self.replaceSubrange(subrange, maximumCount: newCount) { target in while !target.isFull { - target.append(newElements[i]) - newElements.formIndex(after: &i) + target.append(items[i]) + items.formIndex(after: &i) } } } @@ -498,10 +498,10 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(copying:at:)`. /// - /// Likewise, if you pass a zero-length container as the `newElements` + /// Likewise, if you pass a zero-length container as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -509,19 +509,19 @@ extension RigidDeque /* where Element: Copyable */ { /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the array. - /// - newElements: The new elements to copy into the collection. + /// - items: The new elements to copy into the collection. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `items.count`) @inlinable @inline(__always) public mutating func replaceSubrange< C: Container & ~Copyable & ~Escapable >( _ subrange: Range, - copying newElements: borrowing C + copying items: borrowing C ) { _replaceSubrange( - subrange, copyingContainer: newElements, newCount: newElements.count) + subrange, copyingContainer: items, newCount: items.count) } #endif @@ -537,10 +537,10 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(copying:at:)`. /// - /// Likewise, if you pass a zero-length collection as the `newElements` + /// Likewise, if you pass a zero-length collection as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -548,17 +548,17 @@ extension RigidDeque /* where Element: Copyable */ { /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newElements: The new elements to copy into the collection. + /// - items: The new elements to copy into the collection. /// - /// - Complexity: O(`self.count` + `newElements.count`) + /// - Complexity: O(`self.count` + `items.count`) @inlinable @inline(__always) public mutating func replaceSubrange( _ subrange: Range, - copying newElements: __owned some Collection + copying items: __owned some Collection ) { _replaceSubrange( - subrange, copyingCollection: newElements, newCount: newElements.count) + subrange, copyingCollection: items, newCount: items.count) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @@ -574,10 +574,10 @@ extension RigidDeque /* where Element: Copyable */ { /// elements, then this method triggers a runtime error. /// /// If you pass a zero-length range as the `subrange` parameter, this method - /// inserts the elements of `newElements` at `subrange.lowerBound`. This case + /// inserts the elements of `items` at `subrange.lowerBound`. This case /// is more directly expressed by calling `insert(copying:at:)`. /// - /// Likewise, if you pass a zero-length container as the `newElements` + /// Likewise, if you pass a zero-length container as the `items` /// parameter, this method removes the elements in the given subrange /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. @@ -585,20 +585,20 @@ extension RigidDeque /* where Element: Copyable */ { /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the array. - /// - newElements: The new elements to copy into the collection. + /// - items: The new elements to copy into the collection. /// /// - Complexity: O(*n* + *m*), where *n* is count of this deque and - /// *m* is the count of `newElements`. + /// *m* is the count of `items`. @inlinable @inline(__always) public mutating func replaceSubrange< C: Container & Collection >( _ subrange: Range, - copying newElements: C + copying items: C ) { _replaceSubrange( - subrange, copyingContainer: newElements, newCount: newElements.count) + subrange, copyingContainer: items, newCount: items.count) } #endif } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index dd223be5..42c0ac37 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -82,14 +82,26 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { + /// The maximum number of elements this rigid deque can hold. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public var capacity: Int { _assumeNonNegative(_handle.capacity) } + /// The number of additional elements that can be added to this deque without + /// exceeding its storage capacity. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public var freeCapacity: Int { _assumeNonNegative(capacity &- count) } + /// A Boolean value indicating whether this rigid deque is fully populated. + /// If this property returns true, then the array's storage is at capacity, + /// and it cannot accommodate any additional elements. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public var isFull: Bool { count == capacity } @@ -165,10 +177,10 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { - /// Exchanges the values at the specified indices of the array. + /// Exchanges the values at the specified indices of the deque. /// - /// Both parameters must be valid indices of the array and not equal to - /// endIndex. Passing the same index as both `i` and `j` has no effect. + /// Both parameters must be valid indices of the deque and not equal to + /// `endIndex`. Passing the same index as both `i` and `j` has no effect. /// /// - Parameter i: The index of the first value to swap. /// - Parameter j: The index of the second valud to swap. @@ -228,7 +240,7 @@ extension RigidDeque { /// - Complexity: O(`count`) @_alwaysEmitIntoClient public func _clone() -> Self { - RigidDeque(_handle: _handle.allocateCopy()) + RigidDeque(_handle: _handle.allocateCopy(capacity: count)) } /// Copy the contents of this deque into a newly allocated rigid deque diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 6906f334..43602741 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -590,7 +590,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { internal mutating func uncheckedAppend(_ element: consuming Element) { assert(count < capacity) mutablePtr(at: endSlot).initialize(to: element) - count += 1 + count &+= 1 } /// Prepend `element` to the front of this buffer. The buffer must have enough @@ -605,7 +605,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { let slot = self.slot(before: startSlot) mutablePtr(at: slot).initialize(to: element) startSlot = slot - count += 1 + count &+= 1 } } @@ -909,7 +909,6 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// - Parameter offset: The offset from the start at which the uninitialized /// slots should start. @_alwaysEmitIntoClient - @_transparent internal mutating func openGap( ofSize gapSize: Int, atOffset offset: Int @@ -1152,14 +1151,10 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient - @_transparent - @discardableResult internal mutating func rotate( - toStartAt newStart: Slot - ) -> Slot { - let currentCount = count - let suffixCount = distance(from: newStart, to: endSlot) - + toStartAtOffset newStart: Int + ) { + let oldCount = count // Open a gap at `newStart` that's the size of the free capacity, swapping // the positions of the prefix (`startSlot.. 0 { - _ = openGap(ofSize: gapSize, atOffset: gapOffset) + _ = openGap(ofSize: gapSize, atOffset: newStart) } // With the prefix and suffix swapped, update the starting slot and // restore the count. - let oldStart = startSlot - startSlot = slot(startSlot, offsetBy: -suffixCount) - count = currentCount - return oldStart + startSlot = slot(startSlot, offsetBy: newStart - oldCount) + count = oldCount } } @@ -1212,17 +1204,17 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient internal mutating func uncheckedInsert( - capacity: Int, + maximumCount: Int, at offset: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { - guard capacity > 0 else { return } - let gap = self.openGap(ofSize: capacity, atOffset: offset) + guard maximumCount > 0 else { return } + let gap = self.openGap(ofSize: maximumCount, atOffset: offset) var c = 0 defer { - if c < capacity { - closeGap(offsets: offset + c ..< offset + capacity) + if c < maximumCount { + closeGap(offsets: offset + c ..< offset + maximumCount) } } try gap.first._initialize(initializedCount: &c, initializingWith: body) @@ -1245,7 +1237,6 @@ extension _UnsafeDequeHandle { /// - Parameter offset: The desired offset from the start at which to place /// the first element. @_alwaysEmitIntoClient - @_transparent internal mutating func uncheckedInsert( contentsOf newElements: __owned C, count newCount: Int, diff --git a/Sources/InternalCollectionsUtilities/Span+Extras.swift b/Sources/InternalCollectionsUtilities/Span+Extras.swift new file mode 100644 index 00000000..b1994564 --- /dev/null +++ b/Sources/InternalCollectionsUtilities/Span+Extras.swift @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +@available(SwiftStdlib 5.0, *) +extension Span where Element: ~Copyable { + @_lifetime(copy self) + @_alwaysEmitIntoClient + package mutating func _trim(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let cut = Swift.min(maxLength, count) + guard cut > 0 else { return .init() } + let result = self.extracting(first: cut) + self = self.extracting(droppingFirst: cut) + return result + } + + @_lifetime(copy self) + @_alwaysEmitIntoClient + package mutating func _trim(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let cut = Swift.min(maxLength, count) + guard cut > 0 else { return .init() } + let result = self.extracting(last: cut) + self = self.extracting(droppingLast: cut) + return result + } +} + +#endif diff --git a/Tests/DequeTests/DequeInternals.swift b/Tests/DequeTests/DequeInternals.swift index 848d1dba..10b00c43 100644 --- a/Tests/DequeTests/DequeInternals.swift +++ b/Tests/DequeTests/DequeInternals.swift @@ -26,6 +26,20 @@ internal struct RigidTestData: ~Copyable { } } +internal struct UniqueTestData: ~Copyable { + var deque: UniqueDeque + var contents: [Element] + + init(_ deque: consuming RigidDeque, _ contents: [Element]) { + self.init(UniqueDeque(consuming: deque), contents) + } + + init(_ deque: consuming UniqueDeque, _ contents: [Element]) { + self.deque = deque + self.contents = contents + } +} + internal struct DequeLayout: Hashable, CustomStringConvertible { let capacity: Int let startSlot: Int @@ -78,7 +92,7 @@ extension LifetimeTracker { let deque = Deque(layout: layout, contents: contents) return (deque, contents) } - + func rigidDeque( with layout: DequeLayout ) -> RigidTestData> { @@ -86,6 +100,14 @@ extension LifetimeTracker { let deque = RigidDeque(layout: layout, contents: contents) return RigidTestData(deque, contents) } + + func uniqueDeque( + with layout: DequeLayout + ) -> UniqueTestData> { + let contents = self.instances(for: layout.valueRange) + let deque = RigidDeque(layout: layout, contents: contents) + return UniqueTestData(deque, contents) + } } func withEveryDeque( diff --git a/Tests/DequeTests/RigidDequeCrashTests.swift b/Tests/DequeTests/RigidDequeCrashTests.swift index 208cbdca..717919a6 100644 --- a/Tests/DequeTests/RigidDequeCrashTests.swift +++ b/Tests/DequeTests/RigidDequeCrashTests.swift @@ -21,29 +21,6 @@ import ContainersPreview @Suite("RigidDeque Crash Tests") struct RigidDequeCrashTests { - // MARK: - Capacity Management - -#if false - @Test("Resize capacity") - func resizeCapacity() { - var deque = RigidDeque(copying: [1, 2, 3]) - #expect(deque.capacity == 3) - - // Increase capacity - deque.resize(to: 10) - #expect(deque.capacity == 10) - #expect(deque.count == 3) - #expect(deque[0] == 1) - #expect(deque[1] == 2) - #expect(deque[2] == 3) - - // Decrease capacity (but still fits existing elements) - deque.resize(to: 5) - #expect(deque.capacity == 5) - #expect(deque.count == 3) - } -#endif - // MARK: - Edge Cases and Error Conditions @Test("Append to full deque fails") @@ -70,16 +47,6 @@ struct RigidDequeCrashTests { } } - #if false - @Test("Resize too small") - func resizeTooSmall() async { - await #expect(processExitsWith: .failure) { - var deque = RigidDeque(repeating: 0, count: 5) - deque.resize(to: 3) - } - } - #endif - @Test("Invalid index access") func invalidIndexAccess() async { await #expect(processExitsWith: .failure) { @@ -109,74 +76,6 @@ struct RigidDequeCrashTests { deque.removeLast() // Can't remove last element of an empty RigidDeque } } - - // MARK: - Mixed Operations - - @Test("Mixed append and prepend operations") - func mixedAppendPrependOperations() { - var deque = RigidDeque(capacity: 10) - - deque.append(5) - deque.prepend(4) - deque.append(6) - deque.prepend(3) - - #expect(deque.count == 4) - #expect(deque[0] == 3) - #expect(deque[1] == 4) - #expect(deque[2] == 5) - #expect(deque[3] == 6) - } - - @Test("Complex operations sequence") - func complexOperationsSequence() { - var deque = RigidDeque(capacity: 20) - - // Initial setup - deque.append(copying: [10, 20, 30]) - deque.prepend(copying: [5, 7]) - #expect(deque.count == 5) - - // Remove some elements - deque.removeFirst() - deque.removeLast() - #expect(deque.count == 3) - #expect(deque[0] == 7) - #expect(deque[1] == 10) - #expect(deque[2] == 20) - } - - // MARK: - Type Safety Tests (Non-Copyable) - - @Test("Non-copyable element type") - func nonCopyableElementType() { - struct NonCopyable: ~Copyable { - let id: Int - init(_ id: Int) { self.id = id } - } - - var deque = RigidDeque(capacity: 5) - deque.append(NonCopyable(1)) - deque.append(NonCopyable(2)) - - #expect(deque.count == 2) - #expect(deque[0].id == 1) - #expect(deque[1].id == 2) - - let removed = deque.removeFirst() - #expect(removed.id == 1) - #expect(deque.count == 1) - } } -#else -// RigidDeque requires Swift 6.2+ compiler -@Suite("RigidDeque Tests") -struct RigidDequeTests { - @Test("Compiler version check") - func compilerVersionCheck() { - // This test suite requires Swift 6.2+ for RigidDeque availability - #expect(true, "RigidDeque requires Swift 6.2+ compiler") - } -} #endif diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests.swift index 5b176738..5116dc19 100644 --- a/Tests/DequeTests/RigidDequeTests.swift +++ b/Tests/DequeTests/RigidDequeTests.swift @@ -19,6 +19,7 @@ import BasicContainers import ContainersPreview #endif +#if compiler(>=6.2) #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 5.0, *) @@ -536,7 +537,7 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_prependOne() { + func test_prepend() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -549,7 +550,7 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_appendOne() { + func test_append() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) @@ -766,7 +767,7 @@ final class RigidDequeTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - func test_prepend_fromProducer_full() { + func test_prepend_Producer_full() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in withEvery("producerSize", in: 0 ..< 6) { producerSize in withLifetimeTracking { tracker in @@ -791,7 +792,7 @@ final class RigidDequeTests: CollectionTestCase { #endif #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - func test_append_fromProducer() { + func test_append_Producer() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in withEvery("producerSize", in: 0 ..< 6) { producerSize in withLifetimeTracking { tracker in @@ -816,7 +817,7 @@ final class RigidDequeTests: CollectionTestCase { #endif #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - func test_prepend_fromProducer_failing() { + func test_prepend_Producer_failing() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in guard layout.freeCapacity > 0 else { return } withEvery("producerSize", in: 0 ..< layout.freeCapacity - 1) { producerSize in @@ -847,7 +848,7 @@ final class RigidDequeTests: CollectionTestCase { #endif #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - func test_append_fromProducer_failing() { + func test_append_Producer_failing() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in guard layout.freeCapacity > 0 else { return } withEvery("producerSize", in: 0 ..< layout.freeCapacity - 1) { producerSize in @@ -877,16 +878,15 @@ final class RigidDequeTests: CollectionTestCase { } #endif - func test_prependManyFromMinimalSequence() { + func test_prepend_MinimalSequence() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in - withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, prependCount))]) { underestimatedCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, c))]) { underestimatedCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extras = tracker.instances(for: layout.count ..< layout.count + prependCount) + let extras = tracker.instances(for: layout.count ..< layout.count + c) let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) data.contents.insert(contentsOf: extras, at: 0) - guard extras.count <= data.deque.freeCapacity else { return } data.deque.prepend(copying: sequence) expectIterableContents(data.deque, equalTo: data.contents) } @@ -895,16 +895,15 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_appendManyFromMinimalSequence() { + func test_append_MinimalSequence() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in - withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, appendCount))]) { underestimatedCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withEvery("underestimatedCount", in: [UnderestimatedCountBehavior.precise, .half, .value(min(1, c))]) { underestimatedCount in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extras = tracker.instances(for: layout.count ..< layout.count + appendCount) + let extras = tracker.instances(for: layout.count ..< layout.count + c) let sequence = MinimalSequence(elements: extras, underestimatedCount: underestimatedCount) data.contents.append(contentsOf: extras) - guard extras.count <= data.deque.freeCapacity else { return } data.deque.append(copying: sequence) expectIterableContents(data.deque, equalTo: data.contents) } @@ -913,13 +912,12 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_prependManyFromMinimalCollection() { + func test_prepend_MinimalCollection() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extra = tracker.instances(for: layout.count ..< layout.count + prependCount) - guard extra.count <= data.deque.freeCapacity else { return } + let extra = tracker.instances(for: layout.count ..< layout.count + c) let minimal = MinimalCollection(extra) data.contents.insert(contentsOf: extra, at: 0) data.deque.prepend(copying: minimal) @@ -929,13 +927,12 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_appendManyFromMinimalCollection() { + func test_append_MinimalCollection() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extra = tracker.instances(for: layout.count ..< layout.count + appendCount) - guard extra.count <= data.deque.freeCapacity else { return } + let extra = tracker.instances(for: layout.count ..< layout.count + c) let minimal = MinimalCollection(extra) data.contents.append(contentsOf: extra) data.deque.append(copying: minimal) @@ -945,14 +942,13 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_prependManyFromContiguousArray_asCollection() { + func test_prepend_ContiguousArray_asCollection() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + prependCount + let extraRange = layout.count ..< layout.count + c let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } data.contents.insert(contentsOf: extra, at: 0) data.deque.prepend(copying: extra) expectIterableContents(data.deque, equalTo: data.contents) @@ -961,14 +957,13 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_appendManyFromContiguousArray_asCollection() { + func test_append_ContiguousArray_asCollection() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + appendCount + let extraRange = layout.count ..< layout.count + c let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } data.contents.append(contentsOf: extra) data.deque.append(copying: extra) expectIterableContents(data.deque, equalTo: data.contents) @@ -977,7 +972,7 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_prependManyFromContiguousArray_asSequence() { + func test_prepend_ContiguousArray_asSequence() { // This calls the Sequence-based `Deque.prepend` overload, even if // `elements` happens to be of a Collection type. func prependSequence( @@ -988,12 +983,11 @@ final class RigidDequeTests: CollectionTestCase { } withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("prependCount", in: 0 ..< 10) { prependCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + prependCount + let extraRange = layout.count ..< layout.count + c let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } data.contents.insert(contentsOf: extra, at: 0) prependSequence(contentsOf: extra, to: &data.deque) expectIterableContents(data.deque, equalTo: data.contents) @@ -1002,7 +996,7 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_appendManyFromContiguousArray_asSequence() { + func test_append_ContiguousArray_asSequence() { // This calls the Sequence-based `Deque.append` overload, even if // `elements` happens to be of a Collection type. func appendSequence( @@ -1013,12 +1007,11 @@ final class RigidDequeTests: CollectionTestCase { } withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in withLifetimeTracking { tracker in var data = tracker.rigidDeque(with: layout) - let extraRange = layout.count ..< layout.count + appendCount + let extraRange = layout.count ..< layout.count + c let extra = ContiguousArray(tracker.instances(for: extraRange)) - guard extra.count <= data.deque.freeCapacity else { return } data.contents.append(contentsOf: extra) appendSequence(contentsOf: extra, to: &data.deque) expectIterableContents(data.deque, equalTo: data.contents) @@ -1027,19 +1020,18 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_prependManyFromBridgedArray() { + func test_prepend_BridgedArray() { // https://github.com/apple/swift-collections/issues/27 withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } var deque = RigidDeque(layout: layout, contents: contents) - guard appendCount <= deque.freeCapacity else { return } - let extra: [NSObject] = (0 ..< appendCount) + guard c <= deque.freeCapacity else { return } + let extra: [NSObject] = (0 ..< c) .map { _ in NSObject() } .withUnsafeBufferPointer { buffer in NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] } - guard extra.count <= deque.freeCapacity else { return } contents.insert(contentsOf: extra, at: 0) deque.prepend(copying: extra) expectIterableContents( @@ -1051,19 +1043,18 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_appendManyFromBridgedArray() { + func test_append_BridgedArray() { // https://github.com/apple/swift-collections/issues/27 withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("appendCount", in: 0 ..< 10) { appendCount in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in var contents: [NSObject] = (0 ..< layout.count).map { _ in NSObject() } var deque = RigidDeque(layout: layout, contents: contents) - guard appendCount <= deque.freeCapacity else { return } - let extra: [NSObject] = (0 ..< appendCount) + guard c <= deque.freeCapacity else { return } + let extra: [NSObject] = (0 ..< c) .map { _ in NSObject() } .withUnsafeBufferPointer { buffer in NSArray(objects: buffer.baseAddress, count: buffer.count) as! [NSObject] } - guard extra.count <= deque.freeCapacity else { return } contents.append(contentsOf: extra) deque.append(copying: extra) expectIterableContents( @@ -1075,7 +1066,7 @@ final class RigidDequeTests: CollectionTestCase { } } - func test_insertOneElement() { + func test_insert() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("offset", in: 0 ... layout.count) { offset in withLifetimeTracking { tracker in @@ -1089,40 +1080,210 @@ final class RigidDequeTests: CollectionTestCase { } } } + + func test_imsert_initializingWith_full() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + c) + + data.contents.insert(contentsOf: extras, at: i) + + var j = 0 + data.deque.insert(maximumCount: c, at: i) { target in + expectLessThanOrEqual(target.count, extras.count - j) + while !target.isFull { + target.append(extras[j]) + j += 1 + } + } + expectEqual(j, extras.count) + + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } - // func test_insertFromMinimalCollection() { - // withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - // withEvery("offset", in: 0 ... layout.count) { offset in - // withEvery("insertCount", in: 0 ..< 10) { insertCount in - // withLifetimeTracking { tracker in - // var data = tracker.rigidDeque(with: layout) - // let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) - // let minimal = MinimalCollection(extras) - // data.contents.insert(contentsOf: extras, at: offset) - // data.deque.insert(contentsOf: minimal, at: offset) - // expectIterableContents(data.deque, equalTo: data.contents) - // } - // } - // } - // } - // } - // - // func test_insertFromArray() { - // withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - // withEvery("offset", in: 0 ... layout.count) { offset in - // withEvery("insertCount", in: 0 ..< 10) { insertCount in - // withLifetimeTracking { tracker in - // var data = tracker.rigidDeque(with: layout) - // let extras = tracker.instances(for: layout.count ..< layout.count + insertCount) - // data.contents.insert(contentsOf: extras, at: offset) - // data.deque.insert(contentsOf: extras, at: offset) - // expectIterableContents(data.deque, equalTo: data.contents) - // } - // } - // } - // } - // } + func test_insert_initializingWith_partial() { + withEveryDeque("layout", ofCapacities: [1, 2, 3, 5, 10]) { layout in + guard layout.freeCapacity > 0 else { return } + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity - 1) { c in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + c) + + data.contents.insert(contentsOf: extras, at: i) + + var j = 0 + data.deque.insert(maximumCount: layout.freeCapacity, at: i) { target in + while !target.isFull, j < c { + target.append(extras[j]) + j += 1 + } + } + expectEqual(j, extras.count) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } + func test_insert_initializingWith_failing() { + withEveryDeque("layout", ofCapacities: [1, 2, 3, 5, 10]) { layout in + if layout.freeCapacity == 0 { return } + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity - 1) { c in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + let extras = tracker.instances(for: layout.count ..< layout.count + c) + + data.contents.insert(contentsOf: extras, at: i) + + expectThrows { () throws(TestError) in + var j = 0 + try data.deque.insert( + maximumCount: layout.freeCapacity, + at: i + ) { target throws(TestError) in + while !target.isFull, j < c { + target.append(extras[j]) + j += 1 + } + if j == c { + throw TestError(42) + } + } + } + errorHandler: { error in + expectEqual(error.value, 42) + } + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_insert_fromProducer() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< 6) { c in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + var extras = tracker.instances(for: 0 ..< c) + + data.contents.insert( + contentsOf: extras.prefix(layout.freeCapacity), + at: i) + + var producer = CustomProducer, Never> { + guard !extras.isEmpty else { return nil } + return extras.removeFirst() + } + + data.deque.insert( + maximumCount: layout.freeCapacity, + from: &producer, + at: i) + expectEqual(extras.count, max(0, c - layout.freeCapacity)) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_insert_fromProducer_failing() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + guard layout.freeCapacity > 0 else { return } + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity - 1) { c in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + + var extras = tracker.instances(for: 0 ..< c) + + data.contents.insert(contentsOf: extras, at: i) + + var producer = CustomProducer, TestError> { () throws(TestError) in + guard !extras.isEmpty else { throw TestError(23) } + return extras.removeFirst() + } + + expectThrows { () throws(TestError) in + try data.deque.insert( + maximumCount: layout.freeCapacity, + from: &producer, + at: i) + } + errorHandler: { error in + expectEqual(error.value, 23) + } + expectEqual(extras.count, 0) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } +#endif + + func test_insert_MinimalCollection() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withEvery("isContiguous", in: [false, true]) { isContiguous in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extras = tracker.instances( + for: layout.count ..< layout.count + c) + let collection = MinimalCollection( + extras, + isContiguous: isContiguous) + data.contents.insert(contentsOf: extras, at: i) + data.deque.insert(copying: collection, at: i) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_insert_RigidArray() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withLifetimeTracking { tracker in + var data = tracker.rigidDeque(with: layout) + let extras = tracker.instances( + for: layout.count ..< layout.count + c) + data.contents.insert(contentsOf: extras, at: i) + + let array = RigidArray(copying: extras) + data.deque.insert(copying: array, at: i) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } +#endif + func test_removeOne() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("offset", in: 0 ..< layout.count) { offset in @@ -1221,3 +1382,4 @@ final class RigidDequeTests: CollectionTestCase { } } } +#endif diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracked.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracked.swift index b17dbef8..0c7ec3b5 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracked.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracked.swift @@ -32,7 +32,7 @@ public class LifetimeTracked { public let payload: Payload public init(_ payload: Payload, for tracker: LifetimeTracker) { - tracker.instances += 1 + tracker._instances += 1 tracker._nextSerialNumber += 1 self.tracker = tracker self.serialNumber = tracker._nextSerialNumber @@ -41,7 +41,7 @@ public class LifetimeTracked { deinit { precondition(serialNumber != 0, "Double deinit") - tracker.instances -= 1 + tracker._instances -= 1 serialNumber = -serialNumber } } diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift index 10af31f9..7cb8a069 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift @@ -23,13 +23,18 @@ /// } /// } /// } +@frozen public struct LifetimeTrackedStruct: ~Copyable { public let tracker: LifetimeTracker + + @usableFromInline internal var serialNumber: Int = 0 + public var payload: Payload + @inlinable public init(_ payload: consuming Payload, for tracker: LifetimeTracker) { - tracker.instances += 1 + tracker._instances += 1 tracker._nextSerialNumber += 1 self.tracker = tracker self.serialNumber = tracker._nextSerialNumber @@ -39,16 +44,17 @@ public struct LifetimeTrackedStruct: ~Copyable { public init(copying payload: Payload, for tracker: LifetimeTracker) where Payload: Copyable { - tracker.instances += 1 + tracker._instances += 1 tracker._nextSerialNumber += 1 self.tracker = tracker self.serialNumber = tracker._nextSerialNumber self.payload = payload } + @inlinable deinit { precondition(serialNumber != 0, "Double deinit") - tracker.instances -= 1 + tracker._instances -= 1 // Can't mutate in deinit yet // serialNumber = -serialNumber } diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift index 028325f7..57f34eb2 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift @@ -24,14 +24,20 @@ import BasicContainers /// from multiple concurrent threads (or reentrantly) will lead to /// exclusivity violations and therefore undefined behavior. public class LifetimeTracker { - public internal(set) var instances = 0 - var _nextSerialNumber = 0 + @usableFromInline + package var _instances = 0 + + @usableFromInline + package var _nextSerialNumber = 0 public init() {} deinit { check() } + + @inlinable + var instances: Int { _instances } public func check(file: StaticString = #filePath, line: UInt = #line) { expectEqual(instances, 0, From f496dcfb6114067246e53049946988c4cc2ec143 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 00:15:38 -0800 Subject: [PATCH 25/75] Flesh out UniqueDeque operations --- .../RigidArray+Container.swift | 79 +++ Sources/BasicContainers/RigidArray.swift | 49 -- Sources/BasicContainers/UniqueArray.swift | 10 +- .../UniqueDeque/UniqueDeque+Append.swift | 310 ++++++++- .../UniqueDeque/UniqueDeque+Consumption.swift | 82 +++ .../UniqueDeque/UniqueDeque+Container.swift | 68 ++ .../UniqueDeque+Experimental.swift | 4 +- .../UniqueDeque+Initializers.swift | 140 +++- .../UniqueDeque/UniqueDeque+Insertions.swift | 490 +++++++++++++- .../UniqueDeque/UniqueDeque+Prepend.swift | 484 +++++++++++++- .../UniqueDeque/UniqueDeque+Removals.swift | 147 +++-- .../UniqueDeque+Replacements.swift | 616 ++++++++++++++++++ .../DequeModule/UniqueDeque/UniqueDeque.swift | 171 ++++- Tests/DequeTests/UniqueDequeTests.swift | 198 ++++++ 14 files changed, 2692 insertions(+), 156 deletions(-) create mode 100644 Sources/BasicContainers/RigidArray+Container.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift create mode 100644 Tests/DequeTests/UniqueDequeTests.swift diff --git a/Sources/BasicContainers/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray+Container.swift new file mode 100644 index 00000000..4391f2fc --- /dev/null +++ b/Sources/BasicContainers/RigidArray+Container.swift @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension RigidArray: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = Span.BorrowingIterator + + @inlinable + public var estimatedCount: EstimatedCount { + .exactly(count) + } + + @_alwaysEmitIntoClient + @inline(__always) + public func makeBorrowingIterator() -> BorrowingIterator { + self.span.makeBorrowingIterator() + } +} +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension RigidArray: Container where Element: ~Copyable { +} +#endif + +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + @_alwaysEmitIntoClient + @inline(__always) + public func index(after index: Int) -> Int { index + 1 } + + @_alwaysEmitIntoClient + @inline(__always) + public func formIndex(after index: inout Int) { index += 1 } + + @_alwaysEmitIntoClient + @inline(__always) + public func index(_ index: Int, offsetBy n: Int) -> Int { + index + n + } + + @_alwaysEmitIntoClient + public func formIndex( + _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index + ) { + index._advance(by: &n, limitedBy: limit) + } + + @inlinable + @_lifetime(borrow self) + public func nextSpan( + after index: inout Int, maximumCount: Int + ) -> Span { + precondition(index >= 0 && index <= _count, "Index out of bounds") + let start = index + index = start &+ Swift.min(maximumCount, _count &- start) + return _span(in: Range(uncheckedBounds: (start, index))) + } +} + +#endif + diff --git a/Sources/BasicContainers/RigidArray.swift b/Sources/BasicContainers/RigidArray.swift index e636cad6..408dc402 100644 --- a/Sources/BasicContainers/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray.swift @@ -284,55 +284,6 @@ extension RigidArray where Element: ~Copyable { public var count: Int { _count } } -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -@available(SwiftStdlib 5.0, *) -extension RigidArray: BorrowingSequence where Element: ~Copyable { - @frozen - public struct BorrowingIterator: ~Copyable, ~Escapable, BorrowingIteratorProtocol { - @usableFromInline - internal let _span: Span - - @usableFromInline - internal var _offset: Int - - @inlinable - @_lifetime(copy span) - internal init(_span span: Span, offset: Int) { - self._span = span - self._offset = offset - } - - @_lifetime(&self) - @_lifetime(self: copy self) - public mutating func nextSpan(maximumCount: Int) -> Span { - let c = Swift.min(maximumCount, _span.count - _offset) - let end = _offset &+ c - let result = _span.extracting(Range(uncheckedBounds: (_offset, end))) - _offset = end - return result - } - - @_lifetime(self: copy self) - public mutating func skip(by offset: Int) -> Int { - let c = Swift.min(offset, _span.count &- _offset) - _offset += offset - return c - } - } - - @inlinable - public var estimatedCount: EstimatedCount { - .exactly(count) - } - - @_alwaysEmitIntoClient - @inline(__always) - public func makeBorrowingIterator() -> BorrowingIterator { - .init(_span: self.span, offset: 0) - } -} -#endif - @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { /// A type that represents a position in the array: an integer offset from the diff --git a/Sources/BasicContainers/UniqueArray.swift b/Sources/BasicContainers/UniqueArray.swift index a1ff802b..b37c9e79 100644 --- a/Sources/BasicContainers/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray.swift @@ -85,6 +85,8 @@ extension UniqueArray: Sendable where Element: Sendable & ~Copyable {} extension UniqueArray where Element: ~Copyable { /// The maximum number of elements this array can hold without reallocating /// its storage. + /// + /// - Complexity: O(1) @inlinable @inline(__always) public var capacity: Int { _assumeNonNegative(_storage.capacity) } @@ -324,7 +326,7 @@ extension UniqueArray where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent -internal func _growDynamicArrayCapacity(_ capacity: Int) -> Int { +internal func _growUniqueArrayCapacity(_ capacity: Int) -> Int { // A growth factor of 1.5 seems like a reasonable compromise between // over-allocating memory and wasting cycles on repeatedly resizing storage. let c = (3 &* UInt(bitPattern: capacity) &+ 1) / 2 @@ -344,7 +346,7 @@ extension UniqueArray where Element: ~Copyable { /// greater than or equal to the current count. /// /// - Complexity: O(`count`) - @inlinable @inline(never) + @inlinable public mutating func reallocate(capacity: Int) { _storage.reallocate(capacity: capacity) } @@ -357,7 +359,7 @@ extension UniqueArray where Element: ~Copyable { /// Otherwise the array is left as is. /// /// - Complexity: O(`count`) - @inlinable @inline(never) + @inlinable public mutating func reserveCapacity(_ n: Int) { _storage.reserveCapacity(n) } @@ -374,7 +376,7 @@ extension UniqueArray where Element: ~Copyable { internal func _grow(freeCapacity: Int) -> Int { Swift.max( count + freeCapacity, - _growDynamicArrayCapacity(capacity)) + _growUniqueArrayCapacity(capacity)) } @inlinable diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift index c24662a0..7b3a02d8 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -36,63 +36,284 @@ extension UniqueDeque where Element: ~Copyable { } @available(SwiftStdlib 5.0, *) -extension UniqueDeque /*where Element: Copyable*/ { - /// Copies the elements of a buffer to the end of this deque. +extension UniqueDeque where Element: ~Copyable { + /// Efficiently append a given number of items to the back of this deque by + /// populating a series of storage regions through repeated calls of the + /// specified callback function. /// - /// If the deque does not have sufficient capacity to hold all items - /// in the source buffer, then this automatically grows the deque's - /// capacity, using a geometric growth rate. + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. + /// + /// var buffer = UniqueDeque() + /// buffer.append(999) + /// var i = 0 + /// buffer.append(maximumCount: 6) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [999, 0, 1, 2, 3, 4, 5, 6] + /// + /// The newly appended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease when the callback fails to fully populate its output span or if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated the append. + /// + /// var buffer = UniqueDeque() + /// buffer.append(999) + /// var i = 0 + /// buffer.append(maximumCount: 6) { target in + /// while !target.isFull, i <= 3 { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [999, 0, 1, 2, 3] /// /// - Parameters - /// - newElements: A fully initialized buffer whose contents to copy into - /// the deque. + /// - maximumCount: The maximum number of items to append to the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. /// - /// - Complexity: O(`newElements.count`) when amortized over many + /// - Complexity: O(`maximumCount`) in addition to the complexity of the callback + /// invocations, when amortized over many similar invocations on the same + /// deque. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func append( + maximumCount: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + guard maximumCount > 0 else { return } + _ensureFreeCapacity(maximumCount) + try _storage._handle.uncheckedAppend( + maximumCount: maximumCount, initializingWith: body) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Moves the elements of a buffer to the end of this deque, leaving the + /// buffer uninitialized. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar /// invocations on the same deque. @_alwaysEmitIntoClient public mutating func append( - copying newElements: UnsafeBufferPointer + moving items: UnsafeMutableBufferPointer ) { - _ensureFreeCapacity(newElements.count) - unsafe _storage.append(copying: newElements) + _ensureFreeCapacity(items.count) + _storage._handle.uncheckedAppend(moving: items) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Moves the elements of an input span by appending them to the end of + /// this deque, leaving the span empty. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: An input span whose contents need to be appended to this deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout InputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.append(moving: source) + count = 0 + } + } +#endif + + /// Moves the elements of an output span by appending them to the end of + /// this deque, leaving the span empty. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: An output span whose contents need to be appended to this deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout OutputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.append(moving: source) + count = 0 + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Appends at most `maximumCount` items generated by a producer to the end of + /// this deque. If `maximumCount` is nil, this appends every item the producer + /// can generate. + /// + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. + /// + /// This operation appends as many items as the producer can generate before + /// either reaching its end (or throwing an error), or filling the specified + /// capacity. This operation only consumes the first `maximumCount` items in the + /// producer; if the producer has more, then they remain available after this + /// method returns. + /// + /// - Parameters + /// - maximumCount: The maximum number of items to append to the deque, or + /// nil to append every item the producer generates. + /// - producer: A producer that generates the items to append. + /// + /// - Complexity: O(*n*) where *n* is the number of new items, when + /// amortized over many similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func append< + P: Producer & ~Copyable & ~Escapable + >( + maximumCount: Int? = nil, + from producer: inout P + ) throws(P.ProducerError) { + if let maximumCount { + _ensureFreeCapacity(maximumCount) + try _storage._handle.uncheckedAppend( + maximumCount: maximumCount + ) { target throws(P.ProducerError) in + while !target.isFull, try producer.generate(into: &target) { + // Do nothing + } + } + return + } + + while true { + _ensureFreeCapacity(1) + try _storage._handle.uncheckedAppend( + maximumCount: freeCapacity + ) { target throws(P.ProducerError) in + while !target.isFull, try producer.generate(into: &target) { + // Do nothing + } + } + } + } +#endif +} + + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*where Element: Copyable*/ { + /// Copies the elements of a buffer and append them to the end of this + /// deque. + /// + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func append( + copying items: UnsafeBufferPointer + ) { + _ensureFreeCapacity(items.count) + unsafe _storage.append(copying: items) } /// Copies the elements of a buffer to the end of this deque. /// - /// If the deque does not have sufficient capacity to hold enough elements, - /// then this reallocates the deque's storage to extend its capacity, using - /// a geometric growth rate. + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. /// /// - Parameters - /// - newElements: A fully initialized buffer whose contents to copy into + /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// - /// - Complexity: O(`newElements.count`) when amortized over many + /// - Complexity: O(`items.count`) when amortized over many similar /// invocations on the same deque. @_alwaysEmitIntoClient public mutating func append( - copying newElements: UnsafeMutableBufferPointer + copying items: UnsafeMutableBufferPointer ) { - unsafe self.append(copying: UnsafeBufferPointer(newElements)) + unsafe self.append(copying: UnsafeBufferPointer(items)) } /// Copies the elements of a span to the end of this deque. /// - /// If the deque does not have sufficient capacity to hold enough elements, - /// then this reallocates the deque's storage to extend its capacity, using a - /// geometric growth rate. + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. /// /// - Parameters - /// - newElements: A span whose contents to copy into the deque. + /// - items: A span whose contents to copy into the deque. /// - /// - Complexity: O(`newElements.count`) when amortized over many + /// - Complexity: O(`items.count`) when amortized over many similar /// invocations on the same deque. @_alwaysEmitIntoClient - public mutating func append(copying newElements: Span) { - _ensureFreeCapacity(newElements.count) - _storage.append(copying: newElements) + public mutating func append(copying items: Span) { + _ensureFreeCapacity(items.count) + _storage.append(copying: items) } +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @_alwaysEmitIntoClient + internal mutating func _append< + S: BorrowingSequence & ~Copyable & ~Escapable + >(copying items: borrowing S) { + var it = items.makeBorrowingIterator() + while true { + let span = it.nextSpan() + if span.isEmpty { break } + self.append(copying: span) + } + } + + /// Copies the elements of a borrowing sequence and append them to the end of + /// this deque. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `items`, when amortized + /// over many similar invocations on the same deque + @_alwaysEmitIntoClient + public mutating func append & ~Copyable & ~Escapable>( + copying items: borrowing S + ) { + self._append(copying: items) + } +#endif + /// Copies the elements of a sequence to the end of this deque. /// /// If the deque does not have sufficient capacity to hold enough elements, @@ -102,26 +323,49 @@ extension UniqueDeque /*where Element: Copyable*/ { /// more than once. /// /// - Parameters - /// - newElements: The new elements to copy into the deque. + /// - items: The new elements to copy into the deque. /// - /// - Complexity: O(*m*), where *m* is the length of `newElements`, when - /// amortized over many invocations over the same deque. + /// - Complexity: O(*m*), where *m* is the length of `items`, when + /// amortized over many similar invocations over the same deque. @_alwaysEmitIntoClient - public mutating func append(copying newElements: some Sequence) { - let done: Void? = newElements.withContiguousStorageIfAvailable { buffer in + public mutating func append(copying items: some Sequence) { + let done: Void? = items.withContiguousStorageIfAvailable { buffer in _ensureFreeCapacity(buffer.count) unsafe _storage.append(copying: buffer) return } if done != nil { return } - _ensureFreeCapacity(newElements.underestimatedCount) - var it = _storage._handle.uncheckedAppend(copyingPrefixOf: newElements) + _ensureFreeCapacity(items.underestimatedCount) + var it = _storage._handle.uncheckedAppend(copyingPrefixOf: items) while let item = it.next() { _ensureFreeCapacity(1) _storage.append(item) } } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of a borrowing sequence to the end of this deque. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `items`, when + /// amortized over many similar invocations over the same deque. + @_alwaysEmitIntoClient + public mutating func append< + S: BorrowingSequence & Sequence + >( + copying items: S + ) { + self._append(copying: items) + } +#endif + } #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift new file mode 100644 index 00000000..6a8e65d1 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consume( + _ subrange: Range, + consumingWith consumer: (inout InputSpan) -> Void + ) { + _storage.consume(subrange, consumingWith: consumer) + } + + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consume>( + _ subrange: R, + consumingWith consumer: (inout InputSpan) -> Void + ) { + consume(subrange.relative(to: indices), consumingWith: consumer) + } + + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consumeAll( + consumingWith consumer: (inout InputSpan) -> Void + ) { + consume(indices, consumingWith: consumer) + } +#endif +} + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + public typealias SubrangeConsumer = RigidDeque.SubrangeConsumer + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consume( + _ subrange: Range + ) -> SubrangeConsumer { + _storage.consume(subrange) + } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consume>( + _ subrange: R + ) -> SubrangeConsumer { + consume(subrange.relative(to: indices)) + } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consumeAll() -> SubrangeConsumer { + consume(indices) + } +} +#endif + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift new file mode 100644 index 00000000..09f39802 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + public typealias BorrowingIterator = RigidDeque.BorrowingIterator + + @_alwaysEmitIntoClient + @_lifetime(borrow self) + public borrowing func makeBorrowingIterator() -> BorrowingIterator { + BorrowingIterator(_deque: self._storage) + } +#endif +} + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension UniqueDeque: Container where Element: ~Copyable {} +#endif + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + @_alwaysEmitIntoClient + @inline(__always) + public func index(after index: Int) -> Int { index + 1 } + + @_alwaysEmitIntoClient + @inline(__always) + public func formIndex(after index: inout Int) { index += 1 } + + @_alwaysEmitIntoClient + @inline(__always) + public func index(_ index: Int, offsetBy n: Int) -> Int { + index + n + } + + @_alwaysEmitIntoClient + public func formIndex( + _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index + ) { + index._advance(by: &n, limitedBy: limit) + } + + @_alwaysEmitIntoClient + @_lifetime(borrow self) + public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { + _storage.nextSpan(after: &index, maximumCount: maximumCount) + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift index 7d62a203..e150c28c 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Experimental.swift @@ -21,14 +21,14 @@ import ContainersPreview @_alwaysEmitIntoClient @_transparent @_lifetime(borrow self) -public func borrowElement(at index: Int) -> Ref { +public func borrowElement(at index: Int) -> Borrow { _storage.borrowElement(at: index) } @_alwaysEmitIntoClient @_transparent @_lifetime(&self) -public mutating func mutateElement(at index: Int) -> Mut { +public mutating func mutateElement(at index: Int) -> Inout { _storage.mutateElement(at: index) } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift index 36d04b12..273c25b0 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift @@ -18,27 +18,119 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { + /// Initializes a new unique deque with no elements. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient @_transparent public init() { _storage = .init(capacity: 0) } + /// Creates an empty unique deque with the specified capacity. @_alwaysEmitIntoClient @_transparent public init(capacity: Int) { _storage = .init(capacity: capacity) } + + /// Creates a unique deque with the specified capacity, then calls the given + /// closure with an output span covering the deque's uninitialized memory. + /// + /// - Parameters: + /// - capacity: The number of elements to allocate space for in the new + /// rigid deque. + /// - initializer: A closure that initializes the elements of the new deque. + /// - Parameter outputSpan: An `OutputSpan` allowing initialization of the + /// deque's initial elements. + @inlinable @inline(__always) + public init( + capacity: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + _storage = try .init(capacity: capacity, initializingWith: initializer) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Creates a new unique deque taking over the storage of the specified + /// rigid deque instance, consuming it in the process. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public init(consuming deque: consuming RigidDeque) { + self._storage = deque + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Creates a new unique deque of the specified capacity, populating it with + /// all items generated by a given producer. + /// + /// - Parameters + /// - producer: A producer that generates the items to append to the new + /// deque. + /// + /// - Complexity: O(`capacity`) + public init & ~Copyable & ~Escapable>( + capacity: Int, from producer: inout P + ) throws(P.ProducerError) { + self.init(capacity: capacity) + try self.append(from: &producer) + } +#endif } @available(SwiftStdlib 5.0, *) extension UniqueDeque /*where Element: Copyable*/ { + /// Creates a new deque containing the specified number of a single, + /// repeated value. + /// + /// - Parameters: + /// - repeatedValue: The element to repeat. + /// - count: The number of times to repeat the value passed in the + /// `repeating` parameter. `count` must be zero or greater. + /// + /// - Complexity: O(`count`) + @inlinable + public init(repeating repeatedValue: Element, count: Int) { + self._storage = .init(repeating: repeatedValue, count: count) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*where Element: Copyable*/ { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Creates a new deque with the specified capacity, holding a copy + /// of the contents of a given borrowing sequence. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque, or nil to let the + /// deque grow itself as needed to accomodate all items in `contents`. + /// - contents: A sequence whose contents to copy into the new deque. + @_alwaysEmitIntoClient + @inline(__always) + public init< + S: BorrowingSequence & ~Copyable & ~Escapable + >( + capacity: Int? = nil, + copying contents: borrowing S + ) { + self.init(capacity: capacity ?? 0) + self._append(copying: contents) + } +#endif + /// Creates a new deque with the specified initial capacity, holding a copy /// of the contents of a given sequence. /// /// - Parameters: - /// - capacity: The storage capacity of the new deque, or nil to allocate - /// just enough capacity to store the contents. + /// - capacity: The storage capacity of the new deque, or nil to let the + /// deque grow itself as needed to accomodate all items in `contents`. /// - contents: The sequence whose contents to copy into the new deque. @_alwaysEmitIntoClient @inline(__always) @@ -46,9 +138,51 @@ extension UniqueDeque /*where Element: Copyable*/ { capacity: Int? = nil, copying contents: some Sequence ) { - self.init(capacity: capacity ?? 0) + self.init(capacity: capacity ?? contents.underestimatedCount) self.append(copying: contents) } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Creates a new deque with the specified capacity, holding a copy + /// of the contents of a given sequence. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque, or nil to let the + /// deque grow itself as needed to accomodate all items in `contents`. + /// - contents: A sequence whose contents to copy into the new deque. + /// The sequence must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init< + S: BorrowingSequence & Sequence + >( + capacity: Int? = nil, + copying contents: S + ) { + self.init(capacity: capacity ?? contents.underestimatedCount) + self._append(copying: contents) + } + + /// Creates a new deque with the specified capacity, holding a copy + /// of the contents of a given sequence. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new deque. + /// - contents: A sequence whose contents to copy into the new deque. + /// The sequence must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init< + S: BorrowingSequence & Collection + >( + capacity: Int? = nil, + copying contents: S + ) { + self.init(capacity: capacity ?? contents.count) + self._append(copying: contents) + } +#endif + } #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index d6e9c5c3..886b582a 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -18,12 +18,498 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { + /// Inserts a new element into the deque at the specified position. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// The new element is inserted before the element currently at the specified + /// index. If you pass the deque's `endIndex` as the `index` parameter, then + /// the new element is appended to the container. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new item. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// - Parameter item: The new element to insert into the deque. + /// - Parameter index: The position at which to insert the new element. + /// `index` must be a valid index in the deque. + /// + /// - Complexity: O(`self.count`) when amortized over many similar + /// invocations on the same deque. @_alwaysEmitIntoClient @_transparent - public mutating func insert(_ newElement: consuming Element, at index: Int) { + public mutating func insert(_ item: consuming Element, at index: Int) { + precondition(index >= 0 && index <= self.count, "Index out of bounds") _ensureFreeCapacity(1) - _storage.insert(newElement, at: index) + _storage._handle.uncheckedInsert(item, at: index) } } +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Inserts a given number of new items into this deque at the specified + /// position, using a callback to directly initialize deque storage by + /// populating a series of output spans. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough elements, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// var buffer = UniqueDeque(capacity: 20) + /// buffer.append([-999, 999]) + /// var i = 0 + /// buffer.insert(capacity: 3, at: 1) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [-999, 0, 1, 2, 999] + /// + /// The newly inserted items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease if the callback fails to fully populate its output span or if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// + /// Partial insertions create a gap in ring buffer storage that needs to be + /// closed by moving already inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters: + /// - maximumCount: The maximum number of items to insert into the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity + /// of the callback invocations when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert( + maximumCount: Int, + at index: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + precondition(index >= 0 && index <= self.count, "Index out of bounds") + precondition(maximumCount >= 0, "Cannot insert a negative number of items") + _ensureFreeCapacity(maximumCount) + try _storage._handle.uncheckedInsert( + maximumCount: maximumCount, at: index, initializingWith: body) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Inserts the elements of a fully initialized buffer by moving them into + /// this deque, starting at the specified position. After this operation, + /// the supplied buffer becomes uninitialized. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough elements, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the array. + /// + /// - Complexity: O(`self.count` + `items.count`) when amortized over many + /// similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func insert( + moving items: UnsafeMutableBufferPointer, + at index: Int + ) { + guard !items.isEmpty else { return } + var remainder = items + insert(maximumCount: items.count, at: index) { target in + target.withUnsafeMutableBufferPointer { buffer, count in + buffer.moveInitializeAll( + fromContentsOf: remainder._trim(first: buffer.count)) + count = buffer.count + } + } + assert(remainder.isEmpty) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Moves the elements of an input span into this deque, + /// starting at the specified position, and leaving the span empty. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough elements, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: An input span whose contents to move into + /// the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) when amortized over many + /// similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func insert( + moving items: inout InputSpan, + at index: Int + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.insert(moving: source, at: index) + count = 0 + } + } +#endif + + /// Moves the elements of an output span into this deque, + /// starting at the specified position, and leaving the span empty. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough elements, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: An output span whose contents to move into + /// the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) when amortized over many + /// similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func insert( + moving items: inout OutputSpan, + at index: Int + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.insert(moving: source, at: index) + count = 0 + } + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Inserts at most `maximumCount` items generated by a producer into this + /// deque, starting at the given index. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough items, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// This operation inserts as many items as the producer can generate before + /// either reaching `maximumCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `maximumCount` items + /// left in its underlying sequence, then extra items remain available after + /// this method returns. + /// + /// If the operation inserts fewer than `maximumCount` items, then it results + /// in a gap in ring buffer storage that needs to be closed by moving some + /// items to their correct positions given the adjusted count. This adds some + /// overhead compared to adding exactly as many items as promised. + /// + /// - Parameters: + /// - maximumCount: The maximum number of items to insert into the deque. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the deque. + /// - producer: A producer that generates the items to append. + /// + /// - Complexity: O(`self.count` + `maximumCount`) when amortized over many + /// similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func insert< + P: Producer & ~Copyable & ~Escapable + >( + maximumCount: Int, + from producer: inout P, + at index: Int + ) throws(P.ProducerError) { + try insert(maximumCount: maximumCount, at: index) { target throws(P.ProducerError) in + while !target.isFull, try producer.generate(into: &target) { + // Do nothing + } + } + } + #endif +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /* where Element: Copyable */ { + /// Copies the elements of a fully initialized buffer pointer into this + /// deque at the specified position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the array. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough items, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: The new elements to insert into the deque. The buffer + /// must be fully initialized. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of `self`. + /// + /// - Complexity: O(`count` + `newElements.count`) when amortized over many + /// similar invocations on the same deque. + @inlinable + public mutating func insert( + copying items: UnsafeBufferPointer, at index: Int + ) { + guard items.count > 0 else { return } + var remainder = items + insert(maximumCount: remainder.count, at: index) { target in + target.withUnsafeMutableBufferPointer { buffer, count in + buffer.initializeAll( + fromContentsOf: remainder._extracting(first: buffer.count)) + remainder = remainder._extracting(droppingFirst: buffer.count) + count = buffer.count + } + } + assert(remainder.isEmpty) + } + + /// Copies the elements of a fully initialized buffer pointer into this + /// deque at the specified position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough items, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: The new elements to insert into the deque. The buffer + /// must be fully initialized. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of `self`. + /// + /// - Complexity: O(`count` + `newElements.count`) when amortized over many + /// similar invocations on the same deque. + @inlinable + public mutating func insert( + copying items: UnsafeMutableBufferPointer, + at index: Int + ) { + unsafe self.insert(copying: UnsafeBufferPointer(items), at: index) + } + + /// Copies the elements of a span into this deque at the specified position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough items, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`count` + `items.count`) when amortized over many similar + /// invocations on the same deque. + @inlinable + public mutating func insert( + copying items: Span, at index: Int + ) { + unsafe items.withUnsafeBufferPointer { + unsafe self.insert(copying: $0, at: index) + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _insertContainer< + C: Container & ~Copyable & ~Escapable + >( + at index: Int, + copying items: borrowing C, + newCount: Int + ) { + let expectedCount = self.count + newCount + var it = items.makeBorrowingIterator() + insert(maximumCount: newCount, at: index) { target in + it.copyContents(into: &target) + } + precondition( + it.nextSpan().isEmpty && count == expectedCount, + "Broken Container: count doesn't match contents") + } +#endif + + @inlinable + internal mutating func _insertCollection( + at index: Int, + copying items: some Collection, + newCount: Int + ) { + let done: Void? = items.withContiguousStorageIfAvailable { src in + self.insert(copying: src, at: index) + } + if done != nil { return } + + var i = items.startIndex + self.insert(maximumCount: newCount, at: index) { target in + while !target.isFull { + target.append(items[i]) + items.formIndex(after: &i) + } + } + precondition( + i == items.endIndex, + "Broken Collection: count doesn't match contents") + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of a container into this deque at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough items, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - newElements: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) when amortized over many + /// similar invocations on the same deque. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & ~Copyable & ~Escapable + >( + copying items: borrowing C, at index: Int + ) { + _insertContainer( + at: index, copying: items, newCount: items.count) + } +#endif + + /// Copies the elements of a collection into this deque at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough items, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`count` + `newElements.count`) when amortized over many + /// similar invocations on the same deque. + @inlinable + @inline(__always) + public mutating func insert( + copying items: some Collection, at index: Int + ) { + _insertCollection( + at: index, copying: items, newCount: items.count) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of a container into this deque at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the deque's `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the deque. + /// + /// Existing elements in the deque's storage are moved as needed to make room + /// for the new items. (The direction of the move depends on the location of + /// the insertion, minimizing the cost.) + /// + /// If the deque does not have sufficient capacity to hold enough items, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameters + /// - items: The new elements to insert into the deque. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) when amortized over many + /// similar invocations on the same deque. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & Collection + >( + copying items: borrowing C, at index: Int + ) { + _insertContainer( + at: index, copying: items, newCount: items.count) + } +#endif +} + #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index a91b4b33..d4ece9be 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -18,6 +18,15 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { + /// Adds an element to the front of the deque. + /// + /// If the deque does not have sufficient capacity to hold any more elements, + /// then this reallocates the deque's storage to grow its capacity, using a + /// geometric growth rate. + /// + /// - Parameter item: The element to prepend to the deque. + /// + /// - Complexity: O(1) when amortized over many invocations on the same deque. @_alwaysEmitIntoClient @_transparent public mutating func prepend(_ newElement: consuming Element) { @@ -26,4 +35,477 @@ extension UniqueDeque where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Efficiently prepend a given number of items to the front of this deque by + /// populating a series of storage regions through repeated calls of the + /// specified callback function. + /// + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. + /// + /// var buffer = RigidDeque() + /// buffer.append(999) + /// var i = 0 + /// buffer.prepend(count: 6) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [0, 1, 2, 3, 4, 5, 6, 999] + /// + /// The newly prepended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease if the callback fails to fully populate its output span or if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// + /// Note: Partial prepends create a gap in ring buffer storage that needs to + /// be closed by moving newly prepended items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// var buffer = RigidDeque() + /// buffer.append(999) + /// var i = 0 + /// buffer.prepend(count: 6) { target in + /// while !target.isFull, i <= 3 { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [0, 1, 2, 3, 999] + /// + /// - Parameters + /// - maximumCount: The maximum number of items to prepend to the deque. + /// - body: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. + /// + /// - Complexity: O(`maximumCount`) in addition to the complexity of the callback + /// invocations, when amortized over many similar invocations on the same + /// deque. + @_alwaysEmitIntoClient + public mutating func prepend( + maximumCount: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + guard maximumCount > 0 else { return } + _ensureFreeCapacity(maximumCount) + try _storage._handle.uncheckedPrepend( + maximumCount: maximumCount, initializingWith: body) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Moves the elements of a buffer to the front of this deque, leaving the + /// buffer uninitialized. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func prepend( + moving items: UnsafeMutableBufferPointer + ) { + _ensureFreeCapacity(items.count) + _storage._handle.uncheckedPrepend(moving: items) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Moves the elements of an input span by prepending them to the front of + /// this deque, leaving the span empty. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: An input span whose contents need to be prepended to this deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend( + moving items: inout InputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.prepend(moving: source) + count = 0 + } + } +#endif + + /// Moves the elements of an output span by prepending them to the front of + /// this deque, leaving the span empty. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// - Parameters + /// - items: An output span whose contents need to be prepended to this deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend( + moving items: inout OutputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.prepend(moving: source) + count = 0 + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Prepends at most `maximumCount` items generated by a producer to the front of + /// this deque. If `maximumCount` is nil, this appends every item the producer + /// can generate. + /// + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. + /// + /// This operation prepends as many items as the producer can generate before + /// either reaching its end (or throwing an error), or filling the specified + /// capacity. This operation only consumes the first `maximumCount` items in the + /// producer; if the producer has more, then they remain available after this + /// method returns. + /// + /// Note: Partial prepends create a gap in ring buffer storage that needs to + /// be closed by moving newly prepended items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - maximumCount: The maximum number of items to prepend to the deque, or + /// nil to use all available capacity. + /// - producer: A producer that generates the items to prepend. + /// + /// - Complexity: O(*n*) where *n* is the number of new items, when + /// amortized over many similar invocations on the same deque. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func prepend< + P: Producer & ~Copyable & ~Escapable + >( + maximumCount: Int? = nil, + from producer: inout P + ) throws(P.ProducerError) { + if let maximumCount { + _ensureFreeCapacity(maximumCount) + try _storage._handle.uncheckedPrepend( + maximumCount: maximumCount + ) { target throws(P.ProducerError) in + while !target.isFull, try producer.generate(into: &target) { + // Do nothing + } + } + return + } + + while true { + _ensureFreeCapacity(1) + try _storage._handle.uncheckedAppend( + maximumCount: freeCapacity + ) { target throws(P.ProducerError) in + while !target.isFull, try producer.generate(into: &target) { + // Do nothing + } + } + } + } +#endif +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*where Element: Copyable*/ { + /// Copies the elements of a buffer and prepend them to the front of this + /// rigid deque. + /// + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying items: UnsafeBufferPointer + ) { + _ensureFreeCapacity(items.count) + _storage._handle.uncheckedPrepend(copying: items) + } + + /// Copies the elements of a buffer and prepend them to the front of this + /// deque. + /// + /// If the deque doesn't have sufficient capacity to accommodate the specified + /// number of new elements, then this method reallocates the deque's storage + /// to grow it, using a geometric growth rate. + /// + /// - Parameters + /// - items: A fully initialized buffer whose contents to copy into + /// the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying items: UnsafeMutableBufferPointer + ) { + unsafe self.prepend(copying: UnsafeBufferPointer(items)) + } + + /// Copy the elements of a span and prepend them to the front of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// span, then this triggers a runtime error. + /// + /// - Parameters + /// - items: A span whose contents to copy into the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend(copying items: Span) { + unsafe items.withUnsafeBufferPointer { source in + unsafe self.prepend(copying: source) + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _prepend< + S: BorrowingSequence & ~Copyable & ~Escapable + >(copying items: borrowing S) { + // We don't know the exact count of new elements, so we cannot initialize + // them in place. Append them to the end of the deque first, then rotate + // them to their correct location. + // + // FIXME: If we get a BorrowingSequence.estimatedCount with an exact case, + // then we should use that when possible to copy items to their final + // location in a single pass. + let oldCount = self.count + self._append(copying: items) // Not a typo! + _storage._handle.rotate(toStartAtOffset: oldCount) + } + + @inlinable + internal mutating func _prepend< + S: BorrowingSequence & ~Copyable & ~Escapable + >( + copying items: borrowing S, + exactCount: Int + ) { + var it = items.makeBorrowingIterator() + self.prepend(maximumCount: exactCount) { target in + let span = it.nextSpan(maximumCount: target.freeCapacity) + target._append(copying: span) + } + } + + /// Copies the elements of a borrowing sequence and prepend them to the front + /// of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// As borrowing sequences do not necessarily provide an exact count, this + /// operation works by first appending the items, then finalizing the + /// prepend by rotating them in place as a postprocessing step. + /// + /// - Parameters + /// - items: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `items`, as amortized + /// over many similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend & ~Copyable & ~Escapable>( + copying items: borrowing S + ) { + self._prepend(copying: items) + } + + /// Copies the elements of a container and prepends them to the front + /// of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// container, then this triggers a runtime error. + /// + /// - Parameters + /// - items: The new elements to copy into the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend & ~Copyable & ~Escapable>( + copying items: borrowing C + ) { + self._prepend(copying: items, exactCount: items.count) + } +#endif + + /// Prepend the elements of a sequence to the front of this deque by copying + /// them. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// This example prepends the elements of a `Range` instance + /// to a rigid deque of integers. + /// + /// var numbers = RigidDeque(capacity: 10) + /// numbers.append(copying: [1, 2, 3, 4, 5]) + /// numbers.prepend(copying: 10...15) + /// // `numbers` now contains [10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5] + /// + /// As borrowing sequences do not necessarily provide an exact count, this + /// operation works by first appending the items, then finalizing the + /// prepend by rotating them in place as a postprocessing step. + /// + /// - Parameter items: The elements to prepend to the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying items: some Sequence + ) { + let done: Void? = items.withContiguousStorageIfAvailable { source in + unsafe self.prepend(copying: source) + return + } + guard done == nil else { return } + let oldCount = self.count + self.append(copying: items) // Not a typo! + _storage._handle.rotate(toStartAtOffset: oldCount) + } + + /// Prepend the elements of a collection to the front of this deque by copying + /// them. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// This example prepends the elements of a `Range` instance + /// to a rigid deque of integers. + /// + /// var numbers = RigidDeque(capacity: 10) + /// numbers.append(copying: [1, 2, 3, 4, 5]) + /// numbers.prepend(copying: 10...15) + /// // `numbers` now contains [10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5] + /// + /// - Parameter items: The elements to prepend to the deque. + /// + /// - Complexity: O(`items.count`) when amortized over many similar + /// invocations on the same deque. + @inlinable + @_alwaysEmitIntoClient + public mutating func prepend( + copying items: some Collection + ) { + let done: Void? = items.withContiguousStorageIfAvailable { source in + unsafe self.prepend(copying: source) + return + } + guard done == nil else { return } + let c = items.count + guard c > 0 else { return } + _ensureFreeCapacity(c) + _storage._handle.uncheckedPrepend(copying: items, exactCount: c) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Copies the elements of a borrowing sequence to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - items: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `items`, as amortized + /// over many similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend & Sequence>( + copying items: borrowing S + ) { + self._prepend(copying: items) + } + + /// Copies the elements of a borrowing sequence to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `items` when amortized + /// over many similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend & Collection>( + copying items: borrowing S + ) { + self._prepend(copying: items, exactCount: items.count) + } + + /// Copies the elements of a container to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - items: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `items` when amortized + /// over many similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend & Sequence>( + copying items: borrowing C + ) { + self._prepend(copying: items, exactCount: items.count) + } + + /// Copies the elements of a container to the end of this deque. + /// + /// If the deque does not have sufficient capacity to hold all items in the + /// sequence, then this triggers a runtime error. + /// + /// - Parameters + /// - items: The new elements to copy into the deque. + /// + /// - Complexity: O(*m*), where *m* is the length of `items` when amortized + /// over many similar invocations on the same deque. + @_alwaysEmitIntoClient + public mutating func prepend & Collection>( + copying items: C + ) { + self._prepend(copying: items, exactCount: items.count) + } +#endif +} #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift index 41e1eebd..ae7f4a83 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Removals.swift @@ -18,59 +18,130 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { + /// Removes and returns the element at the specified position. + /// + /// Existing elements in the deque's storage are moved as needed to close the + /// gap left by the removed item. (The direction of the move depends on the + /// location of the removal, minimizing the cost.) + /// + /// - Parameter i: The position of the element to remove. `index` must be + /// a valid index of the deque that is not equal to the end index. + /// - Returns: The removed element. + /// + /// - Complexity: O(`count`) @discardableResult @_alwaysEmitIntoClient - @_transparent + @inline(__always) public mutating func remove(at index: Int) -> Element { _storage.remove(at: index) } - + + /// Removes all elements from the deque, preserving its allocated capacity. + /// + /// - Complexity: O(`count`) @_alwaysEmitIntoClient - @_transparent - public mutating func removeSubrange(_ bounds: Range) { - _storage.removeSubrange(bounds) - } - - @discardableResult - @_alwaysEmitIntoClient - @_transparent - public mutating func removeFirst() -> Element { - _storage.removeFirst() - } - - @discardableResult - @_alwaysEmitIntoClient - @_transparent - public mutating func removeLast() -> Element { - _storage.removeLast() - } - - @_alwaysEmitIntoClient - @_transparent - public mutating func removeFirst(_ n: Int) { - _storage.removeFirst(n) - } - - @_alwaysEmitIntoClient - @_transparent - public mutating func removeLast(_ n: Int) { - _storage.removeLast(n) - } - - @_alwaysEmitIntoClient - @_transparent + @inline(__always) public mutating func removeAll() { _storage.removeAll() } - + + /// Removes and returns the first element of the deque. + /// + /// The deque must not be empty. + /// + /// - Returns: The first element of the original deque. + /// + /// - Complexity: O(1) + @discardableResult @_alwaysEmitIntoClient - @_transparent + @inline(__always) + public mutating func removeFirst() -> Element { + _storage.removeFirst() + } + + /// Removes and returns the last element of the deque. + /// + /// The deque must not be empty. + /// + /// - Returns: The last element of the original deque. + /// + /// - Complexity: O(1) + @discardableResult + @_alwaysEmitIntoClient + @inline(__always) + public mutating func removeLast() -> Element { + _storage.removeLast() + } + + /// Removes and discards the specified number of elements from the start of + /// the deque. + /// + /// Attempting to remove more elements than exist in the deque + /// triggers a runtime error. + /// + /// - Parameter k: The number of elements to remove from the deque. + /// `k` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// + /// - Complexity: O(`k`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func removeFirst(_ k: Int) { + _storage.removeFirst(k) + } + + /// Removes and discards the specified number of elements from the end of the + /// deque. + /// + /// Attempting to remove more elements than exist in the deque + /// triggers a runtime error. + /// + /// - Parameter k: The number of elements to remove from the deque. + /// `k` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// + /// - Complexity: O(`k`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func removeLast(_ k: Int) { + _storage.removeLast(k) + } + + /// Removes the specified subrange of elements from the deque. + /// + /// - Parameter bounds: The subrange to remove. The bounds of the + /// range must be valid indices of the deque. + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func removeSubrange(_ bounds: Range) { + _storage.removeSubrange(bounds) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Removes and returns the first element of the deque, if there is one. + /// + /// - Returns: The first element of the original deque if it was not empty; + /// otherwise, `nil`. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) public mutating func popFirst() -> Element? { _storage.popFirst() } + /// Removes and returns the last element of the deque, if there is one. + /// + /// - Returns: The last element of the original deque if it was not empty; + /// otherwise, `nil`. + /// + /// - Complexity: O(1) @_alwaysEmitIntoClient - @_transparent + @inline(__always) public mutating func popLast() -> Element? { _storage.popLast() } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift new file mode 100644 index 00000000..98772671 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -0,0 +1,616 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Replaces the specified range of elements by a given count of new items, + /// using a callback to directly initialize deque storage by populating + /// a series of output spans. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting room for the new elements starting at the + /// same location. The number of new elements need not match the number + /// of elements being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, then + /// this method is equivalent to calling + /// `insert(maximumCount: newCount, at: subrange.lowerBound, initializingWith: body)`. + /// + /// Likewise, if you pass a zero for `newCount`, then this method + /// removes the elements in the given subrange without any replacement. + /// This case is more directly expressed by `removeSubrange(subrange)`. + /// + /// The newly prepended items are not guaranteed to form a single contiguous + /// storage region. Therefore, the supplied callback may be invoked multiple + /// times to initialize each successive chunk of storage. However, invocations + /// cease if the callback fails to fully populate its output span or if + /// it throws an error. In such cases, the deque keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// + /// Partial insertions create a gap in ring buffer storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - maximumCount: the maximum number of items to replace the old subrange. + /// - initializer: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `newCount`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + maximumCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= count, + "Subrange out of bounds") + precondition(maximumCount >= 0, "Can't insert a negative number of items") + _ensureFreeCapacity(maximumCount - subrange.count) + try _storage._handle.uncheckedReplaceSubrange( + subrange, + newCount: capacity, + initializingWith: initializer) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by a given count of new items, + /// using callbacks to consume old items, and to then insert new ones. + /// + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// This method has the same overall effect as calling + /// + /// try deque.consume(subrange, consumingWith: consumer) + /// try deque.insert(maximumCount: maximumCount, at: subrange.lowerBound, initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the deque twice. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// The removed and newly inserted items are not guaranteed to form a single + /// contiguous storage region. Therefore, the supplied callbacks may be + /// invoked multiple times to consume, then initialize successive chunks of + /// storage. Calls to `consumer` do not get interleaved with calls to + /// `initializer`: no new item is inserted until every replaced item has been + /// consumed. + /// + /// The `initializer` callback is not required to fully populate its + /// output span, and it is allowed to throw an error. In such cases, the + /// deque keeps all items that were successfully initialized before the + /// callback terminated. + /// + /// Partial insertions create a gap in ring buffer storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - maximumCount: the maximum number of items to replace the old subrange. + /// - consumer: A callback that gets called at most twice to consume + /// the elements to be removed directly from the deque's storage. The + /// function is always called with a non-empty input span. + /// - initializer: A callback that gets called at most twice to directly + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity + /// of the callback invocations. + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + maximumCount: Int, + consumingWith consumer: (inout InputSpan) -> Void, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= count, + "Subrange out of bounds") + precondition(maximumCount >= 0, "Can't insert a negative number of items") + _ensureFreeCapacity(maximumCount - subrange.count) + try _storage._handle.uncheckedReplaceSubrange( + subrange, + newCount: capacity, + consumingWith: consumer, + initializingWith: initializer) + } +#endif +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Replaces the specified range of elements by moving the elements of a + /// fully initialized buffer into their place. On return, the buffer is left + /// in an uninitialized state. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: A fully initialized buffer whose contents to move into + /// the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving items: UnsafeMutableBufferPointer, + ) { + var remainder = items + replaceSubrange(subrange, maximumCount: remainder.count) { target in + target.withUnsafeMutableBufferPointer { buffer, count in + buffer.moveInitializeAll( + fromContentsOf: remainder._trim(first: buffer.count)) + count = buffer.count + } + } + assert(remainder.isEmpty) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by moving the contents of an + /// input span into their place. On return, the span is left empty. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: An input span whose contents are to be moved into the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving items: inout InputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.replaceSubrange(subrange, moving: source) + count = 0 + } + } +#endif + + /// Replaces the specified range of elements by moving the contents of an + /// output span into their place. On return, the span is left empty. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: An output span whose contents are to be moved into the deque. + /// + /// - Complexity: O(`self.count` + `items.count`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving items: inout OutputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.replaceSubrange(subrange, moving: source) + count = 0 + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by at most `maximumCount` items + /// generated by a producer. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the items generated by `producer` at `subrange.lowerBound`. This + /// case is more directly expressed by calling `insert(moving:at:)`. + /// + /// Likewise, if the given producer is empty, then this method removes the + /// elements in the given subrange without replacement. This case is more + /// directly expressed by calling `removeSubrange`. + /// + /// This operation inserts as many items as the producer can generate before + /// either reaching `maximumCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `maximumCount` items left in + /// its underlying sequence, then extra items remain available after this + /// method returns. + /// + /// If the operation inserts fewer than `maximumCount` items, then it results in + /// a gap in ring buffer storage that needs to be closed by moving some + /// items to their correct positions given the adjusted count. This adds some + /// overhead compared to adding exactly as many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - maximumCount: The maximum number of items to insert into the deque. + /// - producer: A producer that generates the items to append. + /// + /// - Complexity: O(`self.count` + `maximumCount`) + @_alwaysEmitIntoClient + public mutating func replaceSubrange< + P: Producer & ~Copyable & ~Escapable + >( + _ subrange: Range, + maximumCount: Int, + from producer: inout P + ) throws(P.ProducerError) { + try replaceSubrange(subrange, maximumCount: maximumCount) { target throws(P.ProducerError) in + while !target.isFull, try producer.generate(into: &target) { + // Do nothing + } + } + } +#endif +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /* where Element: Copyable */ { + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `items.count`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying items: UnsafeBufferPointer + ) { + var remainder = items + replaceSubrange(subrange, maximumCount: remainder.count) { target in + target.withUnsafeMutableBufferPointer { dst, dstCount in + dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) + dstCount += dst.count + } + } + assert(remainder.isEmpty) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length buffer as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `items.count`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying items: UnsafeMutableBufferPointer + ) { + unsafe self.replaceSubrange( + subrange, + copying: UnsafeBufferPointer(items)) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given span. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length span as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `items.count`) + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying items: Span + ) { + unsafe items.withUnsafeBufferPointer { buffer in + unsafe self.replaceSubrange(subrange, copying: buffer) + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + @inlinable + internal mutating func _replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copyingContainer items: borrowing C, + newCount: Int + ) { + + let expectedCount = self.count - subrange.count + newCount + var it = items.makeBorrowingIterator() + self.replaceSubrange(subrange, maximumCount: newCount) { target in + it.copyContents(into: &target) + } + precondition( + it.nextSpan().isEmpty && count == expectedCount, + "Broken Container: count doesn't match contents") + } +#endif + + @inlinable + internal mutating func _replaceSubrange( + _ subrange: Range, + copyingCollection items: __owned some Collection, + newCount: Int + ) { + let done: Void? = items.withContiguousStorageIfAvailable { src in + precondition( + src.count == newCount, + "Broken Collection: count doesn't match contents") + self.replaceSubrange(subrange, copying: src) + } + if done != nil { return } + + var i = items.startIndex + self.replaceSubrange(subrange, maximumCount: newCount) { target in + while !target.isFull { + target.append(items[i]) + items.formIndex(after: &i) + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length container as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the array. + /// - items: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `items.count`) + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copying items: borrowing C + ) { + _replaceSubrange( + subrange, copyingContainer: items, newCount: items.count) + } +#endif + + /// Replaces the specified subrange of elements by copying the elements of + /// the given collection. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length collection as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - items: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `items.count`) + @inlinable + @inline(__always) + public mutating func replaceSubrange( + _ subrange: Range, + copying items: __owned some Collection + ) { + _replaceSubrange( + subrange, copyingCollection: items, newCount: items.count) + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the deque and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the deque doesn't have sufficient capacity to accommodate the new + /// elements, then this method reallocates the deque's storage to grow it, + /// using a geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `items` at `subrange.lowerBound`. This case + /// is more directly expressed by calling `insert(copying:at:)`. + /// + /// Likewise, if you pass a zero-length container as the `items` + /// parameter, this method removes the elements in the given subrange + /// without replacement. This case is more directly expressed by calling + /// `removeSubrange`. + /// + /// - Parameters: + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the array. + /// - items: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this deque and + /// *m* is the count of `items`. + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & Collection + >( + _ subrange: Range, + copying items: C + ) { + _replaceSubrange( + subrange, copyingContainer: items, newCount: items.count) + } +#endif +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift index e9da7ca8..671ebfa5 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -32,11 +32,55 @@ public struct UniqueDeque: ~Copyable { public struct UniqueDeque: ~Copyable { @usableFromInline package var _storage: RigidDeque + + @_alwaysEmitIntoClient + @inline(__always) + package init(_storage: consuming RigidDeque) { + self._storage = _storage + } } @available(SwiftStdlib 5.0, *) extension UniqueDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { +#if COLLECTIONS_INTERNAL_CHECKS + @usableFromInline @inline(never) @_effects(releasenone) + package func _checkInvariants() { + _handle._checkInvariants() + } +#else + @_transparent + package func _checkInvariants() {} +#endif // COLLECTIONS_INTERNAL_CHECKS +} + +//MARK: - Basics + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// The maximum number of elements this array can hold without reallocating + /// its storage. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public var capacity: Int { _assumeNonNegative(_storage.capacity) } + + /// The number of additional elements that can be added to this array without + /// reallocating its storage. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_transparent + public var freeCapacity: Int { _assumeNonNegative(_storage.freeCapacity) } + + @_alwaysEmitIntoClient + @_transparent + public var _isFull: Bool { _storage.isFull } +} + @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { public typealias Index = Int @@ -98,32 +142,111 @@ extension UniqueDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { - @_alwaysEmitIntoClient + /// Exchanges the values at the specified indices of the deque. + /// + /// Both parameters must be valid indices of the deque and not equal to + /// `endIndex`. Passing the same index as both `i` and `j` has no effect. + /// + /// - Parameter i: The index of the first value to swap. + /// - Parameter j: The index of the second valud to swap. + /// + /// - Complexity: O(1) @_transparent - internal var _capacity: Int { _storage.capacity } - - @_alwaysEmitIntoClient - @_transparent - internal var _freeCapacity: Int { _storage.freeCapacity } - - @_alwaysEmitIntoClient - @_transparent - internal var _isFull: Bool { _storage.isFull } - - @inlinable - internal mutating func _grow(to minimumCapacity: Int) { - if _fastPath(minimumCapacity <= _capacity) { - return - } - - let c = Swift.max(minimumCapacity, 7 * _capacity / 4) - _storage.reallocate(capacity: c) - } - - @inlinable - internal mutating func _ensureFreeCapacity(_ freeCapacity: Int) { - _grow(to: count + freeCapacity) + public mutating func swapAt(_ i: Int, _ j: Int) { + _storage.swapAt(i, j) } } +//MARK: - Resizing + +@_alwaysEmitIntoClient +@_transparent +internal func _growUniqueDequeCapacity(_ capacity: Int) -> Int { + // A growth factor of 1.5 seems like a reasonable compromise between + // over-allocating memory and wasting cycles on repeatedly resizing storage. + let c = (3 &* UInt(bitPattern: capacity) &+ 1) / 2 + return Int(bitPattern: c) +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque where Element: ~Copyable { + /// Grow or shrink the capacity of this deque instance without discarding + /// its contents. + /// + /// This operation replaces the deque's storage buffer with a newly allocated + /// buffer of the specified capacity, moving all existing elements + /// to its new storage. The old storage is then deallocated. + /// + /// - Parameter newCapacity: The desired new capacity. `newCapacity` must be + /// greater than or equal to the current count. + /// + /// - Complexity: O(`count`) + @inlinable + public mutating func reallocate(capacity: Int) { + _storage.reallocate(capacity: capacity) + } + + /// Ensure that the array has capacity to store the specified number of + /// elements, by growing its storage buffer if necessary. + /// + /// If `capacity < n`, then this operation reallocates the unique array's + /// storage to grow it; on return, the array's capacity becomes `n`. + /// Otherwise the array is left as is. + /// + /// - Complexity: O(`count`) + @inlinable + public mutating func reserveCapacity(_ n: Int) { + _storage.reserveCapacity(n) + } + + + @_alwaysEmitIntoClient + @_transparent + internal mutating func _ensureFreeCapacity(_ freeCapacity: Int) { + guard _storage.freeCapacity < freeCapacity else { return } + _ensureFreeCapacitySlow(freeCapacity) + } + + @_alwaysEmitIntoClient + @_transparent + internal func _grow(freeCapacity: Int) -> Int { + Swift.max( + count + freeCapacity, + _growUniqueDequeCapacity(capacity)) + } + + @inlinable + internal mutating func _ensureFreeCapacitySlow(_ freeCapacity: Int) { + let newCapacity = _grow(freeCapacity: freeCapacity) + reallocate(capacity: newCapacity) + } +} + +//MARK: - Copying helpers + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque { + /// Copy the contents of this deque into a newly allocated deque + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + public func _clone() -> Self { + UniqueDeque(_storage: _storage._clone()) + } + + /// Copy the contents of this deque into a newly allocated rigid deque + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting rigid deque. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) + @_alwaysEmitIntoClient + public func _clone(capacity: Int) -> Self { + UniqueDeque(_storage: _storage._clone(capacity: capacity)) + } +} + + #endif // compiler(<6.2) diff --git a/Tests/DequeTests/UniqueDequeTests.swift b/Tests/DequeTests/UniqueDequeTests.swift new file mode 100644 index 00000000..27f5cff3 --- /dev/null +++ b/Tests/DequeTests/UniqueDequeTests.swift @@ -0,0 +1,198 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +import XCTest +#if COLLECTIONS_SINGLE_MODULE +@_spi(Testing) import Collections +#else +import _CollectionsTestSupport +import DequeModule +import BasicContainers +import ContainersPreview +#endif + +#if compiler(>=6.2) +#if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +internal func expectIterableContents< + Element: Equatable, + C2: Collection, +>( + _ left: borrowing UniqueDeque, + equalTo right: C2, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + expectIterableContents( + left, + equivalentTo: right, + by: ==, + message(), trapping: trapping, file: file, line: line) +} + +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +internal func expectIterableContents< + E1, + C2: Collection, +>( + _ left: borrowing UniqueDeque, + equivalentTo right: C2, + by areEquivalent: (borrowing E1, C2.Element) -> Bool, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + expectIterableContents( + left, + equivalentTo: right, + by: areEquivalent, + printer: { "\($0)" }, + message(), + file: file, + line: line) +} + +/// Check if `left` and `right` contain equal elements in the same order. +@available(SwiftStdlib 5.0, *) +internal func expectIterableContents< + E1: ~Copyable, + C2: Collection, +>( + _ left: borrowing UniqueDeque, + equivalentTo right: C2, + by areEquivalent: (borrowing E1, C2.Element) -> Bool, + printer: (borrowing E1) -> String, + _ message: @autoclosure () -> String = "", + trapping: Bool = false, + file: StaticString = #filePath, + line: UInt = #line +) { + var c = 0 + var j = right.startIndex + for i in 0 ..< left.count { + expectEquivalent( + left[i], + right[j], + by: areEquivalent, + printer: printer, + "offset: \(c) \(message())", + trapping: trapping, + file: file, line: line) + right.formIndex(after: &j) + c += 1 + } +} + +#endif + +final class UniqueDequeTests: CollectionTestCase { + struct TestError: Error, Equatable { + let value: Int + init(_ value: Int) { self.value = value } + } + + func test_basicProperties() { + var deque = UniqueDeque() + + // Empty deque + expectEqual(deque.isEmpty, true) + expectEqual(deque._isFull, true) + expectEqual(deque.count, 0) + expectEqual(deque.capacity, 0) + expectEqual(deque.freeCapacity, 0) + expectEqual(deque.startIndex, 0) + expectEqual(deque.endIndex, 0) + expectEqual(deque.indices, 0 ..< 0) + + deque.append(1) + deque.append(2) + deque.append(3) + + expectEqual(deque.isEmpty, false) + expectEqual(deque._isFull, true) + expectEqual(deque.count, 3) + expectEqual(deque.capacity, 3) + expectEqual(deque.freeCapacity, 0) + expectEqual(deque.startIndex, 0) + expectEqual(deque.endIndex, 3) + expectEqual(deque.indices, 0 ..< 3) + + for i in 4...10 { + deque.prepend(i) + } + + expectEqual(deque.isEmpty, false) + expectEqual(deque.count, 10) + expectEqual(deque.capacity, 12) + expectEqual(deque.freeCapacity, 2) + expectEqual(deque.indices, 0 ..< 10) + } + + func test_subscriptBorrow() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withLifetimeTracking { tracker in + let data = tracker.uniqueDeque(with: layout) + withEvery("i", in: 0 ..< layout.count) { i in + expectEqual(data.deque[i], data.contents[i]) + } + } + } + } + + func test_subscriptMutate() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in + withEvery("i", in: 0 ..< layout.count) { i in + withLifetimeTracking { tracker in + var data = tracker.uniqueDeque(with: layout) + let new = tracker.instance(for: 100) + data.deque[i] = new + data.contents[i] = new + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + + func test_swapAt() { + withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5]) { layout in + withEvery("i", in: 0 ..< layout.count) { i in + withEvery("j", in: 0 ..< layout.count) { j in + withLifetimeTracking { tracker in + var data = tracker.uniqueDeque(with: layout) + data.deque.swapAt(i, j) + data.contents.swapAt(i, j) + expectIterableContents(data.deque, equalTo: data.contents) + } + } + } + } + } + + func test_growth() { + let expectedCapacities = [ + 0, 1, 2, 3, 5, 8, 12, 18, 27, 41, 62, 93, 140, 210, 315 + ] + var actualCapacities: Set = [] + var deque = UniqueDeque() + for i in 0 ..< 256 { + actualCapacities.insert(deque.capacity) + deque.append(i) + } + expectEqualElements(actualCapacities.sorted(), expectedCapacities) + } +} + +#endif From 9a4ee93406c6e9b6d511cd707009759868d9320c Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 09:41:40 -0800 Subject: [PATCH 26/75] Simplify some RIgidArray operations --- .../RigidArray+Insertions.swift | 28 +++---- .../Extensions/OutputSpan+Extras.swift | 84 +++++++++++-------- .../Extensions/TemporaryAllocation.swift | 2 +- .../ContainersPreview/Types/InputSpan.swift | 45 +++++++++- 4 files changed, 103 insertions(+), 56 deletions(-) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 43c31f54..7a46c180 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -119,10 +119,7 @@ extension RigidArray where Element: ~Copyable { at index: Int ) { insert(count: items.count, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in - buffer.moveInitializeAll(fromContentsOf: items) - count = items.count - } + target._append(moving: items) } } @@ -207,15 +204,10 @@ extension RigidArray where Element: ~Copyable { at index: Int ) { // FIXME: Remove this in favor of a generic algorithm over consumable containers + guard !items.isEmpty else { return } insert(count: items.count, at: index) { target in - target.withUnsafeMutableBufferPointer { dst, dstCount in - items.edit { source in - source.withUnsafeMutableBufferPointer { src, srcCount in - dst.moveInitializeAll(fromContentsOf: src) - dstCount = src.count - srcCount = 0 - } - } + items.edit { source in + target._append(moving: &source) } } } @@ -279,10 +271,7 @@ extension RigidArray { ) { guard newElements.count > 0 else { return } self.insert(count: newElements.count, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in - buffer.initializeAll(fromContentsOf: newElements) - count = newElements.count - } + target._append(copying: newElements) } } @@ -307,6 +296,7 @@ extension RigidArray { /// /// - Complexity: O(`count` + `newElements.count`) @inlinable + @inline(__always) public mutating func insert( copying newElements: UnsafeMutableBufferPointer, at index: Int @@ -333,11 +323,13 @@ extension RigidArray { /// /// - Complexity: O(`count` + `newElements.count`) @inlinable + @inline(__always) public mutating func insert( copying newElements: Span, at index: Int ) { - unsafe newElements.withUnsafeBufferPointer { - unsafe self.insert(copying: $0, at: index) + guard newElements.count > 0 else { return } + self.insert(count: newElements.count, at: index) { target in + target._append(copying: newElements) } } diff --git a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift index df6c849e..d77c8c57 100644 --- a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if compiler(>=6.2) #if !COLLECTIONS_SINGLE_MODULE import InternalCollectionsUtilities @@ -51,40 +51,48 @@ extension OutputSpan where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension OutputSpan where Element: ~Copyable { - @_lifetime(source: copy source) @inlinable - package mutating func _append(moving source: inout InputSpan) { + @inline(__always) + package mutating func _append( + moving source: UnsafeMutableBufferPointer + ) { // FIXME: This needs to be in the stdlib. + guard source.count > 0 else { return } self.withUnsafeMutableBufferPointer { dst, dstCount in - source.withUnsafeMutableBufferPointer { src, srcCount in - let dstEnd = dstCount + srcCount - let srcStart = src.count - srcCount - precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") - let srcItems = src._extracting(uncheckedFrom: srcStart, to: src.count) - dst - ._extracting(uncheckedFrom: dstCount, to: dstEnd) - .moveInitializeAll(fromContentsOf: srcItems) - dstCount &+= srcCount - srcCount = 0 - } + let dstEnd = dstCount + source.count + precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") + dst + ._extracting(uncheckedFrom: dstCount, to: dstEnd) + .moveInitializeAll(fromContentsOf: source) + dstCount &+= source.count } } - + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @_lifetime(source: copy source) @inlinable + @inline(__always) + package mutating func _append(moving source: inout InputSpan) { + // FIXME: This needs to be in the stdlib. + source.withUnsafeMutableBufferPointer { src, srcCount in + let srcItems = src._extracting( + uncheckedFrom: src.count &- srcCount, + to: src.count) + self._append(moving: srcItems) + srcCount = 0 + } + } +#endif + + @_lifetime(source: copy source) + @inlinable + @inline(__always) package mutating func _append(moving source: inout OutputSpan) { // FIXME: This needs to be in the stdlib. - self.withUnsafeMutableBufferPointer { dst, dstCount in - source.withUnsafeMutableBufferPointer { src, srcCount in - let dstEnd = dstCount + srcCount - precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") - let srcItems = src._extracting(uncheckedFrom: 0, to: srcCount) - dst - ._extracting(uncheckedFrom: dstCount, to: dstEnd) - .moveInitializeAll(fromContentsOf: srcItems) - dstCount &+= srcCount - srcCount = 0 - } + source.withUnsafeMutableBufferPointer { src, srcCount in + let items = src._extracting(uncheckedFrom: 0, to: srcCount) + self._append(moving: items) + srcCount = 0 } } } @@ -92,17 +100,23 @@ extension OutputSpan where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension OutputSpan /* where Element: Copyable */ { @inlinable - package mutating func _append(copying source: borrowing Span) { + package mutating func _append(copying source: UnsafeBufferPointer) { // FIXME: This needs to be in the stdlib. self.withUnsafeMutableBufferPointer { dst, dstCount in - source.withUnsafeBufferPointer { src in - let dstEnd = dstCount + src.count - precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") - dst - ._extracting(uncheckedFrom: dstCount, to: dstEnd) - .initializeAll(fromContentsOf: src) - dstCount &+= src.count - } + let dstEnd = dstCount + source.count + precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") + dst + ._extracting(uncheckedFrom: dstCount, to: dstEnd) + .initializeAll(fromContentsOf: source) + dstCount &+= source.count + } + } + + @inlinable + package mutating func _append(copying source: borrowing Span) { + // FIXME: This needs to be in the stdlib. + source.withUnsafeBufferPointer { src in + self._append(copying: src) } } } diff --git a/Sources/ContainersPreview/Extensions/TemporaryAllocation.swift b/Sources/ContainersPreview/Extensions/TemporaryAllocation.swift index 6a4a3eb1..6ec7b5fe 100644 --- a/Sources/ContainersPreview/Extensions/TemporaryAllocation.swift +++ b/Sources/ContainersPreview/Extensions/TemporaryAllocation.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if compiler(>=6.2) /// A polyfill of the typed-throws supporting `withUnsafeTemporaryAllocation` in the 6.3 stdlib. @_alwaysEmitIntoClient @_transparent diff --git a/Sources/ContainersPreview/Types/InputSpan.swift b/Sources/ContainersPreview/Types/InputSpan.swift index 9eeaebed..e9bc58c6 100644 --- a/Sources/ContainersPreview/Types/InputSpan.swift +++ b/Sources/ContainersPreview/Types/InputSpan.swift @@ -372,10 +372,27 @@ extension InputSpan where Element: ~Copyable { } } -//MARK: Bulk append functions +//MARK: Bulk prepend functions @available(SwiftStdlib 5.0, *) -extension InputSpan { +extension InputSpan where Element: ~Copyable { + @_alwaysEmitIntoClient + @_lifetime(self: copy self) + public mutating func prepend(moving source: UnsafeMutableBufferPointer) { + self.withUnsafeMutableBufferPointer { dst, dstCount in + let dstEnd = dst.count &- dstCount + let dstStart = dstEnd - source.count + precondition(dstStart >= 0, "InputSpan capacity overflow") + dst + ._extracting(uncheckedFrom: dstStart, to: dstEnd) + .moveInitializeAll(fromContentsOf: source) + dstCount &+= source.count + } + } +} + +@available(SwiftStdlib 5.0, *) +extension InputSpan /* where Element: Copyable */ { /// Repeatedly append an element to this span. @_alwaysEmitIntoClient @_lifetime(self: copy self) @@ -388,6 +405,30 @@ extension InputSpan { } } +@available(SwiftStdlib 5.0, *) +extension InputSpan /* where Element: Copyable */ { + @inlinable + package mutating func prepend(copying source: UnsafeBufferPointer) { + self.withUnsafeMutableBufferPointer { dst, dstCount in + let dstEnd = dst.count &- dstCount + let dstStart = dstEnd - source.count + precondition(dstStart >= 0, "InputSpan capacity overflow") + dst + ._extracting(uncheckedFrom: dstStart, to: dstEnd) + .initializeAll(fromContentsOf: source) + dstCount &+= source.count + } + } + + @inlinable + package mutating func prepend(copying source: borrowing Span) { + source.withUnsafeBufferPointer { src in + self.prepend(copying: src) + } + } +} + + @available(SwiftStdlib 5.0, *) extension InputSpan where Element: ~Copyable { /// Borrow the underlying initialized memory for read-only access. From 3a1498781aa1a8842452e87d53f3397c77156f3a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 00:30:30 -0800 Subject: [PATCH 27/75] Fix support for older compilers --- .../Extensions/OutputSpan+Extras.swift | 6 +++++- Sources/DequeModule/_UnsafeDequeHandle.swift | 9 ++++++++- Tests/DequeTests/DequeInternals.swift | 11 +++++++++++ .../AssertionContexts/Assertions.swift | 4 +++- .../Utilities/LifetimeTrackedStruct.swift | 2 ++ .../Utilities/LifetimeTracker.swift | 2 ++ 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift index d77c8c57..d00c3490 100644 --- a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift @@ -53,6 +53,7 @@ extension OutputSpan where Element: ~Copyable { extension OutputSpan where Element: ~Copyable { @inlinable @inline(__always) + @_lifetime(self: copy self) package mutating func _append( moving source: UnsafeMutableBufferPointer ) { @@ -72,6 +73,7 @@ extension OutputSpan where Element: ~Copyable { @_lifetime(source: copy source) @inlinable @inline(__always) + @_lifetime(self: copy self) package mutating func _append(moving source: inout InputSpan) { // FIXME: This needs to be in the stdlib. source.withUnsafeMutableBufferPointer { src, srcCount in @@ -87,6 +89,7 @@ extension OutputSpan where Element: ~Copyable { @_lifetime(source: copy source) @inlinable @inline(__always) + @_lifetime(self: copy self) package mutating func _append(moving source: inout OutputSpan) { // FIXME: This needs to be in the stdlib. source.withUnsafeMutableBufferPointer { src, srcCount in @@ -100,6 +103,7 @@ extension OutputSpan where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension OutputSpan /* where Element: Copyable */ { @inlinable + @_lifetime(self: copy self) package mutating func _append(copying source: UnsafeBufferPointer) { // FIXME: This needs to be in the stdlib. self.withUnsafeMutableBufferPointer { dst, dstCount in @@ -113,6 +117,7 @@ extension OutputSpan /* where Element: Copyable */ { } @inlinable + @_lifetime(self: copy self) package mutating func _append(copying source: borrowing Span) { // FIXME: This needs to be in the stdlib. source.withUnsafeBufferPointer { src in @@ -121,5 +126,4 @@ extension OutputSpan /* where Element: Copyable */ { } } - #endif diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 43602741..c3c4cdde 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -16,7 +16,6 @@ import ContainersPreview @frozen @usableFromInline -@unsafe package struct _UnsafeDequeHandle: ~Copyable { @usableFromInline package typealias Slot = _DequeSlot @@ -609,6 +608,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +#if compiler(>=6.2) @available(SwiftStdlib 5.0, *) extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @@ -625,6 +625,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { return try body(&span) } } +#endif extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient @@ -651,6 +652,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +#if compiler(>=6.2) @available(SwiftStdlib 5.0, *) extension _UnsafeDequeHandle where Element: ~Copyable { /// Append a given number of items to the end of this deque by populating @@ -755,6 +757,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } } +#endif @available(SwiftStdlib 5.0, *) extension _UnsafeDequeHandle where Element: ~Copyable { @@ -1200,6 +1203,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +#if compiler(>=6.2) @available(SwiftStdlib 5.0, *) extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient @@ -1223,6 +1227,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } } +#endif extension _UnsafeDequeHandle { /// Insert all elements from `newElements` into this deque, starting at @@ -1335,6 +1340,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { // MARK: Replacement +#if compiler(>=6.2) @available(SwiftStdlib 5.0, *) extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient @@ -1413,3 +1419,4 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } #endif } +#endif diff --git a/Tests/DequeTests/DequeInternals.swift b/Tests/DequeTests/DequeInternals.swift index 10b00c43..8bf76c0a 100644 --- a/Tests/DequeTests/DequeInternals.swift +++ b/Tests/DequeTests/DequeInternals.swift @@ -16,6 +16,8 @@ import _CollectionsTestSupport @_spi(Testing) import DequeModule #endif +#if compiler(>=6.2) +@available(SwiftStdlib 5.0, *) internal struct RigidTestData: ~Copyable { var deque: RigidDeque var contents: [Element] @@ -26,6 +28,7 @@ internal struct RigidTestData: ~Copyable { } } +@available(SwiftStdlib 5.0, *) internal struct UniqueTestData: ~Copyable { var deque: UniqueDeque var contents: [Element] @@ -39,6 +42,7 @@ internal struct UniqueTestData: ~Copyable { self.contents = contents } } +#endif internal struct DequeLayout: Hashable, CustomStringConvertible { let capacity: Int @@ -77,12 +81,15 @@ extension Deque { } } +#if compiler(>=6.2) +@available(SwiftStdlib 5.0, *) extension RigidDeque { init(layout: DequeLayout, contents: C) where C.Element == Element { precondition(contents.count == layout.count) self.init(_capacity: layout.capacity, startSlot: layout.startSlot, copying: contents) } } +#endif extension LifetimeTracker { func deque( @@ -93,6 +100,8 @@ extension LifetimeTracker { return (deque, contents) } +#if compiler(>=6.2) + @available(SwiftStdlib 5.0, *) func rigidDeque( with layout: DequeLayout ) -> RigidTestData> { @@ -101,6 +110,7 @@ extension LifetimeTracker { return RigidTestData(deque, contents) } + @available(SwiftStdlib 5.0, *) func uniqueDeque( with layout: DequeLayout ) -> UniqueTestData> { @@ -108,6 +118,7 @@ extension LifetimeTracker { let deque = RigidDeque(layout: layout, contents: contents) return UniqueTestData(deque, contents) } +#endif } func withEveryDeque( diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift index a1c0de77..dbdc70fc 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2026 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 @@ -158,6 +158,7 @@ public func expectEquivalent( message, trapping: trapping, file: file, line: line) } +#if compiler(>=6.2) // FIXME: Remove when CustomStringConvertible starts supporting // noncopyable/nonescapable types. public func expectEquivalent< @@ -177,6 +178,7 @@ public func expectEquivalent< "'\(printer(left))' is not equivalent to '\(right)'", message, trapping: trapping, file: file, line: line) } +#endif public func expectEquivalent( _ left: A?, _ right: B?, diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift index 7cb8a069..6c961f98 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTrackedStruct.swift @@ -60,11 +60,13 @@ public struct LifetimeTrackedStruct: ~Copyable { } } +#if compiler(>=6.2) extension LifetimeTrackedStruct: TestPrintable where Payload: TestPrintable & ~Copyable { public var testDescription: String { return "\(payload.testDescription)" } } +#endif extension LifetimeTrackedStruct/*: Equatable*/ where Payload: Equatable /*& ~Copyable*/ { public static func == (left: borrowing Self, right: borrowing Self) -> Bool { diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift index 57f34eb2..54590780 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift @@ -59,6 +59,7 @@ public class LifetimeTracker { return items.map { LifetimeTracked($0, for: self) } } +#if compiler(>=6.2) @available(SwiftStdlib 5.0, *) public func structInstances( count: Int, @@ -72,6 +73,7 @@ public class LifetimeTracker { } } } +#endif public func instances( for items: S, by transform: (S.Element) -> T From 4c9a0da7f1c222dadf46f8366bd4acb26834db36 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 11:08:22 -0800 Subject: [PATCH 28/75] Update CMake configuration --- Sources/BasicContainers/CMakeLists.txt | 1 + Sources/ContainersPreview/CMakeLists.txt | 22 ++++++++++++------- Sources/DequeModule/CMakeLists.txt | 21 ++++++++++++------ .../CMakeLists.txt | 3 ++- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Sources/BasicContainers/CMakeLists.txt b/Sources/BasicContainers/CMakeLists.txt index 94586ef4..ce27daa1 100644 --- a/Sources/BasicContainers/CMakeLists.txt +++ b/Sources/BasicContainers/CMakeLists.txt @@ -25,6 +25,7 @@ endif() target_sources(${module_name} PRIVATE "RigidArray.swift" "RigidArray+Append.swift" + "RigidArray+Container.swift" "RigidArray+Experimental.swift" "RigidArray+Initializers.swift" "RigidArray+Insertions.swift" diff --git a/Sources/ContainersPreview/CMakeLists.txt b/Sources/ContainersPreview/CMakeLists.txt index a7f43d1d..0a2eaaf3 100644 --- a/Sources/ContainersPreview/CMakeLists.txt +++ b/Sources/ContainersPreview/CMakeLists.txt @@ -23,12 +23,18 @@ else() endif() target_sources(${module_name} PRIVATE - "BorrowingIteratorProtocol.swift" - "Box.swift" - "Container.swift" - "Container+Utilities.swift" - "InputSpan.swift" - "Mut.swift" - "Ref.swift" - "Shared.swift" + "Extensions/OutputSpan+Extras.swift" + "Extensions/TemporaryAllocation.swift" + "Protocols/BorrowingIteratorProtocol.swift" + "Protocols/BorrowingSequence.swift" + "Protocols/BorrowingSequence+Standard Conformances.swift" + "Protocols/BorrowingSequence+Utilities.swift" + "Protocols/Container.swift" + "Protocols/Drain.swift" + "Protocols/Producer.swift" + "Types/Borrow.swift" + "Types/Box.swift" + "Types/Inout.swift" + "Types/InputSpan.swift" + "Types/Shared.swift" ) diff --git a/Sources/DequeModule/CMakeLists.txt b/Sources/DequeModule/CMakeLists.txt index 97927d00..e27d4325 100644 --- a/Sources/DequeModule/CMakeLists.txt +++ b/Sources/DequeModule/CMakeLists.txt @@ -14,7 +14,8 @@ else() add_library(DequeModule ${COLLECTIONS_DEQUE_SOURCES}) target_link_libraries(DequeModule PRIVATE - InternalCollectionsUtilities) + InternalCollectionsUtilities + ContainersPreview) set_target_properties(DequeModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) @@ -26,21 +27,27 @@ target_sources(${module_name} PRIVATE "_UnsafeDequeSegments.swift" "_UnsafeDequeHandle.swift" "_DequeSlot.swift" - "RigidDeque/RigidDeque+Append.swift" - "RigidDeque/RigidDeque+Container.swift" "RigidDeque/RigidDeque.swift" + "RigidDeque/RigidDeque+Append.swift" + "RigidDeque/RigidDeque+Consumption.swift" + "RigidDeque/RigidDeque+Container.swift" + "RigidDeque/RigidDeque+Experimental.swift" "RigidDeque/RigidDeque+Initializers.swift" - "RigidDeque/RigidDeque+Testing.swift" "RigidDeque/RigidDeque+Insertions.swift" - "RigidDeque/RigidDeque+Collection.swift" "RigidDeque/RigidDeque+Prepend.swift" "RigidDeque/RigidDeque+Removals.swift" + "RigidDeque/RigidDeque+Replacements.swift" + "RigidDeque/RigidDeque+Testing.swift" + "UniqueDeque/UniqueDeque.swift" + "UniqueDeque/UniqueDeque+Append.swift" + "UniqueDeque/UniqueDeque+Consumption.swift" + "UniqueDeque/UniqueDeque+Container.swift" + "UniqueDeque/UniqueDeque+Experimental.swift" "UniqueDeque/UniqueDeque+Initializers.swift" "UniqueDeque/UniqueDeque+Insertions.swift" - "UniqueDeque/UniqueDeque.swift" "UniqueDeque/UniqueDeque+Prepend.swift" - "UniqueDeque/UniqueDeque+Append.swift" "UniqueDeque/UniqueDeque+Removals.swift" + "UniqueDeque/UniqueDeque+Replacements.swift" "Deque/_DequeBuffer.swift" "Deque/Deque+Collection.swift" "Deque/Deque+CustomReflectable.swift" diff --git a/Sources/InternalCollectionsUtilities/CMakeLists.txt b/Sources/InternalCollectionsUtilities/CMakeLists.txt index c007ce1c..c1154d81 100644 --- a/Sources/InternalCollectionsUtilities/CMakeLists.txt +++ b/Sources/InternalCollectionsUtilities/CMakeLists.txt @@ -25,10 +25,11 @@ target_sources(${module_name} PRIVATE "Descriptions.swift" "LifetimeOverride.swift" "RandomAccessCollection+Offsets.swift" + "Span+Extras.swift" "UnsafeBufferPointer+Extras.swift" "UnsafeMutableBufferPointer+Extras.swift" - "UnsafeRawBufferPointer+Extras.swift" "UnsafeMutableRawBufferPointer+Extras.swift" + "UnsafeRawBufferPointer+Extras.swift" "IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift" "IntegerTricks/Integer rank.swift" "IntegerTricks/UInt+first and last set bit.swift" From 27655b8a92dac983e9b8452c3ab2afeae33a0e02 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 11:08:34 -0800 Subject: [PATCH 29/75] Update Xcode project --- .../Utilities/LifetimeTracker.swift | 4 +- Xcode/Collections.xcodeproj/project.pbxproj | 384 +++++++++++++----- Xcode/Shared.xcconfig | 2 +- 3 files changed, 288 insertions(+), 102 deletions(-) diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift index 54590780..1c08fdb7 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift @@ -10,7 +10,9 @@ // //===----------------------------------------------------------------------===// -#if !COLLECTIONS_SINGLE_MODULE +#if COLLECTIONS_SINGLE_MODULE +import Collections +#else import InternalCollectionsUtilities import ContainersPreview import BasicContainers diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 97c610ec..0b54b6d1 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -7,9 +7,65 @@ objects = { /* Begin PBXBuildFile section */ - 7D48BCD12E51524200D7F6F7 /* InputSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCCB2E51524200D7F6F7 /* InputSpan.swift */; }; - 7D48BCD32E51524200D7F6F7 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCC82E51524200D7F6F7 /* Box.swift */; }; - 7D48BCD62E51524200D7F6F7 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCCD2E51524200D7F6F7 /* Shared.swift */; }; + 7D2A77242F27F1B3005780C7 /* RigidArray+Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77232F27F1B3005780C7 /* RigidArray+Container.swift */; }; + 7D2A77262F27F1D1005780C7 /* Span+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77252F27F1D1005780C7 /* Span+Extras.swift */; }; + 7D2A77382F27F1E4005780C7 /* BorrowingSequence+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A772D2F27F1E4005780C7 /* BorrowingSequence+Utilities.swift */; }; + 7D2A77392F27F1E4005780C7 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77332F27F1E4005780C7 /* Box.swift */; }; + 7D2A773A2F27F1E4005780C7 /* Drain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A772F2F27F1E4005780C7 /* Drain.swift */; }; + 7D2A773B2F27F1E4005780C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A772E2F27F1E4005780C7 /* Container.swift */; }; + 7D2A773C2F27F1E4005780C7 /* TemporaryAllocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77282F27F1E4005780C7 /* TemporaryAllocation.swift */; }; + 7D2A773D2F27F1E4005780C7 /* BorrowingSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A772B2F27F1E4005780C7 /* BorrowingSequence.swift */; }; + 7D2A773E2F27F1E4005780C7 /* BorrowingSequence+Standard Conformances.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A772C2F27F1E4005780C7 /* BorrowingSequence+Standard Conformances.swift */; }; + 7D2A773F2F27F1E4005780C7 /* Borrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77322F27F1E4005780C7 /* Borrow.swift */; }; + 7D2A77402F27F1E4005780C7 /* BorrowingIteratorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A772A2F27F1E4005780C7 /* BorrowingIteratorProtocol.swift */; }; + 7D2A77412F27F1E4005780C7 /* Inout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77342F27F1E4005780C7 /* Inout.swift */; }; + 7D2A77422F27F1E4005780C7 /* OutputSpan+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77272F27F1E4005780C7 /* OutputSpan+Extras.swift */; }; + 7D2A77432F27F1E4005780C7 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77362F27F1E4005780C7 /* Shared.swift */; }; + 7D2A77442F27F1E4005780C7 /* InputSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77352F27F1E4005780C7 /* InputSpan.swift */; }; + 7D2A77452F27F1E4005780C7 /* Producer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77302F27F1E4005780C7 /* Producer.swift */; }; + 7D2A77492F27F271005780C7 /* CustomProducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77482F27F271005780C7 /* CustomProducer.swift */; }; + 7D2A774D2F27F285005780C7 /* RigidDequeCrashTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A774A2F27F285005780C7 /* RigidDequeCrashTests.swift */; }; + 7D2A774E2F27F285005780C7 /* UniqueDequeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A774C2F27F285005780C7 /* UniqueDequeTests.swift */; }; + 7D2A774F2F27F285005780C7 /* RigidDequeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A774B2F27F285005780C7 /* RigidDequeTests.swift */; }; + 7D2A77782F27F2BF005780C7 /* Deque._Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77552F27F2BF005780C7 /* Deque._Storage.swift */; }; + 7D2A77792F27F2BF005780C7 /* RigidDeque+Prepend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77682F27F2BF005780C7 /* RigidDeque+Prepend.swift */; }; + 7D2A777A2F27F2BF005780C7 /* UniqueDeque+Consumption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A776F2F27F2BF005780C7 /* UniqueDeque+Consumption.swift */; }; + 7D2A777B2F27F2BF005780C7 /* _UnsafeDequeHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77502F27F2BF005780C7 /* _UnsafeDequeHandle.swift */; }; + 7D2A777C2F27F2BF005780C7 /* _UnsafeDequeSegments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77512F27F2BF005780C7 /* _UnsafeDequeSegments.swift */; }; + 7D2A777D2F27F2BF005780C7 /* RigidDeque+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77622F27F2BF005780C7 /* RigidDeque+Append.swift */; }; + 7D2A777E2F27F2BF005780C7 /* Deque+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A775E2F27F2BF005780C7 /* Deque+Hashable.swift */; }; + 7D2A777F2F27F2BF005780C7 /* RigidDeque+Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77642F27F2BF005780C7 /* RigidDeque+Container.swift */; }; + 7D2A77802F27F2BF005780C7 /* Deque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77542F27F2BF005780C7 /* Deque.swift */; }; + 7D2A77812F27F2BF005780C7 /* UniqueDeque+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A776E2F27F2BF005780C7 /* UniqueDeque+Append.swift */; }; + 7D2A77822F27F2BF005780C7 /* UniqueDeque+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77722F27F2BF005780C7 /* UniqueDeque+Initializers.swift */; }; + 7D2A77832F27F2BF005780C7 /* Deque+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A775B2F27F2BF005780C7 /* Deque+Equatable.swift */; }; + 7D2A77842F27F2BF005780C7 /* UniqueDeque+Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77702F27F2BF005780C7 /* UniqueDeque+Container.swift */; }; + 7D2A77852F27F2BF005780C7 /* RigidDeque+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77662F27F2BF005780C7 /* RigidDeque+Initializers.swift */; }; + 7D2A77862F27F2BF005780C7 /* RigidDeque+Consumption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77632F27F2BF005780C7 /* RigidDeque+Consumption.swift */; }; + 7D2A77872F27F2BF005780C7 /* Deque._UnsafeHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77562F27F2BF005780C7 /* Deque._UnsafeHandle.swift */; }; + 7D2A77882F27F2BF005780C7 /* Deque+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A775D2F27F2BF005780C7 /* Deque+Extras.swift */; }; + 7D2A77892F27F2BF005780C7 /* UniqueDeque+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77752F27F2BF005780C7 /* UniqueDeque+Removals.swift */; }; + 7D2A778A2F27F2BF005780C7 /* UniqueDeque+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77732F27F2BF005780C7 /* UniqueDeque+Insertions.swift */; }; + 7D2A778B2F27F2BF005780C7 /* UniqueDeque+Replacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77762F27F2BF005780C7 /* UniqueDeque+Replacements.swift */; }; + 7D2A778C2F27F2BF005780C7 /* UniqueDeque+Prepend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77742F27F2BF005780C7 /* UniqueDeque+Prepend.swift */; }; + 7D2A778D2F27F2BF005780C7 /* UniqueDeque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A776D2F27F2BF005780C7 /* UniqueDeque.swift */; }; + 7D2A778E2F27F2BF005780C7 /* RigidDeque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77612F27F2BF005780C7 /* RigidDeque.swift */; }; + 7D2A778F2F27F2BF005780C7 /* Deque+CustomReflectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77592F27F2BF005780C7 /* Deque+CustomReflectable.swift */; }; + 7D2A77902F27F2BF005780C7 /* RigidDeque+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77672F27F2BF005780C7 /* RigidDeque+Insertions.swift */; }; + 7D2A77912F27F2BF005780C7 /* RigidDeque+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77692F27F2BF005780C7 /* RigidDeque+Removals.swift */; }; + 7D2A77922F27F2BF005780C7 /* _DequeBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77522F27F2BF005780C7 /* _DequeBuffer.swift */; }; + 7D2A77932F27F2BF005780C7 /* _DequeBufferHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77532F27F2BF005780C7 /* _DequeBufferHeader.swift */; }; + 7D2A77942F27F2BF005780C7 /* Deque+Collection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77582F27F2BF005780C7 /* Deque+Collection.swift */; }; + 7D2A77952F27F2BF005780C7 /* Deque+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77572F27F2BF005780C7 /* Deque+Codable.swift */; }; + 7D2A77962F27F2BF005780C7 /* RigidDeque+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77652F27F2BF005780C7 /* RigidDeque+Experimental.swift */; }; + 7D2A77972F27F2BF005780C7 /* Deque+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A775F2F27F2BF005780C7 /* Deque+Testing.swift */; }; + 7D2A77982F27F2BF005780C7 /* RigidDeque+Replacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A776A2F27F2BF005780C7 /* RigidDeque+Replacements.swift */; }; + 7D2A77992F27F2BF005780C7 /* Deque+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A775A2F27F2BF005780C7 /* Deque+Descriptions.swift */; }; + 7D2A779A2F27F2BF005780C7 /* RigidDeque+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A776B2F27F2BF005780C7 /* RigidDeque+Testing.swift */; }; + 7D2A779B2F27F2BF005780C7 /* UniqueDeque+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77712F27F2BF005780C7 /* UniqueDeque+Experimental.swift */; }; + 7D2A779C2F27F2BF005780C7 /* Deque+ExpressibleByArrayLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A775C2F27F2BF005780C7 /* Deque+ExpressibleByArrayLiteral.swift */; }; + 7D2A779F2F27F367005780C7 /* InoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A779E2F27F367005780C7 /* InoutTests.swift */; }; + 7D2A77A02F27F367005780C7 /* BorrowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A779D2F27F367005780C7 /* BorrowTests.swift */; }; 7D48BCDC2E51554900D7F6F7 /* ClassBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCDB2E51554900D7F6F7 /* ClassBox.swift */; }; 7D48BCDF2E51558700D7F6F7 /* TestPrintable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCDD2E51558700D7F6F7 /* TestPrintable.swift */; }; 7D48BCE02E51558700D7F6F7 /* LifetimeTrackedStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCDE2E51558700D7F6F7 /* LifetimeTrackedStruct.swift */; }; @@ -17,13 +73,6 @@ 7D48BCF02E51597200D7F6F7 /* Assertions+Containers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCEF2E51597200D7F6F7 /* Assertions+Containers.swift */; }; 7D48BCF22E51599200D7F6F7 /* CheckContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF12E51599200D7F6F7 /* CheckContainer.swift */; }; 7D48BCF42E5159A300D7F6F7 /* StaccatoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF32E5159A300D7F6F7 /* StaccatoContainer.swift */; }; - 7D6FEE0F2E877870007C1B86 /* RefTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE0E2E877870007C1B86 /* RefTests.swift */; }; - 7D6FEE102E877870007C1B86 /* MutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE0D2E877870007C1B86 /* MutTests.swift */; }; - 7D6FEE162E8778CF007C1B86 /* Mut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE142E8778CF007C1B86 /* Mut.swift */; }; - 7D6FEE172E8778CF007C1B86 /* BorrowIteratorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE112E8778CF007C1B86 /* BorrowIteratorProtocol.swift */; }; - 7D6FEE182E8778CF007C1B86 /* Container+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE132E8778CF007C1B86 /* Container+Utilities.swift */; }; - 7D6FEE192E8778CF007C1B86 /* Ref.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE152E8778CF007C1B86 /* Ref.swift */; }; - 7D6FEE1A2E8778CF007C1B86 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE122E8778CF007C1B86 /* Container.swift */; }; 7D6FEE252E8778F3007C1B86 /* UniqueArray+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE202E8778F3007C1B86 /* UniqueArray+Append.swift */; }; 7D6FEE262E8778F3007C1B86 /* RigidArray+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE1E2E8778F3007C1B86 /* RigidArray+Removals.swift */; }; 7D6FEE272E8778F3007C1B86 /* UniqueArray+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE232E8778F3007C1B86 /* UniqueArray+Removals.swift */; }; @@ -121,22 +170,7 @@ 7DE9204729CA70F3004483EB /* _HashTable+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB229CA70F3004483EB /* _HashTable+Testing.swift */; }; 7DE9204829CA70F3004483EB /* _HashTable+CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB329CA70F3004483EB /* _HashTable+CustomStringConvertible.swift */; }; 7DE9204929CA70F3004483EB /* _HashTable+BucketIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB429CA70F3004483EB /* _HashTable+BucketIterator.swift */; }; - 7DE9204B29CA70F3004483EB /* _DequeBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB729CA70F3004483EB /* _DequeBuffer.swift */; }; - 7DE9204C29CA70F3004483EB /* Deque+Collection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB829CA70F3004483EB /* Deque+Collection.swift */; }; - 7DE9204E29CA70F3004483EB /* Deque+CustomReflectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBA29CA70F3004483EB /* Deque+CustomReflectable.swift */; }; - 7DE9204F29CA70F3004483EB /* Deque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBB29CA70F3004483EB /* Deque.swift */; }; 7DE9205029CA70F3004483EB /* _DequeSlot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBC29CA70F3004483EB /* _DequeSlot.swift */; }; - 7DE9205129CA70F3004483EB /* Deque+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBD29CA70F3004483EB /* Deque+Hashable.swift */; }; - 7DE9205229CA70F3004483EB /* _UnsafeWrappedBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBE29CA70F3004483EB /* _UnsafeWrappedBuffer.swift */; }; - 7DE9205329CA70F3004483EB /* _DequeBufferHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBF29CA70F3004483EB /* _DequeBufferHeader.swift */; }; - 7DE9205529CA70F3004483EB /* Deque+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC129CA70F3004483EB /* Deque+Codable.swift */; }; - 7DE9205629CA70F3004483EB /* Deque+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC229CA70F3004483EB /* Deque+Testing.swift */; }; - 7DE9205829CA70F3004483EB /* Deque._UnsafeHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC429CA70F3004483EB /* Deque._UnsafeHandle.swift */; }; - 7DE9205929CA70F3004483EB /* Deque+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC529CA70F3004483EB /* Deque+Descriptions.swift */; }; - 7DE9205A29CA70F3004483EB /* Deque+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC629CA70F3004483EB /* Deque+Extras.swift */; }; - 7DE9205B29CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC729CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift */; }; - 7DE9205C29CA70F3004483EB /* Deque+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC829CA70F3004483EB /* Deque+Equatable.swift */; }; - 7DE9205D29CA70F4004483EB /* Deque._Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC929CA70F3004483EB /* Deque._Storage.swift */; }; 7DE9205E29CA70F4004483EB /* BigString+Metrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91ECD29CA70F3004483EB /* BigString+Metrics.swift */; }; 7DE9205F29CA70F4004483EB /* BigString+Index.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91ECE29CA70F3004483EB /* BigString+Index.swift */; }; 7DE9206029CA70F4004483EB /* BigString+Summary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91ECF29CA70F3004483EB /* BigString+Summary.swift */; }; @@ -456,10 +490,66 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7D48BCC82E51524200D7F6F7 /* Box.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Box.swift; sourceTree = ""; }; + 7D2A77232F27F1B3005780C7 /* RigidArray+Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Container.swift"; sourceTree = ""; }; + 7D2A77252F27F1D1005780C7 /* Span+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Span+Extras.swift"; sourceTree = ""; }; + 7D2A77272F27F1E4005780C7 /* OutputSpan+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OutputSpan+Extras.swift"; sourceTree = ""; }; + 7D2A77282F27F1E4005780C7 /* TemporaryAllocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemporaryAllocation.swift; sourceTree = ""; }; + 7D2A772A2F27F1E4005780C7 /* BorrowingIteratorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorrowingIteratorProtocol.swift; sourceTree = ""; }; + 7D2A772B2F27F1E4005780C7 /* BorrowingSequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorrowingSequence.swift; sourceTree = ""; }; + 7D2A772C2F27F1E4005780C7 /* BorrowingSequence+Standard Conformances.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BorrowingSequence+Standard Conformances.swift"; sourceTree = ""; }; + 7D2A772D2F27F1E4005780C7 /* BorrowingSequence+Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BorrowingSequence+Utilities.swift"; sourceTree = ""; }; + 7D2A772E2F27F1E4005780C7 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + 7D2A772F2F27F1E4005780C7 /* Drain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Drain.swift; sourceTree = ""; }; + 7D2A77302F27F1E4005780C7 /* Producer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Producer.swift; sourceTree = ""; }; + 7D2A77322F27F1E4005780C7 /* Borrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Borrow.swift; sourceTree = ""; }; + 7D2A77332F27F1E4005780C7 /* Box.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Box.swift; sourceTree = ""; }; + 7D2A77342F27F1E4005780C7 /* Inout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Inout.swift; sourceTree = ""; }; + 7D2A77352F27F1E4005780C7 /* InputSpan.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSpan.swift; sourceTree = ""; }; + 7D2A77362F27F1E4005780C7 /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = ""; }; + 7D2A77482F27F271005780C7 /* CustomProducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomProducer.swift; sourceTree = ""; }; + 7D2A774A2F27F285005780C7 /* RigidDequeCrashTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidDequeCrashTests.swift; sourceTree = ""; }; + 7D2A774B2F27F285005780C7 /* RigidDequeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidDequeTests.swift; sourceTree = ""; }; + 7D2A774C2F27F285005780C7 /* UniqueDequeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueDequeTests.swift; sourceTree = ""; }; + 7D2A77502F27F2BF005780C7 /* _UnsafeDequeHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _UnsafeDequeHandle.swift; sourceTree = ""; }; + 7D2A77512F27F2BF005780C7 /* _UnsafeDequeSegments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _UnsafeDequeSegments.swift; sourceTree = ""; }; + 7D2A77522F27F2BF005780C7 /* _DequeBuffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _DequeBuffer.swift; sourceTree = ""; }; + 7D2A77532F27F2BF005780C7 /* _DequeBufferHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _DequeBufferHeader.swift; sourceTree = ""; }; + 7D2A77542F27F2BF005780C7 /* Deque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deque.swift; sourceTree = ""; }; + 7D2A77552F27F2BF005780C7 /* Deque._Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deque._Storage.swift; sourceTree = ""; }; + 7D2A77562F27F2BF005780C7 /* Deque._UnsafeHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deque._UnsafeHandle.swift; sourceTree = ""; }; + 7D2A77572F27F2BF005780C7 /* Deque+Codable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+Codable.swift"; sourceTree = ""; }; + 7D2A77582F27F2BF005780C7 /* Deque+Collection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+Collection.swift"; sourceTree = ""; }; + 7D2A77592F27F2BF005780C7 /* Deque+CustomReflectable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+CustomReflectable.swift"; sourceTree = ""; }; + 7D2A775A2F27F2BF005780C7 /* Deque+Descriptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+Descriptions.swift"; sourceTree = ""; }; + 7D2A775B2F27F2BF005780C7 /* Deque+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+Equatable.swift"; sourceTree = ""; }; + 7D2A775C2F27F2BF005780C7 /* Deque+ExpressibleByArrayLiteral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+ExpressibleByArrayLiteral.swift"; sourceTree = ""; }; + 7D2A775D2F27F2BF005780C7 /* Deque+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+Extras.swift"; sourceTree = ""; }; + 7D2A775E2F27F2BF005780C7 /* Deque+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+Hashable.swift"; sourceTree = ""; }; + 7D2A775F2F27F2BF005780C7 /* Deque+Testing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Deque+Testing.swift"; sourceTree = ""; }; + 7D2A77612F27F2BF005780C7 /* RigidDeque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidDeque.swift; sourceTree = ""; }; + 7D2A77622F27F2BF005780C7 /* RigidDeque+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Append.swift"; sourceTree = ""; }; + 7D2A77632F27F2BF005780C7 /* RigidDeque+Consumption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Consumption.swift"; sourceTree = ""; }; + 7D2A77642F27F2BF005780C7 /* RigidDeque+Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Container.swift"; sourceTree = ""; }; + 7D2A77652F27F2BF005780C7 /* RigidDeque+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Experimental.swift"; sourceTree = ""; }; + 7D2A77662F27F2BF005780C7 /* RigidDeque+Initializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Initializers.swift"; sourceTree = ""; }; + 7D2A77672F27F2BF005780C7 /* RigidDeque+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Insertions.swift"; sourceTree = ""; }; + 7D2A77682F27F2BF005780C7 /* RigidDeque+Prepend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Prepend.swift"; sourceTree = ""; }; + 7D2A77692F27F2BF005780C7 /* RigidDeque+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Removals.swift"; sourceTree = ""; }; + 7D2A776A2F27F2BF005780C7 /* RigidDeque+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Replacements.swift"; sourceTree = ""; }; + 7D2A776B2F27F2BF005780C7 /* RigidDeque+Testing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Testing.swift"; sourceTree = ""; }; + 7D2A776D2F27F2BF005780C7 /* UniqueDeque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueDeque.swift; sourceTree = ""; }; + 7D2A776E2F27F2BF005780C7 /* UniqueDeque+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Append.swift"; sourceTree = ""; }; + 7D2A776F2F27F2BF005780C7 /* UniqueDeque+Consumption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Consumption.swift"; sourceTree = ""; }; + 7D2A77702F27F2BF005780C7 /* UniqueDeque+Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Container.swift"; sourceTree = ""; }; + 7D2A77712F27F2BF005780C7 /* UniqueDeque+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Experimental.swift"; sourceTree = ""; }; + 7D2A77722F27F2BF005780C7 /* UniqueDeque+Initializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Initializers.swift"; sourceTree = ""; }; + 7D2A77732F27F2BF005780C7 /* UniqueDeque+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Insertions.swift"; sourceTree = ""; }; + 7D2A77742F27F2BF005780C7 /* UniqueDeque+Prepend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Prepend.swift"; sourceTree = ""; }; + 7D2A77752F27F2BF005780C7 /* UniqueDeque+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Removals.swift"; sourceTree = ""; }; + 7D2A77762F27F2BF005780C7 /* UniqueDeque+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Replacements.swift"; sourceTree = ""; }; + 7D2A779D2F27F367005780C7 /* BorrowTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorrowTests.swift; sourceTree = ""; }; + 7D2A779E2F27F367005780C7 /* InoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InoutTests.swift; sourceTree = ""; }; 7D48BCC92E51524200D7F6F7 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - 7D48BCCB2E51524200D7F6F7 /* InputSpan.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSpan.swift; sourceTree = ""; }; - 7D48BCCD2E51524200D7F6F7 /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = ""; }; 7D48BCDB2E51554900D7F6F7 /* ClassBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassBox.swift; sourceTree = ""; }; 7D48BCDD2E51558700D7F6F7 /* TestPrintable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestPrintable.swift; sourceTree = ""; }; 7D48BCDE2E51558700D7F6F7 /* LifetimeTrackedStruct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifetimeTrackedStruct.swift; sourceTree = ""; }; @@ -471,13 +561,6 @@ 7D5A64D229CCE8CC00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D329CCEE9A00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D829CCF0FE00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - 7D6FEE0D2E877870007C1B86 /* MutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutTests.swift; sourceTree = ""; }; - 7D6FEE0E2E877870007C1B86 /* RefTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefTests.swift; sourceTree = ""; }; - 7D6FEE112E8778CF007C1B86 /* BorrowIteratorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorrowIteratorProtocol.swift; sourceTree = ""; }; - 7D6FEE122E8778CF007C1B86 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 7D6FEE132E8778CF007C1B86 /* Container+Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Utilities.swift"; sourceTree = ""; }; - 7D6FEE142E8778CF007C1B86 /* Mut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mut.swift; sourceTree = ""; }; - 7D6FEE152E8778CF007C1B86 /* Ref.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ref.swift; sourceTree = ""; }; 7D6FEE1B2E8778F3007C1B86 /* RigidArray+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Append.swift"; sourceTree = ""; }; 7D6FEE1C2E8778F3007C1B86 /* RigidArray+Initializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Initializers.swift"; sourceTree = ""; }; 7D6FEE1D2E8778F3007C1B86 /* RigidArray+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Insertions.swift"; sourceTree = ""; }; @@ -582,24 +665,9 @@ 7DE91EB329CA70F3004483EB /* _HashTable+CustomStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "_HashTable+CustomStringConvertible.swift"; sourceTree = ""; }; 7DE91EB429CA70F3004483EB /* _HashTable+BucketIterator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "_HashTable+BucketIterator.swift"; sourceTree = ""; }; 7DE91EB529CA70F3004483EB /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - 7DE91EB729CA70F3004483EB /* _DequeBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _DequeBuffer.swift; sourceTree = ""; }; - 7DE91EB829CA70F3004483EB /* Deque+Collection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Collection.swift"; sourceTree = ""; }; 7DE91EB929CA70F3004483EB /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - 7DE91EBA29CA70F3004483EB /* Deque+CustomReflectable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+CustomReflectable.swift"; sourceTree = ""; }; - 7DE91EBB29CA70F3004483EB /* Deque.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Deque.swift; sourceTree = ""; }; 7DE91EBC29CA70F3004483EB /* _DequeSlot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _DequeSlot.swift; sourceTree = ""; }; - 7DE91EBD29CA70F3004483EB /* Deque+Hashable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Hashable.swift"; sourceTree = ""; }; - 7DE91EBE29CA70F3004483EB /* _UnsafeWrappedBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _UnsafeWrappedBuffer.swift; sourceTree = ""; }; - 7DE91EBF29CA70F3004483EB /* _DequeBufferHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _DequeBufferHeader.swift; sourceTree = ""; }; - 7DE91EC129CA70F3004483EB /* Deque+Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Codable.swift"; sourceTree = ""; }; - 7DE91EC229CA70F3004483EB /* Deque+Testing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Testing.swift"; sourceTree = ""; }; 7DE91EC329CA70F3004483EB /* DequeModule.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = DequeModule.docc; sourceTree = ""; }; - 7DE91EC429CA70F3004483EB /* Deque._UnsafeHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Deque._UnsafeHandle.swift; sourceTree = ""; }; - 7DE91EC529CA70F3004483EB /* Deque+Descriptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Descriptions.swift"; sourceTree = ""; }; - 7DE91EC629CA70F3004483EB /* Deque+Extras.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Extras.swift"; sourceTree = ""; }; - 7DE91EC729CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+ExpressibleByArrayLiteral.swift"; sourceTree = ""; }; - 7DE91EC829CA70F3004483EB /* Deque+Equatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Equatable.swift"; sourceTree = ""; }; - 7DE91EC929CA70F3004483EB /* Deque._Storage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Deque._Storage.swift; sourceTree = ""; }; 7DE91ECD29CA70F3004483EB /* BigString+Metrics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BigString+Metrics.swift"; sourceTree = ""; }; 7DE91ECE29CA70F3004483EB /* BigString+Index.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BigString+Index.swift"; sourceTree = ""; }; 7DE91ECF29CA70F3004483EB /* BigString+Summary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BigString+Summary.swift"; sourceTree = ""; }; @@ -950,18 +1018,104 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 7D2A77292F27F1E4005780C7 /* Extensions */ = { + isa = PBXGroup; + children = ( + 7D2A77272F27F1E4005780C7 /* OutputSpan+Extras.swift */, + 7D2A77282F27F1E4005780C7 /* TemporaryAllocation.swift */, + ); + path = Extensions; + sourceTree = ""; + }; + 7D2A77312F27F1E4005780C7 /* Protocols */ = { + isa = PBXGroup; + children = ( + 7D2A772A2F27F1E4005780C7 /* BorrowingIteratorProtocol.swift */, + 7D2A772B2F27F1E4005780C7 /* BorrowingSequence.swift */, + 7D2A772C2F27F1E4005780C7 /* BorrowingSequence+Standard Conformances.swift */, + 7D2A772D2F27F1E4005780C7 /* BorrowingSequence+Utilities.swift */, + 7D2A772E2F27F1E4005780C7 /* Container.swift */, + 7D2A772F2F27F1E4005780C7 /* Drain.swift */, + 7D2A77302F27F1E4005780C7 /* Producer.swift */, + ); + path = Protocols; + sourceTree = ""; + }; + 7D2A77372F27F1E4005780C7 /* Types */ = { + isa = PBXGroup; + children = ( + 7D2A77322F27F1E4005780C7 /* Borrow.swift */, + 7D2A77332F27F1E4005780C7 /* Box.swift */, + 7D2A77342F27F1E4005780C7 /* Inout.swift */, + 7D2A77352F27F1E4005780C7 /* InputSpan.swift */, + 7D2A77362F27F1E4005780C7 /* Shared.swift */, + ); + path = Types; + sourceTree = ""; + }; + 7D2A77602F27F2BF005780C7 /* Deque */ = { + isa = PBXGroup; + children = ( + 7D2A77522F27F2BF005780C7 /* _DequeBuffer.swift */, + 7D2A77532F27F2BF005780C7 /* _DequeBufferHeader.swift */, + 7D2A77542F27F2BF005780C7 /* Deque.swift */, + 7D2A77552F27F2BF005780C7 /* Deque._Storage.swift */, + 7D2A77562F27F2BF005780C7 /* Deque._UnsafeHandle.swift */, + 7D2A77572F27F2BF005780C7 /* Deque+Codable.swift */, + 7D2A77582F27F2BF005780C7 /* Deque+Collection.swift */, + 7D2A77592F27F2BF005780C7 /* Deque+CustomReflectable.swift */, + 7D2A775A2F27F2BF005780C7 /* Deque+Descriptions.swift */, + 7D2A775B2F27F2BF005780C7 /* Deque+Equatable.swift */, + 7D2A775C2F27F2BF005780C7 /* Deque+ExpressibleByArrayLiteral.swift */, + 7D2A775D2F27F2BF005780C7 /* Deque+Extras.swift */, + 7D2A775E2F27F2BF005780C7 /* Deque+Hashable.swift */, + 7D2A775F2F27F2BF005780C7 /* Deque+Testing.swift */, + ); + path = Deque; + sourceTree = ""; + }; + 7D2A776C2F27F2BF005780C7 /* RigidDeque */ = { + isa = PBXGroup; + children = ( + 7D2A77612F27F2BF005780C7 /* RigidDeque.swift */, + 7D2A77622F27F2BF005780C7 /* RigidDeque+Append.swift */, + 7D2A77632F27F2BF005780C7 /* RigidDeque+Consumption.swift */, + 7D2A77642F27F2BF005780C7 /* RigidDeque+Container.swift */, + 7D2A77652F27F2BF005780C7 /* RigidDeque+Experimental.swift */, + 7D2A77662F27F2BF005780C7 /* RigidDeque+Initializers.swift */, + 7D2A77672F27F2BF005780C7 /* RigidDeque+Insertions.swift */, + 7D2A77682F27F2BF005780C7 /* RigidDeque+Prepend.swift */, + 7D2A77692F27F2BF005780C7 /* RigidDeque+Removals.swift */, + 7D2A776A2F27F2BF005780C7 /* RigidDeque+Replacements.swift */, + 7D2A776B2F27F2BF005780C7 /* RigidDeque+Testing.swift */, + ); + path = RigidDeque; + sourceTree = ""; + }; + 7D2A77772F27F2BF005780C7 /* UniqueDeque */ = { + isa = PBXGroup; + children = ( + 7D2A776D2F27F2BF005780C7 /* UniqueDeque.swift */, + 7D2A776E2F27F2BF005780C7 /* UniqueDeque+Append.swift */, + 7D2A776F2F27F2BF005780C7 /* UniqueDeque+Consumption.swift */, + 7D2A77702F27F2BF005780C7 /* UniqueDeque+Container.swift */, + 7D2A77712F27F2BF005780C7 /* UniqueDeque+Experimental.swift */, + 7D2A77722F27F2BF005780C7 /* UniqueDeque+Initializers.swift */, + 7D2A77732F27F2BF005780C7 /* UniqueDeque+Insertions.swift */, + 7D2A77742F27F2BF005780C7 /* UniqueDeque+Prepend.swift */, + 7D2A77752F27F2BF005780C7 /* UniqueDeque+Removals.swift */, + 7D2A77762F27F2BF005780C7 /* UniqueDeque+Replacements.swift */, + ); + path = UniqueDeque; + sourceTree = ""; + }; 7D48BCCE2E51524200D7F6F7 /* ContainersPreview */ = { isa = PBXGroup; children = ( - 7D6FEE112E8778CF007C1B86 /* BorrowIteratorProtocol.swift */, - 7D48BCC82E51524200D7F6F7 /* Box.swift */, + 7D2A77292F27F1E4005780C7 /* Extensions */, + 7D2A77312F27F1E4005780C7 /* Protocols */, + 7D2A77372F27F1E4005780C7 /* Types */, 7D48BCC92E51524200D7F6F7 /* CMakeLists.txt */, - 7D6FEE122E8778CF007C1B86 /* Container.swift */, - 7D6FEE132E8778CF007C1B86 /* Container+Utilities.swift */, - 7D48BCCB2E51524200D7F6F7 /* InputSpan.swift */, - 7D6FEE142E8778CF007C1B86 /* Mut.swift */, - 7D6FEE152E8778CF007C1B86 /* Ref.swift */, - 7D48BCCD2E51524200D7F6F7 /* Shared.swift */, 7D6FEE312E88A4B9007C1B86 /* ContainersPreview.docc */, ); path = ContainersPreview; @@ -970,8 +1124,8 @@ 7D48BCE82E5158A100D7F6F7 /* ContainersTests */ = { isa = PBXGroup; children = ( - 7D6FEE0D2E877870007C1B86 /* MutTests.swift */, - 7D6FEE0E2E877870007C1B86 /* RefTests.swift */, + 7D2A779D2F27F367005780C7 /* BorrowTests.swift */, + 7D2A779E2F27F367005780C7 /* InoutTests.swift */, 7D48BCE62E5158A100D7F6F7 /* BoxTests.swift */, ); path = ContainersTests; @@ -1130,22 +1284,12 @@ 7DE91EB629CA70F3004483EB /* DequeModule */ = { isa = PBXGroup; children = ( - 7DE91EB729CA70F3004483EB /* _DequeBuffer.swift */, - 7DE91EBF29CA70F3004483EB /* _DequeBufferHeader.swift */, + 7D2A77602F27F2BF005780C7 /* Deque */, + 7D2A776C2F27F2BF005780C7 /* RigidDeque */, + 7D2A77772F27F2BF005780C7 /* UniqueDeque */, 7DE91EBC29CA70F3004483EB /* _DequeSlot.swift */, - 7DE91EBE29CA70F3004483EB /* _UnsafeWrappedBuffer.swift */, - 7DE91EC929CA70F3004483EB /* Deque._Storage.swift */, - 7DE91EC429CA70F3004483EB /* Deque._UnsafeHandle.swift */, - 7DE91EBB29CA70F3004483EB /* Deque.swift */, - 7DE91EC129CA70F3004483EB /* Deque+Codable.swift */, - 7DE91EB829CA70F3004483EB /* Deque+Collection.swift */, - 7DE91EBA29CA70F3004483EB /* Deque+CustomReflectable.swift */, - 7DE91EC529CA70F3004483EB /* Deque+Descriptions.swift */, - 7DE91EC829CA70F3004483EB /* Deque+Equatable.swift */, - 7DE91EC729CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift */, - 7DE91EC629CA70F3004483EB /* Deque+Extras.swift */, - 7DE91EBD29CA70F3004483EB /* Deque+Hashable.swift */, - 7DE91EC229CA70F3004483EB /* Deque+Testing.swift */, + 7D2A77502F27F2BF005780C7 /* _UnsafeDequeHandle.swift */, + 7D2A77512F27F2BF005780C7 /* _UnsafeDequeSegments.swift */, 7DE91EC329CA70F3004483EB /* DequeModule.docc */, 7DE91EB929CA70F3004483EB /* CMakeLists.txt */, ); @@ -1337,6 +1481,7 @@ 7DAD89A92E8B09EC00DD5786 /* Descriptions.swift */, 7DAD89AA2E8B09EC00DD5786 /* LifetimeOverride.swift */, 7DAD89AB2E8B09EC00DD5786 /* RandomAccessCollection+Offsets.swift */, + 7D2A77252F27F1D1005780C7 /* Span+Extras.swift */, 7DAD89AC2E8B09EC00DD5786 /* UnsafeBufferPointer+Extras.swift */, 7DAD89AD2E8B09EC00DD5786 /* UnsafeMutableBufferPointer+Extras.swift */, 7DAD89AE2E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift */, @@ -1718,6 +1863,9 @@ 7DE921F829CA8576004483EB /* DequeTests.swift */, 7DE921F929CA8576004483EB /* MutableCollectionTests.swift */, 7DE921F729CA8576004483EB /* RangeReplaceableCollectionTests.swift */, + 7D2A774A2F27F285005780C7 /* RigidDequeCrashTests.swift */, + 7D2A774B2F27F285005780C7 /* RigidDequeTests.swift */, + 7D2A774C2F27F285005780C7 /* UniqueDequeTests.swift */, ); path = DequeTests; sourceTree = ""; @@ -1807,6 +1955,7 @@ children = ( 7DEBDB3B29CCE43600ADC226 /* _CollectionState.swift */, 7DEBDB4629CCE43600ADC226 /* _MinimalCollectionCore.swift */, + 7D2A77482F27F271005780C7 /* CustomProducer.swift */, 7DEBDB4029CCE43600ADC226 /* MinimalBidirectionalCollection.swift */, 7DEBDB4829CCE43600ADC226 /* MinimalCollection.swift */, 7DEBDB4729CCE43600ADC226 /* MinimalDecoder.swift */, @@ -1842,6 +1991,7 @@ A93AC20F2E7C841700A824DF /* CMakeLists.txt */, A93AC2102E7C841700A824DF /* RigidArray.swift */, 7D6FEE1B2E8778F3007C1B86 /* RigidArray+Append.swift */, + 7D2A77232F27F1B3005780C7 /* RigidArray+Container.swift */, A93AC2112E7C841700A824DF /* RigidArray+Experimental.swift */, 7D6FEE1C2E8778F3007C1B86 /* RigidArray+Initializers.swift */, 7D6FEE1D2E8778F3007C1B86 /* RigidArray+Insertions.swift */, @@ -1999,7 +2149,6 @@ 7DE920F129CA70F4004483EB /* BitArray+Initializers.swift in Sources */, 7DE9214529CA70F4004483EB /* _HashNode+Structural symmetricDifference.swift in Sources */, 7DE9201029CA70F3004483EB /* OrderedDictionary+Deprecations.swift in Sources */, - 7DE9205929CA70F3004483EB /* Deque+Descriptions.swift in Sources */, 7DE9212729CA70F4004483EB /* TreeSet+Equatable.swift in Sources */, 7DE9213429CA70F4004483EB /* TreeSet+ExpressibleByArrayLiteral.swift in Sources */, 7DE9209729CA70F4004483EB /* _RopePath.swift in Sources */, @@ -2010,11 +2159,43 @@ 7DE920C029CA70F4004483EB /* BitSet+SetAlgebra conformance.swift in Sources */, 7DE9203C29CA70F3004483EB /* OrderedSet+Partial SetAlgebra formSymmetricDifference.swift in Sources */, 7DE9209029CA70F4004483EB /* Rope.swift in Sources */, - 7D6FEE162E8778CF007C1B86 /* Mut.swift in Sources */, - 7D6FEE172E8778CF007C1B86 /* BorrowIteratorProtocol.swift in Sources */, - 7D6FEE182E8778CF007C1B86 /* Container+Utilities.swift in Sources */, - 7D6FEE192E8778CF007C1B86 /* Ref.swift in Sources */, - 7D6FEE1A2E8778CF007C1B86 /* Container.swift in Sources */, + 7D2A77782F27F2BF005780C7 /* Deque._Storage.swift in Sources */, + 7D2A77792F27F2BF005780C7 /* RigidDeque+Prepend.swift in Sources */, + 7D2A777A2F27F2BF005780C7 /* UniqueDeque+Consumption.swift in Sources */, + 7D2A777B2F27F2BF005780C7 /* _UnsafeDequeHandle.swift in Sources */, + 7D2A777C2F27F2BF005780C7 /* _UnsafeDequeSegments.swift in Sources */, + 7D2A777D2F27F2BF005780C7 /* RigidDeque+Append.swift in Sources */, + 7D2A777E2F27F2BF005780C7 /* Deque+Hashable.swift in Sources */, + 7D2A777F2F27F2BF005780C7 /* RigidDeque+Container.swift in Sources */, + 7D2A77802F27F2BF005780C7 /* Deque.swift in Sources */, + 7D2A77812F27F2BF005780C7 /* UniqueDeque+Append.swift in Sources */, + 7D2A77822F27F2BF005780C7 /* UniqueDeque+Initializers.swift in Sources */, + 7D2A77832F27F2BF005780C7 /* Deque+Equatable.swift in Sources */, + 7D2A77842F27F2BF005780C7 /* UniqueDeque+Container.swift in Sources */, + 7D2A77852F27F2BF005780C7 /* RigidDeque+Initializers.swift in Sources */, + 7D2A77862F27F2BF005780C7 /* RigidDeque+Consumption.swift in Sources */, + 7D2A77872F27F2BF005780C7 /* Deque._UnsafeHandle.swift in Sources */, + 7D2A77882F27F2BF005780C7 /* Deque+Extras.swift in Sources */, + 7D2A77892F27F2BF005780C7 /* UniqueDeque+Removals.swift in Sources */, + 7D2A778A2F27F2BF005780C7 /* UniqueDeque+Insertions.swift in Sources */, + 7D2A778B2F27F2BF005780C7 /* UniqueDeque+Replacements.swift in Sources */, + 7D2A778C2F27F2BF005780C7 /* UniqueDeque+Prepend.swift in Sources */, + 7D2A778D2F27F2BF005780C7 /* UniqueDeque.swift in Sources */, + 7D2A778E2F27F2BF005780C7 /* RigidDeque.swift in Sources */, + 7D2A778F2F27F2BF005780C7 /* Deque+CustomReflectable.swift in Sources */, + 7D2A77902F27F2BF005780C7 /* RigidDeque+Insertions.swift in Sources */, + 7D2A77912F27F2BF005780C7 /* RigidDeque+Removals.swift in Sources */, + 7D2A77922F27F2BF005780C7 /* _DequeBuffer.swift in Sources */, + 7D2A77932F27F2BF005780C7 /* _DequeBufferHeader.swift in Sources */, + 7D2A77942F27F2BF005780C7 /* Deque+Collection.swift in Sources */, + 7D2A77952F27F2BF005780C7 /* Deque+Codable.swift in Sources */, + 7D2A77962F27F2BF005780C7 /* RigidDeque+Experimental.swift in Sources */, + 7D2A77972F27F2BF005780C7 /* Deque+Testing.swift in Sources */, + 7D2A77982F27F2BF005780C7 /* RigidDeque+Replacements.swift in Sources */, + 7D2A77992F27F2BF005780C7 /* Deque+Descriptions.swift in Sources */, + 7D2A779A2F27F2BF005780C7 /* RigidDeque+Testing.swift in Sources */, + 7D2A779B2F27F2BF005780C7 /* UniqueDeque+Experimental.swift in Sources */, + 7D2A779C2F27F2BF005780C7 /* Deque+ExpressibleByArrayLiteral.swift in Sources */, 7DE9213B29CA70F4004483EB /* TreeSet+Hashable.swift in Sources */, 7DE9200D29CA70F3004483EB /* OrderedDictionary+Equatable.swift in Sources */, 7DE9207C29CA70F4004483EB /* BigSubstring.swift in Sources */, @@ -2023,7 +2204,6 @@ 7DE9216229CA70F4004483EB /* _AncestorHashSlots.swift in Sources */, 7DE9216B29CA70F4004483EB /* TreeDictionary+Codable.swift in Sources */, 7DE9201A29CA70F3004483EB /* OrderedDictionary+Sendable.swift in Sources */, - 7DE9205D29CA70F4004483EB /* Deque._Storage.swift in Sources */, 7DE9203B29CA70F3004483EB /* OrderedSet+Partial SetAlgebra subtracting.swift in Sources */, 7DE9213A29CA70F4004483EB /* TreeSet.swift in Sources */, 7DE9213829CA70F4004483EB /* TreeSet+Filter.swift in Sources */, @@ -2045,7 +2225,6 @@ 7DE9203129CA70F3004483EB /* OrderedSet+Partial MutableCollection.swift in Sources */, 7DE9209B29CA70F4004483EB /* Rope+Split.swift in Sources */, 7DE9206629CA70F4004483EB /* BigString+Debugging.swift in Sources */, - 7DE9205229CA70F3004483EB /* _UnsafeWrappedBuffer.swift in Sources */, 7DE9201129CA70F3004483EB /* OrderedDictionary+Initializers.swift in Sources */, 7DE9212B29CA70F4004483EB /* TreeSet+SetAlgebra subtracting.swift in Sources */, 7DE920F629CA70F4004483EB /* BitArray+Equatable.swift in Sources */, @@ -2067,6 +2246,7 @@ 7DE920C929CA70F4004483EB /* BitSet+BidirectionalCollection.swift in Sources */, 7DE920ED29CA70F4004483EB /* BitArray+Extras.swift in Sources */, 7DE9206829CA70F4004483EB /* BigString+Chunk+Append and Insert.swift in Sources */, + 7D2A77242F27F1B3005780C7 /* RigidArray+Container.swift in Sources */, 7DE9200E29CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift in Sources */, 7DE920D229CA70F4004483EB /* BitSet+SetAlgebra basics.swift in Sources */, 7DE9212A29CA70F4004483EB /* TreeSet+Extras.swift in Sources */, @@ -2076,9 +2256,6 @@ A93AC2162E7C841700A824DF /* UniqueArray.swift in Sources */, A93AC2172E7C841700A824DF /* RigidArray+Experimental.swift in Sources */, A93AC2182E7C841700A824DF /* UniqueArray+Experimental.swift in Sources */, - 7D48BCD12E51524200D7F6F7 /* InputSpan.swift in Sources */, - 7D48BCD32E51524200D7F6F7 /* Box.swift in Sources */, - 7D48BCD62E51524200D7F6F7 /* Shared.swift in Sources */, 7DE9208629CA70F4004483EB /* BigString+LosslessStringConvertible.swift in Sources */, 7DE9204329CA70F3004483EB /* _HashTable+Bucket.swift in Sources */, 7DE9216A29CA70F4004483EB /* TreeDictionary.swift in Sources */, @@ -2127,7 +2304,6 @@ 7DE9207D29CA70F4004483EB /* BigSubstring+UTF16View.swift in Sources */, 7DE9217229CA70F4004483EB /* TreeDictionary+Sendable.swift in Sources */, 7DE9207729CA70F4004483EB /* Range+BigString.swift in Sources */, - 7DE9204B29CA70F3004483EB /* _DequeBuffer.swift in Sources */, 7DE920DF29CA70F4004483EB /* Slice+Utilities.swift in Sources */, 7DE9215729CA70F4004483EB /* _RawHashNode.swift in Sources */, 7DE9209529CA70F4004483EB /* RopeSummary.swift in Sources */, @@ -2165,7 +2341,6 @@ 7DE9207429CA70F4004483EB /* BigString+ReplaceSubrange.swift in Sources */, 7DE920DC29CA70F4004483EB /* BitSet+Invariants.swift in Sources */, 7DE9216729CA70F4004483EB /* TreeDictionary+Equatable.swift in Sources */, - 7DE9204C29CA70F3004483EB /* Deque+Collection.swift in Sources */, 7DE9201F29CA70F3004483EB /* OrderedSet+RandomAccessCollection.swift in Sources */, 7DE9202E29CA70F3004483EB /* OrderedSet+UnorderedView.swift in Sources */, 7DE9215F29CA70F4004483EB /* _UnsafePath.swift in Sources */, @@ -2203,7 +2378,6 @@ 7DE9212F29CA70F4004483EB /* TreeSet+SetAlgebra formIntersection.swift in Sources */, 7DE920A329CA70F4004483EB /* Rope+Index.swift in Sources */, 7DE9207329CA70F4004483EB /* BigString+RemoveSubrange.swift in Sources */, - 7DE9205829CA70F3004483EB /* Deque._UnsafeHandle.swift in Sources */, 7DE9213529CA70F4004483EB /* TreeSet+SetAlgebra symmetricDifference.swift in Sources */, 7DE920D429CA70F4004483EB /* BitSet+SetAlgebra union.swift in Sources */, 7DE920C329CA70F4004483EB /* BitSet+SetAlgebra formUnion.swift in Sources */, @@ -2221,6 +2395,20 @@ 7DE9213D29CA70F4004483EB /* TreeSet+SetAlgebra isSubset.swift in Sources */, 7DE9203029CA70F3004483EB /* OrderedSet+SubSequence.swift in Sources */, 7DE9215529CA70F4004483EB /* _RawHashNode+UnsafeHandle.swift in Sources */, + 7D2A77382F27F1E4005780C7 /* BorrowingSequence+Utilities.swift in Sources */, + 7D2A77392F27F1E4005780C7 /* Box.swift in Sources */, + 7D2A773A2F27F1E4005780C7 /* Drain.swift in Sources */, + 7D2A773B2F27F1E4005780C7 /* Container.swift in Sources */, + 7D2A773C2F27F1E4005780C7 /* TemporaryAllocation.swift in Sources */, + 7D2A773D2F27F1E4005780C7 /* BorrowingSequence.swift in Sources */, + 7D2A773E2F27F1E4005780C7 /* BorrowingSequence+Standard Conformances.swift in Sources */, + 7D2A773F2F27F1E4005780C7 /* Borrow.swift in Sources */, + 7D2A77402F27F1E4005780C7 /* BorrowingIteratorProtocol.swift in Sources */, + 7D2A77412F27F1E4005780C7 /* Inout.swift in Sources */, + 7D2A77422F27F1E4005780C7 /* OutputSpan+Extras.swift in Sources */, + 7D2A77432F27F1E4005780C7 /* Shared.swift in Sources */, + 7D2A77442F27F1E4005780C7 /* InputSpan.swift in Sources */, + 7D2A77452F27F1E4005780C7 /* Producer.swift in Sources */, 7DE9209429CA70F4004483EB /* Rope+_UnmanagedLeaf.swift in Sources */, 7DE9208429CA70F4004483EB /* BigString+Equatable.swift in Sources */, 7DE9203729CA70F3004483EB /* OrderedSet+Partial SetAlgebra union.swift in Sources */, @@ -2244,13 +2432,11 @@ 7DE9201329CA70F3004483EB /* OrderedDictionary+CustomReflectable.swift in Sources */, 7DE9201C29CA70F3004483EB /* OrderedDictionary+Partial MutableCollection.swift in Sources */, 7DE9202729CA70F3004483EB /* OrderedSet+Insertions.swift in Sources */, - 7DE9205B29CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift in Sources */, 7DE9208729CA70F4004483EB /* BigString+Sequence.swift in Sources */, 7DE9202229CA70F3004483EB /* OrderedSet+Diffing.swift in Sources */, 7DE920CA29CA70F4004483EB /* BitSet+CustomStringConvertible.swift in Sources */, 7DE9212E29CA70F4004483EB /* TreeSet+SetAlgebra isStrictSuperset.swift in Sources */, 7DE920A829CA70F4004483EB /* String.Index+ABI.swift in Sources */, - 7DE9204F29CA70F3004483EB /* Deque.swift in Sources */, 7DE9214129CA70F4004483EB /* _HashNode+Initializers.swift in Sources */, 7D9B859929E4F74400B291CD /* BitArray+LosslessStringConvertible.swift in Sources */, 7DE9202D29CA70F3004483EB /* OrderedSet.swift in Sources */, @@ -2262,8 +2448,6 @@ 7DE9214929CA70F4004483EB /* _HashNode+Structural isEqualSet.swift in Sources */, 7DE9206729CA70F4004483EB /* BigString+Builder.swift in Sources */, 7DE9208B29CA70F4004483EB /* RopeMetric.swift in Sources */, - 7DE9205A29CA70F3004483EB /* Deque+Extras.swift in Sources */, - 7DE9205129CA70F3004483EB /* Deque+Hashable.swift in Sources */, 7DE9209929CA70F4004483EB /* Rope+Extract.swift in Sources */, 7DE9202629CA70F3004483EB /* OrderedSet+Partial SetAlgebra isStrictSubset.swift in Sources */, 7DE920E729CA70F4004483EB /* BitArray+CustomReflectable.swift in Sources */, @@ -2271,7 +2455,6 @@ 7DE9209D29CA70F4004483EB /* Rope+Insert.swift in Sources */, 7DE9214329CA70F4004483EB /* _HashNode+Subtree Removals.swift in Sources */, 7DE9207929CA70F4004483EB /* BigString+UnicodeScalarView.swift in Sources */, - 7DE9205329CA70F3004483EB /* _DequeBufferHeader.swift in Sources */, 7DE9202429CA70F3004483EB /* OrderedSet+Invariants.swift in Sources */, 7D6FEE252E8778F3007C1B86 /* UniqueArray+Append.swift in Sources */, 7D6FEE262E8778F3007C1B86 /* RigidArray+Removals.swift in Sources */, @@ -2288,7 +2471,6 @@ 7DE9201829CA70F3004483EB /* OrderedDictionary+Invariants.swift in Sources */, 7DE920CD29CA70F4004483EB /* BitSet+CustomDebugStringConvertible.swift in Sources */, 7DE9212529CA70F4004483EB /* TreeSet+SetAlgebra isStrictSubset.swift in Sources */, - 7DE9205C29CA70F3004483EB /* Deque+Equatable.swift in Sources */, 7DE9209229CA70F4004483EB /* Rope+_Storage.swift in Sources */, 7DE9203929CA70F3004483EB /* OrderedSet+Partial RangeReplaceableCollection.swift in Sources */, 7DE9206329CA70F4004483EB /* BigString+Contents.swift in Sources */, @@ -2299,7 +2481,6 @@ 7DE9215929CA70F4004483EB /* _HashNode+Structural isSubset.swift in Sources */, 7DE920C629CA70F4004483EB /* BitSet+SetAlgebra formSymmetricDifference.swift in Sources */, 7DE9202129CA70F3004483EB /* OrderedSet+Partial SetAlgebra isEqualSet.swift in Sources */, - 7DE9205529CA70F3004483EB /* Deque+Codable.swift in Sources */, 7DE9206029CA70F4004483EB /* BigString+Summary.swift in Sources */, 7DE9203829CA70F3004483EB /* OrderedSet+Partial SetAlgebra formIntersection.swift in Sources */, 7DE9207629CA70F4004483EB /* BigString+Initializers.swift in Sources */, @@ -2311,6 +2492,7 @@ 7DE9203329CA70F3004483EB /* OrderedSet+Testing.swift in Sources */, 7DE9212429CA70F4004483EB /* TreeSet+Descriptions.swift in Sources */, 7DE9217129CA70F4004483EB /* TreeDictionary+Values.swift in Sources */, + 7D2A77262F27F1D1005780C7 /* Span+Extras.swift in Sources */, 7DE920D029CA70F4004483EB /* BitSet+SetAlgebra isSubset.swift in Sources */, 7DE920C829CA70F4004483EB /* BitSet+SetAlgebra isEqualSet.swift in Sources */, 7DE9215B29CA70F4004483EB /* _HashNode+Structural mapValues.swift in Sources */, @@ -2337,13 +2519,11 @@ 7DE9206C29CA70F4004483EB /* BigString+Chunk.swift in Sources */, 7DE920F329CA70F4004483EB /* BitArray+Copy.swift in Sources */, 7DE9214029CA70F4004483EB /* _Hash.swift in Sources */, - 7DE9205629CA70F3004483EB /* Deque+Testing.swift in Sources */, 7DE9209329CA70F4004483EB /* Rope+Invariants.swift in Sources */, 7DE920EE29CA70F4004483EB /* BitArray+ExpressibleByArrayLiteral.swift in Sources */, 7DE9214C29CA70F4004483EB /* _HashNode+Primitive Insertions.swift in Sources */, 7DE920BE29CA70F4004483EB /* BitSet+SetAlgebra formIntersection.swift in Sources */, 7DE9217329CA70F4004483EB /* TreeDictionary+Merge.swift in Sources */, - 7DE9204E29CA70F3004483EB /* Deque+CustomReflectable.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2388,8 +2568,6 @@ 7DE9221E29CA8576004483EB /* MutableCollectionTests.swift in Sources */, 7DE9221529CA8576004483EB /* RandomAccessCollection+Extras.swift in Sources */, 7DEBDB7929CCE44A00ADC226 /* LifetimeTracked.swift in Sources */, - 7D6FEE0F2E877870007C1B86 /* RefTests.swift in Sources */, - 7D6FEE102E877870007C1B86 /* MutTests.swift in Sources */, 7DE921FC29CA8576004483EB /* IndexRangeCollectionTests.swift in Sources */, 7DE9221229CA8576004483EB /* OrderedDictionary+Elements Tests.swift in Sources */, 7DEBDB7629CCE44A00ADC226 /* MinimalIndex.swift in Sources */, @@ -2416,6 +2594,9 @@ 7DEBDB8329CCE44A00ADC226 /* CheckHashable.swift in Sources */, 7DE921FF29CA8576004483EB /* Utilities.swift in Sources */, 7DEBDB8F29CCE44A00ADC226 /* CheckEquatable.swift in Sources */, + 7D2A774D2F27F285005780C7 /* RigidDequeCrashTests.swift in Sources */, + 7D2A774E2F27F285005780C7 /* UniqueDequeTests.swift in Sources */, + 7D2A774F2F27F285005780C7 /* RigidDequeTests.swift in Sources */, 7DEBDB7729CCE44A00ADC226 /* HashableBox.swift in Sources */, 7DE9220E29CA8576004483EB /* SampleStrings.swift in Sources */, 7D48BCEE2E5158A100D7F6F7 /* BoxTests.swift in Sources */, @@ -2435,8 +2616,11 @@ 7DE9220129CA8576004483EB /* TreeDictionary.Keys Tests.swift in Sources */, 7DE9220729CA8576004483EB /* BitSet.Counted Tests.swift in Sources */, 7DE9220F29CA8576004483EB /* OrderedDictionary Tests.swift in Sources */, + 7D2A779F2F27F367005780C7 /* InoutTests.swift in Sources */, + 7D2A77A02F27F367005780C7 /* BorrowTests.swift in Sources */, 7D48BCDF2E51558700D7F6F7 /* TestPrintable.swift in Sources */, 7D48BCE02E51558700D7F6F7 /* LifetimeTrackedStruct.swift in Sources */, + 7D2A77492F27F271005780C7 /* CustomProducer.swift in Sources */, 7DE9221029CA8576004483EB /* OrderedDictionary Utils.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Xcode/Shared.xcconfig b/Xcode/Shared.xcconfig index bcedd132..c447ce81 100644 --- a/Xcode/Shared.xcconfig +++ b/Xcode/Shared.xcconfig @@ -33,7 +33,7 @@ OTHER_SWIFT_FLAGS = $(inherited) \ ONLY_ACTIVE_ARCH[config=Debug] = YES SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) COLLECTIONS_SINGLE_MODULE -SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug] = $(inherited) COLLECTIONS_INTERNAL_CHECKS DEBUG +SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug] = $(inherited) DEBUG //COLLECTIONS_INTERNAL_CHECKS SWIFT_COMPILATION_MODE[config=Release] = wholemodule SWIFT_COMPILATION_MODE[config=Debug] = singlefile From 14da0b618d3d35ade818772ab024837deedd4a97 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 11:09:04 -0800 Subject: [PATCH 30/75] Fix UniqueDeque with COLLECTIONS_INTERNAL_CHECKS --- Sources/DequeModule/UniqueDeque/UniqueDeque.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift index 671ebfa5..b0deb3ab 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -48,7 +48,7 @@ extension UniqueDeque where Element: ~Copyable { #if COLLECTIONS_INTERNAL_CHECKS @usableFromInline @inline(never) @_effects(releasenone) package func _checkInvariants() { - _handle._checkInvariants() + _storage._handle._checkInvariants() } #else @_transparent From b48508a3a3d9b8e137d8b570892dcbfbd9755325 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 12:56:00 -0800 Subject: [PATCH 31/75] Fix another build regression --- Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift index 1c08fdb7..af68d59f 100644 --- a/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift +++ b/Tests/_CollectionsTestSupport/Utilities/LifetimeTracker.swift @@ -39,7 +39,7 @@ public class LifetimeTracker { } @inlinable - var instances: Int { _instances } + public var instances: Int { _instances } public func check(file: StaticString = #filePath, line: UInt = #line) { expectEqual(instances, 0, From d0169b7d8cc5876d4241801ee4ab628fe9817e9b Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 26 Jan 2026 15:20:40 -0800 Subject: [PATCH 32/75] Temporarily stop testing RigidArray & UniqueArray on release/6.3 snapshots on Linux The current snapshot (2026-01-16) appears to include a miscompilation issue. https://github.com/apple/swift-collections/issues/561 --- Tests/BasicContainersTests/RigidArrayTests.swift | 2 +- Tests/BasicContainersTests/UniqueArrayTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index 3382fe70..7a209097 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -17,7 +17,7 @@ import _CollectionsTestSupport import BasicContainers #endif -#if compiler(>=6.2) +#if compiler(>=6.2) && (compiler(>=6.4) || compiler(<6.3) || !os(Linux)) // FIXME https://github.com/apple/swift-collections/issues/561 #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. diff --git a/Tests/BasicContainersTests/UniqueArrayTests.swift b/Tests/BasicContainersTests/UniqueArrayTests.swift index 9836a702..160d3cd5 100644 --- a/Tests/BasicContainersTests/UniqueArrayTests.swift +++ b/Tests/BasicContainersTests/UniqueArrayTests.swift @@ -17,7 +17,7 @@ import _CollectionsTestSupport import BasicContainers #endif -#if compiler(>=6.2) +#if compiler(>=6.2) && (compiler(>=6.4) || compiler(<6.3) || !os(Linux)) // FIXME https://github.com/apple/swift-collections/issues/561 #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. From 59bb505b1a18e05342fd58d873a967b484f2f268 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 27 Jan 2026 10:49:59 -0800 Subject: [PATCH 33/75] Update to github-workflows 0.0.6 --- .github/workflows/pull_request.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 20d537d2..a4cae847 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -10,7 +10,7 @@ on: jobs: tests: name: Test - uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.2 + uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.6 with: linux_exclude_swift_versions: '[{"swift_version": "5.8"}, {"swift_version": "5.9"}, {"swift_version": "5.10"}]' windows_exclude_swift_versions: '[{"swift_version": "5.9"}, {"swift_version": "5.10"}]' @@ -20,7 +20,7 @@ jobs: embedded-swift: name: Build with Embedded Swift - uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.2 + uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.6 with: enable_linux_checks: false enable_macos_checks: false @@ -31,7 +31,7 @@ jobs: soundness: name: Soundness - uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.2 + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.6 with: license_header_check_project_name: "Swift.org" # https://github.com/apple/swift-collections/issues/428 From de54709ca9dffef94ee4f1b04f6a6483d620d1a3 Mon Sep 17 00:00:00 2001 From: Bassam Khouri Date: Tue, 27 Jan 2026 15:25:28 -0500 Subject: [PATCH 34/75] GHA: Add weekly dependabot Have dependabot scan for new version of the re-usable workflows --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..5ace4600 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" From 942cfbfd68126875e91bce86d7973cbf67e364c8 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Wed, 28 Jan 2026 17:28:15 -0800 Subject: [PATCH 35/75] Add temporary workaround for broken OutputSpan.wUMBP in current toolchain snapshots (cherry picked from commit 0b1ff87d6773fe568945d8af86a236dbbf9157d9) --- .../RigidArray+Insertions.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 856aebd4..80d08c8f 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -250,6 +250,31 @@ extension RigidArray where Element: ~Copyable { #endif } +@available(SwiftStdlib 5.0, *) +extension OutputSpan where Element: ~Copyable { + @_alwaysEmitIntoClient + @_lifetime(self: copy self) + mutating func _withUnsafeMutableBufferPointer( + _ body: ( + UnsafeMutableBufferPointer, + _ initializedCount: inout Int + ) throws(E) -> R + ) throws(E) -> R { + // FIXME: Work around rdar://169036911 + let capacity = self.capacity + let baseAddress = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow. + return try withUnsafeMutableBufferPointer { buffer, count throws(E) in + let correctedBuffer = UnsafeMutableRawBufferPointer( + start: .init(mutating: baseAddress), // Wow, wow. + count: capacity &* MemoryLayout.stride) + return try correctedBuffer.withMemoryRebound(to: Element.self) { + correctBuffer throws(E) in + try body(correctBuffer, &count) + } + } + } +} + @available(SwiftStdlib 5.0, *) extension RigidArray { /// Copies the elements of a fully initialized buffer pointer into this From bcbee23816afb733f7bc3bae618229b4a95c7a98 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Wed, 28 Jan 2026 17:28:23 -0800 Subject: [PATCH 36/75] use the horrible replacement (cherry picked from commit 3f38800c5abd3fa7decf813e8421b4421ec1dd72) --- Sources/BasicContainers/RigidArray+Insertions.swift | 2 +- Sources/BasicContainers/RigidArray+Replacements.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 80d08c8f..f90ed2f1 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -303,7 +303,7 @@ extension RigidArray { ) { guard newElements.count > 0 else { return } self.insert(count: newElements.count, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll(fromContentsOf: newElements) count = newElements.count } diff --git a/Sources/BasicContainers/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray+Replacements.swift index 38717592..27995843 100644 --- a/Sources/BasicContainers/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray+Replacements.swift @@ -303,7 +303,7 @@ extension RigidArray { copying newElements: UnsafeBufferPointer ) { replaceSubrange(subrange, newCount: newElements.count) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._initializePrefix(copying: newElements) } } @@ -410,7 +410,7 @@ extension RigidArray { newCount: Int ) { self.replaceSubrange(subrange, newCount: newCount) { target in - target.withUnsafeMutableBufferPointer { dst, dstCount in + target._withUnsafeMutableBufferPointer { dst, dstCount in let done: Void? = newElements.withContiguousStorageIfAvailable { src in let i = unsafe dst._initializePrefix(copying: src) precondition( From 1fe2fb03a884329ce852f09efc702f1eeefbfda9 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 29 Jan 2026 08:57:43 -0800 Subject: [PATCH 37/75] rearrange horribleness to insert preconditions (cherry picked from commit 085fc446b1bf449c5eedf4754bcc5f17c5fe7c42) --- .../BasicContainers/RigidArray+Insertions.swift | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index f90ed2f1..9069c0d3 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -261,15 +261,14 @@ extension OutputSpan where Element: ~Copyable { ) throws(E) -> R ) throws(E) -> R { // FIXME: Work around rdar://169036911 - let capacity = self.capacity - let baseAddress = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow. - return try withUnsafeMutableBufferPointer { buffer, count throws(E) in - let correctedBuffer = UnsafeMutableRawBufferPointer( - start: .init(mutating: baseAddress), // Wow, wow. - count: capacity &* MemoryLayout.stride) - return try correctedBuffer.withMemoryRebound(to: Element.self) { - correctBuffer throws(E) in - try body(correctBuffer, &count) + let correctedBuffer = UnsafeMutableRawBufferPointer( + start: .init(mutating: span.withUnsafeBufferPointer { $0.baseAddress }), // Wow, wow. + count: capacity &* MemoryLayout.stride) + return try correctedBuffer.withMemoryRebound(to: Element.self) { correctBuffer throws(E) in + precondition(correctBuffer.count == self.capacity) + return try self.withUnsafeMutableBufferPointer { badBuffer, count throws(E) in + precondition(badBuffer.baseAddress == correctBuffer.baseAddress) + return try body(correctBuffer, &count) } } } From e8d53861aeb6d1c8904475e2c7060975bd039d32 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 11:36:52 -0800 Subject: [PATCH 38/75] Move OutputSpan.wUMBP workaround to ContainersPreview, and use it there, too --- .../RigidArray+Insertions.swift | 24 ----------- .../ContainersPreview/OutputSpan+Extras.swift | 40 ++++++++++++++++--- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 9069c0d3..bd6a7631 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -250,30 +250,6 @@ extension RigidArray where Element: ~Copyable { #endif } -@available(SwiftStdlib 5.0, *) -extension OutputSpan where Element: ~Copyable { - @_alwaysEmitIntoClient - @_lifetime(self: copy self) - mutating func _withUnsafeMutableBufferPointer( - _ body: ( - UnsafeMutableBufferPointer, - _ initializedCount: inout Int - ) throws(E) -> R - ) throws(E) -> R { - // FIXME: Work around rdar://169036911 - let correctedBuffer = UnsafeMutableRawBufferPointer( - start: .init(mutating: span.withUnsafeBufferPointer { $0.baseAddress }), // Wow, wow. - count: capacity &* MemoryLayout.stride) - return try correctedBuffer.withMemoryRebound(to: Element.self) { correctBuffer throws(E) in - precondition(correctBuffer.count == self.capacity) - return try self.withUnsafeMutableBufferPointer { badBuffer, count throws(E) in - precondition(badBuffer.baseAddress == correctBuffer.baseAddress) - return try body(correctBuffer, &count) - } - } - } -} - @available(SwiftStdlib 5.0, *) extension RigidArray { /// Copies the elements of a fully initialized buffer pointer into this diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/OutputSpan+Extras.swift index c510bd17..8499d6be 100644 --- a/Sources/ContainersPreview/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/OutputSpan+Extras.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if compiler(>=6.2) #if !COLLECTIONS_SINGLE_MODULE import InternalCollectionsUtilities @@ -17,7 +17,7 @@ import InternalCollectionsUtilities @available(SwiftStdlib 5.0, *) @_alwaysEmitIntoClient -internal func withTemporaryOutputSpan( +package func withTemporaryOutputSpan( of type: Element.Type, capacity: Int, _ body: (inout OutputSpan) throws(E) -> R @@ -39,9 +39,9 @@ extension OutputSpan where Element: ~Copyable { /// /// - Complexity: O(1) @inlinable - internal mutating func _popLast() -> Element? { + package mutating func _popLast() -> Element? { // FIXME: This needs to be in the stdlib. - withUnsafeMutableBufferPointer { buffer, count in + _withUnsafeMutableBufferPointer { buffer, count in guard count > 0 else { return nil } count &-= 1 return buffer.moveElement(from: count) @@ -49,13 +49,14 @@ extension OutputSpan where Element: ~Copyable { } } +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) extension OutputSpan where Element: ~Copyable { @_lifetime(source: copy source) @inlinable - internal mutating func _append(moving source: inout InputSpan) { + package mutating func _append(moving source: inout InputSpan) { // FIXME: This needs to be in the stdlib. - self.withUnsafeMutableBufferPointer { dst, dstCount in + self._withUnsafeMutableBufferPointer { dst, dstCount in source.withUnsafeMutableBufferPointer { src, srcCount in let dstEnd = dstCount + srcCount let srcStart = src.count - srcCount @@ -70,6 +71,33 @@ extension OutputSpan where Element: ~Copyable { } } } +#endif + +@available(SwiftStdlib 5.0, *) +extension OutputSpan where Element: ~Copyable { + @_alwaysEmitIntoClient + @inlinable + @_lifetime(self: copy self) + package mutating func _withUnsafeMutableBufferPointer( + _ body: ( + UnsafeMutableBufferPointer, + _ initializedCount: inout Int + ) throws(E) -> R + ) throws(E) -> R { + // FIXME: Work around https://github.com/apple/swift-collections/issues/561 / rdar://169036911 + let correctedBuffer = UnsafeMutableRawBufferPointer( + start: .init(mutating: span.withUnsafeBufferPointer { $0.baseAddress }), // Wow, wow. + count: capacity &* MemoryLayout.stride) + return try correctedBuffer.withMemoryRebound(to: Element.self) { correctBuffer throws(E) in + precondition(correctBuffer.count == self.capacity) + return try self.withUnsafeMutableBufferPointer { badBuffer, count throws(E) in + precondition(badBuffer.baseAddress == correctBuffer.baseAddress) + return try body(correctBuffer, &count) + } + } + } +} + #endif From 1bced00e1c082d65d8a707ad0205bf2bfbf3cd91 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 12:08:01 -0800 Subject: [PATCH 39/75] Sigh, disable `withTemporaryOutputSpan` on 6.2 The RigidDeque effort will land a polyfill for temporary allocations to let us use this on 6.2. --- Sources/ContainersPreview/OutputSpan+Extras.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/OutputSpan+Extras.swift index 8499d6be..01d959cf 100644 --- a/Sources/ContainersPreview/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/OutputSpan+Extras.swift @@ -9,12 +9,11 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) - #if !COLLECTIONS_SINGLE_MODULE import InternalCollectionsUtilities #endif +#if compiler(>=6.3) @available(SwiftStdlib 5.0, *) @_alwaysEmitIntoClient package func withTemporaryOutputSpan( @@ -29,7 +28,9 @@ package func withTemporaryOutputSpan return try body(&span) } } +#endif +#if compiler(>=6.2) @available(SwiftStdlib 5.0, *) extension OutputSpan where Element: ~Copyable { /// Removes and returns the last element of this output span, if it exists. From 31e9e7c2f0d5d754164d54dca099b47cf9fec8b2 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 13:04:57 -0800 Subject: [PATCH 40/75] =?UTF-8?q?Oops,=20don=E2=80=99t=20use=20the=20worka?= =?UTF-8?q?round=20in=206.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 6.2 implementation works okay, but it loses the base address in the exposed buffer happens to be empty. --- Sources/ContainersPreview/OutputSpan+Extras.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/OutputSpan+Extras.swift index 01d959cf..5b42e34c 100644 --- a/Sources/ContainersPreview/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/OutputSpan+Extras.swift @@ -77,7 +77,7 @@ extension OutputSpan where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension OutputSpan where Element: ~Copyable { @_alwaysEmitIntoClient - @inlinable + @inlinable // FIXME: This should be implied by @_aeic @_lifetime(self: copy self) package mutating func _withUnsafeMutableBufferPointer( _ body: ( @@ -85,10 +85,14 @@ extension OutputSpan where Element: ~Copyable { _ initializedCount: inout Int ) throws(E) -> R ) throws(E) -> R { +#if compiler(<6.3) + return try self.withUnsafeMutableBufferPointer(body) +#else // FIXME: Work around https://github.com/apple/swift-collections/issues/561 / rdar://169036911 + let start = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow. let correctedBuffer = UnsafeMutableRawBufferPointer( - start: .init(mutating: span.withUnsafeBufferPointer { $0.baseAddress }), // Wow, wow. - count: capacity &* MemoryLayout.stride) + start: .init(mutating: start), // Wow, wow. + count: self.capacity &* MemoryLayout.stride) return try correctedBuffer.withMemoryRebound(to: Element.self) { correctBuffer throws(E) in precondition(correctBuffer.count == self.capacity) return try self.withUnsafeMutableBufferPointer { badBuffer, count throws(E) in @@ -96,9 +100,8 @@ extension OutputSpan where Element: ~Copyable { return try body(correctBuffer, &count) } } +#endif } } - - #endif From 790e36c6211365826e421b9ed73b764f21990fee Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 13:09:37 -0800 Subject: [PATCH 41/75] Reenable Rigid/UniqueArray testing on Linux with 6.3 snapshots --- Tests/BasicContainersTests/RigidArrayTests.swift | 2 +- Tests/BasicContainersTests/UniqueArrayTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index 7a209097..3382fe70 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -17,7 +17,7 @@ import _CollectionsTestSupport import BasicContainers #endif -#if compiler(>=6.2) && (compiler(>=6.4) || compiler(<6.3) || !os(Linux)) // FIXME https://github.com/apple/swift-collections/issues/561 +#if compiler(>=6.2) #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. diff --git a/Tests/BasicContainersTests/UniqueArrayTests.swift b/Tests/BasicContainersTests/UniqueArrayTests.swift index 160d3cd5..9836a702 100644 --- a/Tests/BasicContainersTests/UniqueArrayTests.swift +++ b/Tests/BasicContainersTests/UniqueArrayTests.swift @@ -17,7 +17,7 @@ import _CollectionsTestSupport import BasicContainers #endif -#if compiler(>=6.2) && (compiler(>=6.4) || compiler(<6.3) || !os(Linux)) // FIXME https://github.com/apple/swift-collections/issues/561 +#if compiler(>=6.2) #if !COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW /// Check if `left` and `right` contain equal elements in the same order. From ffc56156a52042d23d64f5c58ec4a199fb36824e Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 13:16:39 -0800 Subject: [PATCH 42/75] =?UTF-8?q?Wrinkles=20on=20top=20of=20wrinkles?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ContainersPreview/OutputSpan+Extras.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/OutputSpan+Extras.swift index 5b42e34c..ebf4f816 100644 --- a/Sources/ContainersPreview/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/OutputSpan+Extras.swift @@ -85,7 +85,7 @@ extension OutputSpan where Element: ~Copyable { _ initializedCount: inout Int ) throws(E) -> R ) throws(E) -> R { -#if compiler(<6.3) +#if compiler(<6.3) || compiler(>=6.4) return try self.withUnsafeMutableBufferPointer(body) #else // FIXME: Work around https://github.com/apple/swift-collections/issues/561 / rdar://169036911 From d1efcb19db72befae31841116b43586350a60a72 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 13:23:07 -0800 Subject: [PATCH 43/75] More wrinkles! Shar Peis are adorable --- Sources/ContainersPreview/OutputSpan+Extras.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/ContainersPreview/OutputSpan+Extras.swift b/Sources/ContainersPreview/OutputSpan+Extras.swift index ebf4f816..cac8fa8a 100644 --- a/Sources/ContainersPreview/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/OutputSpan+Extras.swift @@ -85,10 +85,16 @@ extension OutputSpan where Element: ~Copyable { _ initializedCount: inout Int ) throws(E) -> R ) throws(E) -> R { -#if compiler(<6.3) || compiler(>=6.4) - return try self.withUnsafeMutableBufferPointer(body) -#else // FIXME: Work around https://github.com/apple/swift-collections/issues/561 / rdar://169036911 + let capacity = self.capacity + let r = try self.withUnsafeMutableBufferPointer { buffer, initializedCount throws(E) -> R? in + if buffer.count == capacity { + return try body(buffer, &initializedCount) + } + return nil + } + if let r { return r } + let start = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow. let correctedBuffer = UnsafeMutableRawBufferPointer( start: .init(mutating: start), // Wow, wow. @@ -100,7 +106,6 @@ extension OutputSpan where Element: ~Copyable { return try body(correctBuffer, &count) } } -#endif } } From 801d361bbba2879124f14094cba40ade9ed72d68 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 14:35:47 -0800 Subject: [PATCH 44/75] Reinstate OutputSpan additions accidentally removed during merge --- .../Extensions/OutputSpan+Extras.swift | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift index 995b4231..81b2d1a8 100644 --- a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift @@ -68,7 +68,7 @@ extension OutputSpan where Element: ~Copyable { dstCount &+= source.count } } - + #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @_lifetime(source: copy source) @inlinable @@ -85,6 +85,45 @@ extension OutputSpan where Element: ~Copyable { } } #endif + + @_lifetime(source: copy source) + @inlinable + @inline(__always) + @_lifetime(self: copy self) + package mutating func _append(moving source: inout OutputSpan) { + // FIXME: This needs to be in the stdlib. + source.withUnsafeMutableBufferPointer { src, srcCount in + let items = src._extracting(uncheckedFrom: 0, to: srcCount) + self._append(moving: items) + srcCount = 0 + } + } +} + +@available(SwiftStdlib 5.0, *) +extension OutputSpan /*where Element: Copyable*/ { + @inlinable + @_lifetime(self: copy self) + package mutating func _append(copying source: UnsafeBufferPointer) { + // FIXME: This needs to be in the stdlib. + self.withUnsafeMutableBufferPointer { dst, dstCount in + let dstEnd = dstCount + source.count + precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") + dst + ._extracting(uncheckedFrom: dstCount, to: dstEnd) + .initializeAll(fromContentsOf: source) + dstCount &+= source.count + } + } + + @inlinable + @_lifetime(self: copy self) + package mutating func _append(copying source: Span) { + // FIXME: This needs to be in the stdlib. + source.withUnsafeBufferPointer { buffer in + self._append(copying: buffer) + } + } } @available(SwiftStdlib 5.0, *) From 772c426bc906a0a797da837bc13e6bd66c90dbfb Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 15:02:53 -0800 Subject: [PATCH 45/75] Oh this is proving a bit more difficult than ideal --- .../ContainersPreview/Extensions/OutputSpan+Extras.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift index 81b2d1a8..045f7ec2 100644 --- a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift @@ -59,7 +59,7 @@ extension OutputSpan where Element: ~Copyable { ) { // FIXME: This needs to be in the stdlib. guard source.count > 0 else { return } - self.withUnsafeMutableBufferPointer { dst, dstCount in + self._withUnsafeMutableBufferPointer { dst, dstCount in let dstEnd = dstCount + source.count precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") dst @@ -92,7 +92,7 @@ extension OutputSpan where Element: ~Copyable { @_lifetime(self: copy self) package mutating func _append(moving source: inout OutputSpan) { // FIXME: This needs to be in the stdlib. - source.withUnsafeMutableBufferPointer { src, srcCount in + source._withUnsafeMutableBufferPointer { src, srcCount in let items = src._extracting(uncheckedFrom: 0, to: srcCount) self._append(moving: items) srcCount = 0 @@ -106,7 +106,7 @@ extension OutputSpan /*where Element: Copyable*/ { @_lifetime(self: copy self) package mutating func _append(copying source: UnsafeBufferPointer) { // FIXME: This needs to be in the stdlib. - self.withUnsafeMutableBufferPointer { dst, dstCount in + self._withUnsafeMutableBufferPointer { dst, dstCount in let dstEnd = dstCount + source.count precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") dst From 80b8a6fb80ebb1ce7f5e918027b77a99fc57759c Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 29 Jan 2026 15:35:35 -0800 Subject: [PATCH 46/75] Use the OutputSpan workaround everywhere --- Sources/BasicContainers/RigidArray+Append.swift | 2 +- Sources/BasicContainers/RigidArray+Insertions.swift | 2 +- Sources/BasicContainers/RigidArray+Replacements.swift | 4 ++-- Sources/DequeModule/RigidDeque/RigidDeque+Append.swift | 2 +- Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift | 6 +++--- Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift | 2 +- .../DequeModule/RigidDeque/RigidDeque+Replacements.swift | 6 +++--- Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift | 2 +- .../DequeModule/UniqueDeque/UniqueDeque+Insertions.swift | 6 +++--- Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift | 2 +- .../DequeModule/UniqueDeque/UniqueDeque+Replacements.swift | 6 +++--- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Sources/BasicContainers/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray+Append.swift index 43805a6b..b051dabe 100644 --- a/Sources/BasicContainers/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray+Append.swift @@ -148,7 +148,7 @@ extension RigidArray where Element: ~Copyable { public mutating func append( moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.append(moving: source) count = 0 diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 29167d7d..aa83b767 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -174,7 +174,7 @@ extension RigidArray where Element: ~Copyable { moving items: inout OutputSpan, at index: Int ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.insert(moving: source, at: index) count = 0 diff --git a/Sources/BasicContainers/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray+Replacements.swift index fe2824aa..9c32a1b6 100644 --- a/Sources/BasicContainers/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray+Replacements.swift @@ -104,7 +104,7 @@ extension RigidArray where Element: ~Copyable { moving newElements: UnsafeMutableBufferPointer, ) { replaceSubrange(subrange, newCount: newElements.count) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._moveInitializePrefix(from: newElements) } } @@ -181,7 +181,7 @@ extension RigidArray where Element: ~Copyable { _ subrange: Range, moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.replaceSubrange(subrange, moving: source) count = 0 diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 49b8485a..8a9c1392 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -169,7 +169,7 @@ extension RigidDeque where Element: ~Copyable { public mutating func append( moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.append(moving: source) count = 0 diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 21eb8b8c..3d37b48e 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -134,7 +134,7 @@ extension RigidDeque where Element: ~Copyable { guard !items.isEmpty else { return } var remainder = items insert(maximumCount: items.count, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -196,7 +196,7 @@ extension RigidDeque where Element: ~Copyable { moving items: inout OutputSpan, at index: Int ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.insert(moving: source, at: index) count = 0 @@ -282,7 +282,7 @@ extension RigidDeque /* where Element: Copyable */ { guard items.count > 0 else { return } var remainder = items insert(maximumCount: remainder.count, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( fromContentsOf: remainder._extracting(first: buffer.count)) remainder = remainder._extracting(droppingFirst: buffer.count) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 02cd6ad1..1fbb3c6f 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -173,7 +173,7 @@ extension RigidDeque where Element: ~Copyable { public mutating func prepend( moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.prepend(moving: source) count = 0 diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index f8e2978a..475ae2c8 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -186,7 +186,7 @@ extension RigidDeque where Element: ~Copyable { ) { var remainder = items replaceSubrange(subrange, maximumCount: remainder.count) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -266,7 +266,7 @@ extension RigidDeque where Element: ~Copyable { _ subrange: Range, moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.replaceSubrange(subrange, moving: source) count = 0 @@ -361,7 +361,7 @@ extension RigidDeque /* where Element: Copyable */ { ) { var remainder = items replaceSubrange(subrange, maximumCount: remainder.count) { target in - target.withUnsafeMutableBufferPointer { dst, dstCount in + target._withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift index 7b3a02d8..b00f8f01 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -159,7 +159,7 @@ extension UniqueDeque where Element: ~Copyable { public mutating func append( moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.append(moving: source) count = 0 diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index 886b582a..e8c438b3 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -140,7 +140,7 @@ extension UniqueDeque where Element: ~Copyable { guard !items.isEmpty else { return } var remainder = items insert(maximumCount: items.count, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -206,7 +206,7 @@ extension UniqueDeque where Element: ~Copyable { moving items: inout OutputSpan, at index: Int ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.insert(moving: source, at: index) count = 0 @@ -296,7 +296,7 @@ extension UniqueDeque /* where Element: Copyable */ { guard items.count > 0 else { return } var remainder = items insert(maximumCount: remainder.count, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( fromContentsOf: remainder._extracting(first: buffer.count)) remainder = remainder._extracting(droppingFirst: buffer.count) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index d4ece9be..3920cb5d 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -164,7 +164,7 @@ extension UniqueDeque where Element: ~Copyable { public mutating func prepend( moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.prepend(moving: source) count = 0 diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index 98772671..186d20a3 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -185,7 +185,7 @@ extension UniqueDeque where Element: ~Copyable { ) { var remainder = items replaceSubrange(subrange, maximumCount: remainder.count) { target in - target.withUnsafeMutableBufferPointer { buffer, count in + target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -267,7 +267,7 @@ extension UniqueDeque where Element: ~Copyable { _ subrange: Range, moving items: inout OutputSpan ) { - items.withUnsafeMutableBufferPointer { buffer, count in + items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.replaceSubrange(subrange, moving: source) count = 0 @@ -366,7 +366,7 @@ extension UniqueDeque /* where Element: Copyable */ { ) { var remainder = items replaceSubrange(subrange, maximumCount: remainder.count) { target in - target.withUnsafeMutableBufferPointer { dst, dstCount in + target._withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count } From eac10abae2a623803eae75aa32a6a0668d9f3c0a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 30 Jan 2026 12:07:28 -0800 Subject: [PATCH 47/75] Stop using `@_exported import` - Stop using unstable import attributes with undefined/flaky semantics in package contexts. - Freeze the contents of the Collections module. Do not make the new RigidDeque/UniqueDeque types from there, at least not yet. Replace reexported types with typealiases, and reexported protocol extensions with redefinitions forwarding to a common implementation in the original module. --- .../BitArray/BinaryInteger extensions.swift | 216 ++++++++++++++++++ .../BitArray/BitArray+Initializers.swift | 177 -------------- Sources/BitCollections/CMakeLists.txt | 3 +- .../BitCollections reexports.swift | 164 +++++++++++++ Sources/Collections/CMakeLists.txt | 10 +- ...ions.swift => DequeModule reexports.swift} | 12 +- .../HashTreeCollections reexports.swift | 17 ++ .../Collections/HeapModule reexports.swift | 16 ++ .../OrderedCollections reexports.swift | 17 ++ Xcode/Collections.xcodeproj/project.pbxproj | 22 +- 10 files changed, 459 insertions(+), 195 deletions(-) create mode 100644 Sources/BitCollections/BitArray/BinaryInteger extensions.swift create mode 100644 Sources/Collections/BitCollections reexports.swift rename Sources/Collections/{Collections.swift => DequeModule reexports.swift} (53%) create mode 100644 Sources/Collections/HashTreeCollections reexports.swift create mode 100644 Sources/Collections/HeapModule reexports.swift create mode 100644 Sources/Collections/OrderedCollections reexports.swift diff --git a/Sources/BitCollections/BitArray/BinaryInteger extensions.swift b/Sources/BitCollections/BitArray/BinaryInteger extensions.swift new file mode 100644 index 00000000..57b1187c --- /dev/null +++ b/Sources/BitCollections/BitArray/BinaryInteger extensions.swift @@ -0,0 +1,216 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2021 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +extension BitArray { + @inlinable + package func _convert( + to type: T.Type + ) -> ( + value: T, + isNegative: Bool + ) { + var value: T = .zero + let isNegative = self._foreachTwosComplementWordDownward( + isSigned: T.isSigned + ) { _, word in + value <<= UInt.bitWidth + value |= T(truncatingIfNeeded: word) + return true + } + return (value, isNegative) + } + + @inlinable + package func _convertTruncating(to type: T.Type) -> T { + self._convert(to: T.self).value + } + + @inlinable + package func _convertExactly(to type: T.Type) -> T? { + let (value, isNegative) = self._convert(to: T.self) + guard isNegative == (value < 0) else { return nil } + let words = value.words + var equal = true + _ = self._foreachTwosComplementWordDownward(isSigned: T.isSigned) { i, word in + assert(equal) + let w = ( + i < words.count ? words[i] + : isNegative ? UInt.max + : UInt.zero) + equal = (w == word) + return equal + } + guard equal else { return nil } + return value + } + + @inlinable + package func _convertForced(to type: T.Type) -> T { + guard let value = _convertExactly(to: T.self) else { + fatalError(""" + BitArray value cannot be converted to \(Self.self) because it is \ + outside the representable range + """) + } + return value + } +} + +extension BinaryInteger { + /// Creates a new instance by truncating or extending the bits in the given + /// bit array, as needed. The bit at position 0 in `source` will correspond + /// to the least-significant bit in the result. + /// + /// If `Self` is an unsigned integer type, then the result will contain as + /// many bits from `source` it can accommodate, truncating off any extras. + /// + /// UInt8(truncatingIfNeeded: "" as BitArray) // 0 + /// UInt8(truncatingIfNeeded: "0" as BitArray) // 0 + /// UInt8(truncatingIfNeeded: "1" as BitArray) // 1 + /// UInt8(truncatingIfNeeded: "11" as BitArray) // 3 + /// UInt8(truncatingIfNeeded: "11111111" as BitArray) // 255 + /// UInt8(truncatingIfNeeded: "1100000001" as BitArray) // 1 + /// UInt8(truncatingIfNeeded: "1100000101" as BitArray) // 5 + /// + /// If `Self` is a signed integer type, then the contents of the bit array + /// are interpreted to be a two's complement representation of a signed + /// integer value, with the last bit in the array representing the sign of + /// the result. + /// + /// Int8(truncatingIfNeeded: "" as BitArray) // 0 + /// Int8(truncatingIfNeeded: "0" as BitArray) // 0 + /// Int8(truncatingIfNeeded: "1" as BitArray) // -1 + /// Int8(truncatingIfNeeded: "01" as BitArray) // 1 + /// Int8(truncatingIfNeeded: "101" as BitArray) // -3 + /// Int8(truncatingIfNeeded: "0101" as BitArray) // 5 + /// + /// Int8(truncatingIfNeeded: "00000001" as BitArray) // 1 + /// Int8(truncatingIfNeeded: "00000101" as BitArray) // 5 + /// Int8(truncatingIfNeeded: "01111111" as BitArray) // 127 + /// Int8(truncatingIfNeeded: "10000000" as BitArray) // -128 + /// Int8(truncatingIfNeeded: "11111111" as BitArray) // -1 + /// + /// Int8(truncatingIfNeeded: "000011111111" as BitArray) // -1 + /// Int8(truncatingIfNeeded: "111100000000" as BitArray) // 0 + /// Int8(truncatingIfNeeded: "111100000001" as BitArray) // 1 + @inlinable + @inline(__always) + public init(truncatingIfNeeded source: BitArray) { + self = source._convertTruncating(to: Self.self) + } + + /// Creates a new instance from the bits in the given bit array, if the + /// corresponding integer value can be represented exactly. + /// If the value is not representable exactly, then the result is `nil`. + /// + /// If `Self` is an unsigned integer type, then the contents of the bit array + /// are interpreted to be the binary representation of a nonnegative + /// integer value. The bit array is allowed to contain bits in unrepresentable + /// positions, as long as they are all cleared. + /// + /// UInt8(exactly: "" as BitArray) // 0 + /// UInt8(exactly: "0" as BitArray) // 0 + /// UInt8(exactly: "1" as BitArray) // 1 + /// UInt8(exactly: "10" as BitArray) // 2 + /// UInt8(exactly: "00000000" as BitArray) // 0 + /// UInt8(exactly: "11111111" as BitArray) // 255 + /// UInt8(exactly: "0000000000000" as BitArray) // 0 + /// UInt8(exactly: "0000011111111" as BitArray) // 255 + /// UInt8(exactly: "0000100000000" as BitArray) // nil + /// UInt8(exactly: "1111111111111" as BitArray) // nil + /// + /// If `Self` is a signed integer type, then the contents of the bit array + /// are interpreted to be a two's complement representation of a signed + /// integer value, with the last bit in the array representing the sign of + /// the result. + /// + /// Int8(exactly: "" as BitArray) // 0 + /// Int8(exactly: "0" as BitArray) // 0 + /// Int8(exactly: "1" as BitArray) // -1 + /// Int8(exactly: "01" as BitArray) // 1 + /// Int8(exactly: "101" as BitArray) // -3 + /// Int8(exactly: "0101" as BitArray) // 5 + /// + /// Int8(exactly: "00000001" as BitArray) // 1 + /// Int8(exactly: "00000101" as BitArray) // 5 + /// Int8(exactly: "01111111" as BitArray) // 127 + /// Int8(exactly: "10000000" as BitArray) // -128 + /// Int8(exactly: "11111111" as BitArray) // -1 + /// + /// Int8(exactly: "00000000000" as BitArray) // 0 + /// Int8(exactly: "00001111111" as BitArray) // 127 + /// Int8(exactly: "00010000000" as BitArray) // nil + /// Int8(exactly: "11101111111" as BitArray) // nil + /// Int8(exactly: "11110000000" as BitArray) // -128 + /// Int8(exactly: "11111111111" as BitArray) // -1 + @inlinable + @inline(__always) + public init?(exactly source: BitArray) { + guard let v = source._convertExactly(to: Self.self) else { return nil } + self = v + } + + /// Creates a new instance from the bits in the given bit array, if the + /// corresponding integer value can be represented exactly. + /// If the value is not representable exactly, then a runtime error will + /// occur. + /// + /// If `Self` is an unsigned integer type, then the contents of the bit array + /// are interpreted to be the binary representation of a nonnegative + /// integer value. The bit array is allowed to contain bits in unrepresentable + /// positions, as long as they are all cleared. + /// + /// UInt8("" as BitArray) // 0 + /// UInt8("0" as BitArray) // 0 + /// UInt8("1" as BitArray) // 1 + /// UInt8("10" as BitArray) // 2 + /// UInt8("00000000" as BitArray) // 0 + /// UInt8("11111111" as BitArray) // 255 + /// UInt8("0000000000000" as BitArray) // 0 + /// UInt8("0000011111111" as BitArray) // 255 + /// UInt8("0000100000000" as BitArray) // ERROR + /// UInt8("1111111111111" as BitArray) // ERROR + /// + /// If `Self` is a signed integer type, then the contents of the bit array + /// are interpreted to be a two's complement representation of a signed + /// integer value, with the last bit in the array representing the sign of + /// the result. + /// + /// Int8("" as BitArray) // 0 + /// Int8("0" as BitArray) // 0 + /// Int8("1" as BitArray) // -1 + /// Int8("01" as BitArray) // 1 + /// Int8("101" as BitArray) // -3 + /// Int8("0101" as BitArray) // 5 + /// + /// Int8("00000001" as BitArray) // 1 + /// Int8("00000101" as BitArray) // 5 + /// Int8("01111111" as BitArray) // 127 + /// Int8("10000000" as BitArray) // -128 + /// Int8("11111111" as BitArray) // -1 + /// + /// Int8("00000000000" as BitArray) // 0 + /// Int8("00001111111" as BitArray) // 127 + /// Int8("00010000000" as BitArray) // ERROR + /// Int8("11101111111" as BitArray) // ERROR + /// Int8("11110000000" as BitArray) // -128 + /// Int8("11111111111" as BitArray) // -1 + @inlinable + @inline(__always) + public init(_ source: BitArray) { + self = source._convertForced(to: Self.self) + } +} + diff --git a/Sources/BitCollections/BitArray/BitArray+Initializers.swift b/Sources/BitCollections/BitArray/BitArray+Initializers.swift index d2ec9c8d..c8870d79 100644 --- a/Sources/BitCollections/BitArray/BitArray+Initializers.swift +++ b/Sources/BitCollections/BitArray/BitArray+Initializers.swift @@ -67,183 +67,6 @@ extension BitArray { } } -extension BinaryInteger { - @inlinable - internal static func _convert( - _ source: BitArray - ) -> (value: Self, isNegative: Bool) { - var value: Self = .zero - let isNegative = source._foreachTwosComplementWordDownward( - isSigned: Self.isSigned - ) { _, word in - value <<= UInt.bitWidth - value |= Self(truncatingIfNeeded: word) - return true - } - return (value, isNegative) - } - - /// Creates a new instance by truncating or extending the bits in the given - /// bit array, as needed. The bit at position 0 in `source` will correspond - /// to the least-significant bit in the result. - /// - /// If `Self` is an unsigned integer type, then the result will contain as - /// many bits from `source` it can accommodate, truncating off any extras. - /// - /// UInt8(truncatingIfNeeded: "" as BitArray) // 0 - /// UInt8(truncatingIfNeeded: "0" as BitArray) // 0 - /// UInt8(truncatingIfNeeded: "1" as BitArray) // 1 - /// UInt8(truncatingIfNeeded: "11" as BitArray) // 3 - /// UInt8(truncatingIfNeeded: "11111111" as BitArray) // 255 - /// UInt8(truncatingIfNeeded: "1100000001" as BitArray) // 1 - /// UInt8(truncatingIfNeeded: "1100000101" as BitArray) // 5 - /// - /// If `Self` is a signed integer type, then the contents of the bit array - /// are interpreted to be a two's complement representation of a signed - /// integer value, with the last bit in the array representing the sign of - /// the result. - /// - /// Int8(truncatingIfNeeded: "" as BitArray) // 0 - /// Int8(truncatingIfNeeded: "0" as BitArray) // 0 - /// Int8(truncatingIfNeeded: "1" as BitArray) // -1 - /// Int8(truncatingIfNeeded: "01" as BitArray) // 1 - /// Int8(truncatingIfNeeded: "101" as BitArray) // -3 - /// Int8(truncatingIfNeeded: "0101" as BitArray) // 5 - /// - /// Int8(truncatingIfNeeded: "00000001" as BitArray) // 1 - /// Int8(truncatingIfNeeded: "00000101" as BitArray) // 5 - /// Int8(truncatingIfNeeded: "01111111" as BitArray) // 127 - /// Int8(truncatingIfNeeded: "10000000" as BitArray) // -128 - /// Int8(truncatingIfNeeded: "11111111" as BitArray) // -1 - /// - /// Int8(truncatingIfNeeded: "000011111111" as BitArray) // -1 - /// Int8(truncatingIfNeeded: "111100000000" as BitArray) // 0 - /// Int8(truncatingIfNeeded: "111100000001" as BitArray) // 1 - @inlinable - public init(truncatingIfNeeded source: BitArray) { - self = Self._convert(source).value - } - - /// Creates a new instance from the bits in the given bit array, if the - /// corresponding integer value can be represented exactly. - /// If the value is not representable exactly, then the result is `nil`. - /// - /// If `Self` is an unsigned integer type, then the contents of the bit array - /// are interpreted to be the binary representation of a nonnegative - /// integer value. The bit array is allowed to contain bits in unrepresentable - /// positions, as long as they are all cleared. - /// - /// UInt8(exactly: "" as BitArray) // 0 - /// UInt8(exactly: "0" as BitArray) // 0 - /// UInt8(exactly: "1" as BitArray) // 1 - /// UInt8(exactly: "10" as BitArray) // 2 - /// UInt8(exactly: "00000000" as BitArray) // 0 - /// UInt8(exactly: "11111111" as BitArray) // 255 - /// UInt8(exactly: "0000000000000" as BitArray) // 0 - /// UInt8(exactly: "0000011111111" as BitArray) // 255 - /// UInt8(exactly: "0000100000000" as BitArray) // nil - /// UInt8(exactly: "1111111111111" as BitArray) // nil - /// - /// If `Self` is a signed integer type, then the contents of the bit array - /// are interpreted to be a two's complement representation of a signed - /// integer value, with the last bit in the array representing the sign of - /// the result. - /// - /// Int8(exactly: "" as BitArray) // 0 - /// Int8(exactly: "0" as BitArray) // 0 - /// Int8(exactly: "1" as BitArray) // -1 - /// Int8(exactly: "01" as BitArray) // 1 - /// Int8(exactly: "101" as BitArray) // -3 - /// Int8(exactly: "0101" as BitArray) // 5 - /// - /// Int8(exactly: "00000001" as BitArray) // 1 - /// Int8(exactly: "00000101" as BitArray) // 5 - /// Int8(exactly: "01111111" as BitArray) // 127 - /// Int8(exactly: "10000000" as BitArray) // -128 - /// Int8(exactly: "11111111" as BitArray) // -1 - /// - /// Int8(exactly: "00000000000" as BitArray) // 0 - /// Int8(exactly: "00001111111" as BitArray) // 127 - /// Int8(exactly: "00010000000" as BitArray) // nil - /// Int8(exactly: "11101111111" as BitArray) // nil - /// Int8(exactly: "11110000000" as BitArray) // -128 - /// Int8(exactly: "11111111111" as BitArray) // -1 - @inlinable - public init?(exactly source: BitArray) { - let (value, isNegative) = Self._convert(source) - guard isNegative == (value < 0) else { return nil } - let words = value.words - var equal = true - _ = source._foreachTwosComplementWordDownward(isSigned: Self.isSigned) { i, word in - assert(equal) - let w = ( - i < words.count ? words[i] - : isNegative ? UInt.max - : UInt.zero) - equal = (w == word) - return equal - } - guard equal else { return nil } - self = value - } - - /// Creates a new instance from the bits in the given bit array, if the - /// corresponding integer value can be represented exactly. - /// If the value is not representable exactly, then a runtime error will - /// occur. - /// - /// If `Self` is an unsigned integer type, then the contents of the bit array - /// are interpreted to be the binary representation of a nonnegative - /// integer value. The bit array is allowed to contain bits in unrepresentable - /// positions, as long as they are all cleared. - /// - /// UInt8("" as BitArray) // 0 - /// UInt8("0" as BitArray) // 0 - /// UInt8("1" as BitArray) // 1 - /// UInt8("10" as BitArray) // 2 - /// UInt8("00000000" as BitArray) // 0 - /// UInt8("11111111" as BitArray) // 255 - /// UInt8("0000000000000" as BitArray) // 0 - /// UInt8("0000011111111" as BitArray) // 255 - /// UInt8("0000100000000" as BitArray) // ERROR - /// UInt8("1111111111111" as BitArray) // ERROR - /// - /// If `Self` is a signed integer type, then the contents of the bit array - /// are interpreted to be a two's complement representation of a signed - /// integer value, with the last bit in the array representing the sign of - /// the result. - /// - /// Int8("" as BitArray) // 0 - /// Int8("0" as BitArray) // 0 - /// Int8("1" as BitArray) // -1 - /// Int8("01" as BitArray) // 1 - /// Int8("101" as BitArray) // -3 - /// Int8("0101" as BitArray) // 5 - /// - /// Int8("00000001" as BitArray) // 1 - /// Int8("00000101" as BitArray) // 5 - /// Int8("01111111" as BitArray) // 127 - /// Int8("10000000" as BitArray) // -128 - /// Int8("11111111" as BitArray) // -1 - /// - /// Int8("00000000000" as BitArray) // 0 - /// Int8("00001111111" as BitArray) // 127 - /// Int8("00010000000" as BitArray) // ERROR - /// Int8("11101111111" as BitArray) // ERROR - /// Int8("11110000000" as BitArray) // -128 - /// Int8("11111111111" as BitArray) // -1 - @inlinable - public init(_ source: BitArray) { - guard let value = Self(exactly: source) else { - fatalError(""" - BitArray value cannot be converted to \(Self.self) because it is \ - outside the representable range - """) - } - self = value - } -} - extension BitArray { @usableFromInline internal func _foreachTwosComplementWordDownward( diff --git a/Sources/BitCollections/CMakeLists.txt b/Sources/BitCollections/CMakeLists.txt index 9ca7a2d4..39523e27 100644 --- a/Sources/BitCollections/CMakeLists.txt +++ b/Sources/BitCollections/CMakeLists.txt @@ -1,7 +1,7 @@ #[[ This source file is part of the Swift Collections Open Source Project -Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +Copyright (c) 2022 - 2026 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 @@ -23,6 +23,7 @@ else() endif() target_sources(${module_name} PRIVATE + "BitArray/BinaryInteger extensions.swift" "BitArray/BitArray+BitwiseOperations.swift" "BitArray/BitArray+ChunkedBitsIterators.swift" "BitArray/BitArray+Codable.swift" diff --git a/Sources/Collections/BitCollections reexports.swift b/Sources/Collections/BitCollections reexports.swift new file mode 100644 index 00000000..ce1a1641 --- /dev/null +++ b/Sources/Collections/BitCollections reexports.swift @@ -0,0 +1,164 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2021 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import BitCollections + +public typealias BitSet = BitCollections.BitSet +public typealias BitArray = BitCollections.BitArray + +extension BinaryInteger { + /// Creates a new instance by truncating or extending the bits in the given + /// bit array, as needed. The bit at position 0 in `source` will correspond + /// to the least-significant bit in the result. + /// + /// If `Self` is an unsigned integer type, then the result will contain as + /// many bits from `source` it can accommodate, truncating off any extras. + /// + /// UInt8(truncatingIfNeeded: "" as BitArray) // 0 + /// UInt8(truncatingIfNeeded: "0" as BitArray) // 0 + /// UInt8(truncatingIfNeeded: "1" as BitArray) // 1 + /// UInt8(truncatingIfNeeded: "11" as BitArray) // 3 + /// UInt8(truncatingIfNeeded: "11111111" as BitArray) // 255 + /// UInt8(truncatingIfNeeded: "1100000001" as BitArray) // 1 + /// UInt8(truncatingIfNeeded: "1100000101" as BitArray) // 5 + /// + /// If `Self` is a signed integer type, then the contents of the bit array + /// are interpreted to be a two's complement representation of a signed + /// integer value, with the last bit in the array representing the sign of + /// the result. + /// + /// Int8(truncatingIfNeeded: "" as BitArray) // 0 + /// Int8(truncatingIfNeeded: "0" as BitArray) // 0 + /// Int8(truncatingIfNeeded: "1" as BitArray) // -1 + /// Int8(truncatingIfNeeded: "01" as BitArray) // 1 + /// Int8(truncatingIfNeeded: "101" as BitArray) // -3 + /// Int8(truncatingIfNeeded: "0101" as BitArray) // 5 + /// + /// Int8(truncatingIfNeeded: "00000001" as BitArray) // 1 + /// Int8(truncatingIfNeeded: "00000101" as BitArray) // 5 + /// Int8(truncatingIfNeeded: "01111111" as BitArray) // 127 + /// Int8(truncatingIfNeeded: "10000000" as BitArray) // -128 + /// Int8(truncatingIfNeeded: "11111111" as BitArray) // -1 + /// + /// Int8(truncatingIfNeeded: "000011111111" as BitArray) // -1 + /// Int8(truncatingIfNeeded: "111100000000" as BitArray) // 0 + /// Int8(truncatingIfNeeded: "111100000001" as BitArray) // 1 + @inlinable + @inline(__always) + public init(truncatingIfNeeded source: BitArray) { + self = source._convertTruncating(to: Self.self) + } + + /// Creates a new instance from the bits in the given bit array, if the + /// corresponding integer value can be represented exactly. + /// If the value is not representable exactly, then the result is `nil`. + /// + /// If `Self` is an unsigned integer type, then the contents of the bit array + /// are interpreted to be the binary representation of a nonnegative + /// integer value. The bit array is allowed to contain bits in unrepresentable + /// positions, as long as they are all cleared. + /// + /// UInt8(exactly: "" as BitArray) // 0 + /// UInt8(exactly: "0" as BitArray) // 0 + /// UInt8(exactly: "1" as BitArray) // 1 + /// UInt8(exactly: "10" as BitArray) // 2 + /// UInt8(exactly: "00000000" as BitArray) // 0 + /// UInt8(exactly: "11111111" as BitArray) // 255 + /// UInt8(exactly: "0000000000000" as BitArray) // 0 + /// UInt8(exactly: "0000011111111" as BitArray) // 255 + /// UInt8(exactly: "0000100000000" as BitArray) // nil + /// UInt8(exactly: "1111111111111" as BitArray) // nil + /// + /// If `Self` is a signed integer type, then the contents of the bit array + /// are interpreted to be a two's complement representation of a signed + /// integer value, with the last bit in the array representing the sign of + /// the result. + /// + /// Int8(exactly: "" as BitArray) // 0 + /// Int8(exactly: "0" as BitArray) // 0 + /// Int8(exactly: "1" as BitArray) // -1 + /// Int8(exactly: "01" as BitArray) // 1 + /// Int8(exactly: "101" as BitArray) // -3 + /// Int8(exactly: "0101" as BitArray) // 5 + /// + /// Int8(exactly: "00000001" as BitArray) // 1 + /// Int8(exactly: "00000101" as BitArray) // 5 + /// Int8(exactly: "01111111" as BitArray) // 127 + /// Int8(exactly: "10000000" as BitArray) // -128 + /// Int8(exactly: "11111111" as BitArray) // -1 + /// + /// Int8(exactly: "00000000000" as BitArray) // 0 + /// Int8(exactly: "00001111111" as BitArray) // 127 + /// Int8(exactly: "00010000000" as BitArray) // nil + /// Int8(exactly: "11101111111" as BitArray) // nil + /// Int8(exactly: "11110000000" as BitArray) // -128 + /// Int8(exactly: "11111111111" as BitArray) // -1 + @inlinable + @inline(__always) + public init?(exactly source: BitArray) { + guard let v = source._convertExactly(to: Self.self) else { return nil } + self = v + } + + /// Creates a new instance from the bits in the given bit array, if the + /// corresponding integer value can be represented exactly. + /// If the value is not representable exactly, then a runtime error will + /// occur. + /// + /// If `Self` is an unsigned integer type, then the contents of the bit array + /// are interpreted to be the binary representation of a nonnegative + /// integer value. The bit array is allowed to contain bits in unrepresentable + /// positions, as long as they are all cleared. + /// + /// UInt8("" as BitArray) // 0 + /// UInt8("0" as BitArray) // 0 + /// UInt8("1" as BitArray) // 1 + /// UInt8("10" as BitArray) // 2 + /// UInt8("00000000" as BitArray) // 0 + /// UInt8("11111111" as BitArray) // 255 + /// UInt8("0000000000000" as BitArray) // 0 + /// UInt8("0000011111111" as BitArray) // 255 + /// UInt8("0000100000000" as BitArray) // ERROR + /// UInt8("1111111111111" as BitArray) // ERROR + /// + /// If `Self` is a signed integer type, then the contents of the bit array + /// are interpreted to be a two's complement representation of a signed + /// integer value, with the last bit in the array representing the sign of + /// the result. + /// + /// Int8("" as BitArray) // 0 + /// Int8("0" as BitArray) // 0 + /// Int8("1" as BitArray) // -1 + /// Int8("01" as BitArray) // 1 + /// Int8("101" as BitArray) // -3 + /// Int8("0101" as BitArray) // 5 + /// + /// Int8("00000001" as BitArray) // 1 + /// Int8("00000101" as BitArray) // 5 + /// Int8("01111111" as BitArray) // 127 + /// Int8("10000000" as BitArray) // -128 + /// Int8("11111111" as BitArray) // -1 + /// + /// Int8("00000000000" as BitArray) // 0 + /// Int8("00001111111" as BitArray) // 127 + /// Int8("00010000000" as BitArray) // ERROR + /// Int8("11101111111" as BitArray) // ERROR + /// Int8("11110000000" as BitArray) // -128 + /// Int8("11111111111" as BitArray) // -1 + @inlinable + @inline(__always) + public init(_ source: BitArray) { + self = source._convertForced(to: Self.self) + } +} + +#endif diff --git a/Sources/Collections/CMakeLists.txt b/Sources/Collections/CMakeLists.txt index 9f534a46..d49d7584 100644 --- a/Sources/Collections/CMakeLists.txt +++ b/Sources/Collections/CMakeLists.txt @@ -1,20 +1,24 @@ #[[ This source file is part of the Swift Collections Open Source Project -Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +Copyright (c) 2021 - 2026 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 #]] add_library(Collections - "Collections.swift") + "BitCollections reexports.swift" + "DequeModule reexports.swift" + "HashTreeCollections reexports.swift" + "HeapModule reexports.swift" + "OrderedCollections reexports.swift") target_link_libraries(Collections PRIVATE BitCollections DequeModule + HashTreeCollections HeapModule OrderedCollections - HashTreeCollections ) set_target_properties(Collections PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) diff --git a/Sources/Collections/Collections.swift b/Sources/Collections/DequeModule reexports.swift similarity index 53% rename from Sources/Collections/Collections.swift rename to Sources/Collections/DequeModule reexports.swift index 33d5c8a1..6aad0586 100644 --- a/Sources/Collections/Collections.swift +++ b/Sources/Collections/DequeModule reexports.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2026 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 @@ -10,11 +10,7 @@ //===----------------------------------------------------------------------===// #if !COLLECTIONS_SINGLE_MODULE -@_exported import BitCollections -@_exported import DequeModule -@_exported import HashTreeCollections -@_exported import HeapModule -@_exported import OrderedCollections -// Note: _RopeModule is very intentionally not reexported, as its contents -// aren't part of this package's stable API surface (yet). +import DequeModule + +public typealias Deque = DequeModule.Deque #endif diff --git a/Sources/Collections/HashTreeCollections reexports.swift b/Sources/Collections/HashTreeCollections reexports.swift new file mode 100644 index 00000000..e83a2589 --- /dev/null +++ b/Sources/Collections/HashTreeCollections reexports.swift @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2021 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import HashTreeCollections + +public typealias TreeSet = HashTreeCollections.TreeSet +public typealias TreeDictionary = HashTreeCollections.TreeDictionary +#endif diff --git a/Sources/Collections/HeapModule reexports.swift b/Sources/Collections/HeapModule reexports.swift new file mode 100644 index 00000000..a99ce48f --- /dev/null +++ b/Sources/Collections/HeapModule reexports.swift @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2021 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import HeapModule + +public typealias Heap = HeapModule.Heap +#endif diff --git a/Sources/Collections/OrderedCollections reexports.swift b/Sources/Collections/OrderedCollections reexports.swift new file mode 100644 index 00000000..f64b9927 --- /dev/null +++ b/Sources/Collections/OrderedCollections reexports.swift @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2021 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import OrderedCollections + +public typealias OrderedSet = OrderedCollections.OrderedSet +public typealias OrderedDictionary = OrderedCollections.OrderedDictionary +#endif diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 0b54b6d1..19458997 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -108,6 +108,7 @@ 7DAD89B52E8B09EC00DD5786 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89A82E8B09EC00DD5786 /* Debugging.swift */; }; 7DAD89B62E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AE2E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift */; }; 7DAD89B72E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AF2E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift */; }; + 7DE448452F2D3705005853A7 /* BinaryInteger extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE448442F2D36F9005853A7 /* BinaryInteger extensions.swift */; }; 7DE91B2F29CA6721004483EB /* Collections.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DE91B2629CA6721004483EB /* Collections.framework */; }; 7DE9200D29CA70F3004483EB /* OrderedDictionary+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91E7529CA70F3004483EB /* OrderedDictionary+Equatable.swift */; }; 7DE9200E29CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91E7629CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift */; }; @@ -465,7 +466,6 @@ 7DEBDB9029CCE44A00ADC226 /* TestContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2229CCE43600ADC226 /* TestContext.swift */; }; 7DEBDB9129CCE44A00ADC226 /* CollectionTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2429CCE43600ADC226 /* CollectionTestCase.swift */; }; 7DEBDB9229CCE44A00ADC226 /* StringConvertibleValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2B29CCE43600ADC226 /* StringConvertibleValue.swift */; }; - 7DEBDB9D29CCE73D00ADC226 /* Collections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91F7B29CA70F3004483EB /* Collections.swift */; }; A93AC2152E7C841700A824DF /* RigidArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC2102E7C841700A824DF /* RigidArray.swift */; }; A93AC2162E7C841700A824DF /* UniqueArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC2122E7C841700A824DF /* UniqueArray.swift */; }; A93AC2172E7C841700A824DF /* RigidArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC2112E7C841700A824DF /* RigidArray+Experimental.swift */; }; @@ -599,6 +599,12 @@ 7DAD89AD2E8B09EC00DD5786 /* UnsafeMutableBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableBufferPointer+Extras.swift"; sourceTree = ""; }; 7DAD89AE2E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableRawBufferPointer+Extras.swift"; sourceTree = ""; }; 7DAD89AF2E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeRawBufferPointer+Extras.swift"; sourceTree = ""; }; + 7DE448442F2D36F9005853A7 /* BinaryInteger extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BinaryInteger extensions.swift"; sourceTree = ""; }; + 7DE448462F2D3940005853A7 /* BitCollections reexports.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BitCollections reexports.swift"; sourceTree = ""; }; + 7DE448472F2D3984005853A7 /* DequeModule reexports.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DequeModule reexports.swift"; sourceTree = ""; }; + 7DE448482F2D39E9005853A7 /* HashTreeCollections reexports.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HashTreeCollections reexports.swift"; sourceTree = ""; }; + 7DE448492F2D3B48005853A7 /* HeapModule reexports.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HeapModule reexports.swift"; sourceTree = ""; }; + 7DE4484A2F2D3B74005853A7 /* OrderedCollections reexports.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderedCollections reexports.swift"; sourceTree = ""; }; 7DE91B2629CA6721004483EB /* Collections.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Collections.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7DE91B2E29CA6721004483EB /* CollectionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CollectionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 7DE91E7229CA70F3004483EB /* OrderedCollections.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = OrderedCollections.docc; sourceTree = ""; }; @@ -801,7 +807,6 @@ 7DE91F7629CA70F3004483EB /* BitArray+Equatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+Equatable.swift"; sourceTree = ""; }; 7DE91F7829CA70F3004483EB /* BitArray+Testing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+Testing.swift"; sourceTree = ""; }; 7DE91F7A29CA70F3004483EB /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - 7DE91F7B29CA70F3004483EB /* Collections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Collections.swift; sourceTree = ""; }; 7DE91F7C29CA70F3004483EB /* Collections.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Collections.docc; sourceTree = ""; }; 7DE91FA829CA70F3004483EB /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; 7DE91FA929CA70F3004483EB /* HashTreeCollections.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = HashTreeCollections.docc; sourceTree = ""; }; @@ -1162,11 +1167,11 @@ 7DE91E7029CA70F3004483EB /* Sources */ = { isa = PBXGroup; children = ( + 7DE91F7929CA70F3004483EB /* Collections */, A93AC2142E7C841700A824DF /* BasicContainers */, 7DE91F2229CA70F3004483EB /* InternalCollectionsUtilities */, 7D48BCCE2E51524200D7F6F7 /* ContainersPreview */, 7DE91F3929CA70F3004483EB /* BitCollections */, - 7DE91F7929CA70F3004483EB /* Collections */, 7DE91EB629CA70F3004483EB /* DequeModule */, 7DE91FA729CA70F3004483EB /* HashTreeCollections */, 7DE9200229CA70F3004483EB /* HeapModule */, @@ -1578,6 +1583,7 @@ 7DE91F7029CA70F3004483EB /* BitArray+RangeReplaceableCollection.swift */, 7D9B859129E4F74400B291CD /* BitArray+Shifts.swift */, 7DE91F7829CA70F3004483EB /* BitArray+Testing.swift */, + 7DE448442F2D36F9005853A7 /* BinaryInteger extensions.swift */, ); path = BitArray; sourceTree = ""; @@ -1585,9 +1591,13 @@ 7DE91F7929CA70F3004483EB /* Collections */ = { isa = PBXGroup; children = ( - 7DE91F7B29CA70F3004483EB /* Collections.swift */, - 7DE91F7C29CA70F3004483EB /* Collections.docc */, + 7DE448462F2D3940005853A7 /* BitCollections reexports.swift */, + 7DE448472F2D3984005853A7 /* DequeModule reexports.swift */, + 7DE448482F2D39E9005853A7 /* HashTreeCollections reexports.swift */, + 7DE448492F2D3B48005853A7 /* HeapModule reexports.swift */, + 7DE4484A2F2D3B74005853A7 /* OrderedCollections reexports.swift */, 7DE91F7A29CA70F3004483EB /* CMakeLists.txt */, + 7DE91F7C29CA70F3004483EB /* Collections.docc */, ); path = Collections; sourceTree = ""; @@ -2259,7 +2269,6 @@ 7DE9208629CA70F4004483EB /* BigString+LosslessStringConvertible.swift in Sources */, 7DE9204329CA70F3004483EB /* _HashTable+Bucket.swift in Sources */, 7DE9216A29CA70F4004483EB /* TreeDictionary.swift in Sources */, - 7DEBDB9D29CCE73D00ADC226 /* Collections.swift in Sources */, 7DE9215C29CA70F4004483EB /* _Bitmap.swift in Sources */, 7DE9207029CA70F4004483EB /* BigString+Chunk+RopeElement.swift in Sources */, 7DE9213729CA70F4004483EB /* TreeSet+Sequence.swift in Sources */, @@ -2487,6 +2496,7 @@ 7DE9206129CA70F4004483EB /* BigString.swift in Sources */, 7DE9215A29CA70F4004483EB /* _HashNode+Structural subtracting.swift in Sources */, 7DE9217E29CA70F4004483EB /* Heap+ExpressibleByArrayLiteral.swift in Sources */, + 7DE448452F2D3705005853A7 /* BinaryInteger extensions.swift in Sources */, 7DE9204029CA70F3004483EB /* OrderedSet+Partial SetAlgebra isStrictSuperset.swift in Sources */, 7DE920BF29CA70F4004483EB /* BitSet+Codable.swift in Sources */, 7DE9203329CA70F3004483EB /* OrderedSet+Testing.swift in Sources */, From 7de30041d3ea2d327ed5d8c4b1003c63f4acf91a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 30 Jan 2026 16:07:55 -0800 Subject: [PATCH 48/75] Delete stray benchmark results files --- Benchmarks/results | 1 - Benchmarks/results.html | 3247 --------------------------------------- 2 files changed, 3248 deletions(-) delete mode 100644 Benchmarks/results delete mode 100644 Benchmarks/results.html diff --git a/Benchmarks/results b/Benchmarks/results deleted file mode 100644 index 91590537..00000000 --- a/Benchmarks/results +++ /dev/null @@ -1 +0,0 @@ -{"tasks":[{"title":"Deque init from unsafe buffer","results":{"2048":[[0,255410000000],[0,255830000000],[0,316660000000],[0,353750000000]],"1048576":[[0,131833000000000],[0,134804644444444]],"96":[[0,76660000000],[0,77080000000],[0,77920000000],[0,78340000000]],"327680":[[0,41674242424242],[0,42412500000000]],"384":[[0,93750000000],[0,93750000000],[0,94170000000],[0,95830000000]],"12288":[[0,1657920000000],[0,1658750000000],[0,1660830000000],[0,1693330000000]],"81920":[[0,8840840000000],[0,8842666666666],[0,10231660000000],[0,10901250000000]],"8":[[0,61250000000],[0,62500000000],[0,64580000000],[0,65410000000]],"1280":[[0,179590000000],[0,180830000000],[0,181670000000],[0,205410000000]],"3584":[[0,344170000000],[0,359160000000],[0,372500000000],[0,372500000000]],"7":[[0,63750000000],[0,64160000000],[0,65000000000],[0,65830000000]],"524288":[[0,66208000000000],[0,67600574712643]],"112":[[0,79170000000],[0,79580000000],[0,80000000000],[0,80000000000]],"896":[[0,147080000000],[0,147080000000],[0,147500000000],[0,149170000000]],"192":[[0,80410000000],[0,80830000000],[0,80840000000],[0,81660000000]],"80":[[0,75420000000],[0,75830000000],[0,75830000000],[0,77500000000]],"24":[[0,62080000000],[0,63330000000],[0,64170000000],[0,65000000000]],"40960":[[0,4825000000000],[0,4828750000000],[0,4856660000000],[0,5880420000000]],"16":[[0,61670000000],[0,62080000000],[0,63330000000],[0,65410000000]],"3072":[[0,476250000000],[0,477920000000],[0,478330000000],[0,580420000000]],"20":[[0,62080000000],[0,63330000000],[0,63750000000],[0,65420000000]],"224":[[0,82080000000],[0,82910000000],[0,83330000000],[0,83750000000]],"2560":[[0,408750000000],[0,415420000000],[0,417500000000],[0,425000000000]],"1792":[[0,214590000000],[0,220000000000],[0,226250000000],[0,235840000000]],"1024":[[0,158330000000],[0,158750000000],[0,171250000000],[0,189170000000]],"6144":[[0,1146660000000],[0,1160132530120],[0,1192500000000],[0,1371250000000]],"56":[[0,73330000000],[0,73330000000],[0,73750000000],[0,74580000000]],"786432":[[0,103973958333333],[0,105625000000000]],"163840":[[0,17048304347826],[0,21208000000000],[0,22106250000000]],"6":[[0,62500000000],[0,62920000000],[0,63717647058],[0,63750000000]],"48":[[0,72080000000],[0,72500000000],[0,72910000000],[0,73340000000]],"32":[[0,70830000000],[0,71660000000],[0,72080000000],[0,72500000000]],"14":[[0,61250000000],[0,61670000000],[0,62500000000],[0,62500000000]],"28672":[[0,3626660000000],[0,3628340000000],[0,3633330000000],[0,3654170000000]],"512":[[0,111166666666],[0,117080000000],[0,118750000000],[0,127910000000]],"196608":[[0,22008687500000],[0,25305666666666],[0,27252920000000]],"458752":[[0,58467202127659],[0,60358200000000]],"24576":[[0,3214580000000],[0,3219580000000],[0,3224160000000],[0,3248750000000]],"2":[[0,61670000000],[0,62500000000],[0,62920000000],[0,64170000000]],"256":[[0,83340000000],[0,83750000000],[0,84580000000],[0,86250000000]],"1536":[[0,197080000000],[0,198750000000],[0,211250000000],[0,247500000000]],"64":[[0,73750000000],[0,75000000000],[0,75000000000],[0,75000000000]],"320":[[0,90000000000],[0,90000000000],[0,90000000000],[0,90830000000]],"114688":[[0,12068330000000],[0,15093530612244],[0,15125000000000]],"131072":[[0,14504282051282],[0,17159590000000],[0,17440410000000]],"16384":[[0,2318750000000],[0,2351250000000],[0,2352500000000],[0,2424170000000]],"5120":[[0,1067080000000],[0,1104170000000],[0,1105000000000],[0,1109170000000]],"229376":[[0,25226250000000],[0,29459170000000],[0,30474170000000]],"5":[[0,62500000000],[0,63330000000],[0,63330000000],[0,63340000000]],"10":[[0,61660000000],[0,62080000000],[0,62500000000],[0,73330000000]],"28":[[0,70830000000],[0,71250000000],[0,72080000000],[0,72080000000]],"655360":[[0,82875000000000],[0,92386000000000]],"7168":[[0,1238750000000],[0,1247910000000],[0,1260420000000],[0,1332080000000]],"20480":[[0,2815420000000],[0,2840830000000],[0,2841250000000],[0,2980000000000]],"65536":[[0,7230000000000],[0,7258330000000],[0,7274590000000],[0,7278330000000]],"917504":[[0,101833320000000],[0,115831081081081]],"160":[[0,77500000000],[0,78330000000],[0,78330000000],[0,83330000000]],"640":[[0,123750000000],[0,124580000000],[0,124580000000],[0,125840000000]],"40":[[0,71670000000],[0,72080000000],[0,72500000000],[0,72920000000]],"393216":[[0,49916000000000],[0,50606924528301]],"57344":[[0,6434906250000],[0,6437500000000],[0,6447090000000],[0,7167000000000]],"4":[[0,62500000000],[0,62500000000],[0,62910000000],[0,64160000000]],"1":[[0,63750000000],[0,64160000000],[0,66250000000],[0,110000000000]],"768":[[0,136250000000],[0,137500000000],[0,137920000000],[0,152080000000]],"448":[[0,105830000000],[0,106670000000],[0,107080000000],[0,120410000000]],"8192":[[0,1308750000000],[0,1313750000000],[0,1319580000000],[0,1512080000000]],"12":[[0,62500000000],[0,63750000000],[0,63750000000],[0,64160000000]],"10240":[[0,1476250000000],[0,1479580000000],[0,1568750000000],[0,1607910000000]],"14336":[[0,1930000000000],[0,1936250000000],[0,1969170000000],[0,2506670000000]],"32768":[[0,4027080000000],[0,4029580000000],[0,4030533333333],[0,4032500000000]],"128":[[0,73750000000],[0,74160000000],[0,75000000000],[0,75830000000]],"4096":[[0,1219160000000],[0,1219160000000],[0,1220840000000],[0,1231250000000]],"49152":[[0,5631660000000],[0,5633720930232],[0,5636660000000],[0,5642920000000]],"262144":[[0,33500000000000],[0,34251844444444],[0,37196909090909]],"3":[[0,61670000000],[0,62500000000],[0,62500000000],[0,63340000000]],"98304":[[0,10474170000000],[0,10515000000000],[0,13021250000000],[0,13060420000000]]}},{"title":"Deque sequential iteration (contiguous, iterator)","results":{"2048":[[0,1670830000000],[0,1670830000000],[0,1670830000000],[0,1670830000000]],"1048576":[[0,862750000000000],[0,869583000000000]],"96":[[0,85830000000],[0,85830000000],[0,86250000000],[0,86250000000]],"327680":[[0,266542000000000],[0,274041000000000]],"384":[[0,319580000000],[0,319590000000],[0,320000000000],[0,320000000000]],"12288":[[0,9982920000000],[0,9982920000000],[0,9983750000000],[0,10000000000000]],"81920":[[0,66542000000000],[0,66560000000000],[0,66562500000000],[0,66616510204081]],"8":[[0,11660000000],[0,11660000000],[0,11660000000],[0,11660000000]],"1280":[[0,1047080000000],[0,1047090000000],[0,1047090000000],[0,1047500000000]],"3584":[[0,2916750000000],[0,2917500000000],[0,2917500000000],[0,2917920000000]],"7":[[0,10250000000],[0,10830000000],[0,11250000000],[0,11250000000]],"524288":[[0,429375000000000],[0,434000000000000]],"112":[[0,98750000000],[0,98750000000],[0,99160000000],[0,99160000000]],"896":[[0,735410000000],[0,735410000000],[0,735420000000],[0,735830000000]],"192":[[0,163461538461],[0,163750000000],[0,164160000000],[0,164160000000]],"80":[[0,72910000000],[0,72920000000],[0,72920000000],[0,72920000000]],"24":[[0,24580000000],[0,24580000000],[0,24580000000],[0,24580000000]],"40960":[[0,33270500000000],[0,33277784946236],[0,33292000000000],[0,33417000000000]],"16":[[0,17920000000],[0,17920000000],[0,18330000000],[0,18330000000]],"3072":[[0,2500000000000],[0,2500000000000],[0,2502080000000],[0,2502500000000]],"20":[[0,21250000000],[0,21250000000],[0,21250000000],[0,21250000000]],"224":[[0,190000000000],[0,190000000000],[0,190000000000],[0,190000000000]],"2560":[[0,2086250000000],[0,2086250000000],[0,2086660000000],[0,2086660000000]],"1792":[[0,1462910000000],[0,1462920000000],[0,1462920000000],[0,1463330000000]],"1024":[[0,839170000000],[0,839580000000],[0,839580000000],[0,840000000000]],"6144":[[0,4995830000000],[0,4995830000000],[0,4996250000000],[0,4996311111111]],"56":[[0,42000000000],[0,53330000000],[0,53330000000],[0,53750000000]],"786432":[[0,650750000000000],[0,655959000000000]],"163840":[[0,133084000000000],[0,133375567567567],[0,133458000000000]],"6":[[0,9590000000],[0,9590000000],[0,10000000000],[0,10000000000]],"48":[[0,47500000000],[0,47500000000],[0,47500000000],[0,47500000000]],"32":[[0,31250000000],[0,31250000000],[0,31250000000],[0,31250000000]],"14":[[0,16250000000],[0,16250000000],[0,16660000000],[0,16660000000]],"28672":[[0,23284160000000],[0,23288330000000],[0,23315420000000],[0,23322920000000]],"512":[[0,423330000000],[0,423701298701],[0,423750000000],[0,423750000000]],"196608":[[0,160417000000000],[0,161875000000000],[0,165454545454545]],"458752":[[0,372833000000000],[0,388625000000000]],"24576":[[0,19979000000000],[0,19991250000000],[0,19995840000000],[0,20000000000000]],"2":[[0,6660000000],[0,6660000000],[0,6670000000],[0,7080000000]],"256":[[0,215830000000],[0,215830000000],[0,215830000000],[0,215830000000]],"1536":[[0,1255000000000],[0,1255000000000],[0,1255000000000],[0,1255410000000]],"64":[[0,60000000000],[0,60000000000],[0,60000000000],[0,60000000000]],"320":[[0,267500000000],[0,267500000000],[0,267910000000],[0,267920000000]],"114688":[[0,93291000000000],[0,93334000000000],[0,93458000000000]],"131072":[[0,106564075268817],[0,106709000000000],[0,107305666666666]],"16384":[[0,13306680000000],[0,13308340000000],[0,13314580000000],[0,13411670000000]],"5120":[[0,4164160000000],[0,4164160000000],[0,4164170000000],[0,4164580000000]],"229376":[[0,187936111111111],[0,190166000000000],[0,192084000000000]],"5":[[0,9170000000],[0,9580000000],[0,9580000000],[0,9580000000]],"10":[[0,12920000000],[0,12920000000],[0,13330000000],[0,15000000000]],"28":[[0,27500000000],[0,27500000000],[0,27910000000],[0,27910000000]],"655360":[[0,548697875000000],[0,550667000000000]],"7168":[[0,5826660000000],[0,5826670000000],[0,5827080000000],[0,5827920000000]],"20480":[[0,16646000000000],[0,16649333333333],[0,16666250000000],[0,16701660000000]],"65536":[[0,53250000000000],[0,53250000000000],[0,54100420000000],[0,54163650602409]],"917504":[[0,746042000000000],[0,782156250000000]],"160":[[0,137500000000],[0,137910000000],[0,137910000000],[0,137920000000]],"640":[[0,527500000000],[0,527761904761],[0,527910000000],[0,527910000000]],"40":[[0,40830000000],[0,40840000000],[0,41250000000],[0,41250000000]],"393216":[[0,319500000000000],[0,326083333333333]],"57344":[[0,46557250000000],[0,46626670000000],[0,46667000000000],[0,47000000000000]],"4":[[0,8330000000],[0,8330000000],[0,8330000000],[0,8330000000]],"1":[[0,5830000000],[0,6250000000],[0,6660000000],[0,9580000000]],"768":[[0,625000000000],[0,631660000000],[0,631660000000],[0,631660000000]],"448":[[0,371660000000],[0,371670000000],[0,372080000000],[0,421409090909]],"8192":[[0,6657920000000],[0,6658750000000],[0,6659170000000],[0,6692080000000]],"12":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"10240":[[0,8320830000000],[0,8320830000000],[0,8320830000000],[0,8321660000000]],"14336":[[0,11645420000000],[0,11645840000000],[0,11657910000000],[0,11762920000000]],"32768":[[0,26625000000000],[0,26625000000000],[0,26709000000000],[0,26802500000000]],"128":[[0,111670000000],[0,112080000000],[0,112080000000],[0,112080000000]],"4096":[[0,3332500000000],[0,3332920000000],[0,3333330000000],[0,3333942028985]],"49152":[[0,39916000000000],[0,39917000000000],[0,39932500000000],[0,40123330000000]],"262144":[[0,212916000000000],[0,216625000000000],[0,236310975609756]],"3":[[0,7910000000],[0,7910000000],[0,7910000000],[0,7910000000]],"98304":[[0,79806818181818],[0,79871541666666],[0,79959000000000],[0,80118750000000]]}},{"title":"Deque subscript get, random offsets (contiguous)","results":{"2048":[[0,2220830000000],[0,2220924528301],[0,2221250000000],[0,2222080000000]],"1048576":[[0,1147667000000000],[0,1216555666666666]],"96":[[0,83000000000],[0,107920000000],[0,108330000000],[0,108750000000]],"327680":[[0,365383200000000],[0,369483400000000]],"384":[[0,420000000000],[0,420000000000],[0,420410000000],[0,420410000000]],"12288":[[0,13307080000000],[0,13337080000000],[0,13497500000000],[0,13506670000000]],"81920":[[0,88666684210526],[0,88677800000000],[0,88740666666666],[0,90091125000000]],"8":[[0,10000000000],[0,10000000000],[0,10375000000],[0,10410000000]],"1280":[[0,1389590000000],[0,1390000000000],[0,1390000000000],[0,1390410000000]],"3584":[[0,3883750000000],[0,3884160000000],[0,3884170000000],[0,3884590000000]],"7":[[0,5857142857],[0,9160000000],[0,9160000000],[0,9160000000]],"524288":[[0,572937500000000],[0,584147727272727]],"112":[[0,125000000000],[0,125410000000],[0,125420000000],[0,125830000000]],"896":[[0,958000000000],[0,959000000000],[0,974160000000],[0,974170000000]],"192":[[0,212080000000],[0,212090000000],[0,212500000000],[0,212500000000]],"80":[[0,83000000000],[0,83000000000],[0,90830000000],[0,91250000000]],"24":[[0,27080000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,44548263157894],[0,44958000000000],[0,45009823529411],[0,46702910000000]],"16":[[0,18750000000],[0,18750000000],[0,18750000000],[0,21660000000]],"3072":[[0,3329160000000],[0,3329580000000],[0,3329590000000],[0,3330830000000]],"20":[[0,20500000000],[0,22910000000],[0,22920000000],[0,22920000000]],"224":[[0,246250000000],[0,246660000000],[0,246670000000],[0,247080000000]],"2560":[[0,2775000000000],[0,2775000000000],[0,2775410000000],[0,2842500000000]],"1792":[[0,1917000000000],[0,1944160000000],[0,1944170000000],[0,1944580000000]],"1024":[[0,1112500000000],[0,1112500000000],[0,1113330000000],[0,1113750000000]],"6144":[[0,6654590000000],[0,6654590000000],[0,6655840000000],[0,6687920000000]],"56":[[0,64580000000],[0,65000000000],[0,65000000000],[0,65000000000]],"786432":[[0,855152666666666],[0,873760500000000]],"163840":[[0,179635177777777],[0,180713235294117],[0,188530200000000]],"6":[[0,7920000000],[0,8330000000],[0,8330000000],[0,8330000000]],"48":[[0,41000000000],[0,55830000000],[0,55840000000],[0,56250000000]],"32":[[0,31250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"14":[[0,16660000000],[0,16660000000],[0,16660000000],[0,16660000000]],"28672":[[0,31039580000000],[0,31040830000000],[0,31048076923076],[0,31156660000000]],"512":[[0,558330000000],[0,558340000000],[0,558750000000],[0,558750000000]],"196608":[[0,212870333333333],[0,220226142857142],[0,222004555555555]],"458752":[[0,499562500000000],[0,538446428571428]],"24576":[[0,26705000000000],[0,26709580000000],[0,26854590000000],[0,27116250000000]],"2":[[0,3750000000],[0,3750000000],[0,3750000000],[0,4160000000]],"256":[[0,281250000000],[0,281250000000],[0,281660000000],[0,281660000000]],"1536":[[0,1666670000000],[0,1666670000000],[0,1667080000000],[0,1667500000000]],"64":[[0,73330000000],[0,73750000000],[0,73750000000],[0,74160000000]],"320":[[0,350000000000],[0,350420000000],[0,351250000000],[0,351250000000]],"114688":[[0,124602615384615],[0,126128818181818],[0,126327898550724]],"131072":[[0,142991666666666],[0,144269779661016],[0,147034090909090]],"16384":[[0,17741250000000],[0,17748330000000],[0,17754170000000],[0,18002717391304]],"5120":[[0,5545830000000],[0,5546250000000],[0,5546670000000],[0,5550830000000]],"229376":[[0,249601777777777],[0,253843454545454],[0,266223096774193]],"5":[[0,6660000000],[0,6670000000],[0,7080000000],[0,7080000000]],"10":[[0,12080000000],[0,12090000000],[0,12500000000],[0,14160000000]],"28":[[0,32080000000],[0,32080000000],[0,32080000000],[0,32080000000]],"655360":[[0,709666000000000],[0,729615777777777]],"7168":[[0,7763330000000],[0,7763340000000],[0,7764170000000],[0,7764170000000]],"20480":[[0,22175830000000],[0,22250000000000],[0,22262500000000],[0,22445830000000]],"65536":[[0,70958000000000],[0,71333324324324],[0,71750000000000],[0,72000000000000]],"917504":[[0,1004750000000000],[0,1011062500000000]],"160":[[0,177080000000],[0,177500000000],[0,177500000000],[0,177910000000]],"640":[[0,667000000000],[0,687500000000],[0,696670000000],[0,697080000000]],"40":[[0,47080000000],[0,47080000000],[0,47090000000],[0,47090000000]],"393216":[[0,428693647058823],[0,434479000000000]],"57344":[[0,62757920000000],[0,63512920000000],[0,63534160000000],[0,65166000000000]],"4":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5830000000]],"1":[[0,1250000000],[0,1660000000],[0,1660000000],[0,2080000000]],"768":[[0,833000000000],[0,835000000000],[0,835410000000],[0,836250000000]],"448":[[0,489160000000],[0,489580000000],[0,489580000000],[0,542000000000]],"8192":[[0,8871250000000],[0,8871250000000],[0,8875000000000],[0,8875840000000]],"12":[[0,14170000000],[0,14580000000],[0,14580000000],[0,14580000000]],"10240":[[0,11084000000000],[0,11090420000000],[0,11091934782608],[0,11098893333333]],"14336":[[0,15523330000000],[0,15523750000000],[0,15527500000000],[0,15574590000000]],"32768":[[0,35472080000000],[0,35583000000000],[0,35835000000000],[0,36125000000000]],"128":[[0,142910000000],[0,143330000000],[0,143330000000],[0,150000000000]],"4096":[[0,4437920000000],[0,4437920000000],[0,4438330000000],[0,4438340000000]],"49152":[[0,53292000000000],[0,53333000000000],[0,53615410000000],[0,54123330000000]],"262144":[[0,289891962962962],[0,291613142857142],[0,294140625000000]],"3":[[0,3727272727],[0,4580000000],[0,4590000000],[0,4590000000]],"98304":[[0,106406250000000],[0,106520812500000],[0,107579113924050],[0,108232142857142]]}},{"title":"Deque append","results":{"2048":[[0,5227941176470],[0,5235830000000],[0,5267080000000],[0,5288330000000]],"1048576":[[0,2270000000000000],[0,2473750000000000]],"96":[[0,980420000000],[0,987500000000],[0,997920000000],[0,1011250000000]],"327680":[[0,739601888888888],[0,742722333333333]],"384":[[0,1824170000000],[0,1828750000000],[0,1838750000000],[0,1860000000000]],"12288":[[0,27556670000000],[0,27708500000000],[0,27738330000000],[0,28384744680851]],"81920":[[0,160812500000000],[0,160884222222222],[0,163354200000000],[0,163673625000000]],"8":[[0,315830000000],[0,318330000000],[0,323330000000],[0,327500000000]],"1280":[[0,3674160000000],[0,3677500000000],[0,3691666666666],[0,3727500000000]],"3584":[[0,8219590000000],[0,8246660000000],[0,8247500000000],[0,8285410000000]],"7":[[0,312920000000],[0,317080000000],[0,317920000000],[0,325830000000]],"524288":[[0,1120396000000000],[0,1122333500000000]],"112":[[0,1013750000000],[0,1017080000000],[0,1025410000000],[0,1044580000000]],"896":[[0,2816250000000],[0,2820420000000],[0,2833330000000],[0,2870420000000]],"192":[[0,1258330000000],[0,1273330000000],[0,1277910000000],[0,1284170000000]],"80":[[0,859590000000],[0,869047619047],[0,869580000000],[0,900000000000]],"24":[[0,570420000000],[0,570830000000],[0,583333333333],[0,602080000000]],"40960":[[0,86708000000000],[0,87250000000000],[0,87875830000000],[0,88990384615384]],"16":[[0,477920000000],[0,480000000000],[0,507500000000],[0,537500000000]],"3072":[[0,7282090000000],[0,7306250000000],[0,7318340000000],[0,7403340000000]],"20":[[0,485000000000],[0,485420000000],[0,486660000000],[0,499580000000]],"224":[[0,1303330000000],[0,1320830000000],[0,1322080000000],[0,1352080000000]],"2560":[[0,6505000000000],[0,6549160000000],[0,6588768115942],[0,8246500000000]],"1792":[[0,4795830000000],[0,4802000000000],[0,4830410000000],[0,4860830000000]],"1024":[[0,3237080000000],[0,3285420000000],[0,3299160000000],[0,3325000000000]],"6144":[[0,16000000000000],[0,16000000000000],[0,16083500000000],[0,16362546391752]],"56":[[0,726660000000],[0,729170000000],[0,735000000000],[0,750420000000]],"786432":[[0,1612708400000000],[0,1637167000000000]],"163840":[[0,325958333333333],[0,331654000000000],[0,355680666666666]],"6":[[0,307500000000],[0,309160000000],[0,318750000000],[0,331670000000]],"48":[[0,704160000000],[0,710410000000],[0,715000000000],[0,737910000000]],"32":[[0,583500000000],[0,592080000000],[0,598330000000],[0,618340000000]],"14":[[0,396660000000],[0,397500000000],[0,402500000000],[0,412090000000]],"28672":[[0,61750000000000],[0,61764344262295],[0,61867220338983],[0,62317080000000]],"512":[[0,2031660000000],[0,2031660000000],[0,2035000000000],[0,2062500000000]],"196608":[[0,410892857142857],[0,413908333333333],[0,438222166666666]],"458752":[[0,960345285714285],[0,1012819333333333]],"24576":[[0,55166000000000],[0,55396000000000],[0,55825420000000],[0,55960410000000]],"2":[[0,156660000000],[0,157910000000],[0,159160000000],[0,162080000000]],"256":[[0,1476250000000],[0,1478750000000],[0,1486250000000],[0,1513750000000]],"1536":[[0,4330410000000],[0,4406250000000],[0,4431250000000],[0,4437080000000]],"64":[[0,833750000000],[0,835000000000],[0,835000000000],[0,860000000000]],"320":[[0,1582500000000],[0,1595000000000],[0,1605830000000],[0,1626660000000]],"114688":[[0,227257275000000],[0,227508400000000],[0,232295948717948]],"131072":[[0,271625000000000],[0,277600000000000],[0,289309428571428]],"16384":[[0,37050000000000],[0,37571721311475],[0,38322080000000],[0,43763330000000]],"5120":[[0,12208000000000],[0,12285830000000],[0,12371660000000],[0,12497500000000]],"229376":[[0,483270833333333],[0,483433400000000],[0,505610294117647]],"5":[[0,235000000000],[0,242090000000],[0,245000000000],[0,245420000000]],"10":[[0,394590000000],[0,395000000000],[0,401250000000],[0,420000000000]],"28":[[0,578330000000],[0,585420000000],[0,587500000000],[0,605000000000]],"655360":[[0,1362979000000000],[0,1420483400000000]],"7168":[[0,17708000000000],[0,17771739130434],[0,17792000000000],[0,17803750000000]],"20480":[[0,43584000000000],[0,43666000000000],[0,45079580000000],[0,47906670000000]],"65536":[[0,133395500000000],[0,134458333333333],[0,137548472727272],[0,138022887323943]],"917504":[[0,1791875000000000],[0,1919834000000000]],"160":[[0,1190000000000],[0,1204170000000],[0,1224170000000],[0,1224170000000]],"640":[[0,2387080000000],[0,2397500000000],[0,2401250000000],[0,2435830000000]],"40":[[0,690830000000],[0,692920000000],[0,697090000000],[0,724580000000]],"393216":[[0,842333285714285],[0,847180666666666]],"57344":[[0,119417000000000],[0,121979500000000],[0,123030533333333],[0,123458333333333]],"4":[[0,231250000000],[0,231660000000],[0,236660000000],[0,242080000000]],"1":[[0,83750000000],[0,85000000000],[0,90830000000],[0,108750000000]],"768":[[0,2611250000000],[0,2614590000000],[0,2658750000000],[0,2668340000000]],"448":[[0,1924580000000],[0,1927250000000],[0,1966670000000],[0,2185243243243]],"8192":[[0,18906250000000],[0,19157080000000],[0,19197500000000],[0,19354000000000]],"12":[[0,391660000000],[0,393750000000],[0,398750000000],[0,415830000000]],"10240":[[0,23868166666666],[0,24060111111111],[0,24236000000000],[0,24340830000000]],"14336":[[0,30696250000000],[0,30859818181818],[0,31275000000000],[0,31295000000000]],"32768":[[0,68167000000000],[0,69059580000000],[0,69140159090909],[0,70278252873563]],"128":[[0,1045420000000],[0,1049580000000],[0,1055420000000],[0,1073750000000]],"4096":[[0,10548750000000],[0,10560166666666],[0,10625000000000],[0,10671670000000]],"49152":[[0,100667000000000],[0,101000000000000],[0,101250000000000],[0,101567043478260]],"262144":[[0,544698000000000],[0,560513916666666],[0,569927000000000]],"3":[[0,159160000000],[0,159160000000],[0,163330000000],[0,163750000000]],"98304":[[0,199875000000000],[0,200000000000000],[0,201514344827586],[0,205135416666666]]}},{"title":"Deque append, reserving capacity","results":{"2048":[[0,3855000000000],[0,3866670000000],[0,3872080000000],[0,3878750000000]],"1048576":[[0,2048375000000000],[0,2051333500000000]],"96":[[0,269170000000],[0,269170000000],[0,270410000000],[0,270830000000]],"327680":[[0,644584000000000],[0,672604142857142]],"384":[[0,790000000000],[0,794170000000],[0,799580000000],[0,889580000000]],"12288":[[0,22542000000000],[0,23166000000000],[0,23417000000000],[0,24076660000000]],"81920":[[0,159625000000000],[0,159729250000000],[0,161034666666666],[0,162393066666666]],"8":[[0,96660000000],[0,97080000000],[0,97500000000],[0,97920000000]],"1280":[[0,2467500000000],[0,2482500000000],[0,2484170000000],[0,2580000000000]],"3584":[[0,6375000000000],[0,6664170000000],[0,6667000000000],[0,6755420000000]],"7":[[0,95410000000],[0,95420000000],[0,97080000000],[0,97090000000]],"524288":[[0,1023083000000000],[0,1041606555555555]],"112":[[0,298750000000],[0,299580000000],[0,300000000000],[0,301250000000]],"896":[[0,1667000000000],[0,1735410000000],[0,1736670000000],[0,1751660000000]],"192":[[0,440420000000],[0,442500000000],[0,442920000000],[0,443750000000]],"80":[[0,238750000000],[0,240830000000],[0,241250000000],[0,245830000000]],"24":[[0,129580000000],[0,130000000000],[0,130830000000],[0,130840000000]],"40960":[[0,78792000000000],[0,80543478260869],[0,80933750000000],[0,82455000000000]],"16":[[0,110410000000],[0,110840000000],[0,111660000000],[0,117500000000]],"3072":[[0,5625000000000],[0,5745000000000],[0,5794170000000],[0,5801670000000]],"20":[[0,122080000000],[0,122500000000],[0,123750000000],[0,125420000000]],"224":[[0,499580000000],[0,501250000000],[0,503330000000],[0,505000000000]],"2560":[[0,4583000000000],[0,4850420000000],[0,4907576923076],[0,5049580000000]],"1792":[[0,3208500000000],[0,3384170000000],[0,3388750000000],[0,3417920000000]],"1024":[[0,1977500000000],[0,1985000000000],[0,1987500000000],[0,1991250000000]],"6144":[[0,11875000000000],[0,12368750000000],[0,12430000000000],[0,12585420000000]],"56":[[0,194580000000],[0,195830000000],[0,196670000000],[0,196670000000]],"786432":[[0,1528514000000000],[0,1586194500000000]],"163840":[[0,321250000000000],[0,323150000000000],[0,333510777777777]],"6":[[0,93750000000],[0,94170000000],[0,95830000000],[0,95830000000]],"48":[[0,179580000000],[0,181250000000],[0,181660000000],[0,185000000000]],"32":[[0,150410000000],[0,151660000000],[0,152500000000],[0,152920000000]],"14":[[0,106670000000],[0,107080000000],[0,107500000000],[0,109580000000]],"28672":[[0,52750000000000],[0,56446815789473],[0,57426633802816],[0,58049295774647]],"512":[[0,1000000000000],[0,1032500000000],[0,1035000000000],[0,1039160000000]],"196608":[[0,375875000000000],[0,385918320000000],[0,386500000000000]],"458752":[[0,924279200000000],[0,928750000000000]],"24576":[[0,45297571428571],[0,45334000000000],[0,45792000000000],[0,48755840000000]],"2":[[0,87920000000],[0,88750000000],[0,89160000000],[0,100410000000]],"256":[[0,555410000000],[0,558750000000],[0,559580000000],[0,561250000000]],"1536":[[0,2878330000000],[0,2889000000000],[0,2923750000000],[0,2945420000000]],"64":[[0,210410000000],[0,211250000000],[0,211670000000],[0,212080000000]],"320":[[0,675000000000],[0,680000000000],[0,681670000000],[0,687080000000]],"114688":[[0,215958000000000],[0,220084000000000],[0,226500000000000]],"131072":[[0,239084000000000],[0,252264000000000],[0,261769694444444]],"16384":[[0,31291666666666],[0,32000830000000],[0,32319333333333],[0,33553750000000]],"5120":[[0,10083000000000],[0,10125000000000],[0,10331896551724],[0,10497500000000]],"229376":[[0,419042000000000],[0,444792000000000],[0,450263666666666]],"5":[[0,92080000000],[0,92090000000],[0,93750000000],[0,95420000000]],"10":[[0,100000000000],[0,100830000000],[0,102500000000],[0,107910000000]],"28":[[0,142920000000],[0,144160000000],[0,144580000000],[0,146250000000]],"655360":[[0,1342125000000000],[0,1356791666666666]],"7168":[[0,13875000000000],[0,14120830000000],[0,14257500000000],[0,14453330000000]],"20480":[[0,39596288888888],[0,41142910000000],[0,41619580000000],[0,41625000000000]],"65536":[[0,123808400000000],[0,127385250000000],[0,129917000000000],[0,130165540540540]],"917504":[[0,1821066600000000],[0,1857275000000000]],"160":[[0,382080000000],[0,382500000000],[0,386660000000],[0,388750000000]],"640":[[0,1266250000000],[0,1267080000000],[0,1273330000000],[0,1275840000000]],"40":[[0,165420000000],[0,166660000000],[0,167080000000],[0,167500000000]],"393216":[[0,732708000000000],[0,792086833333333]],"57344":[[0,105708000000000],[0,110601142857142],[0,111166000000000],[0,112458400000000]],"4":[[0,90410000000],[0,90830000000],[0,91670000000],[0,92920000000]],"1":[[0,87910000000],[0,87920000000],[0,92910000000],[0,110410000000]],"768":[[0,1479160000000],[0,1502080000000],[0,1508750000000],[0,1513750000000]],"448":[[0,883200000000],[0,913340000000],[0,916660000000],[0,920420000000]],"8192":[[0,15792000000000],[0,16375420000000],[0,16497920000000],[0,16534423913043]],"12":[[0,103750000000],[0,104160000000],[0,105000000000],[0,105420000000]],"10240":[[0,20098340000000],[0,20125000000000],[0,20536670000000],[0,21073750000000]],"14336":[[0,26208000000000],[0,27000000000000],[0,27042000000000],[0,27125000000000]],"32768":[[0,58459000000000],[0,60542000000000],[0,60917000000000],[0,64745921568627]],"128":[[0,319416666666],[0,323750000000],[0,325830000000],[0,327500000000]],"4096":[[0,8333500000000],[0,8366660000000],[0,8367920000000],[0,8455000000000]],"49152":[[0,93584000000000],[0,94395833333333],[0,96930666666666],[0,99642176470588]],"262144":[[0,501479000000000],[0,513583000000000],[0,519037055555555]],"3":[[0,88750000000],[0,89160000000],[0,90830000000],[0,90830000000]],"98304":[[0,183667000000000],[0,185959000000000],[0,191099180000000],[0,192532306122448]]}},{"title":"Deque prepend","results":{"2048":[[0,5199170000000],[0,5207500000000],[0,5208750000000],[0,5248330000000]],"1048576":[[0,2202989500000000],[0,2272541750000000]],"96":[[0,988750000000],[0,993750000000],[0,999160000000],[0,1029170000000]],"327680":[[0,737259615384615],[0,738385416666666]],"384":[[0,1825420000000],[0,1828330000000],[0,1830000000000],[0,1867090000000]],"12288":[[0,27061882352941],[0,27167000000000],[0,27417000000000],[0,30575420000000]],"81920":[[0,159333000000000],[0,159791000000000],[0,160500000000000],[0,163310786885245]],"8":[[0,321250000000],[0,321250000000],[0,324170000000],[0,332080000000]],"1280":[[0,3628750000000],[0,3677500000000],[0,3686660000000],[0,3887080000000]],"3584":[[0,8112080000000],[0,8133200000000],[0,8140840000000],[0,8183750000000]],"7":[[0,317500000000],[0,318750000000],[0,323330000000],[0,330410000000]],"524288":[[0,1088916000000000],[0,1122255250000000]],"112":[[0,1026670000000],[0,1027080000000],[0,1031250000000],[0,1057920000000]],"896":[[0,2808330000000],[0,2810000000000],[0,2810420000000],[0,2870410000000]],"192":[[0,1260830000000],[0,1270830000000],[0,1276250000000],[0,1295420000000]],"80":[[0,876660000000],[0,877090000000],[0,878340000000],[0,913750000000]],"24":[[0,579580000000],[0,589170000000],[0,589170000000],[0,613330000000]],"40960":[[0,85750000000000],[0,86258928571428],[0,86292000000000],[0,86917000000000]],"16":[[0,490420000000],[0,493330000000],[0,510420000000],[0,557080000000]],"3072":[[0,7267090000000],[0,7269170000000],[0,7291250000000],[0,7332080000000]],"20":[[0,489160000000],[0,492080000000],[0,500000000000],[0,511660000000]],"224":[[0,1326670000000],[0,1327500000000],[0,1330830000000],[0,1355420000000]],"2560":[[0,6447920000000],[0,6464170000000],[0,6497080000000],[0,14750000000000]],"1792":[[0,4775830000000],[0,4791250000000],[0,4798330000000],[0,4840410000000]],"1024":[[0,3217500000000],[0,3265830000000],[0,3271250000000],[0,3277920000000]],"6144":[[0,15910714285714],[0,15923330000000],[0,15993750000000],[0,16175830000000]],"56":[[0,737910000000],[0,741670000000],[0,742500000000],[0,761670000000]],"786432":[[0,1591958000000000],[0,1693125000000000]],"163840":[[0,321646000000000],[0,325958344827586],[0,347406250000000]],"6":[[0,315000000000],[0,316250000000],[0,320830000000],[0,326250000000]],"48":[[0,712080000000],[0,720420000000],[0,721250000000],[0,747080000000]],"32":[[0,597500000000],[0,597920000000],[0,602500000000],[0,628330000000]],"14":[[0,405420000000],[0,405830000000],[0,407500000000],[0,423330000000]],"28672":[[0,60166500000000],[0,60750000000000],[0,61098539682539],[0,61329590000000]],"512":[[0,2025000000000],[0,2032090000000],[0,2033330000000],[0,2067500000000]],"196608":[[0,395542000000000],[0,405229500000000],[0,410541000000000]],"458752":[[0,952070900000000],[0,978250000000000]],"24576":[[0,53583000000000],[0,54334580000000],[0,55619580000000],[0,55666670000000]],"2":[[0,155840000000],[0,157500000000],[0,162500000000],[0,178330000000]],"256":[[0,1478330000000],[0,1485830000000],[0,1488750000000],[0,1535420000000]],"1536":[[0,4353340000000],[0,4363330000000],[0,4367080000000],[0,4401250000000]],"64":[[0,844590000000],[0,845000000000],[0,853750000000],[0,881670000000]],"320":[[0,1586250000000],[0,1602500000000],[0,1605830000000],[0,1631250000000]],"114688":[[0,222209000000000],[0,230954357142857],[0,260302250000000]],"131072":[[0,267812500000000],[0,273140151515151],[0,286633588235294]],"16384":[[0,36711660000000],[0,36740000000000],[0,36928340000000],[0,37472500000000]],"5120":[[0,12232910000000],[0,12240420000000],[0,12332500000000],[0,12333000000000]],"229376":[[0,468895500000000],[0,478018750000000],[0,493456000000000]],"5":[[0,236670000000],[0,239590000000],[0,242920000000],[0,248330000000]],"10":[[0,405410000000],[0,405420000000],[0,405830000000],[0,422920000000]],"28":[[0,594170000000],[0,596250000000],[0,597080000000],[0,614580000000]],"655360":[[0,1291292000000000],[0,1319714285714285]],"7168":[[0,17118045454545],[0,17164580000000],[0,17232500000000],[0,17428330000000]],"20480":[[0,43125000000000],[0,43125000000000],[0,43696680000000],[0,48811974358974]],"65536":[[0,131966600000000],[0,133542000000000],[0,134788652173913],[0,134881043478260]],"917504":[[0,1801510500000000],[0,1813650000000000]],"160":[[0,1210830000000],[0,1216600000000],[0,1222500000000],[0,1239160000000]],"640":[[0,2384170000000],[0,2388750000000],[0,2399590000000],[0,2425410000000]],"40":[[0,701333333333],[0,704170000000],[0,712500000000],[0,737080000000]],"393216":[[0,818696909090909],[0,835387500000000]],"57344":[[0,119542000000000],[0,120084000000000],[0,120111000000000],[0,120291666666666]],"4":[[0,233750000000],[0,234160000000],[0,234580000000],[0,244590000000]],"1":[[0,83750000000],[0,85000000000],[0,85410000000],[0,101660000000]],"768":[[0,2594580000000],[0,2607500000000],[0,2612068965517],[0,2655410000000]],"448":[[0,1927125000000],[0,1928340000000],[0,1928750000000],[0,1967090000000]],"8192":[[0,18655420000000],[0,18784590000000],[0,19073750000000],[0,19649890243902]],"12":[[0,402080000000],[0,409580000000],[0,410000000000],[0,426660000000]],"10240":[[0,23920454545454],[0,23958333333333],[0,24166666666666],[0,24308400000000]],"14336":[[0,30370370370370],[0,30540410000000],[0,30562500000000],[0,30642857142857]],"32768":[[0,67042000000000],[0,67708000000000],[0,67920304347826],[0,68458000000000]],"128":[[0,1055410000000],[0,1060000000000],[0,1061250000000],[0,1087500000000]],"4096":[[0,10363750000000],[0,10373800000000],[0,10457500000000],[0,10522500000000]],"49152":[[0,98625000000000],[0,101057112359550],[0,101440571428571],[0,102798684210526]],"262144":[[0,529259277777777],[0,537544117647058],[0,558125000000000]],"3":[[0,163330000000],[0,163340000000],[0,166660000000],[0,168330000000]],"98304":[[0,197500000000000],[0,198958500000000],[0,199192750000000],[0,207265625000000]]}},{"title":"Deque prepend, reserving capacity","results":{"2048":[[0,4120000000000],[0,4120410000000],[0,4120830000000],[0,4124160000000]],"1048576":[[0,2131250000000000],[0,2161792000000000]],"96":[[0,271250000000],[0,271660000000],[0,271660000000],[0,272080000000]],"327680":[[0,676500000000000],[0,677542000000000]],"384":[[0,835420000000],[0,835830000000],[0,836670000000],[0,840830000000]],"12288":[[0,25250000000000],[0,25375000000000],[0,25727090000000],[0,26206250000000]],"81920":[[0,165062500000000],[0,165666000000000],[0,165997169491525],[0,166083000000000]],"8":[[0,95830000000],[0,95830000000],[0,95830000000],[0,97500000000]],"1280":[[0,2604170000000],[0,2605420000000],[0,2609170000000],[0,2754170000000]],"3584":[[0,7132500000000],[0,7145410000000],[0,7147500000000],[0,7162920000000]],"7":[[0,94170000000],[0,94580000000],[0,95000000000],[0,96250000000]],"524288":[[0,1074875000000000],[0,1106542000000000]],"112":[[0,303330000000],[0,303750000000],[0,304160000000],[0,304580000000]],"896":[[0,1846660000000],[0,1847080000000],[0,1848750000000],[0,1848750000000]],"192":[[0,455830000000],[0,456250000000],[0,457080000000],[0,457080000000]],"80":[[0,240000000000],[0,240410000000],[0,240410000000],[0,240840000000]],"24":[[0,127920000000],[0,128330000000],[0,129580000000],[0,130000000000]],"40960":[[0,82942166666666],[0,83250000000000],[0,84745000000000],[0,84757080000000]],"16":[[0,107920000000],[0,108330000000],[0,109170000000],[0,109580000000]],"3072":[[0,6136670000000],[0,6137920000000],[0,6140410000000],[0,6140840000000]],"20":[[0,113750000000],[0,113750000000],[0,115410000000],[0,115830000000]],"224":[[0,520000000000],[0,521660000000],[0,521670000000],[0,522080000000]],"2560":[[0,5125000000000],[0,5137080000000],[0,5138330000000],[0,5140420000000]],"1792":[[0,3607500000000],[0,3612500000000],[0,3615420000000],[0,5166000000000]],"1024":[[0,2099580000000],[0,2100410000000],[0,2100420000000],[0,2103330000000]],"6144":[[0,12862090000000],[0,12870420000000],[0,12875000000000],[0,12900830000000]],"56":[[0,192910000000],[0,193340000000],[0,194160000000],[0,195000000000]],"786432":[[0,1646542000000000],[0,1997073000000000]],"163840":[[0,331166000000000],[0,333625000000000],[0,340488517241379]],"6":[[0,92910000000],[0,92910000000],[0,92920000000],[0,93750000000]],"48":[[0,177920000000],[0,178330000000],[0,179580000000],[0,179580000000]],"32":[[0,149170000000],[0,149590000000],[0,150000000000],[0,151250000000]],"14":[[0,104170000000],[0,104580000000],[0,105000000000],[0,106660000000]],"28672":[[0,57916000000000],[0,58083000000000],[0,58125000000000],[0,58250000000000]],"512":[[0,1092500000000],[0,1092910000000],[0,1093330000000],[0,1097910000000]],"196608":[[0,397625000000000],[0,401042000000000],[0,417000000000000]],"458752":[[0,943541000000000],[0,975375000000000]],"24576":[[0,49875000000000],[0,49917000000000],[0,50000000000000],[0,50670830000000]],"2":[[0,83000000000],[0,87910000000],[0,89160000000],[0,99590000000]],"256":[[0,581670000000],[0,582500000000],[0,583330000000],[0,584170000000]],"1536":[[0,3109170000000],[0,3110410000000],[0,3110830000000],[0,3110840000000]],"64":[[0,207500000000],[0,208750000000],[0,209590000000],[0,210830000000]],"320":[[0,707920000000],[0,709160000000],[0,710420000000],[0,715420000000]],"114688":[[0,231270500000000],[0,231583000000000],[0,242542000000000]],"131072":[[0,269084000000000],[0,269134000000000],[0,278209000000000]],"16384":[[0,33547222222222],[0,33554559523809],[0,33584000000000],[0,33667000000000]],"5120":[[0,10811250000000],[0,10825757575757],[0,10827285714285],[0,10858330000000]],"229376":[[0,462542000000000],[0,468375000000000],[0,469047619047619]],"5":[[0,91660000000],[0,91660000000],[0,92080000000],[0,93750000000]],"10":[[0,98750000000],[0,99580000000],[0,100000000000],[0,100830000000]],"28":[[0,142080000000],[0,142920000000],[0,143330000000],[0,144580000000]],"655360":[[0,1402833000000000],[0,1430673500000000]],"7168":[[0,14893750000000],[0,14915830000000],[0,14955410000000],[0,15042000000000]],"20480":[[0,41685606060606],[0,41750000000000],[0,41875000000000],[0,43127090000000]],"65536":[[0,131791666666666],[0,131991800000000],[0,132000000000000],[0,132667000000000]],"917504":[[0,1855042000000000],[0,1877750000000000]],"160":[[0,393330000000],[0,394170000000],[0,394580000000],[0,395000000000]],"640":[[0,1338750000000],[0,1341250000000],[0,1344580000000],[0,1346250000000]],"40":[[0,162920000000],[0,163330000000],[0,163750000000],[0,165000000000]],"393216":[[0,792916000000000],[0,813750000000000]],"57344":[[0,115417000000000],[0,116167000000000],[0,116209000000000],[0,116334000000000]],"4":[[0,90000000000],[0,90000000000],[0,90830000000],[0,92080000000]],"1":[[0,87080000000],[0,87910000000],[0,88330000000],[0,95830000000]],"768":[[0,1595410000000],[0,1597500000000],[0,1597910000000],[0,1599590000000]],"448":[[0,960410000000],[0,961250000000],[0,962500000000],[0,964160000000]],"8192":[[0,17084000000000],[0,17125830000000],[0,17183340000000],[0,17250000000000]],"12":[[0,101250000000],[0,101670000000],[0,102080000000],[0,103340000000]],"10240":[[0,21244160000000],[0,21250000000000],[0,21333000000000],[0,21458000000000]],"14336":[[0,29542000000000],[0,29583000000000],[0,29625000000000],[0,29750000000000]],"32768":[[0,66315979166666],[0,66334000000000],[0,66625000000000],[0,69829771428571]],"128":[[0,330000000000],[0,330000000000],[0,330000000000],[0,331670000000]],"4096":[[0,8785420000000],[0,8791660000000],[0,8802733333333],[0,8812500000000]],"49152":[[0,99708000000000],[0,99958000000000],[0,100999562500000],[0,101796437500000]],"262144":[[0,529917000000000],[0,535750000000000],[0,542500000000000]],"3":[[0,87920000000],[0,89160000000],[0,90410000000],[0,92080000000]],"98304":[[0,199167000000000],[0,199333000000000],[0,201250000000000],[0,202180541666666]]}},{"title":"Deque removeFirst (contiguous)","results":{"2048":[[0,4584000000000],[0,4666000000000],[0,4666000000000],[0,4667000000000]],"1048576":[[0,2394000000000000],[0,2447833000000000]],"96":[[0,208000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"327680":[[0,777041000000000],[0,782500000000000]],"384":[[0,875000000000],[0,875000000000],[0,875000000000],[0,916000000000]],"12288":[[0,27833000000000],[0,27834000000000],[0,27875000000000],[0,29167000000000]],"81920":[[0,185834000000000],[0,185875000000000],[0,185958000000000],[0,189458000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1280":[[0,2875000000000],[0,2916000000000],[0,2916000000000],[0,3292000000000]],"3584":[[0,8125000000000],[0,8125000000000],[0,8125000000000],[0,9208000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,1189458000000000],[0,1200042000000000]],"112":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"896":[[0,2041000000000],[0,2041000000000],[0,2041000000000],[0,2041000000000]],"192":[[0,416000000000],[0,458000000000],[0,458000000000],[0,459000000000]],"80":[[0,166000000000],[0,167000000000],[0,208000000000],[0,250000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,92875000000000],[0,92916000000000],[0,92917000000000],[0,93000000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,6916000000000],[0,6958000000000],[0,6958000000000],[0,7000000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"224":[[0,500000000000],[0,541000000000],[0,541000000000],[0,709000000000]],"2560":[[0,5791000000000],[0,5792000000000],[0,5833000000000],[0,5833000000000]],"1792":[[0,4042000000000],[0,4083000000000],[0,4083000000000],[0,4625000000000]],"1024":[[0,2333000000000],[0,2333000000000],[0,2333000000000],[0,2333000000000]],"6144":[[0,13917000000000],[0,13917000000000],[0,13958000000000],[0,13958000000000]],"56":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1809917000000000],[0,1915708000000000]],"163840":[[0,371500000000000],[0,371709000000000],[0,375792000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"32":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"28672":[[0,65000000000000],[0,65000000000000],[0,65041000000000],[0,65167000000000]],"512":[[0,1166000000000],[0,1167000000000],[0,1292000000000],[0,1583000000000]],"196608":[[0,446250000000000],[0,449250000000000],[0,466167000000000]],"458752":[[0,1064959000000000],[0,1069334000000000]],"24576":[[0,55708000000000],[0,55750000000000],[0,55750000000000],[0,55791000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,583000000000],[0,583000000000],[0,584000000000],[0,625000000000]],"1536":[[0,3458000000000],[0,3458000000000],[0,3500000000000],[0,3500000000000]],"64":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"320":[[0,708000000000],[0,708000000000],[0,750000000000],[0,750000000000]],"114688":[[0,260125000000000],[0,260209000000000],[0,260250000000000]],"131072":[[0,297292000000000],[0,297292000000000],[0,297417000000000]],"16384":[[0,37125000000000],[0,37125000000000],[0,37166000000000],[0,37167000000000]],"5120":[[0,11625000000000],[0,11625000000000],[0,11625000000000],[0,12541000000000]],"229376":[[0,520334000000000],[0,523750000000000],[0,524000000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"28":[[0,41000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"655360":[[0,1497834000000000],[0,1548500000000000]],"7168":[[0,16250000000000],[0,16250000000000],[0,16292000000000],[0,17625000000000]],"20480":[[0,46458000000000],[0,46459000000000],[0,46542000000000],[0,48791000000000]],"65536":[[0,148583000000000],[0,148666000000000],[0,148667000000000],[0,148875000000000]],"917504":[[0,2082084000000000],[0,2130750000000000]],"160":[[0,375000000000],[0,375000000000],[0,375000000000],[0,500000000000]],"640":[[0,1458000000000],[0,1458000000000],[0,1458000000000],[0,1500000000000]],"40":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"393216":[[0,891666000000000],[0,916541000000000]],"57344":[[0,130083000000000],[0,130083000000000],[0,130084000000000],[0,130125000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1750000000000],[0,1750000000000],[0,1750000000000],[0,1833000000000]],"448":[[0,1000000000000],[0,1000000000000],[0,1042000000000],[0,1042000000000]],"8192":[[0,18583000000000],[0,18583000000000],[0,18584000000000],[0,20166000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,23208000000000],[0,23208000000000],[0,23209000000000],[0,23292000000000]],"14336":[[0,32500000000000],[0,32500000000000],[0,32541000000000],[0,32542000000000]],"32768":[[0,74291000000000],[0,74292000000000],[0,74333000000000],[0,74334000000000]],"128":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"4096":[[0,9291000000000],[0,9291000000000],[0,9292000000000],[0,9333000000000]],"49152":[[0,111500000000000],[0,111500000000000],[0,111541000000000],[0,111583000000000]],"262144":[[0,594750000000000],[0,598042000000000],[0,607166000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,223000000000000],[0,223125000000000],[0,223250000000000],[0,226584000000000]]}},{"title":"Deque removeLast (contiguous)","results":{"2048":[[0,3833000000000],[0,3833000000000],[0,3833000000000],[0,3833000000000]],"1048576":[[0,1969083000000000],[0,2008708000000000]],"96":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"327680":[[0,629834000000000],[0,630833000000000]],"384":[[0,708000000000],[0,708000000000],[0,750000000000],[0,750000000000]],"12288":[[0,23000000000000],[0,23042000000000],[0,23083000000000],[0,24125000000000]],"81920":[[0,153541000000000],[0,153583000000000],[0,153625000000000],[0,153667000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2375000000000],[0,2416000000000],[0,2417000000000],[0,2709000000000]],"3584":[[0,6709000000000],[0,6709000000000],[0,6709000000000],[0,7042000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,984458000000000],[0,986500000000000]],"112":[[0,167000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"896":[[0,1666000000000],[0,1667000000000],[0,1667000000000],[0,1708000000000]],"192":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"80":[[0,166000000000],[0,166000000000],[0,166000000000],[0,209000000000]],"24":[[0,41000000000],[0,41000000000],[0,83000000000],[0,83000000000]],"40960":[[0,76708000000000],[0,76750000000000],[0,76791000000000],[0,76792000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,5750000000000],[0,5750000000000],[0,5750000000000],[0,5750000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,417000000000],[0,417000000000],[0,458000000000],[0,583000000000]],"2560":[[0,4791000000000],[0,4792000000000],[0,4792000000000],[0,4792000000000]],"1792":[[0,3333000000000],[0,3334000000000],[0,3334000000000],[0,3750000000000]],"1024":[[0,1916000000000],[0,1916000000000],[0,1917000000000],[0,1917000000000]],"6144":[[0,11500000000000],[0,11500000000000],[0,11541000000000],[0,11541000000000]],"56":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1486333000000000],[0,1489917000000000]],"163840":[[0,307208000000000],[0,310459000000000],[0,310875000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"32":[[0,42000000000],[0,42000000000],[0,83000000000],[0,84000000000]],"14":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28672":[[0,53750000000000],[0,53750000000000],[0,53750000000000],[0,53791000000000]],"512":[[0,958000000000],[0,958000000000],[0,1083000000000],[0,1291000000000]],"196608":[[0,368666000000000],[0,368875000000000],[0,386292000000000]],"458752":[[0,864958000000000],[0,867792000000000]],"24576":[[0,46000000000000],[0,46041000000000],[0,46083000000000],[0,46083000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,500000000000],[0,500000000000]],"1536":[[0,2875000000000],[0,2875000000000],[0,2875000000000],[0,2875000000000]],"64":[[0,125000000000],[0,125000000000],[0,167000000000],[0,167000000000]],"320":[[0,625000000000],[0,625000000000],[0,625000000000],[0,750000000000]],"114688":[[0,215000000000000],[0,215000000000000],[0,234250000000000]],"131072":[[0,245708000000000],[0,245791000000000],[0,251417000000000]],"16384":[[0,30667000000000],[0,30708000000000],[0,30708000000000],[0,30750000000000]],"5120":[[0,9583000000000],[0,9583000000000],[0,9625000000000],[0,10417000000000]],"229376":[[0,429958000000000],[0,443500000000000],[0,444458000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"655360":[[0,1228666000000000],[0,1228916000000000]],"7168":[[0,13416000000000],[0,13417000000000],[0,13458000000000],[0,14542000000000]],"20480":[[0,38333000000000],[0,38375000000000],[0,38458000000000],[0,40250000000000]],"65536":[[0,122833000000000],[0,122875000000000],[0,122875000000000],[0,122875000000000]],"917504":[[0,1727583000000000],[0,1732916000000000]],"160":[[0,291000000000],[0,291000000000],[0,333000000000],[0,416000000000]],"640":[[0,1208000000000],[0,1208000000000],[0,1208000000000],[0,1250000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"393216":[[0,737375000000000],[0,742667000000000]],"57344":[[0,107417000000000],[0,107500000000000],[0,107500000000000],[0,107500000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1416000000000],[0,1417000000000],[0,1458000000000],[0,1500000000000]],"448":[[0,833000000000],[0,833000000000],[0,834000000000],[0,875000000000]],"8192":[[0,15375000000000],[0,15375000000000],[0,15375000000000],[0,16625000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,19166000000000],[0,19167000000000],[0,19250000000000],[0,19250000000000]],"14336":[[0,26792000000000],[0,26875000000000],[0,26875000000000],[0,26875000000000]],"32768":[[0,61375000000000],[0,61417000000000],[0,61458000000000],[0,61459000000000]],"128":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"4096":[[0,7666000000000],[0,7666000000000],[0,7667000000000],[0,7667000000000]],"49152":[[0,92041000000000],[0,92125000000000],[0,92125000000000],[0,92166000000000]],"262144":[[0,491625000000000],[0,494792000000000],[0,518875000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,184208000000000],[0,184291000000000],[0,184333000000000],[0,184334000000000]]}},{"title":"Deque sort (contiguous)","results":{"2048":[[0,86416000000000],[0,87459000000000],[0,91375000000000],[0,91875000000000]],"1048576":[[0,91693500000000000],[0,93381209000000000]],"96":[[0,2333000000000],[0,2375000000000],[0,2500000000000],[0,2542000000000]],"327680":[[0,26559291000000000],[0,27556250000000000]],"384":[[0,11250000000000],[0,11625000000000],[0,12500000000000],[0,12916000000000]],"12288":[[0,734542000000000],[0,735166000000000],[0,754417000000000],[0,829459000000000]],"81920":[[0,5784667000000000],[0,5785959000000000],[0,5813042000000000],[0,5818500000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,51042000000000],[0,51875000000000],[0,52625000000000],[0,57792000000000]],"3584":[[0,190167000000000],[0,190667000000000],[0,192334000000000],[0,202459000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,43314458000000000],[0,43774083000000000]],"112":[[0,3000000000000],[0,3125000000000],[0,3250000000000],[0,3709000000000]],"896":[[0,35709000000000],[0,35792000000000],[0,36084000000000],[0,36375000000000]],"192":[[0,4667000000000],[0,4750000000000],[0,4834000000000],[0,5208000000000]],"80":[[0,1208000000000],[0,1500000000000],[0,1834000000000],[0,2125000000000]],"24":[[0,208000000000],[0,209000000000],[0,250000000000],[0,291000000000]],"40960":[[0,2703875000000000],[0,2709709000000000],[0,2720166000000000],[0,2722666000000000]],"16":[[0,84000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"3072":[[0,152667000000000],[0,153583000000000],[0,153791000000000],[0,153792000000000]],"20":[[0,125000000000],[0,125000000000],[0,166000000000],[0,209000000000]],"224":[[0,6625000000000],[0,6875000000000],[0,7709000000000],[0,9250000000000]],"2560":[[0,118833000000000],[0,119250000000000],[0,120250000000000],[0,123875000000000]],"1792":[[0,83916000000000],[0,84292000000000],[0,86125000000000],[0,104417000000000]],"1024":[[0,35417000000000],[0,35583000000000],[0,35750000000000],[0,38834000000000]],"6144":[[0,337292000000000],[0,337833000000000],[0,338250000000000],[0,345125000000000]],"56":[[0,1292000000000],[0,1333000000000],[0,1500000000000],[0,1500000000000]],"786432":[[0,70588334000000000],[0,71116542000000000]],"163840":[[0,12285916000000000],[0,12390958000000000],[0,12898208000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,791000000000],[0,791000000000],[0,1000000000000],[0,1000000000000]],"32":[[0,333000000000],[0,333000000000],[0,375000000000],[0,375000000000]],"14":[[0,42000000000],[0,83000000000],[0,125000000000],[0,167000000000]],"28672":[[0,1954208000000000],[0,1956042000000000],[0,1960833000000000],[0,1978958000000000]],"512":[[0,13375000000000],[0,14083000000000],[0,17167000000000],[0,18417000000000]],"196608":[[0,15681750000000000],[0,15742042000000000],[0,16222125000000000]],"458752":[[0,40236334000000000],[0,41881458000000000]],"24576":[[0,1597291000000000],[0,1600750000000000],[0,1604708000000000],[0,1631625000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,5084000000000],[0,5333000000000],[0,5541000000000],[0,5666000000000]],"1536":[[0,66208000000000],[0,66958000000000],[0,67291000000000],[0,67875000000000]],"64":[[0,1000000000000],[0,1125000000000],[0,1250000000000],[0,1666000000000]],"320":[[0,7667000000000],[0,7792000000000],[0,8291000000000],[0,9167000000000]],"114688":[[0,8879583000000000],[0,9062792000000000],[0,10231625000000000]],"131072":[[0,9468833000000000],[0,9504666000000000],[0,9763916000000000]],"16384":[[0,952875000000000],[0,955333000000000],[0,959500000000000],[0,979042000000000]],"5120":[[0,263209000000000],[0,263458000000000],[0,265292000000000],[0,267333000000000]],"229376":[[0,18906000000000000],[0,19117667000000000],[0,20034125000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"28":[[0,250000000000],[0,292000000000],[0,292000000000],[0,333000000000]],"655360":[[0,56738208000000000],[0,58459208000000000]],"7168":[[0,415417000000000],[0,415834000000000],[0,419500000000000],[0,424500000000000]],"20480":[[0,1264750000000000],[0,1265166000000000],[0,1268417000000000],[0,1270291000000000]],"65536":[[0,4410834000000000],[0,4430500000000000],[0,4434042000000000],[0,4448292000000000]],"917504":[[0,84694041000000000],[0,88006834000000000]],"160":[[0,3542000000000],[0,3625000000000],[0,3875000000000],[0,5208000000000]],"640":[[0,19917000000000],[0,20000000000000],[0,21417000000000],[0,24500000000000]],"40":[[0,500000000000],[0,625000000000],[0,667000000000],[0,708000000000]],"393216":[[0,32924458000000000],[0,33645541000000000]],"57344":[[0,4177375000000000],[0,4181625000000000],[0,4189084000000000],[0,4376541000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,27500000000000],[0,27792000000000],[0,28916000000000],[0,29000000000000]],"448":[[0,14750000000000],[0,15083000000000],[0,15375000000000],[0,16000000000000]],"8192":[[0,434291000000000],[0,435375000000000],[0,436625000000000],[0,445667000000000]],"12":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10240":[[0,576375000000000],[0,578167000000000],[0,579416000000000],[0,579875000000000]],"14336":[[0,900334000000000],[0,902000000000000],[0,908167000000000],[0,910625000000000]],"32768":[[0,2065416000000000],[0,2068708000000000],[0,2070292000000000],[0,2076625000000000]],"128":[[0,2250000000000],[0,2333000000000],[0,2334000000000],[0,2500000000000]],"4096":[[0,196333000000000],[0,196917000000000],[0,198333000000000],[0,201958000000000]],"49152":[[0,3411875000000000],[0,3426625000000000],[0,3429375000000000],[0,3472917000000000]],"262144":[[0,20410417000000000],[0,20605250000000000],[0,21132167000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,7259291000000000],[0,7288959000000000],[0,7315167000000000],[0,7381583000000000]]}},{"title":"Deque sort (discontiguous)","results":{"2048":[[0,51334000000000],[0,51791000000000],[0,52125000000000],[0,54125000000000]],"1048576":[[0,59648750000000000],[0,60372875000000000]],"96":[[0,1208000000000],[0,1250000000000],[0,1292000000000],[0,1334000000000]],"327680":[[0,17292417000000000],[0,17777959000000000]],"384":[[0,5292000000000],[0,5292000000000],[0,5375000000000],[0,5500000000000]],"12288":[[0,440417000000000],[0,458083000000000],[0,461750000000000],[0,472500000000000]],"81920":[[0,3688416000000000],[0,3694167000000000],[0,3706250000000000],[0,3713875000000000]],"8":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"1280":[[0,26792000000000],[0,27042000000000],[0,27167000000000],[0,30458000000000]],"3584":[[0,103500000000000],[0,103500000000000],[0,104292000000000],[0,109833000000000]],"7":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"524288":[[0,28410042000000000],[0,28748958000000000]],"112":[[0,1458000000000],[0,1542000000000],[0,1583000000000],[0,1666000000000]],"896":[[0,15792000000000],[0,15958000000000],[0,16167000000000],[0,16334000000000]],"192":[[0,2292000000000],[0,2416000000000],[0,2416000000000],[0,2542000000000]],"80":[[0,833000000000],[0,1000000000000],[0,1000000000000],[0,1042000000000]],"24":[[0,208000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"40960":[[0,1716750000000000],[0,1717500000000000],[0,1728208000000000],[0,1740875000000000]],"16":[[0,167000000000],[0,208000000000],[0,208000000000],[0,291000000000]],"3072":[[0,86000000000000],[0,86000000000000],[0,86208000000000],[0,87791000000000]],"20":[[0,209000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"224":[[0,3083000000000],[0,3166000000000],[0,3375000000000],[0,4416000000000]],"2560":[[0,68458000000000],[0,68875000000000],[0,69792000000000],[0,71375000000000]],"1792":[[0,43000000000000],[0,43250000000000],[0,45041000000000],[0,48958000000000]],"1024":[[0,19292000000000],[0,19625000000000],[0,19625000000000],[0,22250000000000]],"6144":[[0,197625000000000],[0,197791000000000],[0,198000000000000],[0,198083000000000]],"56":[[0,542000000000],[0,583000000000],[0,583000000000],[0,625000000000]],"786432":[[0,43589583000000000],[0,43892292000000000]],"163840":[[0,7899541000000000],[0,7988417000000000],[0,8187291000000000]],"6":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"48":[[0,458000000000],[0,458000000000],[0,542000000000],[0,625000000000]],"32":[[0,291000000000],[0,292000000000],[0,292000000000],[0,375000000000]],"14":[[0,166000000000],[0,167000000000],[0,208000000000],[0,209000000000]],"28672":[[0,1155542000000000],[0,1158333000000000],[0,1172125000000000],[0,1188958000000000]],"512":[[0,6459000000000],[0,6542000000000],[0,6708000000000],[0,7459000000000]],"196608":[[0,9740667000000000],[0,9856708000000000],[0,10085583000000000]],"458752":[[0,24698584000000000],[0,25086292000000000]],"24576":[[0,963541000000000],[0,965125000000000],[0,974916000000000],[0,985667000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,2625000000000],[0,2875000000000],[0,2875000000000],[0,3000000000000]],"1536":[[0,34750000000000],[0,35542000000000],[0,35625000000000],[0,35750000000000]],"64":[[0,708000000000],[0,834000000000],[0,875000000000],[0,959000000000]],"320":[[0,3666000000000],[0,3875000000000],[0,4125000000000],[0,4417000000000]],"114688":[[0,5359250000000000],[0,5412042000000000],[0,5839625000000000]],"131072":[[0,6226541000000000],[0,6261375000000000],[0,6490708000000000]],"16384":[[0,614916000000000],[0,616834000000000],[0,619541000000000],[0,622291000000000]],"5120":[[0,160041000000000],[0,160959000000000],[0,161334000000000],[0,161584000000000]],"229376":[[0,11530792000000000],[0,11556833000000000],[0,11743375000000000]],"5":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"10":[[0,125000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"28":[[0,291000000000],[0,291000000000],[0,292000000000],[0,292000000000]],"655360":[[0,36022500000000000],[0,36369917000000000]],"7168":[[0,236292000000000],[0,236958000000000],[0,240250000000000],[0,243000000000000]],"20480":[[0,785375000000000],[0,795917000000000],[0,799625000000000],[0,850292000000000]],"65536":[[0,2908792000000000],[0,2909333000000000],[0,2919916000000000],[0,2925208000000000]],"917504":[[0,52213458000000000],[0,52319875000000000]],"160":[[0,1833000000000],[0,1959000000000],[0,2000000000000],[0,2041000000000]],"640":[[0,9000000000000],[0,9167000000000],[0,9334000000000],[0,9792000000000]],"40":[[0,333000000000],[0,375000000000],[0,375000000000],[0,416000000000]],"393216":[[0,20451875000000000],[0,20947167000000000]],"57344":[[0,2494834000000000],[0,2495250000000000],[0,2498209000000000],[0,2559666000000000]],"4":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,12083000000000],[0,12292000000000],[0,13833000000000],[0,14375000000000]],"448":[[0,6542000000000],[0,6583000000000],[0,6625000000000],[0,6834000000000]],"8192":[[0,281666000000000],[0,284125000000000],[0,284292000000000],[0,284417000000000]],"12":[[0,166000000000],[0,166000000000],[0,167000000000],[0,167000000000]],"10240":[[0,358166000000000],[0,358375000000000],[0,363291000000000],[0,366250000000000]],"14336":[[0,526833000000000],[0,528417000000000],[0,536875000000000],[0,538250000000000]],"32768":[[0,1340625000000000],[0,1342417000000000],[0,1360417000000000],[0,1479709000000000]],"128":[[0,1333000000000],[0,1416000000000],[0,1417000000000],[0,1500000000000]],"4096":[[0,124083000000000],[0,124541000000000],[0,124709000000000],[0,125334000000000]],"49152":[[0,2098917000000000],[0,2099625000000000],[0,2101667000000000],[0,2131333000000000]],"262144":[[0,13476541000000000],[0,13477667000000000],[0,13581583000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,4520333000000000],[0,4524208000000000],[0,4535458000000000],[0,4600875000000000]]}},{"title":"Deque sequential iteration (discontiguous, iterator)","results":{"2048":[[0,1682080000000],[0,1682080000000],[0,1682080000000],[0,1682080000000]],"1048576":[[0,852458000000000],[0,864799272727272]],"96":[[0,89170000000],[0,89170000000],[0,89580000000],[0,89580000000]],"327680":[[0,266708000000000],[0,273500000000000]],"384":[[0,330410000000],[0,330830000000],[0,331250000000],[0,332500000000]],"12288":[[0,9994565217391],[0,9995830000000],[0,10006660000000],[0,10584000000000]],"81920":[[0,66541000000000],[0,66583000000000],[0,66625000000000],[0,66750000000000]],"8":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"1280":[[0,1057910000000],[0,1057920000000],[0,1058750000000],[0,1109289855072]],"3584":[[0,2928750000000],[0,2929160000000],[0,2929170000000],[0,2929521276595]],"7":[[0,14160000000],[0,14170000000],[0,14580000000],[0,14590000000]],"524288":[[0,426750000000000],[0,436729181818181]],"112":[[0,102080000000],[0,102090000000],[0,102090000000],[0,102500000000]],"896":[[0,746181818181],[0,746660000000],[0,746670000000],[0,747080000000]],"192":[[0,175410000000],[0,175410000000],[0,175420000000],[0,175830000000]],"80":[[0,76250000000],[0,76250000000],[0,76250000000],[0,76660000000]],"24":[[0,27500000000],[0,27910000000],[0,28330000000],[0,28330000000]],"40960":[[0,33292000000000],[0,33292000000000],[0,33304580000000],[0,33333000000000]],"16":[[0,21250000000],[0,21250000000],[0,21250000000],[0,21660000000]],"3072":[[0,2512910000000],[0,2512920000000],[0,2512920000000],[0,2513330000000]],"20":[[0,24580000000],[0,24580000000],[0,24580000000],[0,24590000000]],"224":[[0,200000000000],[0,200830000000],[0,201250000000],[0,201660000000]],"2560":[[0,2084000000000],[0,2097578947368],[0,2097920000000],[0,2098750000000]],"1792":[[0,1459000000000],[0,1474160000000],[0,1474580000000],[0,1670000000000]],"1024":[[0,850000000000],[0,850410000000],[0,850420000000],[0,851250000000]],"6144":[[0,5000000000000],[0,5006670000000],[0,5007500000000],[0,5007928571428]],"56":[[0,57500000000],[0,57500000000],[0,57500000000],[0,57910000000]],"786432":[[0,649852800000000],[0,653500000000000]],"163840":[[0,133125000000000],[0,133166000000000],[0,135684931506849]],"6":[[0,13330000000],[0,13330000000],[0,13330000000],[0,13750000000]],"48":[[0,50410000000],[0,50410000000],[0,50420000000],[0,50830000000]],"32":[[0,34160000000],[0,34580000000],[0,34580000000],[0,34580000000]],"14":[[0,19580000000],[0,20000000000],[0,20000000000],[0,20000000000]],"28672":[[0,23334000000000],[0,23375000000000],[0,23375000000000],[0,23417000000000]],"512":[[0,435000000000],[0,435000000000],[0,435410000000],[0,435830000000]],"196608":[[0,159792000000000],[0,159834000000000],[0,159917000000000]],"458752":[[0,372916000000000],[0,381709000000000]],"24576":[[0,19958000000000],[0,20000000000000],[0,20042000000000],[0,20042000000000]],"2":[[0,7090000000],[0,7090000000],[0,7500000000],[0,8750000000]],"256":[[0,226670000000],[0,227080000000],[0,227080000000],[0,227090000000]],"1536":[[0,1266250000000],[0,1266250000000],[0,1267080000000],[0,1267080000000]],"64":[[0,63750000000],[0,63750000000],[0,63750000000],[0,63750000000]],"320":[[0,279160000000],[0,279580000000],[0,281250000000],[0,292500000000]],"114688":[[0,93145833333333],[0,93208000000000],[0,93708000000000]],"131072":[[0,106542000000000],[0,106582430107526],[0,106791000000000]],"16384":[[0,13291000000000],[0,13320410000000],[0,13321250000000],[0,13375000000000]],"5120":[[0,4176136363636],[0,4176250000000],[0,4176250000000],[0,4176250000000]],"229376":[[0,186375000000000],[0,186375000000000],[0,186792000000000]],"5":[[0,12500000000],[0,12500000000],[0,12500000000],[0,12500000000]],"10":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"28":[[0,31250000000],[0,31250000000],[0,31250000000],[0,31250000000]],"655360":[[0,533048611111111],[0,535125000000000]],"7168":[[0,5833000000000],[0,5838340000000],[0,5838340000000],[0,5873330000000]],"20480":[[0,16646250000000],[0,16666500000000],[0,16709000000000],[0,16709000000000]],"65536":[[0,53250000000000],[0,53292000000000],[0,53333000000000],[0,53417000000000]],"917504":[[0,755322916666666],[0,770614583333333]],"160":[[0,149160000000],[0,149160000000],[0,149170000000],[0,149580000000]],"640":[[0,538330000000],[0,538750000000],[0,538750000000],[0,539580000000]],"40":[[0,40420000000],[0,40830000000],[0,41250000000],[0,41250000000]],"393216":[[0,319750000000000],[0,324041000000000]],"57344":[[0,46568428571428],[0,46583000000000],[0,46583000000000],[0,46875000000000]],"4":[[0,11660000000],[0,11670000000],[0,11670000000],[0,12080000000]],"1":[[0,6250000000],[0,6660000000],[0,6660000000],[0,6670000000]],"768":[[0,643330000000],[0,643330000000],[0,643340000000],[0,643750000000]],"448":[[0,382500000000],[0,382910000000],[0,382910000000],[0,383330000000]],"8192":[[0,6666000000000],[0,6669580000000],[0,6670420000000],[0,6672910000000]],"12":[[0,18330000000],[0,18330000000],[0,18330000000],[0,18330000000]],"10240":[[0,8331250000000],[0,8333330000000],[0,8335000000000],[0,8335410000000]],"14336":[[0,11657500000000],[0,11658330000000],[0,11687500000000],[0,11708000000000]],"32768":[[0,26625000000000],[0,26655000000000],[0,26659580000000],[0,26830000000000]],"128":[[0,115410000000],[0,115410000000],[0,115410000000],[0,115420000000]],"4096":[[0,3345000000000],[0,3345000000000],[0,3345000000000],[0,3345000000000]],"49152":[[0,39925000000000],[0,39953330000000],[0,40000000000000],[0,40042000000000]],"262144":[[0,213000000000000],[0,213000000000000],[0,213250000000000]],"3":[[0,7910000000],[0,8330000000],[0,8330000000],[0,8330000000]],"98304":[[0,79875000000000],[0,79958000000000],[0,80000000000000],[0,80042000000000]]}},{"title":"Deque sequential iteration (contiguous, indices)","results":{"2048":[[0,2208000000000],[0,2220250000000],[0,2220830000000],[0,2221670000000]],"1048576":[[0,1135250000000000],[0,1136000000000000]],"96":[[0,107583333333],[0,108330000000],[0,108330000000],[0,108330000000]],"327680":[[0,354917000000000],[0,371339730769230]],"384":[[0,416500000000],[0,419590000000],[0,419590000000],[0,453340000000]],"12288":[[0,13291500000000],[0,13292000000000],[0,13309170000000],[0,13319333333333]],"81920":[[0,88663250000000],[0,88666727272727],[0,88792000000000],[0,89074590000000]],"8":[[0,10000000000],[0,10420000000],[0,10420000000],[0,10830000000]],"1280":[[0,1388666666666],[0,1389580000000],[0,1390000000000],[0,1390830000000]],"3584":[[0,3883330000000],[0,3883330000000],[0,3883588235294],[0,3883750000000]],"7":[[0,9160000000],[0,9160000000],[0,9580000000],[0,9580000000]],"524288":[[0,568875000000000],[0,570667000000000]],"112":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125410000000]],"896":[[0,974137931034],[0,974160000000],[0,974160000000],[0,974170000000]],"192":[[0,211975000000],[0,212080000000],[0,212080000000],[0,212080000000]],"80":[[0,83000000000],[0,90410000000],[0,90830000000],[0,90830000000]],"24":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27910000000]],"40960":[[0,44333000000000],[0,44375000000000],[0,44458000000000],[0,45405420000000]],"16":[[0,18750000000],[0,19160000000],[0,19160000000],[0,19580000000]],"3072":[[0,3323000000000],[0,3329170000000],[0,3329170000000],[0,3329170000000]],"20":[[0,23330000000],[0,23340000000],[0,23750000000],[0,23750000000]],"224":[[0,246250000000],[0,246660000000],[0,246660000000],[0,246660000000]],"2560":[[0,2770500000000],[0,2775000000000],[0,2775420000000],[0,2775830000000]],"1792":[[0,1937500000000],[0,1943647058823],[0,1943750000000],[0,2202800000000]],"1024":[[0,1104000000000],[0,1112500000000],[0,1112910000000],[0,1112920000000]],"6144":[[0,6625000000000],[0,6654160000000],[0,6654580000000],[0,6655000000000]],"56":[[0,64580000000],[0,65000000000],[0,65000000000],[0,65000000000]],"786432":[[0,855375000000000],[0,859890090909090]],"163840":[[0,177375000000000],[0,177458000000000],[0,177500000000000]],"6":[[0,7910000000],[0,8330000000],[0,8330000000],[0,8340000000]],"48":[[0,52250000000],[0,56250000000],[0,56250000000],[0,56250000000]],"32":[[0,36250000000],[0,36250000000],[0,36660000000],[0,36660000000]],"14":[[0,16660000000],[0,16670000000],[0,17080000000],[0,17080000000]],"28672":[[0,31041647058823],[0,31060000000000],[0,31084000000000],[0,31084000000000]],"512":[[0,542000000000],[0,558330000000],[0,558330000000],[0,558330000000]],"196608":[[0,212812500000000],[0,212854250000000],[0,228121023809523]],"458752":[[0,504379368421052],[0,507791000000000]],"24576":[[0,26584000000000],[0,26625000000000],[0,26667000000000],[0,27433330000000]],"2":[[0,4160000000],[0,4580000000],[0,4580000000],[0,6250000000]],"256":[[0,281250000000],[0,281250000000],[0,281250000000],[0,281250000000]],"1536":[[0,1666670000000],[0,1666670000000],[0,1667000000000],[0,1667080000000]],"64":[[0,73330000000],[0,73340000000],[0,73750000000],[0,73750000000]],"320":[[0,350420000000],[0,350420000000],[0,367500000000],[0,397910000000]],"114688":[[0,124150000000000],[0,124250000000000],[0,124291000000000]],"131072":[[0,142250000000000],[0,142986000000000],[0,149191262295081]],"16384":[[0,17737920000000],[0,17750000000000],[0,17757920000000],[0,17792000000000]],"5120":[[0,5545840000000],[0,5545840000000],[0,5546250000000],[0,5546670000000]],"229376":[[0,248541000000000],[0,253944810810810],[0,261959000000000]],"5":[[0,7080000000],[0,7500000000],[0,7500000000],[0,7500000000]],"10":[[0,12500000000],[0,12500000000],[0,12910000000],[0,12910000000]],"28":[[0,31670000000],[0,32080000000],[0,32080000000],[0,32080000000]],"655360":[[0,710208000000000],[0,714167000000000]],"7168":[[0,7750000000000],[0,7763330000000],[0,7772090000000],[0,7792000000000]],"20480":[[0,22167000000000],[0,22205000000000],[0,22208000000000],[0,22250000000000]],"65536":[[0,70939102564102],[0,71000000000000],[0,71041000000000],[0,71611660000000]],"917504":[[0,1000384222222222],[0,1014000000000000]],"160":[[0,177080000000],[0,177090000000],[0,177090000000],[0,177500000000]],"640":[[0,697080000000],[0,697080000000],[0,697080000000],[0,697080000000]],"40":[[0,47500000000],[0,47910000000],[0,47910000000],[0,47910000000]],"393216":[[0,429208000000000],[0,432214000000000]],"57344":[[0,62125000000000],[0,62167000000000],[0,62622080000000],[0,65709000000000]],"4":[[0,5830000000],[0,6250000000],[0,6250000000],[0,6250000000]],"1":[[0,1670000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,822750000000],[0,835410000000],[0,835420000000],[0,835420000000]],"448":[[0,488750000000],[0,489160000000],[0,489160000000],[0,498750000000]],"8192":[[0,8870840000000],[0,8871250000000],[0,8871660000000],[0,8917000000000]],"12":[[0,13916666666],[0,14580000000],[0,15000000000],[0,15000000000]],"10240":[[0,11084000000000],[0,11087500000000],[0,11087500000000],[0,11096250000000]],"14336":[[0,15500000000000],[0,15519580000000],[0,15635410000000],[0,15667000000000]],"32768":[[0,35458000000000],[0,35489750000000],[0,35500000000000],[0,35502500000000]],"128":[[0,142500000000],[0,142910000000],[0,142910000000],[0,142910000000]],"4096":[[0,4437500000000],[0,4437500000000],[0,4437500000000],[0,4437500000000]],"49152":[[0,53250000000000],[0,53271000000000],[0,53292000000000],[0,53650840000000]],"262144":[[0,283750000000000],[0,287854000000000],[0,288250000000000]],"3":[[0,4580000000],[0,5000000000],[0,5000000000],[0,5410000000]],"98304":[[0,106458000000000],[0,106500000000000],[0,106541000000000],[0,106541000000000]]}},{"title":"Deque sequential iteration (discontiguous, indices)","results":{"2048":[[0,2230000000000],[0,2230410000000],[0,2230410000000],[0,2231660000000]],"1048576":[[0,1135083000000000],[0,1159916625000000]],"96":[[0,108642857142],[0,108750000000],[0,108750000000],[0,109160000000]],"327680":[[0,354958000000000],[0,369130208333333]],"384":[[0,429160000000],[0,429160000000],[0,429170000000],[0,429580000000]],"12288":[[0,13292000000000],[0,13333500000000],[0,13334000000000],[0,13375000000000]],"81920":[[0,88673583333333],[0,88674272727272],[0,89208000000000],[0,89317500000000]],"8":[[0,10420000000],[0,10830000000],[0,10830000000],[0,10830000000]],"1280":[[0,1399160000000],[0,1399160000000],[0,1399170000000],[0,1400420000000]],"3584":[[0,3875000000000],[0,3892500000000],[0,3892910000000],[0,3892920000000]],"7":[[0,9580000000],[0,9580000000],[0,10000000000],[0,10000000000]],"524288":[[0,569497588235294],[0,585334000000000]],"112":[[0,125840000000],[0,126250000000],[0,126250000000],[0,126660000000]],"896":[[0,958000000000],[0,983330000000],[0,983330000000],[0,983750000000]],"192":[[0,208000000000],[0,212910000000],[0,212920000000],[0,213330000000]],"80":[[0,84000000000],[0,91660000000],[0,91660000000],[0,91660000000]],"24":[[0,28330000000],[0,30410000000],[0,30410000000],[0,30420000000]],"40960":[[0,44375000000000],[0,44375000000000],[0,44376250000000],[0,44458000000000]],"16":[[0,19160000000],[0,19170000000],[0,19580000000],[0,20000000000]],"3072":[[0,3334000000000],[0,3338750000000],[0,3338750000000],[0,3339160000000]],"20":[[0,23330000000],[0,23330000000],[0,23750000000],[0,23750000000]],"224":[[0,247500000000],[0,247500000000],[0,247500000000],[0,247910000000]],"2560":[[0,2784580000000],[0,2784580000000],[0,2784580000000],[0,2785000000000]],"1792":[[0,1952920000000],[0,1952920000000],[0,1953330000000],[0,2375000000000]],"1024":[[0,1121250000000],[0,1121846153846],[0,1122080000000],[0,1122080000000]],"6144":[[0,6663750000000],[0,6663750000000],[0,6664170000000],[0,6664580000000]],"56":[[0,65410000000],[0,65410000000],[0,65410000000],[0,65410000000]],"786432":[[0,851584000000000],[0,851875000000000]],"163840":[[0,177334000000000],[0,177417000000000],[0,181500000000000]],"6":[[0,8330000000],[0,8330000000],[0,8750000000],[0,8750000000]],"48":[[0,56250000000],[0,56660000000],[0,56660000000],[0,56670000000]],"32":[[0,36660000000],[0,36660000000],[0,36660000000],[0,36670000000]],"14":[[0,17080000000],[0,17080000000],[0,17090000000],[0,17500000000]],"28672":[[0,31042000000000],[0,31047266666666],[0,31051470588235],[0,31054687500000]],"512":[[0,567418181818],[0,567500000000],[0,567622950819],[0,567910000000]],"196608":[[0,212875000000000],[0,212917000000000],[0,229267441860465]],"458752":[[0,496667000000000],[0,497125000000000]],"24576":[[0,26583000000000],[0,26612847222222],[0,26666000000000],[0,26667000000000]],"2":[[0,4580000000],[0,4580000000],[0,4580000000],[0,4580000000]],"256":[[0,282090000000],[0,282090000000],[0,282500000000],[0,282500000000]],"1536":[[0,1625000000000],[0,1671529411764],[0,1676250000000],[0,1676250000000]],"64":[[0,73750000000],[0,73750000000],[0,74160000000],[0,74160000000]],"320":[[0,333000000000],[0,352080000000],[0,352080000000],[0,369580000000]],"114688":[[0,124250000000000],[0,124913961038961],[0,127164000000000]],"131072":[[0,141875000000000],[0,141917000000000],[0,146459000000000]],"16384":[[0,17750000000000],[0,17750000000000],[0,17768330000000],[0,17929170000000]],"5120":[[0,5542000000000],[0,5555000000000],[0,5555410000000],[0,5555750000000]],"229376":[[0,248458000000000],[0,249000000000000],[0,251090820512820]],"5":[[0,7500000000],[0,7500000000],[0,7500000000],[0,7500000000]],"10":[[0,12910000000],[0,12910000000],[0,12910000000],[0,12910000000]],"28":[[0,32080000000],[0,32090000000],[0,32500000000],[0,32500000000]],"655360":[[0,709584000000000],[0,723227538461538]],"7168":[[0,7750000000000],[0,7772500000000],[0,7791000000000],[0,7792000000000]],"20480":[[0,22166000000000],[0,22196146341463],[0,22209000000000],[0,22250000000000]],"65536":[[0,70956250000000],[0,70959000000000],[0,71000000000000],[0,71000000000000]],"917504":[[0,994417000000000],[0,1021667000000000]],"160":[[0,177000000000],[0,177125000000],[0,178330000000],[0,178330000000]],"640":[[0,706250000000],[0,706660000000],[0,706660000000],[0,706670000000]],"40":[[0,47500000000],[0,47500000000],[0,47910000000],[0,47910000000]],"393216":[[0,425958000000000],[0,436437500000000]],"57344":[[0,62083000000000],[0,62167000000000],[0,62208000000000],[0,62771250000000]],"4":[[0,6250000000],[0,6250000000],[0,6250000000],[0,7080000000]],"1":[[0,1670000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,833000000000],[0,834000000000],[0,845000000000],[0,845000000000]],"448":[[0,498330000000],[0,498330000000],[0,498330000000],[0,498330000000]],"8192":[[0,8880410000000],[0,8880830000000],[0,8916000000000],[0,8916000000000]],"12":[[0,13888888888],[0,15000000000],[0,15000000000],[0,15000000000]],"10240":[[0,11096670000000],[0,11100410000000],[0,11100830000000],[0,11125000000000]],"14336":[[0,15530830000000],[0,15542000000000],[0,15554166666666],[0,15560000000000]],"32768":[[0,35500000000000],[0,35517080000000],[0,35541000000000],[0,35583000000000]],"128":[[0,125000000000],[0,143330000000],[0,143330000000],[0,143750000000]],"4096":[[0,4437500000000],[0,4446660000000],[0,4447080000000],[0,4450000000000]],"49152":[[0,53208000000000],[0,53208000000000],[0,53208000000000],[0,53250000000000]],"262144":[[0,283834000000000],[0,283875000000000],[0,292292000000000]],"3":[[0,5410000000],[0,5410000000],[0,5410000000],[0,5410000000]],"98304":[[0,106417000000000],[0,106417000000000],[0,106542000000000],[0,107082814814814]]}},{"title":"Deque subscript get, random offsets (discontiguous)","results":{"2048":[[0,2208000000000],[0,2221250000000],[0,2221250000000],[0,2221660000000]],"1048576":[[0,1150854500000000],[0,1174270875000000]],"96":[[0,108330000000],[0,108400000000],[0,108750000000],[0,109375000000]],"327680":[[0,354729000000000],[0,366459000000000]],"384":[[0,419444444444],[0,420410000000],[0,420830000000],[0,451333333333]],"12288":[[0,13307920000000],[0,13314590000000],[0,13373750000000],[0,13565410000000]],"81920":[[0,89005830000000],[0,89106670000000],[0,89115420000000],[0,89875000000000]],"8":[[0,10420000000],[0,10420000000],[0,10420000000],[0,10830000000]],"1280":[[0,1390000000000],[0,1390000000000],[0,1390000000000],[0,1391250000000]],"3584":[[0,3875000000000],[0,3884170000000],[0,3884580000000],[0,3884580000000]],"7":[[0,9160000000],[0,9170000000],[0,9580000000],[0,9580000000]],"524288":[[0,568857823529411],[0,580480533333333]],"112":[[0,125000000000],[0,125000000000],[0,125000000000],[0,126250000000]],"896":[[0,958000000000],[0,974170000000],[0,974580000000],[0,974580000000]],"192":[[0,209000000000],[0,212500000000],[0,212500000000],[0,212500000000]],"80":[[0,90840000000],[0,91250000000],[0,92080000000],[0,92080000000]],"24":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27910000000]],"40960":[[0,44345500000000],[0,44370830000000],[0,44541000000000],[0,44542000000000]],"16":[[0,19160000000],[0,19160000000],[0,19160000000],[0,20410000000]],"3072":[[0,3329580000000],[0,3329580000000],[0,3329590000000],[0,3330420000000]],"20":[[0,23340000000],[0,23750000000],[0,23750000000],[0,23750000000]],"224":[[0,246670000000],[0,246670000000],[0,247080000000],[0,247080000000]],"2560":[[0,2775410000000],[0,2775420000000],[0,2775840000000],[0,2776250000000]],"1792":[[0,1943750000000],[0,1944160000000],[0,1944580000000],[0,1944580000000]],"1024":[[0,1112910000000],[0,1112910000000],[0,1113330000000],[0,1113330000000]],"6144":[[0,6655000000000],[0,6655410000000],[0,6655420000000],[0,6655830000000]],"56":[[0,64580000000],[0,65000000000],[0,65000000000],[0,65000000000]],"786432":[[0,853000000000000],[0,884375000000000]],"163840":[[0,177375000000000],[0,180125000000000],[0,191588428571428]],"6":[[0,7920000000],[0,8330000000],[0,8330000000],[0,8330000000]],"48":[[0,41000000000],[0,55830000000],[0,56250000000],[0,56660000000]],"32":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"14":[[0,15625000000],[0,16660000000],[0,17080000000],[0,17080000000]],"28672":[[0,31041642857142],[0,31057090000000],[0,31060166666666],[0,31083000000000]],"512":[[0,558330000000],[0,558750000000],[0,559160000000],[0,559160000000]],"196608":[[0,213104173913043],[0,217667000000000],[0,229504837209302]],"458752":[[0,501486333333333],[0,509750000000000]],"24576":[[0,26606250000000],[0,26750000000000],[0,26750000000000],[0,26904017857142]],"2":[[0,5830000000],[0,5830000000],[0,5830000000],[0,6250000000]],"256":[[0,281250000000],[0,281660000000],[0,281670000000],[0,282080000000]],"1536":[[0,1666000000000],[0,1666670000000],[0,1667000000000],[0,1667080000000]],"64":[[0,73340000000],[0,74160000000],[0,74160000000],[0,74580000000]],"320":[[0,350830000000],[0,351250000000],[0,351250000000],[0,352500000000]],"114688":[[0,124875000000000],[0,125167000000000],[0,134628250000000]],"131072":[[0,141917000000000],[0,144375000000000],[0,145416000000000]],"16384":[[0,17740384615384],[0,17746520833333],[0,17833000000000],[0,17834000000000]],"5120":[[0,5541000000000],[0,5541000000000],[0,5542000000000],[0,6280830000000]],"229376":[[0,250803571428571],[0,251886583333333],[0,257083000000000]],"5":[[0,7080000000],[0,7080000000],[0,7500000000],[0,7500000000]],"10":[[0,12500000000],[0,12500000000],[0,12500000000],[0,12910000000]],"28":[[0,32080000000],[0,32080000000],[0,32080000000],[0,32080000000]],"655360":[[0,714167000000000],[0,741368083333333]],"7168":[[0,7763637931034],[0,7764160000000],[0,7764160000000],[0,7765420000000]],"20480":[[0,22174066666666],[0,22176670000000],[0,22185770833333],[0,22209000000000]],"65536":[[0,70941230769230],[0,70958000000000],[0,71047920000000],[0,71166000000000]],"917504":[[0,1009552000000000],[0,1043209000000000]],"160":[[0,177500000000],[0,177500000000],[0,177910000000],[0,177910000000]],"640":[[0,694333333333],[0,696660000000],[0,697080000000],[0,697500000000]],"40":[[0,47910000000],[0,47910000000],[0,47910000000],[0,47920000000]],"393216":[[0,425708500000000],[0,437406250000000]],"57344":[[0,62042000000000],[0,62208000000000],[0,62375000000000],[0,62583000000000]],"4":[[0,5830000000],[0,6250000000],[0,6250000000],[0,6660000000]],"1":[[0,1670000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,833000000000],[0,835410000000],[0,835830000000],[0,835840000000]],"448":[[0,489160000000],[0,489580000000],[0,489580000000],[0,490000000000]],"8192":[[0,8872080000000],[0,8872500000000],[0,8872920000000],[0,8917000000000]],"12":[[0,14580000000],[0,14580000000],[0,15000000000],[0,15000000000]],"10240":[[0,11089580000000],[0,11089580000000],[0,11091670000000],[0,11105000000000]],"14336":[[0,15522925000000],[0,15524590000000],[0,15530000000000],[0,15533962962962]],"32768":[[0,35458000000000],[0,35473340000000],[0,35500000000000],[0,35500000000000]],"128":[[0,142857142857],[0,142920000000],[0,142920000000],[0,143330000000]],"4096":[[0,4436523809523],[0,4437920000000],[0,4439516129032],[0,4440000000000]],"49152":[[0,53208000000000],[0,53292000000000],[0,53530840000000],[0,53792000000000]],"262144":[[0,285922086956521],[0,286218424242424],[0,298842961538461]],"3":[[0,5000000000],[0,5000000000],[0,5000000000],[0,5000000000]],"98304":[[0,106459000000000],[0,106515625000000],[0,106785397849462],[0,109767325842696]]}},{"title":"Deque mutate through subscript (contiguous)","results":{"2048":[[0,2791000000000],[0,2791000000000],[0,2791000000000],[0,2792000000000]],"1048576":[[0,1436042000000000],[0,1444292000000000]],"96":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"327680":[[0,449459000000000],[0,449583000000000]],"384":[[0,541000000000],[0,541000000000],[0,541000000000],[0,583000000000]],"12288":[[0,16666000000000],[0,16708000000000],[0,17458000000000],[0,17542000000000]],"81920":[[0,110875000000000],[0,110875000000000],[0,110958000000000],[0,111000000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,1750000000000],[0,1750000000000],[0,1959000000000],[0,2208000000000]],"3584":[[0,4833000000000],[0,4833000000000],[0,4875000000000],[0,4875000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,716125000000000],[0,721625000000000]],"112":[[0,166000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"896":[[0,1209000000000],[0,1250000000000],[0,1250000000000],[0,1250000000000]],"192":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,55417000000000],[0,55458000000000],[0,55458000000000],[0,55542000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,4167000000000],[0,4167000000000],[0,4167000000000],[0,4167000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"224":[[0,292000000000],[0,292000000000],[0,333000000000],[0,333000000000]],"2560":[[0,3458000000000],[0,3458000000000],[0,3500000000000],[0,3500000000000]],"1792":[[0,2416000000000],[0,2416000000000],[0,2416000000000],[0,2750000000000]],"1024":[[0,1375000000000],[0,1375000000000],[0,1416000000000],[0,1792000000000]],"6144":[[0,8333000000000],[0,8333000000000],[0,8333000000000],[0,8334000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"786432":[[0,1075625000000000],[0,1080792000000000]],"163840":[[0,221834000000000],[0,222000000000000],[0,233125000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,38833000000000],[0,38833000000000],[0,38834000000000],[0,38916000000000]],"512":[[0,708000000000],[0,708000000000],[0,708000000000],[0,709000000000]],"196608":[[0,266334000000000],[0,268291000000000],[0,270291000000000]],"458752":[[0,630000000000000],[0,635834000000000]],"24576":[[0,33250000000000],[0,33291000000000],[0,33291000000000],[0,33292000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,334000000000],[0,375000000000],[0,416000000000]],"1536":[[0,2083000000000],[0,2083000000000],[0,2084000000000],[0,2166000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,458000000000],[0,458000000000],[0,458000000000],[0,500000000000]],"114688":[[0,155208000000000],[0,155250000000000],[0,155958000000000]],"131072":[[0,177375000000000],[0,177417000000000],[0,191625000000000]],"16384":[[0,22125000000000],[0,22167000000000],[0,22167000000000],[0,27041000000000]],"5120":[[0,6917000000000],[0,6958000000000],[0,6958000000000],[0,6958000000000]],"229376":[[0,312000000000000],[0,312500000000000],[0,316291000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,914083000000000],[0,924917000000000]],"7168":[[0,9708000000000],[0,9708000000000],[0,9709000000000],[0,9709000000000]],"20480":[[0,27708000000000],[0,27708000000000],[0,27750000000000],[0,27792000000000]],"65536":[[0,88667000000000],[0,88708000000000],[0,88750000000000],[0,88791000000000]],"917504":[[0,1257709000000000],[0,1264833000000000]],"160":[[0,208000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"640":[[0,875000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"40":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,535667000000000],[0,543333000000000]],"57344":[[0,77583000000000],[0,77583000000000],[0,77625000000000],[0,77708000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1041000000000],[0,1042000000000],[0,1042000000000],[0,1083000000000]],"448":[[0,625000000000],[0,625000000000],[0,625000000000],[0,667000000000]],"8192":[[0,11000000000000],[0,11083000000000],[0,11083000000000],[0,11084000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,13833000000000],[0,13833000000000],[0,13875000000000],[0,13875000000000]],"14336":[[0,19375000000000],[0,19375000000000],[0,19416000000000],[0,19417000000000]],"32768":[[0,44375000000000],[0,44375000000000],[0,44375000000000],[0,44375000000000]],"128":[[0,166000000000],[0,167000000000],[0,209000000000],[0,209000000000]],"4096":[[0,5541000000000],[0,5541000000000],[0,5542000000000],[0,5583000000000]],"49152":[[0,66541000000000],[0,66542000000000],[0,66542000000000],[0,66625000000000]],"262144":[[0,355917000000000],[0,356500000000000],[0,360791000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,133042000000000],[0,133125000000000],[0,133208000000000],[0,133291000000000]]}},{"title":"Deque mutate through subscript (discontiguous)","results":{"2048":[[0,2791000000000],[0,2791000000000],[0,2791000000000],[0,2791000000000]],"1048576":[[0,1438750000000000],[0,1458042000000000]],"96":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"327680":[[0,446584000000000],[0,465292000000000]],"384":[[0,541000000000],[0,541000000000],[0,542000000000],[0,750000000000]],"12288":[[0,16584000000000],[0,16666000000000],[0,16666000000000],[0,17375000000000]],"81920":[[0,110833000000000],[0,110834000000000],[0,110875000000000],[0,110916000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1750000000000],[0,1750000000000],[0,1833000000000],[0,2000000000000]],"3584":[[0,4833000000000],[0,4833000000000],[0,4875000000000],[0,4875000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,714167000000000],[0,729875000000000]],"112":[[0,166000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"896":[[0,1208000000000],[0,1250000000000],[0,1250000000000],[0,1250000000000]],"192":[[0,250000000000],[0,250000000000],[0,291000000000],[0,291000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"24":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"40960":[[0,55416000000000],[0,55417000000000],[0,55458000000000],[0,55459000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"3072":[[0,4166000000000],[0,4166000000000],[0,4166000000000],[0,4167000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"224":[[0,291000000000],[0,292000000000],[0,333000000000],[0,333000000000]],"2560":[[0,3458000000000],[0,3458000000000],[0,3459000000000],[0,3500000000000]],"1792":[[0,2416000000000],[0,2417000000000],[0,2417000000000],[0,2709000000000]],"1024":[[0,1375000000000],[0,1416000000000],[0,1417000000000],[0,1458000000000]],"6144":[[0,8333000000000],[0,8333000000000],[0,8333000000000],[0,8375000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"786432":[[0,1081292000000000],[0,1103875000000000]],"163840":[[0,221833000000000],[0,221875000000000],[0,233000000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,38750000000000],[0,38792000000000],[0,38875000000000],[0,38875000000000]],"512":[[0,708000000000],[0,708000000000],[0,708000000000],[0,708000000000]],"196608":[[0,266500000000000],[0,267334000000000],[0,273042000000000]],"458752":[[0,628875000000000],[0,629250000000000]],"24576":[[0,33250000000000],[0,33292000000000],[0,33333000000000],[0,33333000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,333000000000],[0,333000000000],[0,375000000000]],"1536":[[0,2083000000000],[0,2084000000000],[0,2084000000000],[0,2208000000000]],"64":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"320":[[0,458000000000],[0,458000000000],[0,458000000000],[0,500000000000]],"114688":[[0,155250000000000],[0,155292000000000],[0,159625000000000]],"131072":[[0,177458000000000],[0,177667000000000],[0,186583000000000]],"16384":[[0,22125000000000],[0,22125000000000],[0,22167000000000],[0,28708000000000]],"5120":[[0,6958000000000],[0,6958000000000],[0,6958000000000],[0,6958000000000]],"229376":[[0,311750000000000],[0,312125000000000],[0,322375000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"655360":[[0,910750000000000],[0,923250000000000]],"7168":[[0,9666000000000],[0,9666000000000],[0,9667000000000],[0,9708000000000]],"20480":[[0,27708000000000],[0,27750000000000],[0,27750000000000],[0,27791000000000]],"65536":[[0,88666000000000],[0,88709000000000],[0,88709000000000],[0,88750000000000]],"917504":[[0,1267333000000000],[0,1277375000000000]],"160":[[0,208000000000],[0,208000000000],[0,250000000000],[0,250000000000]],"640":[[0,875000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"40":[[0,41000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,535167000000000],[0,538291000000000]],"57344":[[0,77583000000000],[0,77584000000000],[0,77625000000000],[0,77625000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1041000000000],[0,1041000000000],[0,1042000000000],[0,1042000000000]],"448":[[0,625000000000],[0,625000000000],[0,625000000000],[0,666000000000]],"8192":[[0,11041000000000],[0,11083000000000],[0,11083000000000],[0,11125000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,13833000000000],[0,13875000000000],[0,13875000000000],[0,13875000000000]],"14336":[[0,19375000000000],[0,19416000000000],[0,19417000000000],[0,19417000000000]],"32768":[[0,44333000000000],[0,44334000000000],[0,44416000000000],[0,44458000000000]],"128":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"4096":[[0,5541000000000],[0,5542000000000],[0,5542000000000],[0,5542000000000]],"49152":[[0,66500000000000],[0,66500000000000],[0,66500000000000],[0,66583000000000]],"262144":[[0,356333000000000],[0,356500000000000],[0,357167000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,133042000000000],[0,133042000000000],[0,133125000000000],[0,133209000000000]]}},{"title":"Deque random swaps (contiguous)","results":{"2048":[[0,3375000000000],[0,3375000000000],[0,3375000000000],[0,3375000000000]],"1048576":[[0,1894291000000000],[0,1907375000000000]],"96":[[0,167000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"327680":[[0,572125000000000],[0,583917000000000]],"384":[[0,625000000000],[0,666000000000],[0,667000000000],[0,917000000000]],"12288":[[0,20000000000000],[0,20042000000000],[0,20125000000000],[0,21042000000000]],"81920":[[0,137709000000000],[0,138041000000000],[0,138542000000000],[0,139333000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2125000000000],[0,2125000000000],[0,2416000000000],[0,2917000000000]],"3584":[[0,5875000000000],[0,5875000000000],[0,5875000000000],[0,5875000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,914125000000000],[0,927375000000000]],"112":[[0,208000000000],[0,208000000000],[0,250000000000],[0,250000000000]],"896":[[0,1458000000000],[0,1500000000000],[0,1500000000000],[0,1500000000000]],"192":[[0,333000000000],[0,333000000000],[0,375000000000],[0,416000000000]],"80":[[0,125000000000],[0,166000000000],[0,167000000000],[0,167000000000]],"24":[[0,42000000000],[0,42000000000],[0,83000000000],[0,84000000000]],"40960":[[0,68125000000000],[0,68167000000000],[0,68250000000000],[0,68291000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"3072":[[0,5000000000000],[0,5042000000000],[0,5042000000000],[0,5042000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"224":[[0,375000000000],[0,375000000000],[0,375000000000],[0,541000000000]],"2560":[[0,4208000000000],[0,4208000000000],[0,4208000000000],[0,4209000000000]],"1792":[[0,2917000000000],[0,2958000000000],[0,2959000000000],[0,3375000000000]],"1024":[[0,1667000000000],[0,1667000000000],[0,1667000000000],[0,1791000000000]],"6144":[[0,10000000000000],[0,10041000000000],[0,10042000000000],[0,10042000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"786432":[[0,1398000000000000],[0,1404250000000000]],"163840":[[0,282916000000000],[0,298709000000000],[0,305084000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,42000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,47125000000000],[0,47208000000000],[0,47291000000000],[0,47291000000000]],"512":[[0,833000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"196608":[[0,336959000000000],[0,340875000000000],[0,344250000000000]],"458752":[[0,795958000000000],[0,802750000000000]],"24576":[[0,40250000000000],[0,40250000000000],[0,40375000000000],[0,40417000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,417000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2500000000000],[0,2541000000000],[0,2542000000000],[0,2666000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,541000000000],[0,542000000000],[0,542000000000],[0,625000000000]],"114688":[[0,194250000000000],[0,195250000000000],[0,197334000000000]],"131072":[[0,226250000000000],[0,234250000000000],[0,244000000000000]],"16384":[[0,26625000000000],[0,26708000000000],[0,26709000000000],[0,32541000000000]],"5120":[[0,8375000000000],[0,8375000000000],[0,8375000000000],[0,8375000000000]],"229376":[[0,394208000000000],[0,398416000000000],[0,399042000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"655360":[[0,1168917000000000],[0,1205958000000000]],"7168":[[0,11708000000000],[0,11708000000000],[0,11708000000000],[0,11708000000000]],"20480":[[0,33417000000000],[0,33459000000000],[0,33500000000000],[0,33542000000000]],"65536":[[0,110083000000000],[0,110416000000000],[0,110792000000000],[0,111000000000000]],"917504":[[0,1654958000000000],[0,1684500000000000]],"160":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"640":[[0,1042000000000],[0,1083000000000],[0,1083000000000],[0,1083000000000]],"40":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"393216":[[0,678000000000000],[0,684584000000000]],"57344":[[0,96000000000000],[0,96292000000000],[0,96292000000000],[0,96541000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,1250000000000],[0,1292000000000],[0,1292000000000],[0,1333000000000]],"448":[[0,750000000000],[0,750000000000],[0,750000000000],[0,1042000000000]],"8192":[[0,13333000000000],[0,13375000000000],[0,13416000000000],[0,13417000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,16708000000000],[0,16708000000000],[0,16709000000000],[0,16709000000000]],"14336":[[0,23333000000000],[0,23375000000000],[0,23417000000000],[0,23458000000000]],"32768":[[0,54000000000000],[0,54208000000000],[0,54209000000000],[0,54333000000000]],"128":[[0,209000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"4096":[[0,6666000000000],[0,6666000000000],[0,6708000000000],[0,6708000000000]],"49152":[[0,82292000000000],[0,82458000000000],[0,82500000000000],[0,82959000000000]],"262144":[[0,450875000000000],[0,454083000000000],[0,454625000000000]],"3":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,166500000000000],[0,166709000000000],[0,167417000000000],[0,167542000000000]]}},{"title":"Deque random swaps (discontiguous)","results":{"2048":[[0,3334000000000],[0,3375000000000],[0,3416000000000],[0,3417000000000]],"1048576":[[0,1955750000000000],[0,1966917000000000]],"96":[[0,166000000000],[0,166000000000],[0,167000000000],[0,208000000000]],"327680":[[0,577000000000000],[0,605792000000000]],"384":[[0,625000000000],[0,666000000000],[0,667000000000],[0,750000000000]],"12288":[[0,20000000000000],[0,20042000000000],[0,20125000000000],[0,21333000000000]],"81920":[[0,137750000000000],[0,138042000000000],[0,138084000000000],[0,139166000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2083000000000],[0,2125000000000],[0,2167000000000],[0,2416000000000]],"3584":[[0,5875000000000],[0,5875000000000],[0,5875000000000],[0,5875000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,910500000000000],[0,963250000000000]],"112":[[0,208000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"896":[[0,1458000000000],[0,1458000000000],[0,1500000000000],[0,1500000000000]],"192":[[0,333000000000],[0,333000000000],[0,333000000000],[0,417000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"40960":[[0,67834000000000],[0,67917000000000],[0,68041000000000],[0,68083000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,5000000000000],[0,5041000000000],[0,5041000000000],[0,5041000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"224":[[0,375000000000],[0,375000000000],[0,375000000000],[0,500000000000]],"2560":[[0,4208000000000],[0,4208000000000],[0,4208000000000],[0,4208000000000]],"1792":[[0,2958000000000],[0,2958000000000],[0,2958000000000],[0,3333000000000]],"1024":[[0,1667000000000],[0,1708000000000],[0,1708000000000],[0,1791000000000]],"6144":[[0,10041000000000],[0,10042000000000],[0,10042000000000],[0,10083000000000]],"56":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1413500000000000],[0,1464458000000000]],"163840":[[0,286375000000000],[0,296833000000000],[0,303208000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,47083000000000],[0,47125000000000],[0,47208000000000],[0,47375000000000]],"512":[[0,833000000000],[0,875000000000],[0,875000000000],[0,1083000000000]],"196608":[[0,334291000000000],[0,342833000000000],[0,345000000000000]],"458752":[[0,802041000000000],[0,830500000000000]],"24576":[[0,40167000000000],[0,40250000000000],[0,40333000000000],[0,40375000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2500000000000],[0,2500000000000],[0,2541000000000],[0,2625000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,541000000000],[0,541000000000],[0,542000000000],[0,625000000000]],"114688":[[0,194667000000000],[0,197500000000000],[0,213375000000000]],"131072":[[0,223125000000000],[0,223916000000000],[0,237250000000000]],"16384":[[0,26708000000000],[0,26708000000000],[0,26709000000000],[0,32708000000000]],"5120":[[0,8375000000000],[0,8375000000000],[0,8375000000000],[0,8375000000000]],"229376":[[0,395958000000000],[0,401584000000000],[0,404958000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"655360":[[0,1196625000000000],[0,1201375000000000]],"7168":[[0,11708000000000],[0,11708000000000],[0,11708000000000],[0,11708000000000]],"20480":[[0,33375000000000],[0,33458000000000],[0,33458000000000],[0,33500000000000]],"65536":[[0,109750000000000],[0,109792000000000],[0,109875000000000],[0,110709000000000]],"917504":[[0,1671000000000000],[0,1734792000000000]],"160":[[0,250000000000],[0,291000000000],[0,291000000000],[0,291000000000]],"640":[[0,1083000000000],[0,1083000000000],[0,1083000000000],[0,1083000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,682542000000000],[0,691792000000000]],"57344":[[0,96000000000000],[0,96083000000000],[0,96416000000000],[0,97833000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1250000000000],[0,1250000000000],[0,1291000000000],[0,1291000000000]],"448":[[0,750000000000],[0,750000000000],[0,750000000000],[0,1042000000000]],"8192":[[0,13333000000000],[0,13334000000000],[0,13375000000000],[0,13375000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,16666000000000],[0,16708000000000],[0,16708000000000],[0,16709000000000]],"14336":[[0,23333000000000],[0,23416000000000],[0,23417000000000],[0,23458000000000]],"32768":[[0,54125000000000],[0,54250000000000],[0,54333000000000],[0,54375000000000]],"128":[[0,209000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"4096":[[0,6625000000000],[0,6666000000000],[0,6667000000000],[0,6667000000000]],"49152":[[0,81834000000000],[0,81875000000000],[0,81958000000000],[0,82083000000000]],"262144":[[0,453125000000000],[0,454583000000000],[0,458833000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,165833000000000],[0,166834000000000],[0,167042000000000],[0,167375000000000]]}},{"title":"Deque partitioning around middle (contiguous)","results":{"2048":[[0,1584000000000],[0,1625000000000],[0,1625000000000],[0,1666000000000]],"1048576":[[0,2989875000000000],[0,2998000000000000]],"96":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"327680":[[0,925667000000000],[0,954041000000000]],"384":[[0,291000000000],[0,291000000000],[0,292000000000],[0,375000000000]],"12288":[[0,11125000000000],[0,16542000000000],[0,18208000000000],[0,20542000000000]],"81920":[[0,209209000000000],[0,209750000000000],[0,213042000000000],[0,222458000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,833000000000],[0,958000000000],[0,1125000000000],[0,1333000000000]],"3584":[[0,2791000000000],[0,2834000000000],[0,2875000000000],[0,3041000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,1470458000000000],[0,1547208000000000]],"112":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"896":[[0,708000000000],[0,709000000000],[0,750000000000],[0,833000000000]],"192":[[0,125000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"80":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"24":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"40960":[[0,94042000000000],[0,94250000000000],[0,94959000000000],[0,106791000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,2333000000000],[0,2333000000000],[0,2416000000000],[0,2459000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,166000000000],[0,167000000000],[0,208000000000],[0,333000000000]],"2560":[[0,1833000000000],[0,2000000000000],[0,2000000000000],[0,2125000000000]],"1792":[[0,1334000000000],[0,1417000000000],[0,1500000000000],[0,1625000000000]],"1024":[[0,750000000000],[0,792000000000],[0,792000000000],[0,1084000000000]],"6144":[[0,4667000000000],[0,5291000000000],[0,5417000000000],[0,5542000000000]],"56":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"786432":[[0,2186583000000000],[0,2194458000000000]],"163840":[[0,446042000000000],[0,453792000000000],[0,472042000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,57125000000000],[0,59208000000000],[0,61042000000000],[0,63042000000000]],"512":[[0,375000000000],[0,375000000000],[0,416000000000],[0,500000000000]],"196608":[[0,539750000000000],[0,544833000000000],[0,548625000000000]],"458752":[[0,1299625000000000],[0,1323125000000000]],"24576":[[0,45958000000000],[0,46042000000000],[0,47834000000000],[0,52750000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,167000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"1536":[[0,1125000000000],[0,1166000000000],[0,1209000000000],[0,1250000000000]],"64":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"320":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"114688":[[0,304417000000000],[0,305292000000000],[0,312833000000000]],"131072":[[0,353000000000000],[0,353292000000000],[0,361292000000000]],"16384":[[0,19000000000000],[0,19500000000000],[0,20000000000000],[0,34375000000000]],"5120":[[0,3875000000000],[0,4042000000000],[0,4083000000000],[0,4125000000000]],"229376":[[0,636375000000000],[0,649667000000000],[0,653584000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"655360":[[0,1833833000000000],[0,1837625000000000]],"7168":[[0,5542000000000],[0,5667000000000],[0,6375000000000],[0,6541000000000]],"20480":[[0,29333000000000],[0,30333000000000],[0,38583000000000],[0,41958000000000]],"65536":[[0,163042000000000],[0,163375000000000],[0,163875000000000],[0,165542000000000]],"917504":[[0,2566166000000000],[0,2607709000000000]],"160":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"640":[[0,458000000000],[0,459000000000],[0,500000000000],[0,500000000000]],"40":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"393216":[[0,1090458000000000],[0,1109709000000000]],"57344":[[0,140125000000000],[0,140250000000000],[0,141208000000000],[0,148208000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,542000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"448":[[0,292000000000],[0,333000000000],[0,334000000000],[0,375000000000]],"8192":[[0,6083000000000],[0,6458000000000],[0,6625000000000],[0,9167000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,8292000000000],[0,8292000000000],[0,8459000000000],[0,8542000000000]],"14336":[[0,14667000000000],[0,14708000000000],[0,19417000000000],[0,23834000000000]],"32768":[[0,68792000000000],[0,69458000000000],[0,71875000000000],[0,73792000000000]],"128":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"4096":[[0,3042000000000],[0,3125000000000],[0,3250000000000],[0,3250000000000]],"49152":[[0,116709000000000],[0,117917000000000],[0,118000000000000],[0,118875000000000]],"262144":[[0,722166000000000],[0,738625000000000],[0,748833000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,256834000000000],[0,259584000000000],[0,270375000000000],[0,281333000000000]]}},{"title":"Deque partitioning around middle (discontiguous)","results":{"2048":[[0,2292000000000],[0,2500000000000],[0,2625000000000],[0,2666000000000]],"1048576":[[0,4625375000000000],[0,4642042000000000]],"96":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"327680":[[0,1441833000000000],[0,1471875000000000]],"384":[[0,417000000000],[0,458000000000],[0,458000000000],[0,583000000000]],"12288":[[0,29542000000000],[0,30542000000000],[0,40459000000000],[0,46000000000000]],"81920":[[0,340958000000000],[0,345167000000000],[0,347875000000000],[0,350041000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1458000000000],[0,1459000000000],[0,1542000000000],[0,2167000000000]],"3584":[[0,5958000000000],[0,6000000000000],[0,6042000000000],[0,8458000000000]],"7":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"524288":[[0,2282000000000000],[0,2337000000000000]],"112":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"896":[[0,1000000000000],[0,1041000000000],[0,1084000000000],[0,1291000000000]],"192":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"80":[[0,83000000000],[0,84000000000],[0,125000000000],[0,167000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,161042000000000],[0,161875000000000],[0,168000000000000],[0,170417000000000]],"16":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"3072":[[0,3583000000000],[0,3583000000000],[0,4542000000000],[0,4667000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"224":[[0,250000000000],[0,250000000000],[0,291000000000],[0,375000000000]],"2560":[[0,2875000000000],[0,2959000000000],[0,3000000000000],[0,3042000000000]],"1792":[[0,2000000000000],[0,2000000000000],[0,2167000000000],[0,2291000000000]],"1024":[[0,1125000000000],[0,1167000000000],[0,1209000000000],[0,1583000000000]],"6144":[[0,8375000000000],[0,9000000000000],[0,9250000000000],[0,10167000000000]],"56":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"786432":[[0,3456500000000000],[0,3477958000000000]],"163840":[[0,696375000000000],[0,700792000000000],[0,768209000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,104209000000000],[0,105875000000000],[0,106042000000000],[0,114917000000000]],"512":[[0,583000000000],[0,584000000000],[0,625000000000],[0,791000000000]],"196608":[[0,861708000000000],[0,908958000000000],[0,916958000000000]],"458752":[[0,2050458000000000],[0,2125583000000000]],"24576":[[0,86458000000000],[0,90833000000000],[0,100125000000000],[0,100625000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,292000000000],[0,292000000000],[0,292000000000],[0,333000000000]],"1536":[[0,1708000000000],[0,1750000000000],[0,1875000000000],[0,1875000000000]],"64":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"320":[[0,375000000000],[0,416000000000],[0,417000000000],[0,417000000000]],"114688":[[0,491167000000000],[0,506000000000000],[0,515166000000000]],"131072":[[0,552542000000000],[0,565500000000000],[0,611250000000000]],"16384":[[0,59250000000000],[0,59584000000000],[0,59875000000000],[0,66208000000000]],"5120":[[0,6959000000000],[0,7041000000000],[0,7625000000000],[0,12333000000000]],"229376":[[0,1003958000000000],[0,1004083000000000],[0,1054708000000000]],"5":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,2863541000000000],[0,2898042000000000]],"7168":[[0,11125000000000],[0,11333000000000],[0,14416000000000],[0,14666000000000]],"20480":[[0,69875000000000],[0,70250000000000],[0,76667000000000],[0,79833000000000]],"65536":[[0,268750000000000],[0,271541000000000],[0,275583000000000],[0,277625000000000]],"917504":[[0,4030833000000000],[0,4075334000000000]],"160":[[0,167000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"640":[[0,708000000000],[0,709000000000],[0,750000000000],[0,750000000000]],"40":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"393216":[[0,1733750000000000],[0,1773834000000000]],"57344":[[0,240250000000000],[0,241792000000000],[0,242958000000000],[0,245875000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,875000000000],[0,875000000000],[0,875000000000],[0,1166000000000]],"448":[[0,500000000000],[0,500000000000],[0,542000000000],[0,792000000000]],"8192":[[0,14666000000000],[0,18500000000000],[0,19500000000000],[0,20042000000000]],"12":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10240":[[0,29042000000000],[0,29916000000000],[0,30417000000000],[0,30625000000000]],"14336":[[0,40167000000000],[0,42958000000000],[0,49708000000000],[0,51083000000000]],"32768":[[0,122500000000000],[0,122916000000000],[0,133500000000000],[0,133958000000000]],"128":[[0,166000000000],[0,167000000000],[0,167000000000],[0,167000000000]],"4096":[[0,4917000000000],[0,5000000000000],[0,5000000000000],[0,5208000000000]],"49152":[[0,194917000000000],[0,195584000000000],[0,195917000000000],[0,197750000000000]],"262144":[[0,1144958000000000],[0,1157625000000000],[0,1186792000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,413750000000000],[0,416125000000000],[0,417125000000000],[0,439250000000000]]}},{"title":"Deque removeFirst (discontiguous)","results":{"2048":[[0,4625000000000],[0,4625000000000],[0,4666000000000],[0,4666000000000]],"1048576":[[0,2382250000000000],[0,2385041000000000]],"96":[[0,208000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"327680":[[0,746708000000000],[0,756208000000000]],"384":[[0,834000000000],[0,875000000000],[0,875000000000],[0,1000000000000]],"12288":[[0,27833000000000],[0,27833000000000],[0,27875000000000],[0,31625000000000]],"81920":[[0,185833000000000],[0,185833000000000],[0,185875000000000],[0,185875000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,2916000000000],[0,2958000000000],[0,3042000000000],[0,4042000000000]],"3584":[[0,8083000000000],[0,8125000000000],[0,8166000000000],[0,8166000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"524288":[[0,1189875000000000],[0,1198333000000000]],"112":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"896":[[0,2041000000000],[0,2041000000000],[0,2042000000000],[0,2042000000000]],"192":[[0,416000000000],[0,416000000000],[0,417000000000],[0,459000000000]],"80":[[0,167000000000],[0,167000000000],[0,208000000000],[0,250000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"40960":[[0,92875000000000],[0,92875000000000],[0,92875000000000],[0,92875000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,6917000000000],[0,6958000000000],[0,6959000000000],[0,7000000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"224":[[0,500000000000],[0,500000000000],[0,541000000000],[0,583000000000]],"2560":[[0,5791000000000],[0,5791000000000],[0,5833000000000],[0,5833000000000]],"1792":[[0,4083000000000],[0,4083000000000],[0,4084000000000],[0,4625000000000]],"1024":[[0,2333000000000],[0,2333000000000],[0,2333000000000],[0,2334000000000]],"6144":[[0,13917000000000],[0,13917000000000],[0,13917000000000],[0,13958000000000]],"56":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"786432":[[0,1795750000000000],[0,1816625000000000]],"163840":[[0,371625000000000],[0,371708000000000],[0,389333000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"32":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,65000000000000],[0,65000000000000],[0,65041000000000],[0,65041000000000]],"512":[[0,1166000000000],[0,1166000000000],[0,1167000000000],[0,1625000000000]],"196608":[[0,448041000000000],[0,449375000000000],[0,465583000000000]],"458752":[[0,1069792000000000],[0,1072584000000000]],"24576":[[0,55709000000000],[0,55750000000000],[0,55750000000000],[0,55791000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,583000000000],[0,583000000000],[0,583000000000],[0,584000000000]],"1536":[[0,3458000000000],[0,3500000000000],[0,3500000000000],[0,3667000000000]],"64":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"320":[[0,709000000000],[0,750000000000],[0,750000000000],[0,833000000000]],"114688":[[0,260125000000000],[0,260208000000000],[0,260209000000000]],"131072":[[0,297250000000000],[0,297500000000000],[0,305292000000000]],"16384":[[0,37125000000000],[0,37166000000000],[0,37167000000000],[0,51750000000000]],"5120":[[0,11625000000000],[0,11625000000000],[0,11625000000000],[0,11625000000000]],"229376":[[0,520333000000000],[0,523917000000000],[0,533250000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"655360":[[0,1489625000000000],[0,1507125000000000]],"7168":[[0,16208000000000],[0,16250000000000],[0,16250000000000],[0,16250000000000]],"20480":[[0,46416000000000],[0,46458000000000],[0,46458000000000],[0,46542000000000]],"65536":[[0,148625000000000],[0,148666000000000],[0,148666000000000],[0,148709000000000]],"917504":[[0,2082834000000000],[0,2084958000000000]],"160":[[0,375000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"640":[[0,1458000000000],[0,1458000000000],[0,1459000000000],[0,1459000000000]],"40":[[0,83000000000],[0,83000000000],[0,125000000000],[0,125000000000]],"393216":[[0,892125000000000],[0,906750000000000]],"57344":[[0,130041000000000],[0,130083000000000],[0,130125000000000],[0,130209000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1750000000000],[0,1750000000000],[0,1750000000000],[0,1750000000000]],"448":[[0,1000000000000],[0,1041000000000],[0,1041000000000],[0,1292000000000]],"8192":[[0,18583000000000],[0,18583000000000],[0,18583000000000],[0,18583000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,23209000000000],[0,23209000000000],[0,23250000000000],[0,23292000000000]],"14336":[[0,32500000000000],[0,32500000000000],[0,32541000000000],[0,32542000000000]],"32768":[[0,74292000000000],[0,74334000000000],[0,74375000000000],[0,74458000000000]],"128":[[0,291000000000],[0,292000000000],[0,292000000000],[0,292000000000]],"4096":[[0,9250000000000],[0,9292000000000],[0,9292000000000],[0,9292000000000]],"49152":[[0,111458000000000],[0,111500000000000],[0,111500000000000],[0,111542000000000]],"262144":[[0,594792000000000],[0,596417000000000],[0,602500000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,223000000000000],[0,223000000000000],[0,223042000000000],[0,223166000000000]]}},{"title":"Deque removeLast (discontiguous)","results":{"2048":[[0,3833000000000],[0,3833000000000],[0,3833000000000],[0,3834000000000]],"1048576":[[0,1969208000000000],[0,1979250000000000]],"96":[[0,167000000000],[0,167000000000],[0,167000000000],[0,167000000000]],"327680":[[0,621625000000000],[0,623042000000000]],"384":[[0,708000000000],[0,708000000000],[0,750000000000],[0,834000000000]],"12288":[[0,23000000000000],[0,23041000000000],[0,23041000000000],[0,26041000000000]],"81920":[[0,153542000000000],[0,153625000000000],[0,153625000000000],[0,153667000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2416000000000],[0,2416000000000],[0,2584000000000],[0,3333000000000]],"3584":[[0,6708000000000],[0,6708000000000],[0,6708000000000],[0,6750000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,984625000000000],[0,996083000000000]],"112":[[0,208000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"896":[[0,1666000000000],[0,1666000000000],[0,1666000000000],[0,1667000000000]],"192":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"80":[[0,166000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,76791000000000],[0,76792000000000],[0,76833000000000],[0,76834000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"3072":[[0,5750000000000],[0,5750000000000],[0,5750000000000],[0,5750000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"224":[[0,416000000000],[0,416000000000],[0,416000000000],[0,458000000000]],"2560":[[0,4791000000000],[0,4791000000000],[0,4791000000000],[0,4833000000000]],"1792":[[0,3375000000000],[0,3375000000000],[0,3375000000000],[0,3792000000000]],"1024":[[0,1916000000000],[0,1916000000000],[0,1916000000000],[0,1917000000000]],"6144":[[0,11500000000000],[0,11500000000000],[0,11500000000000],[0,11542000000000]],"56":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1475333000000000],[0,1508625000000000]],"163840":[[0,307083000000000],[0,307250000000000],[0,336083000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,41000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,53666000000000],[0,53708000000000],[0,53750000000000],[0,58209000000000]],"512":[[0,958000000000],[0,958000000000],[0,959000000000],[0,1083000000000]],"196608":[[0,368625000000000],[0,370375000000000],[0,375625000000000]],"458752":[[0,883625000000000],[0,884083000000000]],"24576":[[0,46041000000000],[0,46042000000000],[0,46083000000000],[0,46083000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,500000000000],[0,500000000000]],"1536":[[0,2833000000000],[0,2875000000000],[0,2875000000000],[0,3000000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,625000000000],[0,625000000000],[0,625000000000],[0,709000000000]],"114688":[[0,215042000000000],[0,215083000000000],[0,215083000000000]],"131072":[[0,245625000000000],[0,245750000000000],[0,245791000000000]],"16384":[[0,30625000000000],[0,30625000000000],[0,30708000000000],[0,30709000000000]],"5120":[[0,9583000000000],[0,9583000000000],[0,9584000000000],[0,9625000000000]],"229376":[[0,433625000000000],[0,433750000000000],[0,454625000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1230083000000000],[0,1243500000000000]],"7168":[[0,13375000000000],[0,13416000000000],[0,13458000000000],[0,13458000000000]],"20480":[[0,38334000000000],[0,38375000000000],[0,38416000000000],[0,40209000000000]],"65536":[[0,122834000000000],[0,122875000000000],[0,122875000000000],[0,122917000000000]],"917504":[[0,1720375000000000],[0,1721292000000000]],"160":[[0,291000000000],[0,292000000000],[0,333000000000],[0,333000000000]],"640":[[0,1208000000000],[0,1208000000000],[0,1208000000000],[0,1209000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,737917000000000],[0,750583000000000]],"57344":[[0,107500000000000],[0,107500000000000],[0,107500000000000],[0,107625000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1417000000000],[0,1417000000000],[0,1417000000000],[0,1417000000000]],"448":[[0,791000000000],[0,833000000000],[0,875000000000],[0,917000000000]],"8192":[[0,15334000000000],[0,15375000000000],[0,15375000000000],[0,15375000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,19166000000000],[0,19167000000000],[0,19167000000000],[0,19250000000000]],"14336":[[0,26792000000000],[0,26834000000000],[0,26875000000000],[0,26875000000000]],"32768":[[0,61375000000000],[0,61416000000000],[0,61417000000000],[0,61500000000000]],"128":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"4096":[[0,7666000000000],[0,7666000000000],[0,7708000000000],[0,7708000000000]],"49152":[[0,92083000000000],[0,92125000000000],[0,92166000000000],[0,92292000000000]],"262144":[[0,491541000000000],[0,491541000000000],[0,517709000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,184250000000000],[0,184292000000000],[0,184292000000000],[0,184292000000000]]}},{"title":"Array init from unsafe buffer","results":{"2048":[[0,244590000000],[0,268330000000],[0,271660000000],[0,322080000000]],"1048576":[[0,114557250000000],[0,114777666666666]],"96":[[0,48330000000],[0,48330000000],[0,49160000000],[0,49580000000]],"327680":[[0,30583000000000],[0,37667000000000]],"384":[[0,64160000000],[0,64160000000],[0,66250000000],[0,67910000000]],"12288":[[0,1613750000000],[0,1620000000000],[0,1677090000000],[0,1751250000000]],"81920":[[0,8144160000000],[0,8159580000000],[0,8166250000000],[0,8231250000000]],"8":[[0,32910000000],[0,32910000000],[0,32910000000],[0,32920000000]],"1280":[[0,148340000000],[0,150000000000],[0,150000000000],[0,152500000000]],"3584":[[0,521250000000],[0,547080000000],[0,559590000000],[0,642910000000]],"7":[[0,35000000000],[0,35410000000],[0,35410000000],[0,35410000000]],"524288":[[0,50807080000000],[0,56819454545454]],"112":[[0,50000000000],[0,50000000000],[0,51250000000],[0,51250000000]],"896":[[0,115830000000],[0,116250000000],[0,117080000000],[0,117500000000]],"192":[[0,50410000000],[0,50420000000],[0,50830000000],[0,50830000000]],"80":[[0,46660000000],[0,46660000000],[0,47500000000],[0,47910000000]],"24":[[0,34580000000],[0,34580000000],[0,34580000000],[0,34580000000]],"40960":[[0,4487500000000],[0,4492500000000],[0,4515000000000],[0,4523330000000]],"16":[[0,32910000000],[0,32920000000],[0,33330000000],[0,33330000000]],"3072":[[0,416250000000],[0,459000000000],[0,459000000000],[0,502080000000]],"20":[[0,32920000000],[0,33330000000],[0,33330000000],[0,33340000000]],"224":[[0,52910000000],[0,53330000000],[0,54160000000],[0,54160000000]],"2560":[[0,317090000000],[0,374590000000],[0,378750000000],[0,409590000000]],"1792":[[0,194449275362],[0,203441176470],[0,214285714285],[0,255000000000]],"1024":[[0,128330000000],[0,128750000000],[0,128750000000],[0,129580000000]],"6144":[[0,1197910000000],[0,1625000000000],[0,1770840000000],[0,1777920000000]],"56":[[0,44160000000],[0,44160000000],[0,45410000000],[0,45410000000]],"786432":[[0,87056680000000],[0,87178277777777]],"163840":[[0,15562090000000],[0,15842080000000],[0,19295000000000]],"6":[[0,34580000000],[0,35000000000],[0,35000000000],[0,35410000000]],"48":[[0,43330000000],[0,43340000000],[0,44580000000],[0,44580000000]],"32":[[0,42080000000],[0,42080000000],[0,42080000000],[0,42080000000]],"14":[[0,32910000000],[0,32910000000],[0,32910000000],[0,33330000000]],"28672":[[0,3377500000000],[0,3384170000000],[0,3397910000000],[0,3402080000000]],"512":[[0,87080000000],[0,87080000000],[0,87090000000],[0,87500000000]],"196608":[[0,18727538461538],[0,19414160000000],[0,20789170000000]],"458752":[[0,47683400000000],[0,54458000000000]],"24576":[[0,3012500000000],[0,3014580000000],[0,3016670000000],[0,3026660000000]],"2":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"256":[[0,55000000000],[0,55410000000],[0,55410000000],[0,55410000000]],"1536":[[0,170830000000],[0,175830000000],[0,195840000000],[0,221660000000]],"64":[[0,45000000000],[0,45000000000],[0,45000000000],[0,45410000000]],"320":[[0,60000000000],[0,60000000000],[0,60000000000],[0,68330000000]],"114688":[[0,11097920000000],[0,11122080000000],[0,15038750000000]],"131072":[[0,12590830000000],[0,12925000000000],[0,13079170000000]],"16384":[[0,2205410000000],[0,2217920000000],[0,2223750000000],[0,2229590000000]],"5120":[[0,1072080000000],[0,1427500000000],[0,1437080000000],[0,1455000000000]],"229376":[[0,21749240740740],[0,21772080000000],[0,22019580000000]],"5":[[0,34580000000],[0,34580000000],[0,34580000000],[0,35000000000]],"10":[[0,32910000000],[0,32920000000],[0,32920000000],[0,33330000000]],"28":[[0,34580000000],[0,34580000000],[0,34590000000],[0,34590000000]],"655360":[[0,63834000000000],[0,65719580000000]],"7168":[[0,1586250000000],[0,1704160000000],[0,1782910000000],[0,1785000000000]],"20480":[[0,2646250000000],[0,2649529411764],[0,2661660000000],[0,2696670000000]],"65536":[[0,6676660000000],[0,6686961538461],[0,6726250000000],[0,6742500000000]],"917504":[[0,100812500000000],[0,100892588888888]],"160":[[0,48330000000],[0,48330000000],[0,49580000000],[0,49590000000]],"640":[[0,95830000000],[0,96660000000],[0,97080000000],[0,97090000000]],"40":[[0,42500000000],[0,42910000000],[0,43750000000],[0,43750000000]],"393216":[[0,37404170000000],[0,37417000000000]],"57344":[[0,5948750000000],[0,5949170000000],[0,6000000000000],[0,6327920000000]],"4":[[0,34160000000],[0,34580000000],[0,34580000000],[0,36250000000]],"1":[[0,35000000000],[0,35000000000],[0,35410000000],[0,35410000000]],"768":[[0,104000000000],[0,106250000000],[0,107500000000],[0,107500000000]],"448":[[0,77080000000],[0,77080000000],[0,77080000000],[0,77080000000]],"8192":[[0,1319590000000],[0,1592080000000],[0,1615846153846],[0,1767500000000]],"12":[[0,32910000000],[0,32910000000],[0,32910000000],[0,32910000000]],"10240":[[0,1529170000000],[0,1565000000000],[0,1602080000000],[0,1617090000000]],"14336":[[0,1845840000000],[0,1859160000000],[0,1859170000000],[0,1862910000000]],"32768":[[0,3744590000000],[0,3747500000000],[0,3755546666666],[0,3757500000000]],"128":[[0,45410000000],[0,45830000000],[0,45840000000],[0,46250000000]],"4096":[[0,1217500000000],[0,1224160000000],[0,1329170000000],[0,1330000000000]],"49152":[[0,5217080000000],[0,5222500000000],[0,5226250000000],[0,5226660000000]],"262144":[[0,25221250000000],[0,25586250000000],[0,26555666666666]],"3":[[0,34160000000],[0,34170000000],[0,34170000000],[0,34580000000]],"98304":[[0,9618000000000],[0,9668330000000],[0,9672910000000],[0,9715000000000]]}},{"title":"Array sequential iteration","results":{"2048":[[0,1664772727272],[0,1666670000000],[0,1667080000000],[0,1667080000000]],"1048576":[[0,857700818181818],[0,863632545454545]],"96":[[0,82080000000],[0,82080000000],[0,82080000000],[0,82090000000]],"327680":[[0,267166000000000],[0,273646454545454]],"384":[[0,315830000000],[0,315830000000],[0,316250000000],[0,335000000000]],"12288":[[0,9979000000000],[0,9979160000000],[0,9980420000000],[0,9983340000000]],"81920":[[0,66500000000000],[0,66542000000000],[0,66583000000000],[0,67013750000000]],"8":[[0,7910000000],[0,7920000000],[0,8330000000],[0,8330000000]],"1280":[[0,1042000000000],[0,1042920000000],[0,1043340000000],[0,1043750000000]],"3584":[[0,2913330000000],[0,2913750000000],[0,2913750000000],[0,2914170000000]],"7":[[0,7500000000],[0,7500000000],[0,7500000000],[0,7500000000]],"524288":[[0,425875000000000],[0,431250000000000]],"112":[[0,91600000000],[0,95000000000],[0,95000000000],[0,95410000000]],"896":[[0,729000000000],[0,731660000000],[0,731660000000],[0,731660000000]],"192":[[0,159750000000],[0,160000000000],[0,160410000000],[0,160410000000]],"80":[[0,68750000000],[0,69160000000],[0,69160000000],[0,69160000000]],"24":[[0,20830000000],[0,21250000000],[0,21250000000],[0,21250000000]],"40960":[[0,33250000000000],[0,33250000000000],[0,33291000000000],[0,33293750000000]],"16":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15830000000]],"3072":[[0,2497920000000],[0,2497920000000],[0,2498330000000],[0,2498330000000]],"20":[[0,17910000000],[0,17920000000],[0,18330000000],[0,18330000000]],"224":[[0,185830000000],[0,186250000000],[0,186250000000],[0,186250000000]],"2560":[[0,2082500000000],[0,2082500000000],[0,2082500000000],[0,2082500000000]],"1792":[[0,1458000000000],[0,1458750000000],[0,1459160000000],[0,1459160000000]],"1024":[[0,833333333333],[0,835410000000],[0,835410000000],[0,835420000000]],"6144":[[0,4991660000000],[0,4991670000000],[0,4991670000000],[0,4992080000000]],"56":[[0,49590000000],[0,50000000000],[0,50000000000],[0,50000000000]],"786432":[[0,657052800000000],[0,657875000000000]],"163840":[[0,133041000000000],[0,133375000000000],[0,139833000000000]],"6":[[0,6660000000],[0,6660000000],[0,6660000000],[0,6660000000]],"48":[[0,43750000000],[0,43750000000],[0,43750000000],[0,43750000000]],"32":[[0,27500000000],[0,27800000000],[0,27910000000],[0,27910000000]],"14":[[0,13330000000],[0,13330000000],[0,13330000000],[0,13330000000]],"28672":[[0,23292000000000],[0,23302100000000],[0,23334000000000],[0,23366670000000]],"512":[[0,416000000000],[0,419580000000],[0,420000000000],[0,420000000000]],"196608":[[0,165114406779661],[0,170403846153846],[0,174203125000000]],"458752":[[0,378250000000000],[0,380583000000000]],"24576":[[0,19959000000000],[0,20000000000000],[0,20000000000000],[0,20014170000000]],"2":[[0,3330000000],[0,3330000000],[0,3750000000],[0,3750000000]],"256":[[0,208000000000],[0,208000000000],[0,212080000000],[0,212080000000]],"1536":[[0,1250840000000],[0,1251250000000],[0,1251250000000],[0,1251250000000]],"64":[[0,56250000000],[0,56250000000],[0,56250000000],[0,56250000000]],"320":[[0,263750000000],[0,263750000000],[0,264160000000],[0,299580000000]],"114688":[[0,93119000000000],[0,95484375000000],[0,105834000000000]],"131072":[[0,106667000000000],[0,107326392857142],[0,109416000000000]],"16384":[[0,13311660000000],[0,13315000000000],[0,13333000000000],[0,13334000000000]],"5120":[[0,4159666666666],[0,4160410000000],[0,4160420000000],[0,4160830000000]],"229376":[[0,186166000000000],[0,187750000000000],[0,190157400000000]],"5":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5840000000]],"10":[[0,9580000000],[0,9580000000],[0,10000000000],[0,10000000000]],"28":[[0,24160000000],[0,24170000000],[0,24580000000],[0,24580000000]],"655360":[[0,541000000000000],[0,542363388888888]],"7168":[[0,5822920000000],[0,5822920000000],[0,5823330000000],[0,5823340000000]],"20480":[[0,16645000000000],[0,16666000000000],[0,16708000000000],[0,16791000000000]],"65536":[[0,53208000000000],[0,53222333333333],[0,53280000000000],[0,53334000000000]],"917504":[[0,746667000000000],[0,747833000000000]],"160":[[0,125000000000],[0,133750000000],[0,134160000000],[0,134160000000]],"640":[[0,523222222222],[0,523750000000],[0,523750000000],[0,523750000000]],"40":[[0,36660000000],[0,36670000000],[0,36670000000],[0,37080000000]],"393216":[[0,319333000000000],[0,327208000000000]],"57344":[[0,46560923076923],[0,46565428571428],[0,46570800000000],[0,46667000000000]],"4":[[0,5000000000],[0,5000000000],[0,5000000000],[0,5410000000]],"1":[[0,1660000000],[0,1660000000],[0,1660000000],[0,1670000000]],"768":[[0,618000000000],[0,625000000000],[0,627500000000],[0,627910000000]],"448":[[0,367500000000],[0,367910000000],[0,367910000000],[0,367920000000]],"8192":[[0,6653750000000],[0,6654170000000],[0,6654170000000],[0,6667000000000]],"12":[[0,11250000000],[0,11250000000],[0,11660000000],[0,11660000000]],"10240":[[0,8316660000000],[0,8317080000000],[0,8317080000000],[0,8333000000000]],"14336":[[0,11642500000000],[0,11644809523809],[0,11647500000000],[0,11667000000000]],"32768":[[0,26614750000000],[0,26615420000000],[0,26643340000000],[0,26897500000000]],"128":[[0,108330000000],[0,108330000000],[0,108330000000],[0,108330000000]],"4096":[[0,3329160000000],[0,3329170000000],[0,3329580000000],[0,3329580000000]],"49152":[[0,39959000000000],[0,40013750000000],[0,40042000000000],[0,40125000000000]],"262144":[[0,212875000000000],[0,213000000000000],[0,213458000000000]],"3":[[0,4160000000],[0,4170000000],[0,4580000000],[0,4580000000]],"98304":[[0,79809782608695],[0,79833000000000],[0,80052083333333],[0,81702681818181]]}},{"title":"Array subscript get, random offsets","results":{"2048":[[0,1666660000000],[0,1667000000000],[0,1667080000000],[0,1667500000000]],"1048576":[[0,872375000000000],[0,879031250000000]],"96":[[0,82090000000],[0,82500000000],[0,82500000000],[0,82500000000]],"327680":[[0,270459000000000],[0,274681250000000]],"384":[[0,315830000000],[0,315830000000],[0,316250000000],[0,337080000000]],"12288":[[0,9993750000000],[0,10056670000000],[0,10122910000000],[0,18291000000000]],"81920":[[0,66634252525252],[0,66682090000000],[0,66802920000000],[0,67373234042553]],"8":[[0,8750000000],[0,8750000000],[0,8750000000],[0,8750000000]],"1280":[[0,1041687500000],[0,1043750000000],[0,1043750000000],[0,1043750000000]],"3584":[[0,2913750000000],[0,2913750000000],[0,2914160000000],[0,2914160000000]],"7":[[0,7500000000],[0,7910000000],[0,7910000000],[0,7910000000]],"524288":[[0,426875000000000],[0,431621769230769]],"112":[[0,95000000000],[0,95410000000],[0,95410000000],[0,95410000000]],"896":[[0,732080000000],[0,732080000000],[0,732080000000],[0,732080000000]],"192":[[0,160000000000],[0,160000000000],[0,160410000000],[0,160410000000]],"80":[[0,68428571428],[0,69580000000],[0,69580000000],[0,69580000000]],"24":[[0,21250000000],[0,21250000000],[0,21250000000],[0,21660000000]],"40960":[[0,33292000000000],[0,33336250000000],[0,33415830000000],[0,33872080000000]],"16":[[0,13916666666],[0,15000000000],[0,15000000000],[0,15410000000]],"3072":[[0,2497900000000],[0,2498330000000],[0,2498330000000],[0,2498750000000]],"20":[[0,18330000000],[0,18330000000],[0,18330000000],[0,18340000000]],"224":[[0,186250000000],[0,186660000000],[0,186660000000],[0,195410000000]],"2560":[[0,2082500000000],[0,2082500000000],[0,2082500000000],[0,2082910000000]],"1792":[[0,1458000000000],[0,1458500000000],[0,1459580000000],[0,1459580000000]],"1024":[[0,823000000000],[0,835830000000],[0,835830000000],[0,835840000000]],"6144":[[0,4991660000000],[0,4992080000000],[0,4992080000000],[0,4992500000000]],"56":[[0,42000000000],[0,50000000000],[0,50000000000],[0,50000000000]],"786432":[[0,643167000000000],[0,650125000000000]],"163840":[[0,133019489361702],[0,133309307692307],[0,140064285714285]],"6":[[0,7080000000],[0,7080000000],[0,7080000000],[0,7080000000]],"48":[[0,42000000000],[0,43330000000],[0,43750000000],[0,43750000000]],"32":[[0,27910000000],[0,27920000000],[0,28330000000],[0,28330000000]],"14":[[0,13330000000],[0,13330000000],[0,13750000000],[0,13750000000]],"28672":[[0,23295454545454],[0,23296875000000],[0,23353330000000],[0,23376660000000]],"512":[[0,416500000000],[0,420000000000],[0,420410000000],[0,420410000000]],"196608":[[0,159750000000000],[0,159791500000000],[0,170862363636363]],"458752":[[0,377833000000000],[0,382795900000000]],"24576":[[0,19979000000000],[0,20000000000000],[0,20012920000000],[0,20138750000000]],"2":[[0,3750000000],[0,3750000000],[0,3750000000],[0,3750000000]],"256":[[0,208000000000],[0,209000000000],[0,209000000000],[0,212080000000]],"1536":[[0,1250000000000],[0,1251660000000],[0,1251660000000],[0,1251660000000]],"64":[[0,42000000000],[0,55555555555],[0,56660000000],[0,56660000000]],"320":[[0,250000000000],[0,264580000000],[0,264580000000],[0,301250000000]],"114688":[[0,93267615384615],[0,94844696969696],[0,110708400000000]],"131072":[[0,106687500000000],[0,107107954545454],[0,107330566666666]],"16384":[[0,13321670000000],[0,13334000000000],[0,13354170000000],[0,13357500000000]],"5120":[[0,4159294117647],[0,4160410000000],[0,4160511363636],[0,4160830000000]],"229376":[[0,186250000000000],[0,188865095238095],[0,215036680000000]],"5":[[0,5830000000],[0,6250000000],[0,6250000000],[0,6250000000]],"10":[[0,10000000000],[0,10410000000],[0,10410000000],[0,10410000000]],"28":[[0,24580000000],[0,24580000000],[0,24580000000],[0,25000000000]],"655360":[[0,534666000000000],[0,539298666666666]],"7168":[[0,5823330000000],[0,5823453608247],[0,5824160000000],[0,5857090000000]],"20480":[[0,16644580000000],[0,16713750000000],[0,16839580000000],[0,16934590000000]],"65536":[[0,53250000000000],[0,53330420000000],[0,53412500000000],[0,53818750000000]],"917504":[[0,753500000000000],[0,758991800000000]],"160":[[0,134170000000],[0,134580000000],[0,134580000000],[0,134580000000]],"640":[[0,522727272727],[0,523816326530],[0,524160000000],[0,524160000000]],"40":[[0,37080000000],[0,37500000000],[0,37500000000],[0,37500000000]],"393216":[[0,320982583333333],[0,331745388888888]],"57344":[[0,46602920000000],[0,47102500000000],[0,47249160000000],[0,47343330000000]],"4":[[0,5000000000],[0,5410000000],[0,5410000000],[0,5420000000]],"1":[[0,2080000000],[0,2080000000],[0,2080000000],[0,2080000000]],"768":[[0,625000000000],[0,627910000000],[0,627910000000],[0,627920000000]],"448":[[0,368330000000],[0,368330000000],[0,368330000000],[0,368750000000]],"8192":[[0,6657920000000],[0,6658340000000],[0,6659580000000],[0,6710410000000]],"12":[[0,11670000000],[0,12080000000],[0,12080000000],[0,12080000000]],"10240":[[0,8325830000000],[0,8325840000000],[0,8326250000000],[0,8369580000000]],"14336":[[0,11655000000000],[0,11659160000000],[0,11663330000000],[0,11690420000000]],"32768":[[0,26616554054054],[0,26653750000000],[0,26667000000000],[0,27095000000000]],"128":[[0,107920000000],[0,108330000000],[0,108340000000],[0,108750000000]],"4096":[[0,3329545454545],[0,3329580000000],[0,3330000000000],[0,3330000000000]],"49152":[[0,39935367346938],[0,39959000000000],[0,40045840000000],[0,40127080000000]],"262144":[[0,212917000000000],[0,213500000000000],[0,216917000000000]],"3":[[0,4170000000],[0,4580000000],[0,4580000000],[0,4580000000]],"98304":[[0,79958333333333],[0,80310425000000],[0,80869513157894],[0,81386075949367]]}},{"title":"Array mutate through subscript","results":{"2048":[[0,2750000000000],[0,2750000000000],[0,2791000000000],[0,2792000000000]],"1048576":[[0,1432917000000000],[0,1435209000000000]],"96":[[0,125000000000],[0,125000000000],[0,125000000000],[0,208000000000]],"327680":[[0,451708000000000],[0,464958000000000]],"384":[[0,500000000000],[0,542000000000],[0,584000000000],[0,584000000000]],"12288":[[0,16625000000000],[0,16625000000000],[0,16666000000000],[0,18792000000000]],"81920":[[0,110791000000000],[0,110833000000000],[0,110875000000000],[0,110917000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1750000000000],[0,1750000000000],[0,1750000000000],[0,1833000000000]],"3584":[[0,4833000000000],[0,4833000000000],[0,4875000000000],[0,4875000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,709625000000000],[0,719333000000000]],"112":[[0,166000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"896":[[0,1209000000000],[0,1250000000000],[0,1250000000000],[0,1250000000000]],"192":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"24":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,55416000000000],[0,55417000000000],[0,55417000000000],[0,55458000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,4125000000000],[0,4166000000000],[0,4166000000000],[0,4166000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,292000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"2560":[[0,3458000000000],[0,3458000000000],[0,3459000000000],[0,3459000000000]],"1792":[[0,2416000000000],[0,2417000000000],[0,2417000000000],[0,2542000000000]],"1024":[[0,1375000000000],[0,1375000000000],[0,1375000000000],[0,1458000000000]],"6144":[[0,8291000000000],[0,8333000000000],[0,8333000000000],[0,8333000000000]],"56":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"786432":[[0,1064917000000000],[0,1097000000000000]],"163840":[[0,221666000000000],[0,221791000000000],[0,222000000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"32":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28672":[[0,38791000000000],[0,38791000000000],[0,38792000000000],[0,38792000000000]],"512":[[0,708000000000],[0,708000000000],[0,708000000000],[0,708000000000]],"196608":[[0,265958000000000],[0,266083000000000],[0,278250000000000]],"458752":[[0,631458000000000],[0,681167000000000]],"24576":[[0,33250000000000],[0,33250000000000],[0,33250000000000],[0,33250000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"1536":[[0,2083000000000],[0,2083000000000],[0,2083000000000],[0,2084000000000]],"64":[[0,83000000000],[0,83000000000],[0,84000000000],[0,84000000000]],"320":[[0,458000000000],[0,458000000000],[0,500000000000],[0,875000000000]],"114688":[[0,155208000000000],[0,155250000000000],[0,162750000000000]],"131072":[[0,177333000000000],[0,177375000000000],[0,177542000000000]],"16384":[[0,22125000000000],[0,22166000000000],[0,22167000000000],[0,22583000000000]],"5120":[[0,6916000000000],[0,6958000000000],[0,6958000000000],[0,6958000000000]],"229376":[[0,310416000000000],[0,310666000000000],[0,325583000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"655360":[[0,887291000000000],[0,887500000000000]],"7168":[[0,9667000000000],[0,9667000000000],[0,9708000000000],[0,9708000000000]],"20480":[[0,27708000000000],[0,27750000000000],[0,27750000000000],[0,27750000000000]],"65536":[[0,88625000000000],[0,88708000000000],[0,88750000000000],[0,88750000000000]],"917504":[[0,1241916000000000],[0,1271167000000000]],"160":[[0,208000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"640":[[0,875000000000],[0,875000000000],[0,875000000000],[0,916000000000]],"40":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"393216":[[0,532125000000000],[0,539209000000000]],"57344":[[0,77583000000000],[0,77583000000000],[0,77584000000000],[0,77584000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1041000000000],[0,1042000000000],[0,1042000000000],[0,1083000000000]],"448":[[0,625000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"8192":[[0,11083000000000],[0,11083000000000],[0,11083000000000],[0,11125000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,13875000000000],[0,13875000000000],[0,13875000000000],[0,13875000000000]],"14336":[[0,19375000000000],[0,19375000000000],[0,19375000000000],[0,19416000000000]],"32768":[[0,44291000000000],[0,44292000000000],[0,44334000000000],[0,44334000000000]],"128":[[0,166000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"4096":[[0,5541000000000],[0,5541000000000],[0,5542000000000],[0,5542000000000]],"49152":[[0,66500000000000],[0,66541000000000],[0,66541000000000],[0,66584000000000]],"262144":[[0,354750000000000],[0,358167000000000],[0,360958000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,132958000000000],[0,133000000000000],[0,133083000000000],[0,133209000000000]]}},{"title":"Array random swaps","results":{"2048":[[0,2833000000000],[0,2875000000000],[0,2875000000000],[0,2875000000000]],"1048576":[[0,1757375000000000],[0,1787542000000000]],"96":[[0,125000000000],[0,166000000000],[0,166000000000],[0,209000000000]],"327680":[[0,513250000000000],[0,559875000000000]],"384":[[0,542000000000],[0,583000000000],[0,625000000000],[0,625000000000]],"12288":[[0,17083000000000],[0,17125000000000],[0,18083000000000],[0,19541000000000]],"81920":[[0,123834000000000],[0,123958000000000],[0,124125000000000],[0,125000000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,1791000000000],[0,1792000000000],[0,1834000000000],[0,1875000000000]],"3584":[[0,5000000000000],[0,5000000000000],[0,5000000000000],[0,5000000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,838709000000000],[0,842541000000000]],"112":[[0,166000000000],[0,167000000000],[0,208000000000],[0,209000000000]],"896":[[0,1250000000000],[0,1250000000000],[0,1291000000000],[0,1333000000000]],"192":[[0,250000000000],[0,291000000000],[0,292000000000],[0,292000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"24":[[0,41000000000],[0,41000000000],[0,41000000000],[0,83000000000]],"40960":[[0,59958000000000],[0,60042000000000],[0,60334000000000],[0,61750000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"3072":[[0,4292000000000],[0,4292000000000],[0,4292000000000],[0,4292000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"224":[[0,333000000000],[0,333000000000],[0,333000000000],[0,375000000000]],"2560":[[0,3583000000000],[0,3583000000000],[0,3584000000000],[0,3625000000000]],"1792":[[0,2500000000000],[0,2500000000000],[0,2541000000000],[0,2625000000000]],"1024":[[0,1416000000000],[0,1417000000000],[0,1458000000000],[0,1500000000000]],"6144":[[0,8542000000000],[0,8542000000000],[0,8583000000000],[0,8584000000000]],"56":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1324958000000000],[0,1336542000000000]],"163840":[[0,252334000000000],[0,255083000000000],[0,286959000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,40833000000000],[0,40917000000000],[0,41083000000000],[0,41166000000000]],"512":[[0,708000000000],[0,709000000000],[0,750000000000],[0,750000000000]],"196608":[[0,312417000000000],[0,318833000000000],[0,320250000000000]],"458752":[[0,727875000000000],[0,745625000000000]],"24576":[[0,34625000000000],[0,34708000000000],[0,34709000000000],[0,34750000000000]],"2":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"256":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"1536":[[0,2125000000000],[0,2166000000000],[0,2166000000000],[0,2167000000000]],"64":[[0,84000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,458000000000],[0,500000000000],[0,541000000000],[0,1083000000000]],"114688":[[0,175375000000000],[0,175458000000000],[0,185875000000000]],"131072":[[0,201875000000000],[0,202792000000000],[0,205000000000000]],"16384":[[0,22667000000000],[0,22792000000000],[0,22792000000000],[0,22792000000000]],"5120":[[0,7125000000000],[0,7125000000000],[0,7166000000000],[0,7166000000000]],"229376":[[0,357583000000000],[0,358333000000000],[0,395167000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"655360":[[0,1088416000000000],[0,1102542000000000]],"7168":[[0,9958000000000],[0,9958000000000],[0,10000000000000],[0,10041000000000]],"20480":[[0,28625000000000],[0,28625000000000],[0,28708000000000],[0,28750000000000]],"65536":[[0,98375000000000],[0,98500000000000],[0,98625000000000],[0,99250000000000]],"917504":[[0,1526792000000000],[0,1540250000000000]],"160":[[0,208000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"640":[[0,916000000000],[0,917000000000],[0,917000000000],[0,917000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"393216":[[0,613417000000000],[0,618584000000000]],"57344":[[0,84958000000000],[0,85333000000000],[0,85917000000000],[0,86084000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1083000000000],[0,1083000000000],[0,1125000000000],[0,1166000000000]],"448":[[0,625000000000],[0,625000000000],[0,666000000000],[0,666000000000]],"8192":[[0,11375000000000],[0,11416000000000],[0,11458000000000],[0,11459000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10240":[[0,14250000000000],[0,14250000000000],[0,14291000000000],[0,14292000000000]],"14336":[[0,19875000000000],[0,19875000000000],[0,19917000000000],[0,19958000000000]],"32768":[[0,47375000000000],[0,47375000000000],[0,47500000000000],[0,47667000000000]],"128":[[0,166000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"4096":[[0,5708000000000],[0,5708000000000],[0,5708000000000],[0,5708000000000]],"49152":[[0,72625000000000],[0,72834000000000],[0,73000000000000],[0,73125000000000]],"262144":[[0,407583000000000],[0,412375000000000],[0,418958000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,150000000000000],[0,150125000000000],[0,150625000000000],[0,150792000000000]]}},{"title":"Array partitioning around middle","results":{"2048":[[0,1333000000000],[0,1375000000000],[0,1375000000000],[0,1375000000000]],"1048576":[[0,2955792000000000],[0,3077500000000000]],"96":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"327680":[[0,919125000000000],[0,920458000000000]],"384":[[0,291000000000],[0,292000000000],[0,292000000000],[0,292000000000]],"12288":[[0,13375000000000],[0,20959000000000],[0,21542000000000],[0,38791000000000]],"81920":[[0,218292000000000],[0,218917000000000],[0,219666000000000],[0,222584000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,792000000000],[0,875000000000],[0,875000000000],[0,875000000000]],"3584":[[0,2375000000000],[0,2417000000000],[0,2542000000000],[0,3208000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,1477250000000000],[0,1486875000000000]],"112":[[0,83000000000],[0,83000000000],[0,84000000000],[0,84000000000]],"896":[[0,583000000000],[0,583000000000],[0,625000000000],[0,791000000000]],"192":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"80":[[0,41000000000],[0,41000000000],[0,83000000000],[0,83000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,96834000000000],[0,97208000000000],[0,100542000000000],[0,105042000000000]],"16":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"3072":[[0,2000000000000],[0,2084000000000],[0,2125000000000],[0,2125000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"224":[[0,125000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"2560":[[0,1708000000000],[0,1708000000000],[0,1750000000000],[0,1750000000000]],"1792":[[0,1167000000000],[0,1208000000000],[0,1209000000000],[0,1250000000000]],"1024":[[0,667000000000],[0,667000000000],[0,708000000000],[0,709000000000]],"6144":[[0,4166000000000],[0,4250000000000],[0,4750000000000],[0,5666000000000]],"56":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"786432":[[0,2220625000000000],[0,2235458000000000]],"163840":[[0,455417000000000],[0,466916000000000],[0,473917000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"48":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,58791000000000],[0,59084000000000],[0,60417000000000],[0,70875000000000]],"512":[[0,333000000000],[0,333000000000],[0,334000000000],[0,375000000000]],"196608":[[0,557542000000000],[0,562583000000000],[0,581708000000000]],"458752":[[0,1317625000000000],[0,1347917000000000]],"24576":[[0,43791000000000],[0,45833000000000],[0,50916000000000],[0,58791000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,166000000000],[0,166000000000],[0,167000000000],[0,208000000000]],"1536":[[0,1000000000000],[0,1000000000000],[0,1042000000000],[0,1042000000000]],"64":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"320":[[0,250000000000],[0,250000000000],[0,250000000000],[0,291000000000]],"114688":[[0,313458000000000],[0,317083000000000],[0,340250000000000]],"131072":[[0,362291000000000],[0,363792000000000],[0,364750000000000]],"16384":[[0,19250000000000],[0,19666000000000],[0,21375000000000],[0,34084000000000]],"5120":[[0,3375000000000],[0,3417000000000],[0,3750000000000],[0,4083000000000]],"229376":[[0,641959000000000],[0,648000000000000],[0,676708000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1879125000000000],[0,1889875000000000]],"7168":[[0,4875000000000],[0,4875000000000],[0,4916000000000],[0,5084000000000]],"20480":[[0,33417000000000],[0,34209000000000],[0,45708000000000],[0,46166000000000]],"65536":[[0,171584000000000],[0,174458000000000],[0,174625000000000],[0,175500000000000]],"917504":[[0,2582708000000000],[0,2643167000000000]],"160":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"640":[[0,417000000000],[0,417000000000],[0,459000000000],[0,500000000000]],"40":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"393216":[[0,1105708000000000],[0,1109792000000000]],"57344":[[0,146333000000000],[0,152583000000000],[0,153333000000000],[0,156333000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,500000000000],[0,500000000000],[0,542000000000],[0,542000000000]],"448":[[0,291000000000],[0,292000000000],[0,333000000000],[0,334000000000]],"8192":[[0,5792000000000],[0,6250000000000],[0,6709000000000],[0,8875000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,7500000000000],[0,14958000000000],[0,15041000000000],[0,15250000000000]],"14336":[[0,13208000000000],[0,14667000000000],[0,18375000000000],[0,22500000000000]],"32768":[[0,71709000000000],[0,72125000000000],[0,81291000000000],[0,81667000000000]],"128":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"4096":[[0,2625000000000],[0,2791000000000],[0,2792000000000],[0,2833000000000]],"49152":[[0,120500000000000],[0,122000000000000],[0,122583000000000],[0,123042000000000]],"262144":[[0,733916000000000],[0,744708000000000],[0,769750000000000]],"3":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,256167000000000],[0,265625000000000],[0,265916000000000],[0,267125000000000]]}},{"title":"Array sort","results":{"2048":[[0,45042000000000],[0,45250000000000],[0,46125000000000],[0,48292000000000]],"1048576":[[0,57984166000000000],[0,58791750000000000]],"96":[[0,916000000000],[0,1000000000000],[0,1000000000000],[0,1042000000000]],"327680":[[0,16667416000000000],[0,16717959000000000]],"384":[[0,4542000000000],[0,5333000000000],[0,5708000000000],[0,6125000000000]],"12288":[[0,420417000000000],[0,425791000000000],[0,437916000000000],[0,500000000000000]],"81920":[[0,3571459000000000],[0,3573375000000000],[0,3575375000000000],[0,3624375000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1280":[[0,24250000000000],[0,24417000000000],[0,25958000000000],[0,26084000000000]],"3584":[[0,96584000000000],[0,96709000000000],[0,97167000000000],[0,101042000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,27784958000000000],[0,27989000000000000]],"112":[[0,1208000000000],[0,1291000000000],[0,1333000000000],[0,1416000000000]],"896":[[0,14083000000000],[0,14333000000000],[0,14625000000000],[0,15542000000000]],"192":[[0,1958000000000],[0,2000000000000],[0,2042000000000],[0,2167000000000]],"80":[[0,625000000000],[0,667000000000],[0,708000000000],[0,875000000000]],"24":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"40960":[[0,1643958000000000],[0,1661084000000000],[0,1673334000000000],[0,1687291000000000]],"16":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"3072":[[0,79750000000000],[0,81584000000000],[0,81833000000000],[0,83333000000000]],"20":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"224":[[0,2625000000000],[0,2750000000000],[0,2875000000000],[0,4334000000000]],"2560":[[0,62042000000000],[0,65209000000000],[0,65583000000000],[0,72583000000000]],"1792":[[0,38250000000000],[0,39958000000000],[0,40417000000000],[0,41417000000000]],"1024":[[0,16750000000000],[0,16916000000000],[0,19375000000000],[0,23958000000000]],"6144":[[0,186542000000000],[0,186667000000000],[0,187916000000000],[0,188792000000000]],"56":[[0,375000000000],[0,417000000000],[0,417000000000],[0,458000000000]],"786432":[[0,42428709000000000],[0,42774125000000000]],"163840":[[0,7643666000000000],[0,7733958000000000],[0,7959333000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"32":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,1108166000000000],[0,1109791000000000],[0,1124458000000000],[0,1125584000000000]],"512":[[0,5167000000000],[0,5208000000000],[0,5458000000000],[0,5500000000000]],"196608":[[0,9563917000000000],[0,9572208000000000],[0,9755416000000000]],"458752":[[0,24058167000000000],[0,24717333000000000]],"24576":[[0,925542000000000],[0,930708000000000],[0,934083000000000],[0,946167000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,2250000000000],[0,2291000000000],[0,2334000000000],[0,3125000000000]],"1536":[[0,31125000000000],[0,31333000000000],[0,31917000000000],[0,32208000000000]],"64":[[0,500000000000],[0,542000000000],[0,542000000000],[0,625000000000]],"320":[[0,3125000000000],[0,3459000000000],[0,3583000000000],[0,3917000000000]],"114688":[[0,5171708000000000],[0,5172125000000000],[0,5275333000000000]],"131072":[[0,6044916000000000],[0,6046417000000000],[0,6169209000000000]],"16384":[[0,589583000000000],[0,590250000000000],[0,593917000000000],[0,595250000000000]],"5120":[[0,149833000000000],[0,150917000000000],[0,151417000000000],[0,151709000000000]],"229376":[[0,11077875000000000],[0,11092000000000000],[0,11436958000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"28":[[0,83000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"655360":[[0,35075792000000000],[0,35163500000000000]],"7168":[[0,222500000000000],[0,224125000000000],[0,225583000000000],[0,229833000000000]],"20480":[[0,752834000000000],[0,762625000000000],[0,768959000000000],[0,788375000000000]],"65536":[[0,2810792000000000],[0,2811000000000000],[0,2812208000000000],[0,2855125000000000]],"917504":[[0,50169666000000000],[0,50444458000000000]],"160":[[0,1500000000000],[0,1500000000000],[0,1584000000000],[0,1666000000000]],"640":[[0,7542000000000],[0,7584000000000],[0,7625000000000],[0,9750000000000]],"40":[[0,167000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"393216":[[0,19878792000000000],[0,19983750000000000]],"57344":[[0,2398000000000000],[0,2410208000000000],[0,2427167000000000],[0,2446041000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,10666000000000],[0,10875000000000],[0,12000000000000],[0,15125000000000]],"448":[[0,5667000000000],[0,5708000000000],[0,5917000000000],[0,5959000000000]],"8192":[[0,263833000000000],[0,264208000000000],[0,270125000000000],[0,271542000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,339583000000000],[0,340625000000000],[0,348167000000000],[0,355542000000000]],"14336":[[0,499000000000000],[0,500708000000000],[0,505209000000000],[0,512042000000000]],"32768":[[0,1295625000000000],[0,1307208000000000],[0,1310083000000000],[0,1310875000000000]],"128":[[0,1083000000000],[0,1167000000000],[0,1167000000000],[0,1208000000000]],"4096":[[0,115209000000000],[0,115459000000000],[0,117917000000000],[0,121959000000000]],"49152":[[0,2019500000000000],[0,2022208000000000],[0,2023417000000000],[0,2028250000000000]],"262144":[[0,13015958000000000],[0,13121334000000000],[0,13137333000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,4358000000000000],[0,4369542000000000],[0,4373542000000000],[0,4453042000000000]]}},{"title":"Array append","results":{"2048":[[0,1623750000000],[0,1629590000000],[0,1645420000000],[0,1653750000000]],"1048576":[[0,1286521000000000],[0,1454854000000000]],"96":[[0,316600000000],[0,316670000000],[0,316670000000],[0,317500000000]],"327680":[[0,343750000000000],[0,399262166666666]],"384":[[0,576660000000],[0,577080000000],[0,577910000000],[0,637920000000]],"12288":[[0,11334000000000],[0,11513888888888],[0,11939160000000],[0,15652500000000]],"81920":[[0,64459000000000],[0,70125000000000],[0,89489472527472],[0,92027597402597]],"8":[[0,114580000000],[0,114580000000],[0,114580000000],[0,114580000000]],"1280":[[0,1303750000000],[0,1305000000000],[0,1314160000000],[0,1329580000000]],"3584":[[0,3156670000000],[0,3321250000000],[0,3346670000000],[0,3371670000000]],"7":[[0,114160000000],[0,114160000000],[0,114170000000],[0,114580000000]],"524288":[[0,601958000000000],[0,716758300000000]],"112":[[0,322920000000],[0,323750000000],[0,323750000000],[0,324160000000]],"896":[[0,909090909090],[0,913750000000],[0,920000000000],[0,966250000000]],"192":[[0,411250000000],[0,411670000000],[0,412500000000],[0,418750000000]],"80":[[0,311660000000],[0,311670000000],[0,313750000000],[0,322920000000]],"24":[[0,198750000000],[0,198750000000],[0,198750000000],[0,199160000000]],"40960":[[0,32821670000000],[0,33917000000000],[0,34416000000000],[0,46448330000000]],"16":[[0,150410000000],[0,150410000000],[0,150830000000],[0,151660000000]],"3072":[[0,2948750000000],[0,3111702127659],[0,3123330000000],[0,3147920000000]],"20":[[0,197080000000],[0,197080000000],[0,197500000000],[0,197910000000]],"224":[[0,424590000000],[0,425000000000],[0,425000000000],[0,429160000000]],"2560":[[0,2866250000000],[0,2882500000000],[0,2892090000000],[0,2908750000000]],"1792":[[0,1520420000000],[0,1522080000000],[0,1524170000000],[0,1537080000000]],"1024":[[0,978330000000],[0,983750000000],[0,984170000000],[0,1022920000000]],"6144":[[0,6211670000000],[0,6277500000000],[0,6339170000000],[0,6444590000000]],"56":[[0,257500000000],[0,257500000000],[0,258750000000],[0,263330000000]],"786432":[[0,845916750000000],[0,870406250000000]],"163840":[[0,139167000000000],[0,149667000000000],[0,191550675675675]],"6":[[0,114160000000],[0,114160000000],[0,114160000000],[0,114170000000]],"48":[[0,254160000000],[0,254160000000],[0,254590000000],[0,256250000000]],"32":[[0,200410000000],[0,201660000000],[0,202080000000],[0,202500000000]],"14":[[0,149580000000],[0,150000000000],[0,150410000000],[0,150410000000]],"28672":[[0,28333000000000],[0,30041000000000],[0,31750000000000],[0,34209000000000]],"512":[[0,627080000000],[0,627080000000],[0,629170000000],[0,629580000000]],"196608":[[0,191285450000000],[0,234241680000000],[0,243644083333333]],"458752":[[0,613875000000000],[0,616812500000000]],"24576":[[0,26658854166666],[0,27152777777777],[0,30036100000000],[0,30276259259259]],"2":[[0,40410000000],[0,40410000000],[0,40410000000],[0,40410000000]],"256":[[0,437910000000],[0,437910000000],[0,438330000000],[0,440000000000]],"1536":[[0,1375000000000],[0,1398320000000],[0,1426660000000],[0,1430000000000]],"64":[[0,260000000000],[0,260410000000],[0,260830000000],[0,260830000000]],"320":[[0,548330000000],[0,548750000000],[0,549580000000],[0,634160000000]],"114688":[[0,115738102040816],[0,118103000000000],[0,130963636363636]],"131072":[[0,141339285714285],[0,145304200000000],[0,154866071428571]],"16384":[[0,18833250000000],[0,19238000000000],[0,19297920000000],[0,19343750000000]],"5120":[[0,4125000000000],[0,4172920000000],[0,4179170000000],[0,4183340000000]],"229376":[[0,231103260869565],[0,270084000000000],[0,273917000000000]],"5":[[0,113330000000],[0,113750000000],[0,113750000000],[0,113750000000]],"10":[[0,149170000000],[0,149580000000],[0,150000000000],[0,150410000000]],"28":[[0,199590000000],[0,199590000000],[0,201660000000],[0,202500000000]],"655360":[[0,620292000000000],[0,826910714285714]],"7168":[[0,6535714285714],[0,6736670000000],[0,6798728813559],[0,6804170000000]],"20480":[[0,15797090000000],[0,20708000000000],[0,22890827586206],[0,23132500000000]],"65536":[[0,71875000000000],[0,73807142857142],[0,74626660000000],[0,74902080000000]],"917504":[[0,744166000000000],[0,996302000000000]],"160":[[0,399580000000],[0,399590000000],[0,400410000000],[0,400830000000]],"640":[[0,807500000000],[0,808330000000],[0,811670000000],[0,812080000000]],"40":[[0,252080000000],[0,252080000000],[0,252090000000],[0,252910000000]],"393216":[[0,444892857142857],[0,506084000000000]],"57344":[[0,55134508771929],[0,58292000000000],[0,59958000000000],[0,68341032608695]],"4":[[0,78750000000],[0,79160000000],[0,79170000000],[0,79580000000]],"1":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40000000000]],"768":[[0,861250000000],[0,869160000000],[0,870830000000],[0,923750000000]],"448":[[0,606250000000],[0,606250000000],[0,607090000000],[0,607920000000]],"8192":[[0,7831250000000],[0,7840420000000],[0,7861250000000],[0,7872000000000]],"12":[[0,149580000000],[0,149580000000],[0,150000000000],[0,150000000000]],"10240":[[0,8377243243243],[0,8449021276595],[0,8636250000000],[0,11561250000000]],"14336":[[0,16828330000000],[0,17167000000000],[0,17407910000000],[0,17731250000000]],"32768":[[0,29797080000000],[0,29875000000000],[0,31288340000000],[0,32083000000000]],"128":[[0,329580000000],[0,330000000000],[0,330000000000],[0,330000000000]],"4096":[[0,3489586956521],[0,3502786666666],[0,3514580000000],[0,3533750000000]],"49152":[[0,50542000000000],[0,57911840579710],[0,58814580000000],[0,59812500000000]],"262144":[[0,263667000000000],[0,315562500000000],[0,326899529411764]],"3":[[0,77500000000],[0,77910000000],[0,77910000000],[0,77910000000]],"98304":[[0,79827148148148],[0,82792000000000],[0,109833000000000],[0,116560190476190]]}},{"title":"Array append, reserving capacity","results":{"2048":[[0,993750000000],[0,995840000000],[0,996250000000],[0,998750000000]],"1048576":[[0,598016000000000],[0,701739625000000]],"96":[[0,84160000000],[0,84160000000],[0,85410000000],[0,85410000000]],"327680":[[0,178413793103448],[0,192706409090909]],"384":[[0,216250000000],[0,216670000000],[0,217391304347],[0,218330000000]],"12288":[[0,8708000000000],[0,10734590000000],[0,10835000000000],[0,10993750000000]],"81920":[[0,41848775280898],[0,44707500000000],[0,52756406593406],[0,73607954545454]],"8":[[0,39590000000],[0,40000000000],[0,40000000000],[0,40000000000]],"1280":[[0,633200000000],[0,637080000000],[0,638750000000],[0,639170000000]],"3584":[[0,1708000000000],[0,1710420000000],[0,1713330000000],[0,1715000000000]],"7":[[0,39580000000],[0,39580000000],[0,39580000000],[0,40000000000]],"524288":[[0,265647461538461],[0,344559428571428]],"112":[[0,98750000000],[0,100000000000],[0,100840000000],[0,101250000000]],"896":[[0,458750000000],[0,458750000000],[0,458750000000],[0,459160000000]],"192":[[0,127500000000],[0,127500000000],[0,128330000000],[0,128330000000]],"80":[[0,77090000000],[0,77500000000],[0,78330000000],[0,78330000000]],"24":[[0,45830000000],[0,45830000000],[0,45830000000],[0,45830000000]],"40960":[[0,21792000000000],[0,22657848484848],[0,37364160000000],[0,37657920000000]],"16":[[0,42080000000],[0,42090000000],[0,42500000000],[0,42500000000]],"3072":[[0,1458000000000],[0,1472080000000],[0,1473750000000],[0,1475410000000]],"20":[[0,44160000000],[0,44160000000],[0,44160000000],[0,44160000000]],"224":[[0,143330000000],[0,143330000000],[0,143555555555],[0,143750000000]],"2560":[[0,1234170000000],[0,1234590000000],[0,1235840000000],[0,1236670000000]],"1792":[[0,872920000000],[0,875840000000],[0,876250000000],[0,877500000000]],"1024":[[0,517500000000],[0,520420000000],[0,520830000000],[0,521250000000]],"6144":[[0,3416000000000],[0,3417000000000],[0,3458000000000],[0,3534666666666]],"56":[[0,65840000000],[0,66660000000],[0,67500000000],[0,67910000000]],"786432":[[0,467459000000000],[0,481997000000000]],"163840":[[0,116917000000000],[0,148300695652173],[0,154358974358974]],"6":[[0,39160000000],[0,39170000000],[0,39580000000],[0,39580000000]],"48":[[0,62910000000],[0,62910000000],[0,63750000000],[0,64160000000]],"32":[[0,55420000000],[0,55830000000],[0,55830000000],[0,56250000000]],"14":[[0,41250000000],[0,41660000000],[0,41660000000],[0,41660000000]],"28672":[[0,14037920000000],[0,14044340425531],[0,14069500000000],[0,14347080000000]],"512":[[0,278750000000],[0,279170000000],[0,279170000000],[0,279580000000]],"196608":[[0,111834000000000],[0,112875000000000],[0,183779771428571]],"458752":[[0,389150000000000],[0,401208000000000]],"24576":[[0,11375000000000],[0,15542000000000],[0,22438085714285],[0,22618750000000]],"2":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40000000000]],"256":[[0,157080000000],[0,157500000000],[0,157910000000],[0,157910000000]],"1536":[[0,756250000000],[0,757500000000],[0,757910000000],[0,758330000000]],"64":[[0,70000000000],[0,70000000000],[0,70000000000],[0,70000000000]],"320":[[0,186250000000],[0,187500000000],[0,187500000000],[0,213750000000]],"114688":[[0,54000000000000],[0,54125000000000],[0,69256048387096]],"131072":[[0,62948490909090],[0,73660888888888],[0,85888406779661]],"16384":[[0,8250000000000],[0,8250000000000],[0,8336250000000],[0,8917000000000]],"5120":[[0,3000000000000],[0,3047910000000],[0,3047910000000],[0,3056250000000]],"229376":[[0,151625000000000],[0,167966871794871],[0,194125000000000]],"5":[[0,38750000000],[0,39160000000],[0,39160000000],[0,39160000000]],"10":[[0,40410000000],[0,40420000000],[0,40420000000],[0,40830000000]],"28":[[0,47080000000],[0,47080000000],[0,47500000000],[0,47500000000]],"655360":[[0,299512500000000],[0,455640625000000]],"7168":[[0,3983340000000],[0,3989590000000],[0,3993750000000],[0,3994580000000]],"20480":[[0,9958000000000],[0,10042000000000],[0,10167000000000],[0,12075840000000]],"65536":[[0,30041000000000],[0,30125000000000],[0,33125000000000],[0,59700000000000]],"917504":[[0,464825000000000],[0,655178571428571]],"160":[[0,115000000000],[0,115000000000],[0,115410000000],[0,115830000000]],"640":[[0,337500000000],[0,339580000000],[0,340410000000],[0,340420000000]],"40":[[0,59580000000],[0,59580000000],[0,60420000000],[0,60830000000]],"393216":[[0,300055555555555],[0,310750000000000]],"57344":[[0,25042000000000],[0,34000000000000],[0,51880830000000],[0,52534170000000]],"4":[[0,38750000000],[0,38750000000],[0,38750000000],[0,38750000000]],"1":[[0,39580000000],[0,39590000000],[0,39590000000],[0,39590000000]],"768":[[0,375000000000],[0,399580000000],[0,399580000000],[0,399580000000]],"448":[[0,248330000000],[0,248750000000],[0,248750000000],[0,249160000000]],"8192":[[0,4417000000000],[0,5072000000000],[0,5178330000000],[0,5219160000000]],"12":[[0,40830000000],[0,40840000000],[0,41250000000],[0,41250000000]],"10240":[[0,5333000000000],[0,5407920000000],[0,5444580000000],[0,5475840000000]],"14336":[[0,7380000000000],[0,7382090000000],[0,7441793650793],[0,8145420000000]],"32768":[[0,15500000000000],[0,17625000000000],[0,19625000000000],[0,29970250000000]],"128":[[0,103330000000],[0,103330000000],[0,103750000000],[0,103750000000]],"4096":[[0,2562500000000],[0,2569170000000],[0,2573330000000],[0,2576670000000]],"49152":[[0,23505420000000],[0,23666642857142],[0,23766222222222],[0,24976250000000]],"262144":[[0,124458000000000],[0,150667000000000],[0,170416000000000]],"3":[[0,38330000000],[0,38750000000],[0,38750000000],[0,38750000000]],"98304":[[0,44041000000000],[0,58875000000000],[0,63125000000000],[0,68375000000000]]}},{"title":"Array prepend","results":{"2048":[[0,193958250000000],[0,195625000000000],[0,196166000000000],[0,196875000000000]],"96":[[0,911250000000],[0,914580000000],[0,915000000000],[0,915830000000]],"384":[[0,7659590000000],[0,7670420000000],[0,7684160000000],[0,7692307692307]],"12288":[[0,6916625000000000],[0,6973500000000000],[0,7142041000000000],[0,7181542000000000]],"81920":[[0,440244625000000000],[0,441185166500000000],[0,441425375000000000],[0,468525187500000000]],"8":[[0,159160000000],[0,159160000000],[0,159170000000],[0,159580000000]],"1280":[[0,74667000000000],[0,76186250000000],[0,76366250000000],[0,78347920000000]],"3584":[[0,583042000000000],[0,583416000000000],[0,586975529411764],[0,597971375000000]],"7":[[0,154160000000],[0,154160000000],[0,154170000000],[0,155000000000]],"112":[[0,1086538461538],[0,1087500000000],[0,1089170000000],[0,1090420000000]],"896":[[0,37437500000000],[0,37876984126984],[0,37915000000000],[0,38686660000000]],"192":[[0,2320840000000],[0,2322090000000],[0,2322500000000],[0,2323750000000]],"80":[[0,758750000000],[0,759160000000],[0,759580000000],[0,761670000000]],"24":[[0,300420000000],[0,302080000000],[0,302080000000],[0,302080000000]],"40960":[[0,105376958500000000],[0,105670667000000000],[0,106193104000000000],[0,106904625000000000]],"16":[[0,224160000000],[0,224160000000],[0,224170000000],[0,224580000000]],"3072":[[0,429307956521739],[0,432500000000000],[0,438793666666666],[0,439125000000000]],"20":[[0,283330000000],[0,283750000000],[0,283750000000],[0,283750000000]],"224":[[0,2995000000000],[0,3001250000000],[0,3008121951219],[0,3009580000000]],"2560":[[0,298750000000000],[0,300834000000000],[0,301644433333333],[0,307343750000000]],"1792":[[0,144542000000000],[0,145314516129032],[0,145366411764705],[0,147500000000000]],"1024":[[0,52652500000000],[0,52727876543209],[0,53141250000000],[0,53342436781609]],"6144":[[0,1706166000000000],[0,1730209000000000],[0,1750633400000000],[0,1763066600000000]],"56":[[0,529170000000],[0,530410000000],[0,530420000000],[0,530830000000]],"163840":[[0,1769782250000000000],[0,1774790542000000000],[0,1806581958500000000]],"6":[[0,148330000000],[0,148750000000],[0,149160000000],[0,149160000000]],"48":[[0,481250000000],[0,481604651162],[0,481670000000],[0,482090000000]],"32":[[0,337080000000],[0,338330000000],[0,338330000000],[0,339170000000]],"14":[[0,217080000000],[0,217500000000],[0,217910000000],[0,217920000000]],"28672":[[0,48598625000000000],[0,48847959000000000],[0,49015166500000000],[0,49340291500000000]],"512":[[0,14638377358490],[0,14646250000000],[0,14694235294117],[0,14787500000000]],"24576":[[0,34118625000000000],[0,34376729000000000],[0,34442625000000000],[0,34681875000000000]],"2":[[0,53330000000],[0,53330000000],[0,53330000000],[0,53330000000]],"256":[[0,3754580000000],[0,3755000000000],[0,3759590000000],[0,3761928571428]],"1536":[[0,106946428571428],[0,107760500000000],[0,107926173913043],[0,108708000000000]],"64":[[0,582090000000],[0,582500000000],[0,582920000000],[0,583330000000]],"320":[[0,5577090000000],[0,5581670000000],[0,5602080000000],[0,5615420000000]],"114688":[[0,864015583000000000],[0,873840292000000000],[0,884949125000000000]],"131072":[[0,1131745291000000000],[0,1133971812500000000],[0,1184277041000000000]],"16384":[[0,12310167000000000],[0,12395458000000000],[0,12423521000000000],[0,12525375000000000]],"5120":[[0,1191292000000000],[0,1196500000000000],[0,1242892857142857],[0,1246601285714285]],"5":[[0,141660000000],[0,141660000000],[0,141670000000],[0,142080000000]],"10":[[0,202500000000],[0,202500000000],[0,202500000000],[0,202910000000]],"28":[[0,318750000000],[0,319333333333],[0,319580000000],[0,320410000000]],"7168":[[0,2346364750000000],[0,2364375000000000],[0,2402281250000000],[0,2410791750000000]],"20480":[[0,21816208000000000],[0,22076792000000000],[0,22105750000000000],[0,22184875000000000]],"65536":[[0,277921750000000000],[0,279177542000000000],[0,279268208000000000],[0,280837000000000000]],"160":[[0,1778750000000],[0,1781250000000],[0,1781670000000],[0,1784170000000]],"640":[[0,19832080000000],[0,19942920000000],[0,20092080000000],[0,20194590000000]],"40":[[0,433340000000],[0,433750000000],[0,434580000000],[0,435000000000]],"57344":[[0,210840208000000000],[0,212173709000000000],[0,212482916500000000],[0,215023000000000000]],"4":[[0,101250000000],[0,101250000000],[0,101250000000],[0,101250000000]],"1":[[0,41666666666],[0,46660000000],[0,46660000000],[0,46660000000]],"768":[[0,27917000000000],[0,28074160000000],[0,28174580000000],[0,28186250000000]],"448":[[0,10132920000000],[0,10153750000000],[0,10173340000000],[0,10307920000000]],"8192":[[0,3079291000000000],[0,3086667000000000],[0,3088472333333333],[0,3180000000000000]],"12":[[0,209160000000],[0,209580000000],[0,209580000000],[0,209580000000]],"10240":[[0,4792791500000000],[0,4805791500000000],[0,4877000000000000],[0,4914959000000000]],"14336":[[0,9364541000000000],[0,9381000000000000],[0,9414500000000000],[0,9988833500000000]],"32768":[[0,65044500000000000],[0,65353417000000000],[0,65398750000000000],[0,66346687500000000]],"128":[[0,1275420000000],[0,1278330000000],[0,1279580000000],[0,1280000000000]],"4096":[[0,761667000000000],[0,762375000000000],[0,766625000000000],[0,773218750000000]],"49152":[[0,154421250000000000],[0,154479292000000000],[0,155197250000000000],[0,155492792000000000]],"3":[[0,94580000000],[0,94590000000],[0,95000000000],[0,95000000000]],"98304":[[0,634430479000000000],[0,636545250000000000],[0,638048625000000000],[0,639070770500000000]]}},{"title":"Array prepend, reserving capacity","results":{"2048":[[0,199583000000000],[0,202816833333333],[0,203042000000000],[0,219708000000000]],"96":[[0,594160000000],[0,594580000000],[0,595000000000],[0,595830000000]],"384":[[0,7153750000000],[0,7155000000000],[0,7155830000000],[0,7158000000000]],"12288":[[0,6883958000000000],[0,6904208000000000],[0,7112709000000000],[0,7602125000000000]],"81920":[[0,437997437500000000],[0,439889583000000000],[0,440908416000000000],[0,442717792000000000]],"8":[[0,69160000000],[0,69160000000],[0,69160000000],[0,69170000000]],"1280":[[0,75082080000000],[0,75117500000000],[0,75169170000000],[0,76459000000000]],"3584":[[0,579536764705882],[0,581919250000000],[0,583542000000000],[0,587033875000000]],"7":[[0,64580000000],[0,64580000000],[0,65000000000],[0,65000000000]],"112":[[0,762080000000],[0,763330000000],[0,763750000000],[0,764160000000]],"896":[[0,36583000000000],[0,36789580000000],[0,37748340000000],[0,38215830000000]],"192":[[0,1928571428571],[0,1930420000000],[0,1931250000000],[0,1935420000000]],"80":[[0,445420000000],[0,445830000000],[0,447090000000],[0,449580000000]],"24":[[0,119160000000],[0,119170000000],[0,119580000000],[0,119580000000]],"40960":[[0,105562250000000000],[0,106057375000000000],[0,106086562500000000],[0,106262917000000000]],"16":[[0,92920000000],[0,92920000000],[0,93330000000],[0,93330000000]],"3072":[[0,426417000000000],[0,430320090909090],[0,436583000000000],[0,439909090909090]],"20":[[0,104160000000],[0,104160000000],[0,104160000000],[0,104170000000]],"224":[[0,2581670000000],[0,2583000000000],[0,2583750000000],[0,2588750000000]],"2560":[[0,301375000000000],[0,306083000000000],[0,308042000000000],[0,310177093750000]],"1792":[[0,143194666666666],[0,144792000000000],[0,145025735294117],[0,146541000000000]],"1024":[[0,54502666666666],[0,55458000000000],[0,55459000000000],[0,56956106666666]],"6144":[[0,1706292000000000],[0,1719300000000000],[0,1726958000000000],[0,1733916600000000]],"56":[[0,284580000000],[0,285000000000],[0,285830000000],[0,285931034482]],"163840":[[0,1773467333500000000],[0,1783305770500000000],[0,1802613750000000000]],"6":[[0,58400000000],[0,60000000000],[0,60000000000],[0,60410000000]],"48":[[0,239500000000],[0,240000000000],[0,240410000000],[0,241250000000]],"32":[[0,159580000000],[0,159580000000],[0,159580000000],[0,159580000000]],"14":[[0,87500000000],[0,87500000000],[0,87500000000],[0,87500000000]],"28672":[[0,48592833000000000],[0,48600166500000000],[0,48746417000000000],[0,48878958000000000]],"512":[[0,15852500000000],[0,15875000000000],[0,15983340000000],[0,16000000000000]],"24576":[[0,34093750000000000],[0,34164125000000000],[0,34608417000000000],[0,34649354000000000]],"2":[[0,46250000000],[0,46250000000],[0,46660000000],[0,46660000000]],"256":[[0,3330420000000],[0,3331670000000],[0,3333000000000],[0,3341125000000]],"1536":[[0,112750000000000],[0,112895833333333],[0,113958000000000],[0,116027777777777]],"64":[[0,333343750000],[0,334160000000],[0,334160000000],[0,334160000000]],"320":[[0,5064115384615],[0,5065420000000],[0,5071660000000],[0,5745830000000]],"114688":[[0,864847917000000000],[0,865456917000000000],[0,903782250000000000]],"131072":[[0,1128955166000000000],[0,1129494125000000000],[0,1149837209000000000]],"16384":[[0,12338583500000000],[0,12375583000000000],[0,12418375000000000],[0,12427750000000000]],"5120":[[0,1192531250000000],[0,1193302125000000],[0,1203542000000000],[0,1227625000000000]],"5":[[0,56250000000],[0,56250000000],[0,56660000000],[0,57080000000]],"10":[[0,74580000000],[0,74580000000],[0,74580000000],[0,74625000000]],"28":[[0,135000000000],[0,135000000000],[0,135000000000],[0,135000000000]],"7168":[[0,2327489750000000],[0,2341833000000000],[0,2346468750000000],[0,2401573000000000]],"20480":[[0,21960062500000000],[0,22046771000000000],[0,22048625000000000],[0,22133125000000000]],"65536":[[0,277559646000000000],[0,277747458500000000],[0,280174562500000000],[0,280537167000000000]],"160":[[0,1391250000000],[0,1391250000000],[0,1392080000000],[0,1392500000000]],"640":[[0,19069333333333],[0,19099590000000],[0,19930830000000],[0,20180420000000]],"40":[[0,197910000000],[0,197910000000],[0,198750000000],[0,199160000000]],"57344":[[0,211575583500000000],[0,211977917000000000],[0,213069875000000000],[0,213253729500000000]],"4":[[0,52080000000],[0,52080000000],[0,52500000000],[0,52500000000]],"1":[[0,41600000000],[0,43330000000],[0,43330000000],[0,43330000000]],"768":[[0,27165224137931],[0,27331983870967],[0,29331660000000],[0,31839285714285]],"448":[[0,9610830000000],[0,9611000000000],[0,9621670000000],[0,9630000000000]],"8192":[[0,3056083333333333],[0,3059180666666666],[0,3073319333333333],[0,3135416000000000]],"12":[[0,80840000000],[0,81250000000],[0,81250000000],[0,81250000000]],"10240":[[0,4772770500000000],[0,4806541500000000],[0,4852500000000000],[0,4954625000000000]],"14336":[[0,9301958000000000],[0,9329833000000000],[0,9445500000000000],[0,9768020500000000]],"32768":[[0,65524437500000000],[0,65573333000000000],[0,65680479000000000],[0,66692542000000000]],"128":[[0,941600000000],[0,944160000000],[0,944160000000],[0,944160000000]],"4096":[[0,752917000000000],[0,760673076923076],[0,774288166666666],[0,779899333333333]],"49152":[[0,154179375000000000],[0,154376125000000000],[0,155114167000000000],[0,155484000000000000]],"3":[[0,47642857142],[0,47910000000],[0,48330000000],[0,48330000000]],"98304":[[0,632908500000000000],[0,633085917000000000],[0,634985209000000000],[0,639984292000000000]]}},{"title":"Deque random insertions","results":{"2048":[[0,77542000000000],[0,78167000000000],[0,78334000000000],[0,79708000000000]],"96":[[0,2042000000000],[0,2084000000000],[0,2208000000000],[0,2209000000000]],"327680":[[0,1799383041000000000],[0,1815287167000000000]],"384":[[0,7667000000000],[0,7750000000000],[0,9000000000000],[0,11500000000000]],"12288":[[0,1860750000000000],[0,1885708000000000],[0,1886375000000000],[0,2168417000000000]],"81920":[[0,104147750000000000],[0,104342875000000000],[0,104529458000000000],[0,104856792000000000]],"8":[[0,333000000000],[0,334000000000],[0,375000000000],[0,375000000000]],"1280":[[0,38500000000000],[0,39208000000000],[0,40042000000000],[0,40084000000000]],"3584":[[0,191875000000000],[0,194209000000000],[0,195541000000000],[0,196708000000000]],"7":[[0,333000000000],[0,334000000000],[0,375000000000],[0,500000000000]],"524288":[[0,4572937708000000000],[0,4594848375000000000]],"112":[[0,2333000000000],[0,2375000000000],[0,2417000000000],[0,2750000000000]],"896":[[0,23334000000000],[0,23583000000000],[0,24500000000000],[0,25167000000000]],"192":[[0,3625000000000],[0,3666000000000],[0,3750000000000],[0,3750000000000]],"80":[[0,1792000000000],[0,1833000000000],[0,1875000000000],[0,1958000000000]],"24":[[0,791000000000],[0,833000000000],[0,834000000000],[0,875000000000]],"40960":[[0,23036041000000000],[0,23351291000000000],[0,23355250000000000],[0,25114459000000000]],"16":[[0,584000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"3072":[[0,150625000000000],[0,150667000000000],[0,152459000000000],[0,152834000000000]],"20":[[0,666000000000],[0,667000000000],[0,667000000000],[0,667000000000]],"224":[[0,4166000000000],[0,4291000000000],[0,4292000000000],[0,4792000000000]],"2560":[[0,110459000000000],[0,110917000000000],[0,111584000000000],[0,112916000000000]],"1792":[[0,63042000000000],[0,63417000000000],[0,64417000000000],[0,64417000000000]],"1024":[[0,28250000000000],[0,28625000000000],[0,28625000000000],[0,30209000000000]],"6144":[[0,503125000000000],[0,503167000000000],[0,505250000000000],[0,511125000000000]],"56":[[0,1292000000000],[0,1292000000000],[0,1375000000000],[0,1416000000000]],"163840":[[0,437246875000000000],[0,437837667000000000],[0,447756125000000000]],"6":[[0,333000000000],[0,334000000000],[0,375000000000],[0,375000000000]],"48":[[0,1167000000000],[0,1167000000000],[0,1250000000000],[0,1292000000000]],"32":[[0,917000000000],[0,917000000000],[0,917000000000],[0,917000000000]],"14":[[0,500000000000],[0,500000000000],[0,500000000000],[0,541000000000]],"28672":[[0,10520542000000000],[0,10545709000000000],[0,10592250000000000],[0,10597208000000000]],"512":[[0,10833000000000],[0,11125000000000],[0,11125000000000],[0,11166000000000]],"196608":[[0,637178167000000000],[0,639957417000000000],[0,640568208000000000]],"458752":[[0,3516831833000000000],[0,3545877833000000000]],"24576":[[0,7439292000000000],[0,7520167000000000],[0,7643167000000000],[0,7651959000000000]],"2":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"256":[[0,4833000000000],[0,4875000000000],[0,4875000000000],[0,5125000000000]],"1536":[[0,50208000000000],[0,50542000000000],[0,50584000000000],[0,51500000000000]],"64":[[0,1541000000000],[0,1542000000000],[0,1625000000000],[0,1708000000000]],"320":[[0,6208000000000],[0,6542000000000],[0,7000000000000],[0,8667000000000]],"114688":[[0,210441041000000000],[0,211379041000000000],[0,213083625000000000]],"131072":[[0,277890625000000000],[0,278134458000000000],[0,291486167000000000]],"16384":[[0,3226083000000000],[0,3241834000000000],[0,3283959000000000],[0,3301958000000000]],"5120":[[0,364542000000000],[0,367000000000000],[0,367708000000000],[0,371042000000000]],"229376":[[0,865471083000000000],[0,870728417000000000],[0,885183000000000000]],"5":[[0,208000000000],[0,209000000000],[0,250000000000],[0,292000000000]],"10":[[0,417000000000],[0,458000000000],[0,500000000000],[0,500000000000]],"28":[[0,833000000000],[0,834000000000],[0,875000000000],[0,875000000000]],"655360":[[0,7273490375000000000],[0,7344989083000000000]],"7168":[[0,678166000000000],[0,682041000000000],[0,683458000000000],[0,688958000000000]],"20480":[[0,5115166000000000],[0,5120417000000000],[0,5147209000000000],[0,5182709000000000]],"65536":[[0,64126708000000000],[0,64738541000000000],[0,65089709000000000],[0,65580541000000000]],"160":[[0,3208000000000],[0,3292000000000],[0,3417000000000],[0,3666000000000]],"640":[[0,14584000000000],[0,14916000000000],[0,14959000000000],[0,15125000000000]],"40":[[0,1084000000000],[0,1125000000000],[0,1167000000000],[0,1209000000000]],"393216":[[0,2577692417000000000],[0,2586244125000000000]],"57344":[[0,47996416000000000],[0,48304875000000000],[0,48539834000000000],[0,48911750000000000]],"4":[[0,208000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"768":[[0,18750000000000],[0,18875000000000],[0,19250000000000],[0,19375000000000]],"448":[[0,9417000000000],[0,9458000000000],[0,9500000000000],[0,12875000000000]],"8192":[[0,866583000000000],[0,867250000000000],[0,867959000000000],[0,877041000000000]],"12":[[0,458000000000],[0,500000000000],[0,500000000000],[0,500000000000]],"10240":[[0,1312916000000000],[0,1317125000000000],[0,1325959000000000],[0,1330250000000000]],"14336":[[0,2503542000000000],[0,2510166000000000],[0,2539292000000000],[0,2546625000000000]],"32768":[[0,13945250000000000],[0,14049333000000000],[0,14163542000000000],[0,14237750000000000]],"128":[[0,2500000000000],[0,2583000000000],[0,2625000000000],[0,2667000000000]],"4096":[[0,245375000000000],[0,245708000000000],[0,245875000000000],[0,248584000000000]],"49152":[[0,34565167000000000],[0,34734750000000000],[0,35037209000000000],[0,36129459000000000]],"262144":[[0,1140667500000000000],[0,1142460833000000000],[0,1148025750000000000]],"3":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"98304":[[0,152794084000000000],[0,153238041000000000],[0,154277416000000000],[0,155675167000000000]]}},{"title":"Array random insertions","results":{"2048":[[0,96375000000000],[0,99459000000000],[0,100042000000000],[0,101834000000000]],"96":[[0,833000000000],[0,833000000000],[0,875000000000],[0,1042000000000]],"327680":[[0,3563127708000000000],[0,3621825625000000000]],"384":[[0,5250000000000],[0,5625000000000],[0,6208000000000],[0,7917000000000]],"12288":[[0,3504583000000000],[0,3507875000000000],[0,3529792000000000],[0,3622333000000000]],"81920":[[0,211884958000000000],[0,212494167000000000],[0,212638750000000000],[0,213024166000000000]],"8":[[0,125000000000],[0,167000000000],[0,167000000000],[0,167000000000]],"1280":[[0,41542000000000],[0,42458000000000],[0,43250000000000],[0,43375000000000]],"3584":[[0,296958000000000],[0,299875000000000],[0,304917000000000],[0,309417000000000]],"7":[[0,125000000000],[0,167000000000],[0,167000000000],[0,208000000000]],"112":[[0,917000000000],[0,917000000000],[0,958000000000],[0,1167000000000]],"896":[[0,21833000000000],[0,21834000000000],[0,21916000000000],[0,22000000000000]],"192":[[0,1750000000000],[0,1833000000000],[0,1833000000000],[0,1875000000000]],"80":[[0,708000000000],[0,709000000000],[0,750000000000],[0,792000000000]],"24":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"40960":[[0,47772000000000000],[0,47966750000000000],[0,48324333000000000],[0,49109500000000000]],"16":[[0,208000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"3072":[[0,222916000000000],[0,224833000000000],[0,226375000000000],[0,235792000000000]],"20":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"224":[[0,2250000000000],[0,2291000000000],[0,2291000000000],[0,2666000000000]],"2560":[[0,156125000000000],[0,156875000000000],[0,158666000000000],[0,160250000000000]],"1792":[[0,76541000000000],[0,77166000000000],[0,77875000000000],[0,78750000000000]],"1024":[[0,27167000000000],[0,27208000000000],[0,28000000000000],[0,29209000000000]],"6144":[[0,878833000000000],[0,886625000000000],[0,895625000000000],[0,917750000000000]],"56":[[0,500000000000],[0,500000000000],[0,541000000000],[0,542000000000]],"163840":[[0,874514916000000000],[0,878311667000000000],[0,900940417000000000]],"6":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"48":[[0,458000000000],[0,459000000000],[0,500000000000],[0,500000000000]],"32":[[0,333000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"14":[[0,208000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"28672":[[0,21473500000000000],[0,21501667000000000],[0,21509666000000000],[0,21660750000000000]],"512":[[0,8333000000000],[0,8417000000000],[0,8667000000000],[0,8958000000000]],"196608":[[0,1253092250000000000],[0,1267524792000000000],[0,1315321208000000000]],"24576":[[0,14999333000000000],[0,15094667000000000],[0,15190792000000000],[0,15406792000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,2750000000000],[0,2750000000000],[0,2792000000000],[0,2792000000000]],"1536":[[0,56041000000000],[0,58000000000000],[0,58792000000000],[0,58959000000000]],"64":[[0,541000000000],[0,542000000000],[0,542000000000],[0,583000000000]],"320":[[0,3917000000000],[0,4208000000000],[0,4209000000000],[0,4583000000000]],"114688":[[0,423671542000000000],[0,426929583000000000],[0,434068000000000000]],"131072":[[0,555018417000000000],[0,556340416000000000],[0,566469250000000000]],"16384":[[0,6235042000000000],[0,6241750000000000],[0,6253708000000000],[0,6313834000000000]],"5120":[[0,611792000000000],[0,614667000000000],[0,624042000000000],[0,624084000000000]],"229376":[[0,1732770042000000000],[0,1739194167000000000],[0,1762526542000000000]],"5":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"10":[[0,208000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"28":[[0,333000000000],[0,333000000000],[0,333000000000],[0,333000000000]],"7168":[[0,1193041000000000],[0,1200791000000000],[0,1221084000000000],[0,1227625000000000]],"20480":[[0,10007875000000000],[0,10046458000000000],[0,10078042000000000],[0,10138708000000000]],"65536":[[0,131969666000000000],[0,132293042000000000],[0,132363583000000000],[0,134061416000000000]],"160":[[0,1459000000000],[0,1542000000000],[0,1542000000000],[0,1708000000000]],"640":[[0,12375000000000],[0,12500000000000],[0,12625000000000],[0,12834000000000]],"40":[[0,416000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"57344":[[0,99751542000000000],[0,99785917000000000],[0,100114000000000000],[0,100410333000000000]],"4":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"768":[[0,16791000000000],[0,16958000000000],[0,17042000000000],[0,17084000000000]],"448":[[0,6792000000000],[0,6875000000000],[0,6958000000000],[0,7750000000000]],"8192":[[0,1548667000000000],[0,1550875000000000],[0,1559708000000000],[0,1567167000000000]],"12":[[0,208000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"10240":[[0,2442209000000000],[0,2448292000000000],[0,2460917000000000],[0,2491541000000000]],"14336":[[0,4700583000000000],[0,4727458000000000],[0,4732625000000000],[0,4802125000000000]],"32768":[[0,29065541000000000],[0,29083208000000000],[0,29388833000000000],[0,29620334000000000]],"128":[[0,1042000000000],[0,1083000000000],[0,1084000000000],[0,1125000000000]],"4096":[[0,391292000000000],[0,399291000000000],[0,400292000000000],[0,400792000000000]],"49152":[[0,71369125000000000],[0,71795250000000000],[0,72075750000000000],[0,75652750000000000]],"262144":[[0,2264100416000000000],[0,2291629375000000000],[0,2305592875000000000]],"3":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"98304":[[0,307726959000000000],[0,308725708000000000],[0,311906209000000000],[0,315174958000000000]]}},{"title":"Array removeFirst","results":{"2048":[[0,186292000000000],[0,186334000000000],[0,186458000000000],[0,189750000000000]],"96":[[0,750000000000],[0,750000000000],[0,792000000000],[0,1041000000000]],"384":[[0,7583000000000],[0,7583000000000],[0,7625000000000],[0,7625000000000]],"12288":[[0,6817541000000000],[0,6832834000000000],[0,6965834000000000],[0,7268416000000000]],"81920":[[0,436868291000000000],[0,437877166000000000],[0,439169333000000000],[0,442099209000000000]],"8":[[0,41000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"1280":[[0,74209000000000],[0,74417000000000],[0,74584000000000],[0,77916000000000]],"3584":[[0,576375000000000],[0,576542000000000],[0,576625000000000],[0,577584000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"112":[[0,916000000000],[0,917000000000],[0,958000000000],[0,1125000000000]],"896":[[0,37375000000000],[0,37375000000000],[0,37417000000000],[0,37584000000000]],"192":[[0,2250000000000],[0,2250000000000],[0,2292000000000],[0,2292000000000]],"80":[[0,541000000000],[0,542000000000],[0,542000000000],[0,584000000000]],"24":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"40960":[[0,105067375000000000],[0,105143208000000000],[0,105212416000000000],[0,107461500000000000]],"16":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"3072":[[0,423958000000000],[0,424167000000000],[0,424542000000000],[0,424875000000000]],"20":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"224":[[0,2917000000000],[0,2959000000000],[0,2959000000000],[0,3000000000000]],"2560":[[0,293875000000000],[0,293916000000000],[0,294083000000000],[0,305500000000000]],"1792":[[0,143209000000000],[0,143375000000000],[0,143375000000000],[0,143500000000000]],"1024":[[0,48125000000000],[0,48166000000000],[0,50500000000000],[0,51791000000000]],"6144":[[0,1696000000000000],[0,1696000000000000],[0,1696125000000000],[0,1698625000000000]],"56":[[0,292000000000],[0,333000000000],[0,333000000000],[0,334000000000]],"163840":[[0,1766937291000000000],[0,1777288625000000000],[0,1792210792000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"32":[[0,125000000000],[0,166000000000],[0,166000000000],[0,167000000000]],"14":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"28672":[[0,48356792000000000],[0,49136000000000000],[0,49556708000000000],[0,49558958000000000]],"512":[[0,12917000000000],[0,12958000000000],[0,12958000000000],[0,12959000000000]],"24576":[[0,33876875000000000],[0,33895750000000000],[0,33918166000000000],[0,34052625000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,3709000000000],[0,3750000000000],[0,3792000000000],[0,3792000000000]],"1536":[[0,108208000000000],[0,110708000000000],[0,111000000000000],[0,111708000000000]],"64":[[0,375000000000],[0,375000000000],[0,375000000000],[0,458000000000]],"320":[[0,5500000000000],[0,5541000000000],[0,5833000000000],[0,6292000000000]],"114688":[[0,864377708000000000],[0,868022541000000000],[0,879795417000000000]],"131072":[[0,1124339916000000000],[0,1131278583000000000],[0,1176903250000000000]],"16384":[[0,12283625000000000],[0,12336333000000000],[0,12344333000000000],[0,12394292000000000]],"5120":[[0,1178750000000000],[0,1178833000000000],[0,1182083000000000],[0,1203542000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"7168":[[0,2315334000000000],[0,2323708000000000],[0,2324500000000000],[0,2337334000000000]],"20480":[[0,21618750000000000],[0,21742041000000000],[0,21777875000000000],[0,21789167000000000]],"65536":[[0,278570792000000000],[0,278652334000000000],[0,278937875000000000],[0,279806167000000000]],"160":[[0,1667000000000],[0,1667000000000],[0,1750000000000],[0,1917000000000]],"640":[[0,19708000000000],[0,19709000000000],[0,19833000000000],[0,19917000000000]],"40":[[0,166000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"57344":[[0,211588084000000000],[0,211860333000000000],[0,212847500000000000],[0,212972333000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,28000000000000],[0,29875000000000],[0,30000000000000],[0,30083000000000]],"448":[[0,10042000000000],[0,10083000000000],[0,10084000000000],[0,14334000000000]],"8192":[[0,3022750000000000],[0,3034417000000000],[0,3035125000000000],[0,3089834000000000]],"12":[[0,42000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"10240":[[0,4730666000000000],[0,4730916000000000],[0,4750667000000000],[0,4900792000000000]],"14336":[[0,9293083000000000],[0,9297083000000000],[0,9318417000000000],[0,9369584000000000]],"32768":[[0,64943541000000000],[0,64956375000000000],[0,64971708000000000],[0,66360375000000000]],"128":[[0,1125000000000],[0,1167000000000],[0,1167000000000],[0,1209000000000]],"4096":[[0,751833000000000],[0,751875000000000],[0,751917000000000],[0,752666000000000]],"49152":[[0,152998084000000000],[0,153553916000000000],[0,153691000000000000],[0,158358208000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,632928959000000000],[0,634819000000000000],[0,639937292000000000],[0,646272041000000000]]}},{"title":"Array removeLast","results":{"2048":[[0,3667000000000],[0,3708000000000],[0,3708000000000],[0,3708000000000]],"1048576":[[0,1914875000000000],[0,1934667000000000]],"96":[[0,166000000000],[0,166000000000],[0,208000000000],[0,250000000000]],"327680":[[0,594458000000000],[0,601333000000000]],"384":[[0,667000000000],[0,667000000000],[0,708000000000],[0,708000000000]],"12288":[[0,22209000000000],[0,22250000000000],[0,22250000000000],[0,25250000000000]],"81920":[[0,148542000000000],[0,148542000000000],[0,148666000000000],[0,148667000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2292000000000],[0,2333000000000],[0,2333000000000],[0,2416000000000]],"3584":[[0,6458000000000],[0,6458000000000],[0,6459000000000],[0,6459000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,963042000000000],[0,964333000000000]],"112":[[0,167000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"896":[[0,1625000000000],[0,1625000000000],[0,1625000000000],[0,1625000000000]],"192":[[0,333000000000],[0,333000000000],[0,333000000000],[0,334000000000]],"80":[[0,125000000000],[0,125000000000],[0,166000000000],[0,167000000000]],"24":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"40960":[[0,74209000000000],[0,74292000000000],[0,74292000000000],[0,77792000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,5500000000000],[0,5541000000000],[0,5583000000000],[0,5583000000000]],"20":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"224":[[0,375000000000],[0,416000000000],[0,416000000000],[0,417000000000]],"2560":[[0,4625000000000],[0,4625000000000],[0,4625000000000],[0,4625000000000]],"1792":[[0,3209000000000],[0,3250000000000],[0,3250000000000],[0,3250000000000]],"1024":[[0,1834000000000],[0,1875000000000],[0,1875000000000],[0,1916000000000]],"6144":[[0,11125000000000],[0,11125000000000],[0,11125000000000],[0,11125000000000]],"56":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1441541000000000],[0,1450375000000000]],"163840":[[0,297208000000000],[0,297209000000000],[0,305709000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28672":[[0,51917000000000],[0,51959000000000],[0,52000000000000],[0,52000000000000]],"512":[[0,916000000000],[0,916000000000],[0,916000000000],[0,916000000000]],"196608":[[0,356542000000000],[0,356833000000000],[0,360750000000000]],"458752":[[0,885291000000000],[0,909709000000000]],"24576":[[0,44542000000000],[0,44583000000000],[0,44583000000000],[0,48375000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2750000000000],[0,2791000000000],[0,2791000000000],[0,2792000000000]],"64":[[0,84000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,542000000000],[0,583000000000],[0,583000000000],[0,666000000000]],"114688":[[0,208083000000000],[0,211959000000000],[0,225000000000000]],"131072":[[0,237708000000000],[0,237750000000000],[0,237750000000000]],"16384":[[0,29708000000000],[0,29708000000000],[0,29875000000000],[0,32208000000000]],"5120":[[0,9250000000000],[0,9250000000000],[0,9250000000000],[0,9291000000000]],"229376":[[0,416042000000000],[0,416042000000000],[0,422250000000000]],"5":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1205834000000000],[0,1211417000000000]],"7168":[[0,12958000000000],[0,13000000000000],[0,13000000000000],[0,14041000000000]],"20480":[[0,37125000000000],[0,37125000000000],[0,37166000000000],[0,37166000000000]],"65536":[[0,118792000000000],[0,118833000000000],[0,118875000000000],[0,119000000000000]],"917504":[[0,1664083000000000],[0,1681250000000000]],"160":[[0,291000000000],[0,291000000000],[0,292000000000],[0,292000000000]],"640":[[0,1125000000000],[0,1166000000000],[0,1208000000000],[0,1250000000000]],"40":[[0,41000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"393216":[[0,713084000000000],[0,762458000000000]],"57344":[[0,103958000000000],[0,104041000000000],[0,104083000000000],[0,109000000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,1375000000000],[0,1375000000000],[0,1375000000000],[0,1791000000000]],"448":[[0,791000000000],[0,791000000000],[0,791000000000],[0,1042000000000]],"8192":[[0,14833000000000],[0,14833000000000],[0,14834000000000],[0,14875000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,18541000000000],[0,18542000000000],[0,18542000000000],[0,18583000000000]],"14336":[[0,25917000000000],[0,26000000000000],[0,26000000000000],[0,26084000000000]],"32768":[[0,59375000000000],[0,59500000000000],[0,59625000000000],[0,64459000000000]],"128":[[0,208000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"4096":[[0,7375000000000],[0,7416000000000],[0,7417000000000],[0,8042000000000]],"49152":[[0,89042000000000],[0,89125000000000],[0,89125000000000],[0,89167000000000]],"262144":[[0,475500000000000],[0,490125000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,178250000000000],[0,178333000000000],[0,181583000000000],[0,202416000000000]]}},{"title":"Deque random removals (contiguous)","results":{"2048":[[0,67209000000000],[0,67542000000000],[0,67708000000000],[0,72125000000000]],"96":[[0,917000000000],[0,958000000000],[0,1000000000000],[0,1292000000000]],"327680":[[0,1796300667000000000],[0,1807783167000000000]],"384":[[0,5792000000000],[0,5833000000000],[0,5875000000000],[0,6333000000000]],"12288":[[0,1805292000000000],[0,1814917000000000],[0,1818833000000000],[0,1838250000000000]],"81920":[[0,102879667000000000],[0,103801875000000000],[0,103823291000000000],[0,106182542000000000]],"8":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"1280":[[0,31208000000000],[0,31958000000000],[0,32875000000000],[0,33750000000000]],"3584":[[0,173791000000000],[0,176875000000000],[0,178292000000000],[0,178459000000000]],"7":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"524288":[[0,4540974334000000000],[0,4614357583000000000]],"112":[[0,1125000000000],[0,1125000000000],[0,1167000000000],[0,1250000000000]],"896":[[0,18417000000000],[0,18458000000000],[0,18792000000000],[0,19417000000000]],"192":[[0,2125000000000],[0,2166000000000],[0,2167000000000],[0,2209000000000]],"80":[[0,792000000000],[0,792000000000],[0,833000000000],[0,875000000000]],"24":[[0,209000000000],[0,209000000000],[0,209000000000],[0,250000000000]],"40960":[[0,22933041000000000],[0,23022750000000000],[0,23441458000000000],[0,23847750000000000]],"16":[[0,166000000000],[0,166000000000],[0,208000000000],[0,209000000000]],"3072":[[0,136041000000000],[0,137500000000000],[0,138500000000000],[0,148125000000000]],"20":[[0,166000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"224":[[0,2542000000000],[0,2625000000000],[0,2625000000000],[0,2792000000000]],"2560":[[0,99500000000000],[0,99833000000000],[0,100250000000000],[0,100584000000000]],"1792":[[0,53166000000000],[0,53667000000000],[0,54375000000000],[0,54959000000000]],"1024":[[0,22584000000000],[0,22709000000000],[0,23000000000000],[0,23750000000000]],"6144":[[0,478875000000000],[0,480250000000000],[0,485167000000000],[0,488458000000000]],"56":[[0,542000000000],[0,542000000000],[0,584000000000],[0,750000000000]],"163840":[[0,435658791000000000],[0,438935958000000000],[0,440537375000000000]],"6":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"48":[[0,458000000000],[0,458000000000],[0,459000000000],[0,459000000000]],"32":[[0,291000000000],[0,292000000000],[0,292000000000],[0,333000000000]],"14":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"28672":[[0,10392792000000000],[0,10432625000000000],[0,10543250000000000],[0,10609792000000000]],"512":[[0,8084000000000],[0,8125000000000],[0,8625000000000],[0,8750000000000]],"196608":[[0,625336792000000000],[0,633694083000000000],[0,642442417000000000]],"458752":[[0,3510720792000000000],[0,3531612541000000000]],"24576":[[0,7427750000000000],[0,7499333000000000],[0,7538916000000000],[0,7591792000000000]],"2":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,3125000000000],[0,3125000000000],[0,3166000000000],[0,3208000000000]],"1536":[[0,41583000000000],[0,41667000000000],[0,41750000000000],[0,41958000000000]],"64":[[0,583000000000],[0,583000000000],[0,625000000000],[0,666000000000]],"320":[[0,4375000000000],[0,4500000000000],[0,4667000000000],[0,5041000000000]],"114688":[[0,208903541000000000],[0,208910041000000000],[0,211485417000000000]],"131072":[[0,276030416000000000],[0,276282583000000000],[0,279459834000000000]],"16384":[[0,3186250000000000],[0,3198167000000000],[0,3213375000000000],[0,3272083000000000]],"5120":[[0,342083000000000],[0,346541000000000],[0,346666000000000],[0,355000000000000]],"229376":[[0,862069916000000000],[0,873240833000000000],[0,882546209000000000]],"5":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"10":[[0,84000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"28":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"655360":[[0,7222284042000000000],[0,7250690125000000000]],"7168":[[0,647208000000000],[0,651542000000000],[0,654333000000000],[0,663166000000000]],"20480":[[0,5009167000000000],[0,5028541000000000],[0,5033417000000000],[0,5119166000000000]],"65536":[[0,64466875000000000],[0,64737875000000000],[0,64856500000000000],[0,64911834000000000]],"160":[[0,1791000000000],[0,1791000000000],[0,1833000000000],[0,3709000000000]],"640":[[0,11042000000000],[0,11417000000000],[0,11459000000000],[0,11625000000000]],"40":[[0,333000000000],[0,375000000000],[0,375000000000],[0,417000000000]],"393216":[[0,2583790667000000000],[0,2590543417000000000]],"57344":[[0,47866667000000000],[0,47923958000000000],[0,48151042000000000],[0,48400333000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,14584000000000],[0,14584000000000],[0,14875000000000],[0,14958000000000]],"448":[[0,6583000000000],[0,7000000000000],[0,7083000000000],[0,7334000000000]],"8192":[[0,825833000000000],[0,826000000000000],[0,830625000000000],[0,835292000000000]],"12":[[0,83000000000],[0,84000000000],[0,125000000000],[0,125000000000]],"10240":[[0,1288542000000000],[0,1294375000000000],[0,1303583000000000],[0,1318583000000000]],"14336":[[0,2470625000000000],[0,2490542000000000],[0,2521750000000000],[0,2537917000000000]],"32768":[[0,13858959000000000],[0,13945292000000000],[0,14076041000000000],[0,14225917000000000]],"128":[[0,1292000000000],[0,1292000000000],[0,1333000000000],[0,1417000000000]],"4096":[[0,221833000000000],[0,222208000000000],[0,223167000000000],[0,235042000000000]],"49152":[[0,34212333000000000],[0,34225583000000000],[0,34759459000000000],[0,35141667000000000]],"262144":[[0,1131187000000000000],[0,1147657041000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,152015834000000000],[0,153186583000000000],[0,153503500000000000],[0,153839042000000000]]}},{"title":"Deque random removals (discontiguous)","results":{"2048":[[0,70583000000000],[0,71125000000000],[0,71875000000000],[0,80292000000000]],"96":[[0,1000000000000],[0,1042000000000],[0,1125000000000],[0,1375000000000]],"327680":[[0,1789362125000000000],[0,1803995833000000000]],"384":[[0,6000000000000],[0,6084000000000],[0,6209000000000],[0,6291000000000]],"12288":[[0,1840416000000000],[0,1843917000000000],[0,1863125000000000],[0,1867250000000000]],"81920":[[0,103387625000000000],[0,103953541000000000],[0,104688042000000000],[0,108450709000000000]],"8":[[0,83000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"1280":[[0,33250000000000],[0,34084000000000],[0,34500000000000],[0,34917000000000]],"3584":[[0,183083000000000],[0,186375000000000],[0,186417000000000],[0,186959000000000]],"7":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"524288":[[0,4563766625000000000],[0,4610543917000000000]],"112":[[0,1209000000000],[0,1250000000000],[0,1250000000000],[0,1458000000000]],"896":[[0,19292000000000],[0,19333000000000],[0,20000000000000],[0,25250000000000]],"192":[[0,2250000000000],[0,2250000000000],[0,2292000000000],[0,2292000000000]],"80":[[0,833000000000],[0,875000000000],[0,875000000000],[0,917000000000]],"24":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"40960":[[0,23035500000000000],[0,23296000000000000],[0,23321375000000000],[0,23725375000000000]],"16":[[0,125000000000],[0,125000000000],[0,166000000000],[0,250000000000]],"3072":[[0,140791000000000],[0,141417000000000],[0,143417000000000],[0,143875000000000]],"20":[[0,167000000000],[0,208000000000],[0,209000000000],[0,250000000000]],"224":[[0,2791000000000],[0,2792000000000],[0,2833000000000],[0,2875000000000]],"2560":[[0,102292000000000],[0,103084000000000],[0,103166000000000],[0,103209000000000]],"1792":[[0,55833000000000],[0,56875000000000],[0,57250000000000],[0,57416000000000]],"1024":[[0,24000000000000],[0,24333000000000],[0,24709000000000],[0,25417000000000]],"6144":[[0,487625000000000],[0,487875000000000],[0,495209000000000],[0,497292000000000]],"56":[[0,583000000000],[0,625000000000],[0,625000000000],[0,708000000000]],"163840":[[0,435343083000000000],[0,439994166000000000],[0,440677166000000000]],"6":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"48":[[0,500000000000],[0,500000000000],[0,500000000000],[0,541000000000]],"32":[[0,333000000000],[0,334000000000],[0,375000000000],[0,375000000000]],"14":[[0,125000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"28672":[[0,10487125000000000],[0,10500250000000000],[0,10521958000000000],[0,10630792000000000]],"512":[[0,8125000000000],[0,8166000000000],[0,8250000000000],[0,9667000000000]],"196608":[[0,630806333000000000],[0,635012375000000000],[0,652094958000000000]],"458752":[[0,3525657542000000000],[0,3529456125000000000]],"24576":[[0,7444500000000000],[0,7507250000000000],[0,7599292000000000],[0,7717459000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"256":[[0,3292000000000],[0,3292000000000],[0,3375000000000],[0,3459000000000]],"1536":[[0,44041000000000],[0,44250000000000],[0,44333000000000],[0,44500000000000]],"64":[[0,625000000000],[0,667000000000],[0,667000000000],[0,708000000000]],"320":[[0,4709000000000],[0,4875000000000],[0,4875000000000],[0,5375000000000]],"114688":[[0,208421084000000000],[0,210266250000000000],[0,211433042000000000]],"131072":[[0,274901584000000000],[0,275627958000000000],[0,281188250000000000]],"16384":[[0,3219375000000000],[0,3230958000000000],[0,3239667000000000],[0,3251750000000000]],"5120":[[0,348583000000000],[0,352167000000000],[0,352375000000000],[0,353416000000000]],"229376":[[0,868196666000000000],[0,871868625000000000],[0,874626083000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"28":[[0,250000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"655360":[[0,7202242000000000000],[0,7249707041000000000]],"7168":[[0,649041000000000],[0,653583000000000],[0,658125000000000],[0,665958000000000]],"20480":[[0,5062333000000000],[0,5095291000000000],[0,5111375000000000],[0,5154375000000000]],"65536":[[0,64346250000000000],[0,64677666000000000],[0,64708041000000000],[0,65053000000000000]],"160":[[0,1875000000000],[0,1917000000000],[0,2625000000000],[0,4042000000000]],"640":[[0,11333000000000],[0,11667000000000],[0,11750000000000],[0,12000000000000]],"40":[[0,416000000000],[0,417000000000],[0,417000000000],[0,458000000000]],"393216":[[0,2574145375000000000],[0,2589748875000000000]],"57344":[[0,48031333000000000],[0,48073000000000000],[0,48336291000000000],[0,48368792000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,15125000000000],[0,15375000000000],[0,15458000000000],[0,15666000000000]],"448":[[0,6959000000000],[0,7125000000000],[0,7458000000000],[0,7583000000000]],"8192":[[0,833625000000000],[0,833875000000000],[0,852250000000000],[0,855084000000000]],"12":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"10240":[[0,1291333000000000],[0,1300209000000000],[0,1315542000000000],[0,1317375000000000]],"14336":[[0,2487875000000000],[0,2488833000000000],[0,2497417000000000],[0,2510584000000000]],"32768":[[0,13996167000000000],[0,14065208000000000],[0,14127583000000000],[0,14207541000000000]],"128":[[0,1417000000000],[0,1417000000000],[0,1417000000000],[0,1458000000000]],"4096":[[0,236666000000000],[0,236917000000000],[0,237250000000000],[0,237416000000000]],"49152":[[0,34557583000000000],[0,34576042000000000],[0,34934042000000000],[0,34978292000000000]],"262144":[[0,1133198125000000000],[0,1158030500000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"98304":[[0,151353000000000000],[0,153338250000000000],[0,154086333000000000]]}},{"title":"Array random removals","results":{"2048":[[0,100458000000000],[0,101125000000000],[0,102792000000000],[0,122000000000000]],"96":[[0,500000000000],[0,500000000000],[0,542000000000],[0,542000000000]],"327680":[[0,3559716167000000000],[0,3565444500000000000]],"384":[[0,4542000000000],[0,4875000000000],[0,5125000000000],[0,5125000000000]],"12288":[[0,3447000000000000],[0,3462833000000000],[0,3562792000000000],[0,3619334000000000]],"81920":[[0,209812125000000000],[0,210154916000000000],[0,211326666000000000],[0,212324083000000000]],"8":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"1280":[[0,43500000000000],[0,44625000000000],[0,45042000000000],[0,46250000000000]],"3584":[[0,292792000000000],[0,298500000000000],[0,298750000000000],[0,299166000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"112":[[0,583000000000],[0,583000000000],[0,625000000000],[0,708000000000]],"896":[[0,20667000000000],[0,20791000000000],[0,20875000000000],[0,22458000000000]],"192":[[0,1375000000000],[0,1458000000000],[0,1459000000000],[0,1542000000000]],"80":[[0,416000000000],[0,417000000000],[0,417000000000],[0,458000000000]],"24":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"40960":[[0,47248709000000000],[0,47435292000000000],[0,47686542000000000],[0,47871292000000000]],"16":[[0,42000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"3072":[[0,222833000000000],[0,224417000000000],[0,225083000000000],[0,230167000000000]],"20":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"224":[[0,1875000000000],[0,1875000000000],[0,1917000000000],[0,1958000000000]],"2560":[[0,155708000000000],[0,156917000000000],[0,158334000000000],[0,160417000000000]],"1792":[[0,73625000000000],[0,74500000000000],[0,75167000000000],[0,75917000000000]],"1024":[[0,25917000000000],[0,25917000000000],[0,26625000000000],[0,27416000000000]],"6144":[[0,866875000000000],[0,872000000000000],[0,879458000000000],[0,897041000000000]],"56":[[0,250000000000],[0,291000000000],[0,291000000000],[0,292000000000]],"163840":[[0,877871042000000000],[0,883954125000000000],[0,906897250000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,208000000000],[0,209000000000],[0,250000000000],[0,250000000000]],"32":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"14":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28672":[[0,21064334000000000],[0,21143958000000000],[0,21162375000000000],[0,21607125000000000]],"512":[[0,7416000000000],[0,7750000000000],[0,7792000000000],[0,8042000000000]],"196608":[[0,1264192708000000000],[0,1274076875000000000],[0,1318074875000000000]],"24576":[[0,14806875000000000],[0,14830666000000000],[0,14896500000000000],[0,15118584000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,2333000000000],[0,2417000000000],[0,2417000000000],[0,2458000000000]],"1536":[[0,55500000000000],[0,56541000000000],[0,58167000000000],[0,59167000000000]],"64":[[0,333000000000],[0,333000000000],[0,333000000000],[0,334000000000]],"320":[[0,3834000000000],[0,3917000000000],[0,4333000000000],[0,4667000000000]],"114688":[[0,421166375000000000],[0,423334375000000000],[0,425622000000000000]],"131072":[[0,556071709000000000],[0,556959334000000000],[0,562054875000000000]],"16384":[[0,6146333000000000],[0,6177084000000000],[0,6216500000000000],[0,6229583000000000]],"5120":[[0,601333000000000],[0,603750000000000],[0,608708000000000],[0,614375000000000]],"229376":[[0,1727134416000000000],[0,1737635834000000000],[0,1743512375000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"10":[[0,41000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"28":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"7168":[[0,1172791000000000],[0,1181209000000000],[0,1192959000000000],[0,1222417000000000]],"20480":[[0,9855459000000000],[0,9890500000000000],[0,9951042000000000],[0,9954208000000000]],"65536":[[0,131104333000000000],[0,131168083000000000],[0,131741792000000000],[0,132521667000000000]],"160":[[0,1042000000000],[0,1083000000000],[0,1125000000000],[0,1459000000000]],"640":[[0,11417000000000],[0,13208000000000],[0,13334000000000],[0,13500000000000]],"40":[[0,166000000000],[0,166000000000],[0,167000000000],[0,208000000000]],"57344":[[0,98051959000000000],[0,98891500000000000],[0,99060500000000000],[0,99224750000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,15750000000000],[0,15917000000000],[0,16083000000000],[0,17667000000000]],"448":[[0,5875000000000],[0,6042000000000],[0,6042000000000],[0,6250000000000]],"8192":[[0,1546500000000000],[0,1546875000000000],[0,1567333000000000],[0,1598000000000000]],"12":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"10240":[[0,2394875000000000],[0,2401459000000000],[0,2421542000000000],[0,2458583000000000]],"14336":[[0,4673750000000000],[0,4675417000000000],[0,4735292000000000],[0,4748416000000000]],"32768":[[0,28673792000000000],[0,28710583000000000],[0,29020334000000000],[0,29311292000000000]],"128":[[0,708000000000],[0,708000000000],[0,750000000000],[0,791000000000]],"4096":[[0,384125000000000],[0,387916000000000],[0,391541000000000],[0,393250000000000]],"49152":[[0,70881208000000000],[0,71110166000000000],[0,71232125000000000],[0,72713584000000000]],"262144":[[0,2258017208000000000],[0,2260444792000000000]],"3":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,306931542000000000],[0,309892958000000000],[0,313012417000000000]]}},{"title":"std::deque constructor from buffer","results":{"2048":[[0,357090000000],[0,364160000000],[0,377910000000],[0,402080000000]],"1048576":[[0,318125000000000],[0,327476888888888]],"96":[[0,44580000000],[0,44580000000],[0,45000000000],[0,45000000000]],"327680":[[0,100620290322580],[0,101398255813953]],"384":[[0,65000000000],[0,65830000000],[0,65830000000],[0,66250000000]],"12288":[[0,1632500000000],[0,1730769230769],[0,1820830000000],[0,1842920000000]],"81920":[[0,24593750000000],[0,24708000000000],[0,24725000000000],[0,24837500000000]],"8":[[0,38750000000],[0,38750000000],[0,39160000000],[0,39160000000]],"1280":[[0,179160000000],[0,179580000000],[0,180830000000],[0,181250000000]],"3584":[[0,481670000000],[0,492500000000],[0,514580000000],[0,540000000000]],"7":[[0,40000000000],[0,40000000000],[0,40410000000],[0,40410000000]],"524288":[[0,158561608695652],[0,159031250000000]],"112":[[0,45830000000],[0,45830000000],[0,45830000000],[0,52500000000]],"896":[[0,126660000000],[0,127080000000],[0,127500000000],[0,131250000000]],"192":[[0,51250000000],[0,51250000000],[0,51660000000],[0,51660000000]],"80":[[0,43330000000],[0,43330000000],[0,43330000000],[0,43750000000]],"24":[[0,39580000000],[0,40000000000],[0,40000000000],[0,40000000000]],"40960":[[0,11660420000000],[0,12415420000000],[0,12457500000000],[0,13121023809523]],"16":[[0,39170000000],[0,39170000000],[0,39580000000],[0,39590000000]],"3072":[[0,436250000000],[0,455410000000],[0,465410000000],[0,474590000000]],"20":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40410000000]],"224":[[0,53330000000],[0,53750000000],[0,53750000000],[0,53750000000]],"2560":[[0,378330000000],[0,390410000000],[0,393330000000],[0,408330000000]],"1792":[[0,242080000000],[0,242500000000],[0,244590000000],[0,247920000000]],"1024":[[0,157080000000],[0,162920000000],[0,163330000000],[0,164160000000]],"6144":[[0,855830000000],[0,859170000000],[0,865830000000],[0,1033340000000]],"56":[[0,41660000000],[0,42080000000],[0,42500000000],[0,42500000000]],"786432":[[0,233583000000000],[0,241169740740740]],"163840":[[0,49125000000000],[0,49703340000000],[0,51115966666666]],"6":[[0,40000000000],[0,40000000000],[0,40000000000],[0,40000000000]],"48":[[0,40840000000],[0,41250000000],[0,41250000000],[0,41250000000]],"32":[[0,40410000000],[0,40410000000],[0,40410000000],[0,40420000000]],"14":[[0,40000000000],[0,40410000000],[0,40410000000],[0,40410000000]],"28672":[[0,7809590000000],[0,7835227272727],[0,7875000000000],[0,7901670000000]],"512":[[0,93750000000],[0,95000000000],[0,95000000000],[0,95830000000]],"196608":[[0,57542000000000],[0,58000000000000],[0,58125000000000]],"458752":[[0,139021358974358],[0,140483200000000]],"24576":[[0,6925830000000],[0,7071670000000],[0,7126670000000],[0,7140000000000]],"2":[[0,38750000000],[0,38750000000],[0,39160000000],[0,39160000000]],"256":[[0,55830000000],[0,55830000000],[0,56250000000],[0,56250000000]],"1536":[[0,221250000000],[0,221670000000],[0,225830000000],[0,227080000000]],"64":[[0,42080000000],[0,42090000000],[0,42090000000],[0,42500000000]],"320":[[0,60000000000],[0,60420000000],[0,60830000000],[0,64580000000]],"114688":[[0,33083000000000],[0,33432692307692],[0,33855000000000]],"131072":[[0,38472080000000],[0,38583000000000],[0,38994590000000]],"16384":[[0,2501670000000],[0,2566660000000],[0,2566670000000],[0,2586660000000]],"5120":[[0,702080000000],[0,725000000000],[0,730420000000],[0,740420000000]],"229376":[[0,68333000000000],[0,68917000000000],[0,70595238095238]],"5":[[0,39160000000],[0,39580000000],[0,39590000000],[0,40000000000]],"10":[[0,39160000000],[0,39170000000],[0,39580000000],[0,39580000000]],"28":[[0,40000000000],[0,40410000000],[0,40420000000],[0,40830000000]],"655360":[[0,196798500000000],[0,198600000000000]],"7168":[[0,954170000000],[0,961660000000],[0,995000000000],[0,1008750000000]],"20480":[[0,6112080000000],[0,6243750000000],[0,6247090000000],[0,6308340000000]],"65536":[[0,19334000000000],[0,19358200000000],[0,19378649122807],[0,19472080000000]],"917504":[[0,281209000000000],[0,282102272727272]],"160":[[0,49160000000],[0,49170000000],[0,49170000000],[0,49580000000]],"640":[[0,105420000000],[0,105830000000],[0,105830000000],[0,106250000000]],"40":[[0,40410000000],[0,40830000000],[0,40830000000],[0,40830000000]],"393216":[[0,119250000000000],[0,125099137931034]],"57344":[[0,13070696969696],[0,15465000000000],[0,15517857142857],[0,15667000000000]],"4":[[0,39580000000],[0,39580000000],[0,39580000000],[0,39590000000]],"1":[[0,38330000000],[0,38330000000],[0,38330000000],[0,38750000000]],"768":[[0,114500000000],[0,116250000000],[0,116600000000],[0,117080000000]],"448":[[0,70410000000],[0,71250000000],[0,71250000000],[0,71250000000]],"8192":[[0,1054160000000],[0,1077090000000],[0,1100000000000],[0,1273750000000]],"12":[[0,39170000000],[0,39590000000],[0,39590000000],[0,39590000000]],"10240":[[0,1320420000000],[0,1330000000000],[0,1353750000000],[0,1517920000000]],"14336":[[0,2051366666666],[0,2064363636363],[0,2127976190476],[0,2162500000000]],"32768":[[0,8641660000000],[0,8722500000000],[0,8727080000000],[0,8892500000000]],"128":[[0,47080000000],[0,47080000000],[0,47080000000],[0,47500000000]],"4096":[[0,569580000000],[0,575000000000],[0,592920000000],[0,720000000000]],"49152":[[0,13875000000000],[0,13959000000000],[0,14011250000000],[0,14041750000000]],"262144":[[0,78021604938271],[0,81722727272727]],"3":[[0,39160000000],[0,39170000000],[0,39580000000],[0,39580000000]],"98304":[[0,27917000000000],[0,27942080000000],[0,28048330000000]]}},{"title":"VecDeque constructor from buffer","results":{"2048":[[0,1206250000000],[0,1206660000000],[0,1206660000000],[0,1207910000000]],"1048576":[[0,848000000000000],[0,941548666666666]],"96":[[0,79160000000],[0,79170000000],[0,79580000000],[0,79580000000]],"327680":[[0,192862764705882],[0,236392176470588]],"384":[[0,245830000000],[0,246250000000],[0,246250000000],[0,246250000000]],"12288":[[0,7915420000000],[0,8195410000000],[0,8500000000000],[0,11333000000000]],"81920":[[0,49250000000000],[0,50073770270270],[0,51667000000000],[0,66239297297297]],"8":[[0,18750000000],[0,18750000000],[0,19160000000],[0,19160000000]],"1280":[[0,766153061224],[0,766250000000],[0,766250000000],[0,766660000000]],"3584":[[0,2090557692307],[0,2090830000000],[0,2090840000000],[0,2091250000000]],"7":[[0,17910000000],[0,18330000000],[0,18330000000],[0,18340000000]],"524288":[[0,322803571428571],[0,333083000000000]],"112":[[0,95410000000],[0,95830000000],[0,95830000000],[0,107090000000]],"896":[[0,541000000000],[0,545000000000],[0,545410000000],[0,545410000000]],"192":[[0,135410000000],[0,135410000000],[0,135420000000],[0,135420000000]],"80":[[0,67910000000],[0,69580000000],[0,69590000000],[0,70000000000]],"24":[[0,27920000000],[0,28330000000],[0,28330000000],[0,28330000000]],"40960":[[0,24273320000000],[0,25458000000000],[0,25625000000000],[0,26760830000000]],"16":[[0,23330000000],[0,23340000000],[0,23750000000],[0,23750000000]],"3072":[[0,1796250000000],[0,1796511627906],[0,1796660000000],[0,1796670000000]],"20":[[0,25830000000],[0,25830000000],[0,25840000000],[0,26250000000]],"224":[[0,153750000000],[0,153750000000],[0,153750000000],[0,154160000000]],"2560":[[0,1502080000000],[0,1502090000000],[0,1502090000000],[0,1502500000000]],"1792":[[0,1060410000000],[0,1060410000000],[0,1060420000000],[0,1060420000000]],"1024":[[0,616071428571],[0,618166666666],[0,619160000000],[0,619160000000]],"6144":[[0,4193965517241],[0,4195000000000],[0,4203340000000],[0,4204580000000]],"56":[[0,52910000000],[0,53330000000],[0,53330000000],[0,53330000000]],"786432":[[0,465625000000000],[0,624708000000000]],"163840":[[0,95750000000000],[0,96167000000000],[0,103958000000000]],"6":[[0,19160000000],[0,19170000000],[0,19170000000],[0,19580000000]],"48":[[0,50420000000],[0,50420000000],[0,50420000000],[0,50830000000]],"32":[[0,32076923076],[0,32910000000],[0,32910000000],[0,32920000000]],"14":[[0,22080000000],[0,22090000000],[0,22090000000],[0,22500000000]],"28672":[[0,17245410000000],[0,17267988636363],[0,31972500000000],[0,32067625000000]],"512":[[0,317500000000],[0,319580000000],[0,319580000000],[0,319580000000]],"196608":[[0,121732516129032],[0,145145833333333],[0,212952392857142]],"458752":[[0,282375000000000],[0,478521000000000]],"24576":[[0,14944590000000],[0,18250000000000],[0,20447080000000],[0,27550000000000]],"2":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"256":[[0,172080000000],[0,172500000000],[0,172500000000],[0,172500000000]],"1536":[[0,912645161290],[0,913330000000],[0,913330000000],[0,913330000000]],"64":[[0,60000000000],[0,60000000000],[0,60000000000],[0,60000000000]],"320":[[0,207500000000],[0,207500000000],[0,207500000000],[0,217080000000]],"114688":[[0,68708000000000],[0,69750000000000],[0,72541000000000]],"131072":[[0,78417000000000],[0,81625000000000],[0,118459000000000]],"16384":[[0,10208000000000],[0,15250000000000],[0,18483750000000],[0,18513330000000]],"5120":[[0,3586670000000],[0,3586670000000],[0,3592500000000],[0,3594580000000]],"229376":[[0,139166000000000],[0,187667000000000],[0,235041000000000]],"5":[[0,18750000000],[0,19160000000],[0,19160000000],[0,19160000000]],"10":[[0,19580000000],[0,20000000000],[0,20000000000],[0,20000000000]],"28":[[0,30830000000],[0,30830000000],[0,30830000000],[0,30830000000]],"655360":[[0,384407333333333],[0,401542000000000]],"7168":[[0,4797080000000],[0,4798330000000],[0,4799170000000],[0,4802080000000]],"20480":[[0,12541000000000],[0,12987920000000],[0,23011250000000],[0,23027230769230]],"65536":[[0,39875000000000],[0,40125000000000],[0,40292000000000],[0,83020454545454]],"917504":[[0,668154714285714],[0,1234042000000000]],"160":[[0,115000000000],[0,115410000000],[0,115410000000],[0,117080000000]],"640":[[0,397910000000],[0,398330000000],[0,398330000000],[0,398330000000]],"40":[[0,41500000000],[0,43330000000],[0,45410000000],[0,45410000000]],"393216":[[0,246584000000000],[0,515395857142857]],"57344":[[0,34583000000000],[0,54500000000000],[0,63804545454545],[0,64053330000000]],"4":[[0,17920000000],[0,18330000000],[0,18330000000],[0,18330000000]],"1":[[0,14160000000],[0,14580000000],[0,14580000000],[0,14580000000]],"768":[[0,469580000000],[0,470410000000],[0,470410000000],[0,471660000000]],"448":[[0,282500000000],[0,282910000000],[0,282910000000],[0,293750000000]],"8192":[[0,5435410000000],[0,5439076923076],[0,5442910000000],[0,5445000000000]],"12":[[0,20830000000],[0,20830000000],[0,21250000000],[0,21250000000]],"10240":[[0,7000000000000],[0,9476063829787],[0,9482920000000],[0,9594170000000]],"14336":[[0,10375000000000],[0,15735410000000],[0,15823750000000],[0,15854170000000]],"32768":[[0,20166000000000],[0,36692500000000],[0,36869170000000],[0,37387500000000]],"128":[[0,105000000000],[0,105000000000],[0,105000000000],[0,105000000000]],"4096":[[0,2385000000000],[0,2385420000000],[0,2385830000000],[0,2731250000000]],"49152":[[0,40205981132075],[0,47750410000000],[0,54958330000000],[0,55686670000000]],"262144":[[0,156792000000000],[0,291456000000000]],"3":[[0,17910000000],[0,17910000000],[0,17910000000],[0,17910000000]],"98304":[[0,57305333333333],[0,114768360000000],[0,140375688524590]]}},{"title":"std::deque sequential iteration","results":{"2048":[[0,2208000000000],[0,2243750000000],[0,2244160000000],[0,2244160000000]],"1048576":[[0,1158031250000000],[0,1169072875000000]],"96":[[0,110410000000],[0,110410000000],[0,110410000000],[0,113750000000]],"327680":[[0,358084000000000],[0,395035000000000]],"384":[[0,422080000000],[0,422500000000],[0,422500000000],[0,422500000000]],"12288":[[0,13417000000000],[0,13426250000000],[0,13426470588235],[0,13613330000000]],"81920":[[0,89503818181818],[0,89675410000000],[0,89921333333333],[0,91094590000000]],"8":[[0,8400000000],[0,10000000000],[0,10000000000],[0,10410000000]],"1280":[[0,1402080000000],[0,1402322580645],[0,1402500000000],[0,1402500000000]],"3584":[[0,3920830000000],[0,3920830000000],[0,3921250000000],[0,3926250000000]],"7":[[0,9160000000],[0,9160000000],[0,9170000000],[0,9170000000]],"524288":[[0,613145500000000],[0,619167000000000]],"112":[[0,127500000000],[0,127910000000],[0,127910000000],[0,145000000000]],"896":[[0,980190476190],[0,981250000000],[0,981660000000],[0,981660000000]],"192":[[0,208000000000],[0,209000000000],[0,214170000000],[0,214580000000]],"80":[[0,92910000000],[0,92910000000],[0,92920000000],[0,92920000000]],"24":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,44757545454545],[0,44874160000000],[0,44891660000000],[0,45088750000000]],"16":[[0,18750000000],[0,19160000000],[0,19160000000],[0,19160000000]],"3072":[[0,3354250000000],[0,3362090000000],[0,3362500000000],[0,3362910000000]],"20":[[0,21000000000],[0,23330000000],[0,23330000000],[0,23330000000]],"224":[[0,248750000000],[0,249160000000],[0,249160000000],[0,250000000000]],"2560":[[0,2802500000000],[0,2802910000000],[0,2802910000000],[0,2803750000000]],"1792":[[0,1958000000000],[0,1958000000000],[0,1961660000000],[0,1962080000000]],"1024":[[0,1125420000000],[0,1125420000000],[0,1125830000000],[0,1125830000000]],"6144":[[0,6715830000000],[0,6715830000000],[0,6716250000000],[0,6718330000000]],"56":[[0,66600000000],[0,67080000000],[0,67500000000],[0,67500000000]],"786432":[[0,872208000000000],[0,874416727272727]],"163840":[[0,180958500000000],[0,183457538461538],[0,188709208333333]],"6":[[0,7920000000],[0,8330000000],[0,8330000000],[0,8330000000]],"48":[[0,58750000000],[0,58750000000],[0,58750000000],[0,58750000000]],"32":[[0,41250000000],[0,41660000000],[0,41660000000],[0,41660000000]],"14":[[0,16660000000],[0,16660000000],[0,16670000000],[0,16670000000]],"28672":[[0,31337090000000],[0,31365000000000],[0,31541000000000],[0,31734580000000]],"512":[[0,560420000000],[0,560830000000],[0,560830000000],[0,561250000000]],"196608":[[0,214777666666666],[0,219500000000000],[0,225833500000000]],"458752":[[0,501925421052631],[0,510625000000000]],"24576":[[0,26854580000000],[0,26875000000000],[0,26916000000000],[0,27229170000000]],"2":[[0,3750000000],[0,3750000000],[0,3750000000],[0,3750000000]],"256":[[0,283750000000],[0,283750000000],[0,283750000000],[0,283750000000]],"1536":[[0,1684580000000],[0,1684580000000],[0,1684590000000],[0,1685000000000]],"64":[[0,75830000000],[0,75830000000],[0,75840000000],[0,76250000000]],"320":[[0,352920000000],[0,353330000000],[0,370000000000],[0,378340000000]],"114688":[[0,126875000000000],[0,127311264705882],[0,128259315789473]],"131072":[[0,143384057971014],[0,144500000000000],[0,144833000000000]],"16384":[[0,17900000000000],[0,17909738095238],[0,17933340000000],[0,17938750000000]],"5120":[[0,5584000000000],[0,5597920000000],[0,5597920000000],[0,5598750000000]],"229376":[[0,253750000000000],[0,271357142857142],[0,273667000000000]],"5":[[0,7080000000],[0,7080000000],[0,7080000000],[0,7080000000]],"10":[[0,12500000000],[0,12500000000],[0,12500000000],[0,12500000000]],"28":[[0,36660000000],[0,36670000000],[0,37080000000],[0,37080000000]],"655360":[[0,719917000000000],[0,722025692307692]],"7168":[[0,7833750000000],[0,7834051724137],[0,7834580000000],[0,7835000000000]],"20480":[[0,22375000000000],[0,22428330000000],[0,22429170000000],[0,22488750000000]],"65536":[[0,71709000000000],[0,71927918918918],[0,72135000000000],[0,72283340000000]],"917504":[[0,1014676000000000],[0,1074984375000000]],"160":[[0,179580000000],[0,180000000000],[0,180000000000],[0,180410000000]],"640":[[0,704160000000],[0,704580000000],[0,704580000000],[0,704580000000]],"40":[[0,49580000000],[0,50000000000],[0,50000000000],[0,52910000000]],"393216":[[0,440166000000000],[0,478458500000000]],"57344":[[0,62666000000000],[0,62745067796610],[0,62952586206896],[0,63334070175438]],"4":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5840000000]],"1":[[0,2080000000],[0,2080000000],[0,2080000000],[0,2090000000]],"768":[[0,842910000000],[0,842910000000],[0,842910000000],[0,843330000000]],"448":[[0,491250000000],[0,491660000000],[0,491660000000],[0,499590000000]],"8192":[[0,8952500000000],[0,8952500000000],[0,8990410000000],[0,9004160000000]],"12":[[0,14170000000],[0,14580000000],[0,14580000000],[0,14580000000]],"10240":[[0,11188635135135],[0,11189430232558],[0,11199580000000],[0,11238352941176]],"14336":[[0,15661670000000],[0,15664062500000],[0,15666000000000],[0,15670830000000]],"32768":[[0,35802080000000],[0,35924580000000],[0,36208000000000],[0,36375000000000]],"128":[[0,145410000000],[0,145410000000],[0,145410000000],[0,145410000000]],"4096":[[0,4479166666666],[0,4479580000000],[0,4479580000000],[0,5709000000000]],"49152":[[0,53933750000000],[0,53968750000000],[0,54100000000000],[0,54515000000000]],"262144":[[0,290083000000000],[0,306497290322580]],"3":[[0,4590000000],[0,5000000000],[0,5000000000],[0,5000000000]],"98304":[[0,107449111111111],[0,108167000000000],[0,108542000000000]]}},{"title":"std::deque random-access offset lookups (operator [])","results":{"2048":[[0,2219681818181],[0,2220830000000],[0,2220840000000],[0,2221250000000]],"1048576":[[0,1210334000000000],[0,1214458400000000]],"96":[[0,107500000000],[0,107910000000],[0,108330000000],[0,109160000000]],"327680":[[0,361425000000000],[0,367529411764705]],"384":[[0,416666666666],[0,420830000000],[0,420840000000],[0,422950000000]],"12288":[[0,13291000000000],[0,13306250000000],[0,13307090000000],[0,13307500000000]],"81920":[[0,88769170000000],[0,88926660000000],[0,90042920000000],[0,90737500000000]],"8":[[0,10000000000],[0,10410000000],[0,10410000000],[0,10410000000]],"1280":[[0,1375000000000],[0,1385500000000],[0,1388000000000],[0,1389580000000]],"3584":[[0,3875000000000],[0,3883330000000],[0,3883330000000],[0,3883750000000]],"7":[[0,8750000000],[0,8750000000],[0,9160000000],[0,9160000000]],"524288":[[0,589683400000000],[0,596359909090909]],"112":[[0,125000000000],[0,125000000000],[0,125410000000],[0,126250000000]],"896":[[0,968750000000],[0,973500000000],[0,973750000000],[0,973750000000]],"192":[[0,209000000000],[0,212910000000],[0,212920000000],[0,213330000000]],"80":[[0,90410000000],[0,90410000000],[0,90830000000],[0,91670000000]],"24":[[0,27090000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,44405684210526],[0,44460000000000],[0,44475708333333],[0,44526500000000]],"16":[[0,18750000000],[0,18750000000],[0,18750000000],[0,18750000000]],"3072":[[0,3329160000000],[0,3329160000000],[0,3329170000000],[0,3329580000000]],"20":[[0,22910000000],[0,22910000000],[0,22910000000],[0,22920000000]],"224":[[0,246541666666],[0,247080000000],[0,248330000000],[0,248340000000]],"2560":[[0,2774580000000],[0,2774580000000],[0,2775000000000],[0,2776250000000]],"1792":[[0,1943340000000],[0,1943750000000],[0,1943750000000],[0,1944170000000]],"1024":[[0,1112381578947],[0,1112500000000],[0,1112500000000],[0,1112500000000]],"6144":[[0,6653761904761],[0,6655000000000],[0,6655000000000],[0,6655000000000]],"56":[[0,64160000000],[0,64580000000],[0,65000000000],[0,65830000000]],"786432":[[0,862151000000000],[0,871356444444444]],"163840":[[0,179396000000000],[0,183550925925925],[0,184672571428571]],"6":[[0,7910000000],[0,7910000000],[0,7910000000],[0,8330000000]],"48":[[0,55830000000],[0,55830000000],[0,55840000000],[0,56250000000]],"32":[[0,35830000000],[0,35840000000],[0,36250000000],[0,36250000000]],"14":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"28672":[[0,31073750000000],[0,31083333333333],[0,31167000000000],[0,31845420000000]],"512":[[0,557910000000],[0,559580000000],[0,559580000000],[0,559580000000]],"196608":[[0,212958000000000],[0,216287111111111],[0,225317750000000]],"458752":[[0,502575562500000],[0,531991600000000]],"24576":[[0,26606670000000],[0,26625000000000],[0,26625000000000],[0,26642080000000]],"2":[[0,3330000000],[0,3750000000],[0,3750000000],[0,3750000000]],"256":[[0,280830000000],[0,281250000000],[0,282080000000],[0,282500000000]],"1536":[[0,1663166666666],[0,1666660000000],[0,1666660000000],[0,1666660000000]],"64":[[0,73330000000],[0,73330000000],[0,73330000000],[0,74160000000]],"320":[[0,333000000000],[0,350410000000],[0,351660000000],[0,367080000000]],"114688":[[0,124145750000000],[0,124151000000000],[0,125520833333333]],"131072":[[0,141917000000000],[0,142716800000000],[0,143354250000000]],"16384":[[0,17739160000000],[0,17750000000000],[0,17772090000000],[0,17964170000000]],"5120":[[0,5500000000000],[0,5545830000000],[0,5546250000000],[0,5546250000000]],"229376":[[0,255148437500000],[0,270450222222222],[0,350875000000000]],"5":[[0,6660000000],[0,6958333333],[0,7080000000],[0,7080000000]],"10":[[0,12080000000],[0,12500000000],[0,12500000000],[0,12500000000]],"28":[[0,31250000000],[0,31660000000],[0,31670000000],[0,32080000000]],"655360":[[0,712154857142857],[0,717917000000000]],"7168":[[0,7762500000000],[0,7762500000000],[0,7763330000000],[0,7798750000000]],"20480":[[0,22167000000000],[0,22173750000000],[0,22187500000000],[0,22250954545454]],"65536":[[0,71190179487179],[0,71612947368421],[0,71770597701149],[0,71832080000000]],"917504":[[0,1001625000000000],[0,1019777833333333]],"160":[[0,175000000000],[0,177080000000],[0,177090000000],[0,177500000000]],"640":[[0,696660000000],[0,696660000000],[0,696660000000],[0,696660000000]],"40":[[0,47910000000],[0,47910000000],[0,48330000000],[0,48330000000]],"393216":[[0,427656250000000],[0,439459000000000]],"57344":[[0,62042000000000],[0,62537500000000],[0,62632067796610],[0,62673016949152]],"4":[[0,5830000000],[0,5830000000],[0,5830000000],[0,5830000000]],"1":[[0,1660000000],[0,1660000000],[0,1660000000],[0,1660000000]],"768":[[0,833000000000],[0,833000000000],[0,834000000000],[0,835420000000]],"448":[[0,488750000000],[0,489160000000],[0,489160000000],[0,490410000000]],"8192":[[0,8871660000000],[0,8872500000000],[0,8875000000000],[0,8905410000000]],"12":[[0,14580000000],[0,14580000000],[0,14580000000],[0,14580000000]],"10240":[[0,11083500000000],[0,11089580000000],[0,11091567901234],[0,11094170000000]],"14336":[[0,15521428571428],[0,15523750000000],[0,15525653846153],[0,15534160000000]],"32768":[[0,35500000000000],[0,35500000000000],[0,35582753424657],[0,35997080000000]],"128":[[0,142080000000],[0,142500000000],[0,142910000000],[0,143330000000]],"4096":[[0,4437080000000],[0,4437080000000],[0,4437910000000],[0,4516250000000]],"49152":[[0,53291000000000],[0,53332500000000],[0,53458325000000],[0,53737095238095]],"262144":[[0,293018750000000],[0,480375000000000]],"3":[[0,4590000000],[0,5000000000],[0,5000000000],[0,5000000000]],"98304":[[0,107728917647058],[0,108097418918918],[0,108729000000000]]}},{"title":"std::deque at, random offsets","results":{"2048":[[0,1667000000000],[0,1667080000000],[0,1667080000000],[0,1667500000000]],"1048576":[[0,1070202428571428],[0,1087095285714285]],"96":[[0,82080000000],[0,82500000000],[0,82500000000],[0,82500000000]],"327680":[[0,288222333333333],[0,290634093750000]],"384":[[0,316250000000],[0,316250000000],[0,316660000000],[0,317080000000]],"12288":[[0,9996250000000],[0,9997500000000],[0,10003750000000],[0,10023148148148]],"81920":[[0,67651595744680],[0,67886363636363],[0,68208000000000],[0,70575000000000]],"8":[[0,7910000000],[0,8330000000],[0,8330000000],[0,8340000000]],"1280":[[0,1043750000000],[0,1043750000000],[0,1043750000000],[0,1043750000000]],"3584":[[0,2913750000000],[0,2913750000000],[0,2913793103448],[0,2914170000000]],"7":[[0,7500000000],[0,7500000000],[0,7500000000],[0,7910000000]],"524288":[[0,487914473684210],[0,491354000000000]],"112":[[0,95410000000],[0,95420000000],[0,95420000000],[0,95830000000]],"896":[[0,731670000000],[0,732080000000],[0,732080000000],[0,732090000000]],"192":[[0,160000000000],[0,160410000000],[0,160410000000],[0,160410000000]],"80":[[0,69170000000],[0,69580000000],[0,69580000000],[0,69580000000]],"24":[[0,20830000000],[0,20850000000],[0,21250000000],[0,21250000000]],"40960":[[0,33312080000000],[0,33333000000000],[0,33413750000000],[0,33584000000000]],"16":[[0,14580000000],[0,14590000000],[0,15000000000],[0,15000000000]],"3072":[[0,2498047619047],[0,2498330000000],[0,2498340000000],[0,2498750000000]],"20":[[0,17920000000],[0,18330000000],[0,18330000000],[0,18330000000]],"224":[[0,186660000000],[0,186660000000],[0,186660000000],[0,186660000000]],"2560":[[0,2082500000000],[0,2082500000000],[0,2082500000000],[0,2082500000000]],"1792":[[0,1458000000000],[0,1458000000000],[0,1459000000000],[0,1459580000000]],"1024":[[0,833000000000],[0,833333333333],[0,835830000000],[0,836250000000]],"6144":[[0,4992920000000],[0,4993363636363],[0,4993589743589],[0,4993750000000]],"56":[[0,42000000000],[0,50000000000],[0,50000000000],[0,50000000000]],"786432":[[0,728896000000000],[0,732159666666666]],"163840":[[0,141500000000000],[0,142372579710144],[0,145291000000000]],"6":[[0,6660000000],[0,6660000000],[0,6660000000],[0,6660000000]],"48":[[0,42000000000],[0,43750000000],[0,44160000000],[0,44160000000]],"32":[[0,27500000000],[0,27500000000],[0,27910000000],[0,27910000000]],"14":[[0,12920000000],[0,13330000000],[0,13330000000],[0,13330000000]],"28672":[[0,23326670000000],[0,23327500000000],[0,23347920000000],[0,23500000000000]],"512":[[0,416000000000],[0,416000000000],[0,416750000000],[0,417000000000]],"196608":[[0,170208000000000],[0,170659482758620],[0,182158340000000]],"458752":[[0,414584000000000],[0,416726434782608]],"24576":[[0,20012500000000],[0,20050830000000],[0,20082500000000],[0,20118750000000]],"2":[[0,3330000000],[0,3330000000],[0,3330000000],[0,3330000000]],"256":[[0,212080000000],[0,212090000000],[0,212500000000],[0,212500000000]],"1536":[[0,1250000000000],[0,1251660000000],[0,1251660000000],[0,1251660000000]],"64":[[0,56250000000],[0,56250000000],[0,56250000000],[0,56660000000]],"320":[[0,250000000000],[0,264580000000],[0,276670000000],[0,277080000000]],"114688":[[0,96458000000000],[0,96472333333333],[0,100025938775510]],"131072":[[0,110875000000000],[0,112167000000000],[0,112334000000000]],"16384":[[0,13314024390243],[0,13314393939393],[0,13315340909090],[0,13393330000000]],"5120":[[0,4160830000000],[0,4160830000000],[0,4161250000000],[0,4161670000000]],"229376":[[0,204479000000000],[0,210670619047619],[0,263583000000000]],"5":[[0,5410000000],[0,5830000000],[0,5830000000],[0,6250000000]],"10":[[0,10000000000],[0,10000000000],[0,10000000000],[0,10000000000]],"28":[[0,24170000000],[0,24170000000],[0,24170000000],[0,24580000000]],"655360":[[0,594667000000000],[0,628711357142857]],"7168":[[0,5825000000000],[0,5826670000000],[0,5827500000000],[0,5843117647058]],"20480":[[0,16653750000000],[0,16681250000000],[0,16750000000000],[0,17052910000000]],"65536":[[0,53551950617283],[0,53717090000000],[0,53951250000000],[0,55375000000000]],"917504":[[0,861078666666666],[0,878333000000000]],"160":[[0,134170000000],[0,134170000000],[0,134580000000],[0,134580000000]],"640":[[0,524160000000],[0,524160000000],[0,524160000000],[0,524160000000]],"40":[[0,36660000000],[0,36660000000],[0,37080000000],[0,37500000000]],"393216":[[0,358649703703703],[0,365958000000000]],"57344":[[0,46666727272727],[0,46731444444444],[0,46923330000000],[0,47179170000000]],"4":[[0,4580000000],[0,5000000000],[0,5000000000],[0,5000000000]],"1":[[0,1660000000],[0,1660000000],[0,1660000000],[0,1670000000]],"768":[[0,627910000000],[0,627910000000],[0,628330000000],[0,628330000000]],"448":[[0,368330000000],[0,368330000000],[0,368330000000],[0,368330000000]],"8192":[[0,6658750000000],[0,6659170000000],[0,6660410000000],[0,6696660000000]],"12":[[0,11660000000],[0,11660000000],[0,11660000000],[0,11660000000]],"10240":[[0,8312500000000],[0,8325420000000],[0,8325830000000],[0,8329580000000]],"14336":[[0,11625000000000],[0,11651250000000],[0,11660000000000],[0,11681250000000]],"32768":[[0,26625000000000],[0,26625000000000],[0,26646000000000],[0,26791000000000]],"128":[[0,108330000000],[0,108750000000],[0,108750000000],[0,108750000000]],"4096":[[0,3329580000000],[0,3329580000000],[0,3329580000000],[0,3461250000000]],"49152":[[0,40083000000000],[0,40167000000000],[0,40208000000000],[0,40521250000000]],"262144":[[0,230729000000000],[0,247745388888888]],"3":[[0,4170000000],[0,4170000000],[0,4580000000],[0,4580000000]],"98304":[[0,81934875000000],[0,82487080000000],[0,82956000000000]]}},{"title":"std::deque push_back","results":{"2048":[[0,2270420000000],[0,2296250000000],[0,2296660000000],[0,2298330000000]],"1048576":[[0,1362916000000000],[0,1421083333333333]],"96":[[0,132080000000],[0,132500000000],[0,132500000000],[0,133330000000]],"327680":[[0,426145833333333],[0,430820210526315]],"384":[[0,415000000000],[0,415000000000],[0,415000000000],[0,416250000000]],"12288":[[0,13665000000000],[0,13813750000000],[0,14167000000000],[0,14255420000000]],"81920":[[0,102741650000000],[0,102875000000000],[0,105409090909090],[0,109180811320754]],"8":[[0,41250000000],[0,41660000000],[0,41660000000],[0,42920000000]],"1280":[[0,1410830000000],[0,1411250000000],[0,1411670000000],[0,1419580000000]],"3584":[[0,3928750000000],[0,3932500000000],[0,3935830000000],[0,4453750000000]],"7":[[0,40830000000],[0,40830000000],[0,40830000000],[0,42500000000]],"524288":[[0,699425000000000],[0,717370900000000]],"112":[[0,148330000000],[0,148330000000],[0,148330000000],[0,149160000000]],"896":[[0,975830000000],[0,975840000000],[0,976250000000],[0,978330000000]],"192":[[0,226250000000],[0,226660000000],[0,226660000000],[0,227500000000]],"80":[[0,116660000000],[0,116660000000],[0,116660000000],[0,117910000000]],"24":[[0,57080000000],[0,57080000000],[0,57080000000],[0,58330000000]],"40960":[[0,49958000000000],[0,51159580000000],[0,51607500000000],[0,53488750000000]],"16":[[0,48583333333],[0,49170000000],[0,49170000000],[0,50420000000]],"3072":[[0,3360410000000],[0,3385416666666],[0,3385420000000],[0,3391250000000]],"20":[[0,52910000000],[0,53330000000],[0,53330000000],[0,55000000000]],"224":[[0,257500000000],[0,257910000000],[0,257910000000],[0,259160000000]],"2560":[[0,2812500000000],[0,2840830000000],[0,2841660000000],[0,2841670000000]],"1792":[[0,1958330000000],[0,1958750000000],[0,1959000000000],[0,1960000000000]],"1024":[[0,1145833333333],[0,1147500000000],[0,1149170000000],[0,1159170000000]],"6144":[[0,6697500000000],[0,6707500000000],[0,6713750000000],[0,6829170000000]],"56":[[0,92920000000],[0,92920000000],[0,93330000000],[0,94160000000]],"786432":[[0,989959000000000],[0,1045062500000000]],"163840":[[0,206416666666666],[0,212172642857142],[0,214056571428571]],"6":[[0,39580000000],[0,40000000000],[0,40000000000],[0,41250000000]],"48":[[0,86250000000],[0,86250000000],[0,86250000000],[0,87080000000]],"32":[[0,65000000000],[0,65000000000],[0,65000000000],[0,66660000000]],"14":[[0,47080000000],[0,47080000000],[0,47500000000],[0,48750000000]],"28672":[[0,35584000000000],[0,36444029850746],[0,36575000000000],[0,37523330000000]],"512":[[0,583333333333],[0,587080000000],[0,587080000000],[0,589580000000]],"196608":[[0,256485142857142],[0,259540178571428],[0,263141800000000]],"458752":[[0,604243000000000],[0,614170800000000]],"24576":[[0,28549590000000],[0,31159666666666],[0,31773330000000],[0,32671670000000]],"2":[[0,36660000000],[0,36670000000],[0,37080000000],[0,37910000000]],"256":[[0,289580000000],[0,289580000000],[0,289580000000],[0,290410000000]],"1536":[[0,1692090000000],[0,1692500000000],[0,1692907407407],[0,1694160000000]],"64":[[0,100830000000],[0,100830000000],[0,101250000000],[0,101660000000]],"320":[[0,352080000000],[0,352080000000],[0,352500000000],[0,353330000000]],"114688":[[0,148416636363636],[0,148491700000000],[0,150157000000000]],"131072":[[0,166833500000000],[0,168810636363636],[0,170958333333333]],"16384":[[0,18629666666666],[0,19035000000000],[0,19298340000000],[0,19349580000000]],"5120":[[0,5608750000000],[0,5625000000000],[0,5640420000000],[0,5647500000000]],"229376":[[0,307422607142857],[0,308395818181818],[0,446292000000000]],"5":[[0,38750000000],[0,39160000000],[0,39160000000],[0,40410000000]],"10":[[0,42920000000],[0,43330000000],[0,43340000000],[0,45000000000]],"28":[[0,60830000000],[0,60830000000],[0,60840000000],[0,62500000000]],"655360":[[0,837792000000000],[0,845021000000000]],"7168":[[0,7843330000000],[0,7899291666666],[0,7990000000000],[0,8024160000000]],"20480":[[0,23717920000000],[0,23763750000000],[0,24558330000000],[0,24636670000000]],"65536":[[0,81083000000000],[0,81334000000000],[0,83848750000000],[0,85105705263157]],"917504":[[0,1230857142857142],[0,1272722166666666]],"160":[[0,195000000000],[0,195410000000],[0,195410000000],[0,196250000000]],"640":[[0,723750000000],[0,724160000000],[0,724160000000],[0,726250000000]],"40":[[0,77910000000],[0,77910000000],[0,77920000000],[0,79160000000]],"393216":[[0,516230769230769],[0,528431571428571]],"57344":[[0,71334000000000],[0,71583000000000],[0,73562920000000],[0,73612910000000]],"4":[[0,38750000000],[0,38750000000],[0,39160000000],[0,40000000000]],"1":[[0,34170000000],[0,34580000000],[0,34580000000],[0,35830000000]],"768":[[0,850830000000],[0,850830000000],[0,850830000000],[0,853330000000]],"448":[[0,477500000000],[0,477910000000],[0,478330000000],[0,478330000000]],"8192":[[0,9021000000000],[0,9080420000000],[0,9089170000000],[0,9260420000000]],"12":[[0,45000000000],[0,45000000000],[0,45000000000],[0,46670000000]],"10240":[[0,11416000000000],[0,11456660000000],[0,11721823529411],[0,11859160000000]],"14336":[[0,16332080000000],[0,16569160000000],[0,16625000000000],[0,16677090000000]],"32768":[[0,40875931818181],[0,42688330000000],[0,42780410000000],[0,43101670000000]],"128":[[0,163750000000],[0,163750000000],[0,163750000000],[0,165000000000]],"4096":[[0,4497500000000],[0,4502910000000],[0,4529170000000],[0,4740410000000]],"49152":[[0,63037920000000],[0,63282732142857],[0,64770000000000],[0,65265000000000]],"262144":[[0,344182571428571],[0,344541571428571]],"3":[[0,38330000000],[0,38330000000],[0,38330000000],[0,39170000000]],"98304":[[0,123625000000000],[0,127508680555555],[0,130001317460317]]}},{"title":"VecDeque push_back","results":{"2048":[[0,1778750000000],[0,1786250000000],[0,1818750000000],[0,1837920000000]],"1048576":[[0,1231583000000000],[0,1977812500000000]],"96":[[0,253750000000],[0,255420000000],[0,255840000000],[0,258750000000]],"327680":[[0,318646000000000],[0,397388888888888]],"384":[[0,555830000000],[0,556670000000],[0,560000000000],[0,563750000000]],"12288":[[0,11677920000000],[0,13060420000000],[0,14635000000000],[0,15163750000000]],"81920":[[0,51750000000000],[0,57875000000000],[0,65505712328767],[0,69231739726027]],"8":[[0,52910000000],[0,52910000000],[0,52910000000],[0,52910000000]],"1280":[[0,1379580000000],[0,1389590000000],[0,1397920000000],[0,1399170000000]],"3584":[[0,2888330000000],[0,2896250000000],[0,2897920000000],[0,3309590000000]],"7":[[0,52080000000],[0,52500000000],[0,52500000000],[0,52500000000]],"524288":[[0,516541000000000],[0,559834000000000]],"112":[[0,263340000000],[0,264580000000],[0,265000000000],[0,267080000000]],"896":[[0,947500000000],[0,953330000000],[0,957090000000],[0,957596491228]],"192":[[0,367500000000],[0,370000000000],[0,371250000000],[0,372500000000]],"80":[[0,245000000000],[0,245420000000],[0,246670000000],[0,247500000000]],"24":[[0,117910000000],[0,118750000000],[0,118750000000],[0,119160000000]],"40960":[[0,28239160000000],[0,28300000000000],[0,32880617977528],[0,47927253968253]],"16":[[0,84580000000],[0,84580000000],[0,84580000000],[0,85000000000]],"3072":[[0,2593750000000],[0,2603330000000],[0,2641250000000],[0,2702080000000]],"20":[[0,115420000000],[0,115840000000],[0,116660000000],[0,116670000000]],"224":[[0,382920000000],[0,386670000000],[0,387500000000],[0,389170000000]],"2560":[[0,2336734693877],[0,2349590000000],[0,2372500000000],[0,2376660000000]],"1792":[[0,1625000000000],[0,1635830000000],[0,1642080000000],[0,1668750000000]],"1024":[[0,1027500000000],[0,1034170000000],[0,1036660000000],[0,1038330000000]],"6144":[[0,5974170000000],[0,6077080000000],[0,6087500000000],[0,6093340000000]],"56":[[0,177500000000],[0,179160000000],[0,179580000000],[0,180000000000]],"786432":[[0,1010292000000000],[0,1038875000000000]],"163840":[[0,105833000000000],[0,142956157894736],[0,149011133333333]],"6":[[0,51660000000],[0,51660000000],[0,51660000000],[0,52080000000]],"48":[[0,172920000000],[0,174160000000],[0,174170000000],[0,174170000000]],"32":[[0,123330000000],[0,123330000000],[0,123330000000],[0,123750000000]],"14":[[0,83750000000],[0,83750000000],[0,83750000000],[0,83750000000]],"28672":[[0,20000000000000],[0,32208000000000],[0,32937920000000],[0,33107090000000]],"512":[[0,627080000000],[0,630000000000],[0,632080000000],[0,637500000000]],"196608":[[0,120667000000000],[0,168583000000000],[0,209729692307692]],"458752":[[0,509953125000000],[0,519180666666666]],"24576":[[0,18867500000000],[0,19083000000000],[0,21958000000000],[0,28522910000000]],"2":[[0,20420000000],[0,20420000000],[0,20830000000],[0,21250000000]],"256":[[0,408330000000],[0,410840000000],[0,412080000000],[0,412910000000]],"1536":[[0,1496250000000],[0,1527080000000],[0,1528750000000],[0,1552080000000]],"64":[[0,183340000000],[0,183750000000],[0,183750000000],[0,183750000000]],"320":[[0,513750000000],[0,514580000000],[0,515830000000],[0,525000000000]],"114688":[[0,77084000000000],[0,82916000000000],[0,98617472222222]],"131072":[[0,116979500000000],[0,126872200000000],[0,154162162162162]],"16384":[[0,13917000000000],[0,14791000000000],[0,15417000000000],[0,19405000000000]],"5120":[[0,5336236111111],[0,5368750000000],[0,5381670000000],[0,5389170000000]],"229376":[[0,145833000000000],[0,206438735294117],[0,268333400000000]],"5":[[0,50830000000],[0,51250000000],[0,51250000000],[0,51250000000]],"10":[[0,80830000000],[0,81250000000],[0,81250000000],[0,81250000000]],"28":[[0,120000000000],[0,120410000000],[0,120420000000],[0,120840000000]],"655360":[[0,842709000000000],[0,879666000000000]],"7168":[[0,6427920000000],[0,6430410000000],[0,6470451612903],[0,6496670000000]],"20480":[[0,15964170000000],[0,22167000000000],[0,23806571428571],[0,23892857142857]],"65536":[[0,51125000000000],[0,53109756097560],[0,53208000000000],[0,62928571428571]],"917504":[[0,1251000000000000],[0,1381167000000000]],"160":[[0,345840000000],[0,348750000000],[0,350420000000],[0,351660000000]],"640":[[0,802500000000],[0,806660000000],[0,809160000000],[0,811250000000]],"40":[[0,168750000000],[0,169580000000],[0,170000000000],[0,171250000000]],"393216":[[0,321500000000000],[0,492681571428571]],"57344":[[0,39000000000000],[0,64320000000000],[0,64881670000000],[0,64927096153846]],"4":[[0,22500000000],[0,22500000000],[0,22500000000],[0,22500000000]],"1":[[0,19160000000],[0,19160000000],[0,19160000000],[0,19160000000]],"768":[[0,875830000000],[0,883340000000],[0,889170000000],[0,892910000000]],"448":[[0,588750000000],[0,592920000000],[0,594580000000],[0,595410000000]],"8192":[[0,7919170000000],[0,7925000000000],[0,8312920000000],[0,8736670000000]],"12":[[0,82080000000],[0,82500000000],[0,82500000000],[0,82910000000]],"10240":[[0,9031250000000],[0,9708000000000],[0,10149580000000],[0,10962920000000]],"14336":[[0,11298750000000],[0,11301670000000],[0,12756250000000],[0,13318330000000]],"32768":[[0,24274703703703],[0,24825657894736],[0,29805000000000],[0,35561670000000]],"128":[[0,272090000000],[0,273330000000],[0,275830000000],[0,276670000000]],"4096":[[0,3188750000000],[0,3188750000000],[0,3238866666666],[0,3315840000000]],"49152":[[0,49250000000000],[0,56518581081081],[0,56687920000000],[0,56908109589041]],"262144":[[0,255550310344827],[0,271054200000000]],"3":[[0,21670000000],[0,21670000000],[0,22080000000],[0,22080000000]],"98304":[[0,74583000000000],[0,96670562500000],[0,110139583333333]]}},{"title":"UniqueDeque append","results":{"2048":[[0,5122500000000],[0,5130420000000],[0,5136660000000],[0,5163750000000]],"1048576":[[0,2795708000000000],[0,2890437500000000]],"96":[[0,449170000000],[0,452920000000],[0,454160000000],[0,454170000000]],"327680":[[0,865542000000000],[0,877312500000000]],"384":[[0,1183340000000],[0,1191670000000],[0,1194580000000],[0,1197920000000]],"12288":[[0,31384160000000],[0,31854170000000],[0,33072500000000],[0,33123330000000]],"81920":[[0,188875000000000],[0,189419941176470],[0,193151156862745],[0,203673604166666]],"8":[[0,113750000000],[0,113750000000],[0,114160000000],[0,114160000000]],"1280":[[0,3481670000000],[0,3487910000000],[0,3488750000000],[0,3493330000000]],"3584":[[0,8580357142857],[0,8590000000000],[0,8616250000000],[0,16209000000000]],"7":[[0,112500000000],[0,112910000000],[0,112910000000],[0,113330000000]],"524288":[[0,1295042000000000],[0,1371917000000000]],"112":[[0,488330000000],[0,491250000000],[0,492090000000],[0,492500000000]],"896":[[0,2469580000000],[0,2472500000000],[0,2473330000000],[0,2489160000000]],"192":[[0,709170000000],[0,711250000000],[0,711670000000],[0,713750000000]],"80":[[0,416250000000],[0,419580000000],[0,420830000000],[0,421250000000]],"24":[[0,175000000000],[0,175410000000],[0,175410000000],[0,175830000000]],"40960":[[0,97042000000000],[0,97278000000000],[0,97666800000000],[0,100543478260869]],"16":[[0,166250000000],[0,166250000000],[0,166250000000],[0,166670000000]],"3072":[[0,7504170000000],[0,7513750000000],[0,7562920000000],[0,7607500000000]],"20":[[0,170410000000],[0,170830000000],[0,171250000000],[0,171670000000]],"224":[[0,848750000000],[0,849590000000],[0,853750000000],[0,855566666666]],"2560":[[0,6464000000000],[0,6474580000000],[0,6489590000000],[0,6523750000000]],"1792":[[0,4574580000000],[0,4593340000000],[0,4598330000000],[0,4598750000000]],"1024":[[0,2741600000000],[0,2753750000000],[0,2753750000000],[0,2755410000000]],"6144":[[0,15673750000000],[0,15681670000000],[0,15715000000000],[0,15718340000000]],"56":[[0,305830000000],[0,305840000000],[0,306250000000],[0,311670000000]],"786432":[[0,2010468750000000],[0,2022479250000000]],"163840":[[0,399541000000000],[0,403896000000000],[0,419581250000000]],"6":[[0,110830000000],[0,110830000000],[0,111250000000],[0,111250000000]],"48":[[0,290000000000],[0,290830000000],[0,292500000000],[0,295000000000]],"32":[[0,219160000000],[0,219580000000],[0,219580000000],[0,220410000000]],"14":[[0,142910000000],[0,142920000000],[0,142920000000],[0,143330000000]],"28672":[[0,68125000000000],[0,68296288888888],[0,68333000000000],[0,69486119047619]],"512":[[0,1535830000000],[0,1538750000000],[0,1538847457627],[0,1540420000000]],"196608":[[0,478108400000000],[0,522544250000000],[0,552636066666666]],"458752":[[0,1149979000000000],[0,1236583333333333]],"24576":[[0,60243330000000],[0,60375410000000],[0,60477500000000],[0,61215000000000]],"2":[[0,37080000000],[0,37080000000],[0,37080000000],[0,37080000000]],"256":[[0,914580000000],[0,917080000000],[0,919590000000],[0,924170000000]],"1536":[[0,4010830000000],[0,4014000000000],[0,4031670000000],[0,4042920000000]],"64":[[0,317910000000],[0,317920000000],[0,318330000000],[0,322500000000]],"320":[[0,1049160000000],[0,1055000000000],[0,1056250000000],[0,1057090000000]],"114688":[[0,274792000000000],[0,279542000000000],[0,288250000000000]],"131072":[[0,304250000000000],[0,314750000000000],[0,322764379310344]],"16384":[[0,39865000000000],[0,40189326086956],[0,40362080000000],[0,40568750000000]],"5120":[[0,13260000000000],[0,13275410000000],[0,13284170000000],[0,13585840000000]],"229376":[[0,569125000000000],[0,607524250000000],[0,646719727272727]],"5":[[0,87080000000],[0,87080000000],[0,87500000000],[0,87500000000]],"10":[[0,137500000000],[0,137910000000],[0,138330000000],[0,138330000000]],"28":[[0,215000000000],[0,215830000000],[0,216250000000],[0,216250000000]],"655360":[[0,1788593750000000],[0,1826218750000000]],"7168":[[0,19529580000000],[0,19562500000000],[0,19657920000000],[0,19782080000000]],"20480":[[0,51480830000000],[0,51559160000000],[0,51917000000000],[0,51923527472527]],"65536":[[0,157516129032258],[0,158541666666666],[0,158724049180327],[0,163078781818181]],"917504":[[0,2301972333333333],[0,2392264000000000]],"160":[[0,644590000000],[0,645000000000],[0,646670000000],[0,648330000000]],"640":[[0,1806660000000],[0,1807920000000],[0,1809170000000],[0,1810410000000]],"40":[[0,230830000000],[0,230840000000],[0,232080000000],[0,232080000000]],"393216":[[0,1035685111111111],[0,1058958500000000]],"57344":[[0,131445611111111],[0,131521123287671],[0,132466600000000],[0,132555666666666]],"4":[[0,85410000000],[0,85830000000],[0,85830000000],[0,85830000000]],"1":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17920000000]],"768":[[0,2200420000000],[0,2203340000000],[0,2207090000000],[0,2209160000000]],"448":[[0,1397920000000],[0,1400000000000],[0,1401660000000],[0,1403330000000]],"8192":[[0,21253330000000],[0,21619040816326],[0,21750000000000],[0,22635000000000]],"12":[[0,140000000000],[0,140410000000],[0,140410000000],[0,140830000000]],"10240":[[0,25333750000000],[0,25392910000000],[0,25838750000000],[0,25937220779220]],"14336":[[0,35604000000000],[0,35845420000000],[0,36331597222222],[0,36334000000000]],"32768":[[0,77026250000000],[0,77158330000000],[0,77955000000000],[0,78915038461538]],"128":[[0,578330000000],[0,578750000000],[0,579580000000],[0,582920000000]],"4096":[[0,10891250000000],[0,10952806122448],[0,10972090000000],[0,11166000000000]],"49152":[[0,115937500000000],[0,116104000000000],[0,117110445783132],[0,117976678571428]],"262144":[[0,641416000000000],[0,654406250000000]],"3":[[0,61250000000],[0,61250000000],[0,61250000000],[0,61660000000]],"98304":[[0,228708000000000],[0,232434702702702],[0,241375000000000]]}},{"title":"VecDeque push_back, reserving capacity","results":{"2048":[[0,1209000000000],[0,1209160000000],[0,1209580000000],[0,1210000000000]],"1048576":[[0,686458000000000],[0,1014708000000000]],"96":[[0,79170000000],[0,79580000000],[0,79580000000],[0,79580000000]],"327680":[[0,215047363636363],[0,266101142857142]],"384":[[0,247500000000],[0,247910000000],[0,247910000000],[0,247910000000]],"12288":[[0,7806491525423],[0,7820000000000],[0,7833000000000],[0,8250000000000]],"81920":[[0,50065878378378],[0,52238679012345],[0,53125000000000],[0,66958750000000]],"8":[[0,19230769230],[0,20000000000],[0,20000000000],[0,20000000000]],"1280":[[0,767920000000],[0,767920000000],[0,767920000000],[0,767920000000]],"3584":[[0,2092500000000],[0,2092920000000],[0,2092920000000],[0,2094590000000]],"7":[[0,19580000000],[0,19580000000],[0,19580000000],[0,19580000000]],"524288":[[0,397907227272727],[0,443570800000000]],"112":[[0,95000000000],[0,95410000000],[0,95410000000],[0,95410000000]],"896":[[0,547080000000],[0,547080000000],[0,547080000000],[0,547090000000]],"192":[[0,137090000000],[0,137500000000],[0,137500000000],[0,137500000000]],"80":[[0,69170000000],[0,69580000000],[0,69580000000],[0,70000000000]],"24":[[0,28330000000],[0,28750000000],[0,28750000000],[0,28750000000]],"40960":[[0,24458000000000],[0,24583000000000],[0,28246660000000],[0,28398035294117]],"16":[[0,24160000000],[0,24580000000],[0,24580000000],[0,24580000000]],"3072":[[0,1798330000000],[0,1798330000000],[0,1798330000000],[0,1798750000000]],"20":[[0,26250000000],[0,26660000000],[0,26660000000],[0,26660000000]],"224":[[0,155830000000],[0,155830000000],[0,155830000000],[0,155830000000]],"2560":[[0,1503750000000],[0,1504160000000],[0,1504170000000],[0,1504580000000]],"1792":[[0,1060923076923],[0,1061250000000],[0,1062500000000],[0,1062500000000]],"1024":[[0,620420000000],[0,620830000000],[0,620830000000],[0,620830000000]],"6144":[[0,4195000000000],[0,4202920000000],[0,4207500000000],[0,4215840000000]],"56":[[0,52000000000],[0,53750000000],[0,53750000000],[0,55410000000]],"786432":[[0,651366666666666],[0,773003500000000]],"163840":[[0,96667000000000],[0,100625000000000],[0,157922322033898]],"6":[[0,20830000000],[0,21000000000],[0,21250000000],[0,21250000000]],"48":[[0,50000000000],[0,50410000000],[0,50410000000],[0,50410000000]],"32":[[0,32910000000],[0,32910000000],[0,33330000000],[0,33330000000]],"14":[[0,23330000000],[0,23330000000],[0,23330000000],[0,23330000000]],"28672":[[0,17237080000000],[0,17320461538461],[0,17334000000000],[0,32104000000000]],"512":[[0,319580000000],[0,321250000000],[0,321660000000],[0,321660000000]],"196608":[[0,115792000000000],[0,138250000000000],[0,224393179487179]],"458752":[[0,334833000000000],[0,336075772727272]],"24576":[[0,14865410000000],[0,14889608247422],[0,17590420000000],[0,27592500000000]],"2":[[0,14580000000],[0,14580000000],[0,14590000000],[0,15410000000]],"256":[[0,174160000000],[0,174160000000],[0,174160000000],[0,174580000000]],"1536":[[0,915000000000],[0,915000000000],[0,915000000000],[0,915000000000]],"64":[[0,60000000000],[0,60000000000],[0,60000000000],[0,60000000000]],"320":[[0,210830000000],[0,210830000000],[0,211250000000],[0,211250000000]],"114688":[[0,77125000000000],[0,85167000000000],[0,100583500000000]],"131072":[[0,77958000000000],[0,110542000000000],[0,140000000000000]],"16384":[[0,10209000000000],[0,10334000000000],[0,17666000000000],[0,18482920000000]],"5120":[[0,3587080000000],[0,3588330000000],[0,3595830000000],[0,3609574074074]],"229376":[[0,153934782608695],[0,181105200000000],[0,260158088235294]],"5":[[0,20420000000],[0,20420000000],[0,20830000000],[0,20830000000]],"10":[[0,20857142857],[0,21250000000],[0,21250000000],[0,21250000000]],"28":[[0,30410000000],[0,30420000000],[0,30830000000],[0,30830000000]],"655360":[[0,459229250000000],[0,608879666666666]],"7168":[[0,4793842105263],[0,4801250000000],[0,4809580000000],[0,4906882352941]],"20480":[[0,12541000000000],[0,12558400000000],[0,12583000000000],[0,23017080000000]],"65536":[[0,39000000000000],[0,42042000000000],[0,52292000000000],[0,56061827956989]],"917504":[[0,561042000000000],[0,740625000000000]],"160":[[0,118750000000],[0,118750000000],[0,119160000000],[0,119160000000]],"640":[[0,399580000000],[0,399636363636],[0,400000000000],[0,400000000000]],"40":[[0,41666666666],[0,45000000000],[0,45410000000],[0,45830000000]],"393216":[[0,230791000000000],[0,343750000000000]],"57344":[[0,34166000000000],[0,34167000000000],[0,34167000000000],[0,34417000000000]],"4":[[0,19580000000],[0,19580000000],[0,19580000000],[0,19580000000]],"1":[[0,13750000000],[0,13750000000],[0,13750000000],[0,14160000000]],"768":[[0,472333333333],[0,473340000000],[0,473750000000],[0,473750000000]],"448":[[0,282500000000],[0,284580000000],[0,284580000000],[0,284580000000]],"8192":[[0,5444160000000],[0,5447920000000],[0,5819170000000],[0,6042000000000]],"12":[[0,22080000000],[0,22080000000],[0,22090000000],[0,22500000000]],"10240":[[0,6750000000000],[0,9470830000000],[0,9505840000000],[0,9537080000000]],"14336":[[0,9041000000000],[0,9166000000000],[0,15816670000000],[0,15914580000000]],"32768":[[0,19708000000000],[0,19833000000000],[0,19875000000000],[0,20042000000000]],"128":[[0,105000000000],[0,105000000000],[0,105000000000],[0,105000000000]],"4096":[[0,2387080000000],[0,2387090000000],[0,2387500000000],[0,2387500000000]],"49152":[[0,29333000000000],[0,34694170000000],[0,35567090000000],[0,56278330000000]],"262144":[[0,166333000000000],[0,191375000000000]],"3":[[0,18330000000],[0,18340000000],[0,18750000000],[0,19160000000]],"98304":[[0,58250000000000],[0,58708000000000],[0,63312500000000]]}},{"title":"RigidDeque append, reserving capacity","results":{"2048":[[0,176670000000],[0,177500000000],[0,177920000000],[0,191660000000]],"1048576":[[0,152167000000000],[0,164583327586206]],"96":[[0,32920000000],[0,32920000000],[0,32920000000],[0,33330000000]],"327680":[[0,48008200000000],[0,49210051546391]],"384":[[0,49160000000],[0,49160000000],[0,49160000000],[0,49170000000]],"12288":[[0,1630000000000],[0,1665420000000],[0,1668750000000],[0,1706250000000]],"81920":[[0,12447010869565],[0,12458330000000],[0,12459000000000],[0,12515682352941]],"8":[[0,17500000000],[0,17910000000],[0,17910000000],[0,17910000000]],"1280":[[0,132500000000],[0,132500000000],[0,133750000000],[0,161250000000]],"3584":[[0,281670000000],[0,297080000000],[0,311660000000],[0,372920000000]],"7":[[0,17500000000],[0,17500000000],[0,17500000000],[0,17500000000]],"524288":[[0,76125000000000],[0,83234000000000]],"112":[[0,34580000000],[0,34580000000],[0,34580000000],[0,34580000000]],"896":[[0,100000000000],[0,101250000000],[0,101250000000],[0,101660000000]],"192":[[0,35830000000],[0,35840000000],[0,36250000000],[0,36660000000]],"80":[[0,31250000000],[0,31250000000],[0,31250000000],[0,31660000000]],"24":[[0,18750000000],[0,18750000000],[0,18750000000],[0,18750000000]],"40960":[[0,5837080000000],[0,6540000000000],[0,6562500000000],[0,6566660000000]],"16":[[0,17920000000],[0,18330000000],[0,18330000000],[0,18330000000]],"3072":[[0,246670000000],[0,247080000000],[0,281660000000],[0,282080000000]],"20":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17910000000]],"224":[[0,37910000000],[0,37910000000],[0,37920000000],[0,38330000000]],"2560":[[0,275000000000],[0,285000000000],[0,296660000000],[0,368910112359]],"1792":[[0,157500000000],[0,160000000000],[0,174580000000],[0,219580000000]],"1024":[[0,109580000000],[0,111250000000],[0,111660000000],[0,117500000000]],"6144":[[0,1461250000000],[0,1466250000000],[0,1491250000000],[0,1559580000000]],"56":[[0,26670000000],[0,29160000000],[0,29160000000],[0,29170000000]],"786432":[[0,115041000000000],[0,115208000000000]],"163840":[[0,24375000000000],[0,24698330000000],[0,25112090000000]],"6":[[0,17080000000],[0,17080000000],[0,17080000000],[0,17080000000]],"48":[[0,27910000000],[0,29160000000],[0,29160000000],[0,29580000000]],"32":[[0,19580000000],[0,19580000000],[0,19580000000],[0,19580000000]],"14":[[0,17500000000],[0,17910000000],[0,18330000000],[0,18330000000]],"28672":[[0,4693750000000],[0,4775420000000],[0,4797500000000],[0,4798340000000]],"512":[[0,56250000000],[0,57090000000],[0,57910000000],[0,57910000000]],"196608":[[0,29092080000000],[0,29416000000000],[0,29542000000000]],"458752":[[0,67133333333333],[0,70065420000000]],"24576":[[0,3996250000000],[0,4186670000000],[0,4200840000000],[0,4239590000000]],"2":[[0,14580000000],[0,14580000000],[0,14580000000],[0,14580000000]],"256":[[0,40000000000],[0,40410000000],[0,40410000000],[0,40410000000]],"1536":[[0,142080000000],[0,154170000000],[0,154170000000],[0,175830000000]],"64":[[0,29590000000],[0,29590000000],[0,30000000000],[0,30000000000]],"320":[[0,42910000000],[0,44580000000],[0,44580000000],[0,44580000000]],"114688":[[0,17105000000000],[0,17169590000000],[0,17222500000000]],"131072":[[0,19495830000000],[0,19535840000000],[0,19708000000000]],"16384":[[0,2574160000000],[0,2595420000000],[0,2621660000000],[0,2624590000000]],"5120":[[0,1230000000000],[0,1295830000000],[0,1335000000000],[0,1356306122448]],"229376":[[0,33615000000000],[0,33708333333333],[0,33852500000000]],"5":[[0,16660000000],[0,17080000000],[0,17080000000],[0,17080000000]],"10":[[0,16250000000],[0,16250000000],[0,16660000000],[0,16660000000]],"28":[[0,18330000000],[0,18340000000],[0,18750000000],[0,18750000000]],"655360":[[0,84684083333333],[0,96834000000000]],"7168":[[0,1549160000000],[0,1623750000000],[0,1625000000000],[0,1635000000000]],"20480":[[0,3427910000000],[0,3575000000000],[0,3583000000000],[0,3624590000000]],"65536":[[0,10080000000000],[0,10082500000000],[0,10101470588235],[0,10162162162162]],"917504":[[0,135631849315068],[0,141287184615384]],"160":[[0,33750000000],[0,33750000000],[0,33750000000],[0,33750000000]],"640":[[0,73750000000],[0,73750000000],[0,73750000000],[0,74160000000]],"40":[[0,27500000000],[0,27500000000],[0,27500000000],[0,27500000000]],"393216":[[0,58875000000000],[0,61566372881355]],"57344":[[0,6387090000000],[0,8657500000000],[0,8944500000000],[0,8985420000000]],"4":[[0,18330000000],[0,18330000000],[0,18340000000],[0,19170000000]],"1":[[0,14344827586],[0,14580000000],[0,14580000000],[0,14580000000]],"768":[[0,85000000000],[0,85000000000],[0,85000000000],[0,86660000000]],"448":[[0,53330000000],[0,53330000000],[0,53330000000],[0,53750000000]],"8192":[[0,1608750000000],[0,1639590000000],[0,1660410000000],[0,1667080000000]],"12":[[0,16670000000],[0,17080000000],[0,17080000000],[0,17080000000]],"10240":[[0,1526250000000],[0,1558750000000],[0,1562080000000],[0,1615420000000]],"14336":[[0,1822920000000],[0,1830830000000],[0,1849590000000],[0,1857558139534]],"32768":[[0,5319580000000],[0,5346250000000],[0,5389580000000],[0,5428340000000]],"128":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"4096":[[0,352080000000],[0,468750000000],[0,517080000000],[0,545000000000]],"49152":[[0,7626670000000],[0,7735830000000],[0,7743330000000],[0,7802920000000]],"262144":[[0,38750000000000],[0,39083000000000]],"3":[[0,17920000000],[0,17920000000],[0,17920000000],[0,18330000000]],"98304":[[0,14788750000000],[0,14917000000000],[0,15013750000000]]}},{"title":"UniqueDeque append, reserving capacity","results":{"2048":[[0,4273437500000],[0,4284580000000],[0,4285000000000],[0,4287698412698]],"1048576":[[0,2346542000000000],[0,2499111333333333]],"96":[[0,209000000000],[0,218750000000],[0,218750000000],[0,218750000000]],"327680":[[0,728291692307692],[0,749542000000000]],"384":[[0,809129032258],[0,810750000000],[0,812500000000],[0,812910000000]],"12288":[[0,26356000000000],[0,26755830000000],[0,26867500000000],[0,26883750000000]],"81920":[[0,174542000000000],[0,177342418181818],[0,177531250000000],[0,178946963636363]],"8":[[0,25830000000],[0,25840000000],[0,26250000000],[0,26250000000]],"1280":[[0,2684590000000],[0,2685410000000],[0,2685420000000],[0,2685420000000]],"3584":[[0,7458000000000],[0,7483340000000],[0,7485000000000],[0,7600000000000]],"7":[[0,24580000000],[0,24580000000],[0,24580000000],[0,24580000000]],"524288":[[0,1187208000000000],[0,1229750000000000]],"112":[[0,252080000000],[0,252080000000],[0,252500000000],[0,252500000000]],"896":[[0,1883330000000],[0,1883750000000],[0,1884160000000],[0,1885000000000]],"192":[[0,413330000000],[0,413750000000],[0,413750000000],[0,414580000000]],"80":[[0,184580000000],[0,184590000000],[0,185000000000],[0,185000000000]],"24":[[0,52500000000],[0,52500000000],[0,52500000000],[0,52500000000]],"40960":[[0,86871769230769],[0,87862153846153],[0,88156250000000],[0,88583300000000]],"16":[[0,36670000000],[0,37080000000],[0,37080000000],[0,37080000000]],"3072":[[0,6419160000000],[0,6420850000000],[0,6421670000000],[0,6422920000000]],"20":[[0,42000000000],[0,44160000000],[0,44170000000],[0,44580000000]],"224":[[0,479580000000],[0,480000000000],[0,480000000000],[0,480410000000]],"2560":[[0,5348083333333],[0,5349170000000],[0,5352910000000],[0,5367080000000]],"1792":[[0,3747080000000],[0,3747722222222],[0,3750000000000],[0,3751250000000]],"1024":[[0,2150420000000],[0,2150830000000],[0,2150830000000],[0,2153330000000]],"6144":[[0,13462821428571],[0,13484160000000],[0,13509590000000],[0,13511670000000]],"56":[[0,132910000000],[0,133350000000],[0,134160000000],[0,134580000000]],"786432":[[0,1757292000000000],[0,1767433400000000]],"163840":[[0,366667000000000],[0,370011230769230],[0,379897727272727]],"6":[[0,22920000000],[0,23330000000],[0,23330000000],[0,23330000000]],"48":[[0,117090000000],[0,117910000000],[0,117920000000],[0,118330000000]],"32":[[0,75410000000],[0,75830000000],[0,75830000000],[0,75830000000]],"14":[[0,33750000000],[0,33750000000],[0,34580000000],[0,34580000000]],"28672":[[0,60959650793650],[0,61842090000000],[0,63334000000000],[0,63833000000000]],"512":[[0,1078330000000],[0,1078340000000],[0,1078750000000],[0,1079170000000]],"196608":[[0,408958000000000],[0,435098500000000],[0,490729166666666]],"458752":[[0,1028000000000000],[0,1037250000000000]],"24576":[[0,52175840000000],[0,52447500000000],[0,52560602272727],[0,52774160000000]],"2":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"256":[[0,542000000000],[0,546250000000],[0,546250000000],[0,547080000000]],"1536":[[0,3217500000000],[0,3218330000000],[0,3218330000000],[0,3218750000000]],"64":[[0,151250000000],[0,151250000000],[0,151250000000],[0,151250000000]],"320":[[0,667000000000],[0,677500000000],[0,679580000000],[0,680555555555]],"114688":[[0,248486842105263],[0,249178710526315],[0,251736000000000]],"131072":[[0,283160333333333],[0,284270823529411],[0,295375000000000]],"16384":[[0,35194170000000],[0,35270840000000],[0,35346660000000],[0,35393750000000]],"5120":[[0,11285000000000],[0,11290830000000],[0,11301670000000],[0,11339590000000]],"229376":[[0,506792000000000],[0,507917000000000],[0,518416000000000]],"5":[[0,21660000000],[0,21670000000],[0,21670000000],[0,22080000000]],"10":[[0,28330000000],[0,28750000000],[0,28750000000],[0,28750000000]],"28":[[0,67080000000],[0,67080000000],[0,67080000000],[0,67080000000]],"655360":[[0,1462000000000000],[0,1527917000000000]],"7168":[[0,15888157894736],[0,15899470588235],[0,15997200000000],[0,16069500000000]],"20480":[[0,43784090909090],[0,44069170000000],[0,44165000000000],[0,44434523809523]],"65536":[[0,140876253731343],[0,142051923076923],[0,142919117647058],[0,143735911764705]],"917504":[[0,2053010250000000],[0,2103968750000000]],"160":[[0,347080000000],[0,347080000000],[0,347500000000],[0,347500000000]],"640":[[0,1351250000000],[0,1351660000000],[0,1351670000000],[0,1351670000000]],"40":[[0,101250000000],[0,101250000000],[0,101250000000],[0,106660000000]],"393216":[[0,872917000000000],[0,921000000000000]],"57344":[[0,120020750000000],[0,122518513888888],[0,122921405063291],[0,124202464788732]],"4":[[0,21250000000],[0,21250000000],[0,21670000000],[0,22500000000]],"1":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"768":[[0,1617500000000],[0,1617910000000],[0,1618750000000],[0,1618750000000]],"448":[[0,947500000000],[0,948750000000],[0,949170000000],[0,990420000000]],"8192":[[0,18029094339622],[0,18037080000000],[0,18079170000000],[0,18625000000000]],"12":[[0,31250000000],[0,31250000000],[0,31660000000],[0,31660000000]],"10240":[[0,22359590000000],[0,22741660000000],[0,22785830000000],[0,23016250000000]],"14336":[[0,30773750000000],[0,30780736842105],[0,30801136363636],[0,31220420000000]],"32768":[[0,69288634146341],[0,70005952380952],[0,70820184210526],[0,71657500000000]],"128":[[0,285830000000],[0,285830000000],[0,285840000000],[0,286250000000]],"4096":[[0,8542000000000],[0,8551670000000],[0,8553750000000],[0,8631250000000]],"49152":[[0,104500000000000],[0,104541500000000],[0,105658890109890],[0,109042000000000]],"262144":[[0,581917000000000],[0,602667000000000]],"3":[[0,20410000000],[0,20410000000],[0,20420000000],[0,20830000000]],"98304":[[0,209041000000000],[0,210171195652173],[0,213804622222222]]}},{"title":"std::deque push_front","results":{"2048":[[0,7060420000000],[0,7062080000000],[0,7069580000000],[0,7070830000000]],"1048576":[[0,3789541500000000],[0,4043167000000000]],"96":[[0,332910000000],[0,333330000000],[0,333750000000],[0,337920000000]],"327680":[[0,1164333375000000],[0,1211145875000000]],"384":[[0,1333000000000],[0,1343750000000],[0,1345410000000],[0,1347920000000]],"12288":[[0,43138330000000],[0,43182500000000],[0,43690420000000],[0,43932910000000]],"81920":[[0,288542000000000],[0,290354000000000],[0,293792000000000],[0,295251272727272]],"8":[[0,42500000000],[0,42910000000],[0,42910000000],[0,46250000000]],"1280":[[0,4395840000000],[0,4397541666666],[0,4399160000000],[0,4399580000000]],"3584":[[0,12367500000000],[0,12397920000000],[0,12458000000000],[0,12550420000000]],"7":[[0,41250000000],[0,41660000000],[0,41670000000],[0,42920000000]],"524288":[[0,1938250000000000],[0,1964906250000000]],"112":[[0,386250000000],[0,386660000000],[0,387080000000],[0,391250000000]],"896":[[0,3110830000000],[0,3111250000000],[0,3114500000000],[0,3123750000000]],"192":[[0,652500000000],[0,652920000000],[0,653273809523],[0,657920000000]],"80":[[0,279580000000],[0,280000000000],[0,280000000000],[0,285000000000]],"24":[[0,94170000000],[0,94580000000],[0,95000000000],[0,98750000000]],"40960":[[0,143354250000000],[0,143566600000000],[0,143800373134328],[0,146611116666666]],"16":[[0,67910000000],[0,67920000000],[0,68330000000],[0,72500000000]],"3072":[[0,10595830000000],[0,10619318181818],[0,10623750000000],[0,10689590000000]],"20":[[0,81250000000],[0,81250000000],[0,81250000000],[0,86250000000]],"224":[[0,757920000000],[0,758750000000],[0,759170000000],[0,764170000000]],"2560":[[0,8849190476190],[0,8860000000000],[0,8860420000000],[0,8862500000000]],"1792":[[0,6125000000000],[0,6147080000000],[0,6148330000000],[0,6148340000000]],"1024":[[0,3541660000000],[0,3542080000000],[0,3542080000000],[0,3553750000000]],"6144":[[0,21176437500000],[0,21208000000000],[0,21217500000000],[0,21239417910447]],"56":[[0,200420000000],[0,200830000000],[0,201250000000],[0,205000000000]],"786432":[[0,2832555666666666],[0,2868097000000000]],"163840":[[0,586833000000000],[0,603316666666666],[0,612030533333333]],"6":[[0,40420000000],[0,40420000000],[0,40830000000],[0,41670000000]],"48":[[0,173330000000],[0,173750000000],[0,174160000000],[0,178750000000]],"32":[[0,120410000000],[0,120830000000],[0,121250000000],[0,125420000000]],"14":[[0,60830000000],[0,61250000000],[0,61250000000],[0,65830000000]],"28672":[[0,98959000000000],[0,99000000000000],[0,101453125000000],[0,101596010869565]],"512":[[0,1767500000000],[0,1767910000000],[0,1767920000000],[0,1771670000000]],"196608":[[0,698958000000000],[0,711557692307692],[0,768121583333333]],"458752":[[0,1639958000000000],[0,1698233400000000]],"24576":[[0,85267080000000],[0,85517500000000],[0,85687080000000],[0,85734375000000]],"2":[[0,35840000000],[0,36250000000],[0,36250000000],[0,37344827586]],"256":[[0,865420000000],[0,865830000000],[0,866660000000],[0,870689655172]],"1536":[[0,5250000000000],[0,5273330000000],[0,5281250000000],[0,5289160000000]],"64":[[0,226670000000],[0,226670000000],[0,227080000000],[0,232080000000]],"320":[[0,1130420000000],[0,1130830000000],[0,1130840000000],[0,1130857142857]],"114688":[[0,405125000000000],[0,406833000000000],[0,417292000000000]],"131072":[[0,470390368421052],[0,470454380952380],[0,472375000000000]],"16384":[[0,57028750000000],[0,57884847222222],[0,57959000000000],[0,58342090000000]],"5120":[[0,17676587301587],[0,17689170000000],[0,17689580000000],[0,17770830000000]],"229376":[[0,830417000000000],[0,831996181818181],[0,864972222222222]],"5":[[0,39160000000],[0,39580000000],[0,39580000000],[0,40830000000]],"10":[[0,47910000000],[0,47920000000],[0,48330000000],[0,52910000000]],"28":[[0,107090000000],[0,107910000000],[0,107910000000],[0,112080000000]],"655360":[[0,2411187500000000],[0,2414739750000000]],"7168":[[0,24785000000000],[0,24833000000000],[0,24867614583333],[0,24946808510638]],"20480":[[0,70916000000000],[0,71050420000000],[0,71135425000000],[0,71432500000000]],"65536":[[0,230270750000000],[0,230875000000000],[0,231887500000000],[0,233404761904761]],"917504":[[0,3280791500000000],[0,3352875000000000]],"160":[[0,541500000000],[0,545840000000],[0,546250000000],[0,550830000000]],"640":[[0,2194170000000],[0,2194580000000],[0,2195000000000],[0,2199160000000]],"40":[[0,146000000000],[0,147500000000],[0,147500000000],[0,152090000000]],"393216":[[0,1425729166666666],[0,1488270833333333]],"57344":[[0,202167000000000],[0,202375000000000],[0,202652666666666],[0,203219444444444]],"4":[[0,38750000000],[0,38750000000],[0,39160000000],[0,40000000000]],"1":[[0,33750000000],[0,34160000000],[0,34160000000],[0,35420000000]],"768":[[0,2618330000000],[0,2619318181818],[0,2621660000000],[0,2622920000000]],"448":[[0,1554580000000],[0,1554580000000],[0,1560410000000],[0,1645000000000]],"8192":[[0,28310420000000],[0,28333000000000],[0,28543842105263],[0,28599630434782]],"12":[[0,54160000000],[0,54580000000],[0,54580000000],[0,59160000000]],"10240":[[0,35312500000000],[0,35458000000000],[0,36125000000000],[0,36189590000000]],"14336":[[0,49583500000000],[0,49868340000000],[0,50433330000000],[0,50708330000000]],"32768":[[0,113375000000000],[0,113416000000000],[0,114604000000000],[0,115510500000000]],"128":[[0,439170000000],[0,439170000000],[0,440000000000],[0,444580000000]],"4096":[[0,14111670000000],[0,14123750000000],[0,14142080000000],[0,14194160000000]],"49152":[[0,172543140350877],[0,174000000000000],[0,174125000000000],[0,174292000000000]],"262144":[[0,945120800000000],[0,957262500000000]],"3":[[0,37500000000],[0,37500000000],[0,37500000000],[0,38750000000]],"98304":[[0,348431571428571],[0,350441964285714],[0,350597333333333]]}},{"title":"VecDeque push_front","results":{"2048":[[0,5350000000000],[0,5375000000000],[0,5382080000000],[0,5407500000000]],"1048576":[[0,3438916000000000],[0,3591000000000000]],"96":[[0,374160000000],[0,374170000000],[0,375000000000],[0,377910000000]],"327680":[[0,856709000000000],[0,870428000000000]],"384":[[0,1155000000000],[0,1155000000000],[0,1157080000000],[0,1161660000000]],"12288":[[0,31770833333333],[0,31842920000000],[0,32140420000000],[0,32271000000000]],"81920":[[0,202791000000000],[0,203250000000000],[0,203875000000000],[0,205917000000000]],"8":[[0,50410000000],[0,50410000000],[0,50830000000],[0,58750000000]],"1280":[[0,3583330000000],[0,3621250000000],[0,3626250000000],[0,3627080000000]],"3584":[[0,9215410000000],[0,9260420000000],[0,9277080000000],[0,9375000000000]],"7":[[0,50410000000],[0,50420000000],[0,50420000000],[0,50830000000]],"524288":[[0,1337250000000000],[0,1354250000000000]],"112":[[0,411250000000],[0,411670000000],[0,412090000000],[0,415830000000]],"896":[[0,2466670000000],[0,2467080000000],[0,2470000000000],[0,2471250000000]],"192":[[0,623330000000],[0,626670000000],[0,627080000000],[0,627500000000]],"80":[[0,336670000000],[0,337500000000],[0,337500000000],[0,339580000000]],"24":[[0,147500000000],[0,147910000000],[0,148330000000],[0,148330000000]],"40960":[[0,101458000000000],[0,101708000000000],[0,102917000000000],[0,103750000000000]],"16":[[0,100000000000],[0,100410000000],[0,100410000000],[0,100420000000]],"3072":[[0,8000000000000],[0,8017333333333],[0,8050830000000],[0,8076670000000]],"20":[[0,135420000000],[0,135830000000],[0,136670000000],[0,137080000000]],"224":[[0,696670000000],[0,699580000000],[0,700000000000],[0,703750000000]],"2560":[[0,6828750000000],[0,6845000000000],[0,6845500000000],[0,6853330000000]],"1792":[[0,4746670000000],[0,4750830000000],[0,4767080000000],[0,4800420000000]],"1024":[[0,2768750000000],[0,2768750000000],[0,2771660000000],[0,2775420000000]],"6144":[[0,16990420000000],[0,17003676470588],[0,17012500000000],[0,17056660000000]],"56":[[0,236250000000],[0,237080000000],[0,237500000000],[0,237910000000]],"786432":[[0,2529416666666666],[0,2529541000000000]],"163840":[[0,404625000000000],[0,419141304347826],[0,428875000000000]],"6":[[0,50000000000],[0,50410000000],[0,50420000000],[0,50830000000]],"48":[[0,217910000000],[0,217920000000],[0,218330000000],[0,218750000000]],"32":[[0,149160000000],[0,149580000000],[0,150000000000],[0,150000000000]],"14":[[0,98750000000],[0,98750000000],[0,98750000000],[0,100000000000]],"28672":[[0,71583000000000],[0,71587090000000],[0,72019057142857],[0,72445000000000]],"512":[[0,1450000000000],[0,1458750000000],[0,1460000000000],[0,1460420000000]],"196608":[[0,482837500000000],[0,487500000000000],[0,529645833333333]],"458752":[[0,1161739625000000],[0,1175458250000000]],"24576":[[0,62135000000000],[0,62270000000000],[0,62338900000000],[0,63035420000000]],"2":[[0,20000000000],[0,20000000000],[0,20000000000],[0,20410000000]],"256":[[0,774590000000],[0,775000000000],[0,776250000000],[0,779170000000]],"1536":[[0,4158203125000],[0,4212500000000],[0,4219160000000],[0,4229000000000]],"64":[[0,255000000000],[0,255410000000],[0,255830000000],[0,256670000000]],"320":[[0,1005000000000],[0,1007080000000],[0,1007500000000],[0,1011670000000]],"114688":[[0,281250000000000],[0,281292000000000],[0,282794212121212]],"131072":[[0,320236548387096],[0,330916000000000],[0,333280172413793]],"16384":[[0,41334000000000],[0,41553330000000],[0,41625000000000],[0,42114170000000]],"5120":[[0,14486250000000],[0,14495420000000],[0,14514580000000],[0,14723330000000]],"229376":[[0,561500000000000],[0,564250000000000],[0,569042000000000]],"5":[[0,51250000000],[0,52090000000],[0,52920000000],[0,54590000000]],"10":[[0,96670000000],[0,96670000000],[0,97080000000],[0,97080000000]],"28":[[0,142080000000],[0,142500000000],[0,142500000000],[0,142500000000]],"655360":[[0,2204177000000000],[0,2224468750000000]],"7168":[[0,19259170000000],[0,19309160000000],[0,19317090000000],[0,19408400000000]],"20480":[[0,52286250000000],[0,52292000000000],[0,52375000000000],[0,54240000000000]],"65536":[[0,159375000000000],[0,159750000000000],[0,161556704918032],[0,164316600000000]],"917504":[[0,2946916000000000],[0,3102709000000000]],"160":[[0,549170000000],[0,551660000000],[0,551670000000],[0,554580000000]],"640":[[0,1870000000000],[0,1870420000000],[0,1873330000000],[0,1875000000000]],"40":[[0,202500000000],[0,202920000000],[0,203330000000],[0,203750000000]],"393216":[[0,1007125000000000],[0,1027209000000000]],"57344":[[0,140250000000000],[0,140625000000000],[0,140916000000000],[0,141517257142857]],"4":[[0,20420000000],[0,20830000000],[0,20840000000],[0,21250000000]],"1":[[0,19160000000],[0,19170000000],[0,19580000000],[0,19580000000]],"768":[[0,2165000000000],[0,2172920000000],[0,2174580000000],[0,2175420000000]],"448":[[0,1300830000000],[0,1301250000000],[0,1305548387096],[0,1333000000000]],"8192":[[0,21889580000000],[0,21920000000000],[0,21988330000000],[0,23032910000000]],"12":[[0,97500000000],[0,97500000000],[0,97500000000],[0,97500000000]],"10240":[[0,26989724637681],[0,27007920000000],[0,27424580000000],[0,27655420000000]],"14336":[[0,36549295774647],[0,36625000000000],[0,36635830000000],[0,37254580000000]],"32768":[[0,80984818181818],[0,81278409090909],[0,81292000000000],[0,81306250000000]],"128":[[0,449170000000],[0,449170000000],[0,451250000000],[0,453750000000]],"4096":[[0,10407500000000],[0,10444500000000],[0,10450420000000],[0,10500410000000]],"49152":[[0,120833000000000],[0,121041000000000],[0,122750000000000],[0,127963740259740]],"262144":[[0,641625000000000],[0,654333000000000]],"3":[[0,20410000000],[0,20410000000],[0,20410000000],[0,21250000000]],"98304":[[0,241916500000000],[0,242167000000000],[0,243270825000000]]}},{"title":"UniqueDeque prepend","results":{"2048":[[0,4601250000000],[0,4602920000000],[0,4610420000000],[0,4612910000000]],"1048576":[[0,2568222333333333],[0,2648834000000000]],"96":[[0,445000000000],[0,450840000000],[0,454580000000],[0,458000000000]],"327680":[[0,772805583333333],[0,817459000000000]],"384":[[0,1101670000000],[0,1108340000000],[0,1112500000000],[0,1112910000000]],"12288":[[0,29539405405405],[0,29540840000000],[0,29583000000000],[0,29692500000000]],"81920":[[0,182167000000000],[0,182292000000000],[0,183097750000000],[0,190387254901960]],"8":[[0,120420000000],[0,120420000000],[0,120420000000],[0,120420000000]],"1280":[[0,3123340000000],[0,3127920000000],[0,3148330000000],[0,3174580000000]],"3584":[[0,7800420000000],[0,7818330000000],[0,7848843137254],[0,7875000000000]],"7":[[0,118750000000],[0,118750000000],[0,118750000000],[0,118750000000]],"524288":[[0,1195750000000000],[0,1244922714285714]],"112":[[0,482080000000],[0,482500000000],[0,484580000000],[0,489170000000]],"896":[[0,2231670000000],[0,2235830000000],[0,2237500000000],[0,2237920000000]],"192":[[0,684580000000],[0,685000000000],[0,685830000000],[0,686660000000]],"80":[[0,419590000000],[0,426250000000],[0,426660000000],[0,444580000000]],"24":[[0,194580000000],[0,195000000000],[0,195410000000],[0,195420000000]],"40960":[[0,92334000000000],[0,92964285714285],[0,93073684210526],[0,96135000000000]],"16":[[0,185410000000],[0,185830000000],[0,186250000000],[0,186660000000]],"3072":[[0,6792080000000],[0,6798611111111],[0,6821670000000],[0,6821670000000]],"20":[[0,189580000000],[0,190410000000],[0,190420000000],[0,191250000000]],"224":[[0,803330000000],[0,811250000000],[0,813330000000],[0,813750000000]],"2560":[[0,5831250000000],[0,5842080000000],[0,5844590000000],[0,5855830000000]],"1792":[[0,4083000000000],[0,4113330000000],[0,4122500000000],[0,4142090000000]],"1024":[[0,2480000000000],[0,2480420000000],[0,2484170000000],[0,2485000000000]],"6144":[[0,14041670000000],[0,14063750000000],[0,14065830000000],[0,14123750000000]],"56":[[0,317910000000],[0,318330000000],[0,318340000000],[0,323340000000]],"786432":[[0,1805042000000000],[0,1818111000000000]],"163840":[[0,371437500000000],[0,372333000000000],[0,377485000000000]],"6":[[0,116250000000],[0,116250000000],[0,117080000000],[0,117080000000]],"48":[[0,302500000000],[0,302910000000],[0,307500000000],[0,307500000000]],"32":[[0,237500000000],[0,238750000000],[0,240420000000],[0,240830000000]],"14":[[0,158330000000],[0,158330000000],[0,158340000000],[0,158750000000]],"28672":[[0,64382910000000],[0,64947080000000],[0,65543750000000],[0,65665830000000]],"512":[[0,1413320000000],[0,1414580000000],[0,1416250000000],[0,1419590000000]],"196608":[[0,456351190476190],[0,471943750000000],[0,478908300000000]],"458752":[[0,1043417000000000],[0,1070680555555555]],"24576":[[0,55951923076923],[0,56412090000000],[0,56968750000000],[0,57085830000000]],"2":[[0,37500000000],[0,37500000000],[0,37500000000],[0,37910000000]],"256":[[0,862500000000],[0,870000000000],[0,870000000000],[0,870420000000]],"1536":[[0,3605000000000],[0,3607920000000],[0,3608750000000],[0,3645500000000]],"64":[[0,328340000000],[0,328750000000],[0,329580000000],[0,334580000000]],"320":[[0,977500000000],[0,986670000000],[0,987920000000],[0,992080000000]],"114688":[[0,259687500000000],[0,263802250000000],[0,265757352941176]],"131072":[[0,289958000000000],[0,292813121212121],[0,306387931034482]],"16384":[[0,37385587301587],[0,37435830000000],[0,37681451612903],[0,38054170000000]],"5120":[[0,11992920000000],[0,12002500000000],[0,12040000000000],[0,12058330000000]],"229376":[[0,514042000000000],[0,519750000000000],[0,543333000000000]],"5":[[0,89580000000],[0,89580000000],[0,90000000000],[0,90420000000]],"10":[[0,150830000000],[0,150840000000],[0,151224719101],[0,151670000000]],"28":[[0,235410000000],[0,235830000000],[0,236250000000],[0,236660000000]],"655360":[[0,1589591600000000],[0,1604708000000000]],"7168":[[0,17750000000000],[0,17856924528301],[0,17927920000000],[0,18270000000000]],"20480":[[0,48132000000000],[0,48312500000000],[0,48724170000000],[0,49020840000000]],"65536":[[0,149667287878787],[0,150623645161290],[0,150883620689655],[0,151524460317460]],"917504":[[0,2078722333333333],[0,2108667000000000]],"160":[[0,620410000000],[0,625000000000],[0,627080000000],[0,627500000000]],"640":[[0,1652920000000],[0,1657920000000],[0,1658340000000],[0,1658750000000]],"40":[[0,248330000000],[0,248750000000],[0,250000000000],[0,252080000000]],"393216":[[0,959958000000000],[0,967893555555555]],"57344":[[0,125000000000000],[0,125264453333333],[0,125709000000000],[0,126125000000000]],"4":[[0,87920000000],[0,88330000000],[0,88340000000],[0,88750000000]],"1":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17920000000]],"768":[[0,1986250000000],[0,1994170000000],[0,1996250000000],[0,1999170000000]],"448":[[0,1286250000000],[0,1295000000000],[0,1295000000000],[0,1295830000000]],"8192":[[0,19792000000000],[0,19834000000000],[0,19851250000000],[0,20724170000000]],"12":[[0,155428571428],[0,155830000000],[0,156250000000],[0,156250000000]],"10240":[[0,23601660000000],[0,23645500000000],[0,23664062500000],[0,24021250000000]],"14336":[[0,33444590000000],[0,33590000000000],[0,33662080000000],[0,33818330000000]],"32768":[[0,72268027027027],[0,72442500000000],[0,72723750000000],[0,73514590000000]],"128":[[0,567920000000],[0,568750000000],[0,568750000000],[0,570000000000]],"4096":[[0,9916660000000],[0,9932080000000],[0,9934170000000],[0,10057080000000]],"49152":[[0,109417000000000],[0,110187988372093],[0,110574077777777],[0,111878230769230]],"262144":[[0,584062500000000],[0,608646000000000]],"3":[[0,63750000000],[0,63750000000],[0,63750000000],[0,64160000000]],"98304":[[0,215416000000000],[0,216791000000000],[0,218924595238095]]}},{"title":"VecDeque push_front, reserving capacity","results":{"2048":[[0,4757584415584],[0,4759170000000],[0,4760000000000],[0,4762090000000]],"1048576":[[0,2522333333333333],[0,2673542000000000]],"96":[[0,231660000000],[0,231660000000],[0,231660000000],[0,232500000000]],"327680":[[0,807003500000000],[0,807017333333333]],"384":[[0,892910000000],[0,892920000000],[0,893330000000],[0,896250000000]],"12288":[[0,29478750000000],[0,29560830000000],[0,29597500000000],[0,29722080000000]],"81920":[[0,192083000000000],[0,195166000000000],[0,195250000000000],[0,204709000000000]],"8":[[0,20410000000],[0,20410000000],[0,20830000000],[0,20830000000]],"1280":[[0,2976214285714],[0,2978330000000],[0,2978330000000],[0,2979580000000]],"3584":[[0,8322080000000],[0,8326250000000],[0,8328750000000],[0,8329590000000]],"7":[[0,17910000000],[0,17910000000],[0,18330000000],[0,18330000000]],"524288":[[0,1268583000000000],[0,1319571428571428]],"112":[[0,271660000000],[0,271670000000],[0,273330000000],[0,277090000000]],"896":[[0,2087500000000],[0,2087655172413],[0,2087910000000],[0,2090000000000]],"192":[[0,446660000000],[0,446660000000],[0,447090000000],[0,454160000000]],"80":[[0,193330000000],[0,193750000000],[0,193750000000],[0,195000000000]],"24":[[0,56250000000],[0,56250000000],[0,56250000000],[0,56250000000]],"40960":[[0,96597333333333],[0,96805333333333],[0,97159666666666],[0,97750000000000]],"16":[[0,37500000000],[0,37500000000],[0,37500000000],[0,37500000000]],"3072":[[0,7128340000000],[0,7131670000000],[0,7132500000000],[0,7136670000000]],"20":[[0,46660000000],[0,46670000000],[0,46670000000],[0,47080000000]],"224":[[0,521250000000],[0,522500000000],[0,524160000000],[0,524170000000]],"2560":[[0,5942209677419],[0,5944160000000],[0,5944170000000],[0,5946565217391]],"1792":[[0,4162500000000],[0,4164580000000],[0,4166660000000],[0,4169170000000]],"1024":[[0,2383750000000],[0,2384170000000],[0,2385000000000],[0,2386660000000]],"6144":[[0,14873340000000],[0,14882920000000],[0,14924170000000],[0,14950830000000]],"56":[[0,131660000000],[0,131660000000],[0,137500000000],[0,138330000000]],"786432":[[0,1888000000000000],[0,1894584000000000]],"163840":[[0,389166000000000],[0,389417000000000],[0,395898521739130]],"6":[[0,18340000000],[0,18750000000],[0,18750000000],[0,18750000000]],"48":[[0,118330000000],[0,119160000000],[0,119170000000],[0,119580000000]],"32":[[0,75000000000],[0,75000000000],[0,75000000000],[0,75000000000]],"14":[[0,32910000000],[0,32920000000],[0,33330000000],[0,33330000000]],"28672":[[0,67889170000000],[0,68092910000000],[0,68250000000000],[0,68583000000000]],"512":[[0,1189590000000],[0,1190420000000],[0,1197910000000],[0,1198340000000]],"196608":[[0,468000000000000],[0,485584000000000],[0,502535105263157]],"458752":[[0,1088875000000000],[0,1090042000000000]],"24576":[[0,58125000000000],[0,58249580000000],[0,58435000000000],[0,58440000000000]],"2":[[0,14170000000],[0,14580000000],[0,14580000000],[0,14580000000]],"256":[[0,595420000000],[0,595840000000],[0,596250000000],[0,600000000000]],"1536":[[0,3542000000000],[0,3570000000000],[0,3571250000000],[0,3571670000000]],"64":[[0,157500000000],[0,157910000000],[0,157910000000],[0,157920000000]],"320":[[0,744170000000],[0,744590000000],[0,751670000000],[0,787500000000]],"114688":[[0,272667000000000],[0,273042000000000],[0,274704676470588]],"131072":[[0,310208000000000],[0,317282258064516],[0,318589103448275]],"16384":[[0,38958000000000],[0,39044076923076],[0,39257500000000],[0,39516268292682]],"5120":[[0,12494170000000],[0,12500000000000],[0,12501660000000],[0,12505000000000]],"229376":[[0,545750000000000],[0,547625000000000],[0,548625000000000]],"5":[[0,18330000000],[0,18330000000],[0,18330000000],[0,18330000000]],"10":[[0,23750000000],[0,24160000000],[0,24580000000],[0,24580000000]],"28":[[0,65420000000],[0,65420000000],[0,65830000000],[0,65830000000]],"655360":[[0,1599888833333333],[0,1605850000000000]],"7168":[[0,17328750000000],[0,17339160000000],[0,17339170000000],[0,17529580000000]],"20480":[[0,48528000000000],[0,48708000000000],[0,48875000000000],[0,49056250000000]],"65536":[[0,154784666666666],[0,154791000000000],[0,156167000000000],[0,164237500000000]],"917504":[[0,2203489500000000],[0,2204145750000000]],"160":[[0,372500000000],[0,372920000000],[0,375830000000],[0,375830000000]],"640":[[0,1492080000000],[0,1493750000000],[0,1494580000000],[0,1496250000000]],"40":[[0,98750000000],[0,100420000000],[0,100420000000],[0,102500000000]],"393216":[[0,945333000000000],[0,975583300000000]],"57344":[[0,134958500000000],[0,135379561643835],[0,136042000000000],[0,136250000000000]],"4":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17910000000]],"1":[[0,13340000000],[0,13750000000],[0,13750000000],[0,13750000000]],"768":[[0,1790420000000],[0,1790420000000],[0,1790830000000],[0,1791250000000]],"448":[[0,1040840000000],[0,1041670000000],[0,1041673684210],[0,1048750000000]],"8192":[[0,19877090000000],[0,19909590000000],[0,19941670000000],[0,20042000000000]],"12":[[0,27910000000],[0,27910000000],[0,28330000000],[0,28330000000]],"10240":[[0,24750000000000],[0,24763750000000],[0,24834000000000],[0,24958000000000]],"14336":[[0,34243220930232],[0,34291000000000],[0,34292000000000],[0,34687500000000]],"32768":[[0,77540038461538],[0,77546142857142],[0,78037920000000],[0,78125000000000]],"128":[[0,307910000000],[0,307920000000],[0,308330000000],[0,308330000000]],"4096":[[0,9506660000000],[0,9507891891891],[0,9541500000000],[0,9600830000000]],"49152":[[0,116062500000000],[0,116347058823529],[0,117734130952380],[0,120834000000000]],"262144":[[0,629167000000000],[0,672672571428571]],"3":[[0,17500000000],[0,17500000000],[0,17500000000],[0,17910000000]],"98304":[[0,229958000000000],[0,233791000000000],[0,235292000000000]]}},{"title":"RigidDeque prepend, reserving capacity","results":{"2048":[[0,1152080000000],[0,1152500000000],[0,1152500000000],[0,1152910000000]],"1048576":[[0,579125000000000],[0,580265625000000]],"96":[[0,75830000000],[0,75830000000],[0,75830000000],[0,76250000000]],"327680":[[0,179583000000000],[0,185294018867924]],"384":[[0,236250000000],[0,236660000000],[0,236660000000],[0,236670000000]],"12288":[[0,7332910000000],[0,7352920000000],[0,7356670000000],[0,7568750000000]],"81920":[[0,45167000000000],[0,45252733333333],[0,45750000000000],[0,45890420000000]],"8":[[0,18750000000],[0,18750000000],[0,18750000000],[0,19160000000]],"1280":[[0,729170000000],[0,730410000000],[0,730410000000],[0,730420000000]],"3584":[[0,1983750000000],[0,1983750000000],[0,1983750000000],[0,1984170000000]],"7":[[0,17920000000],[0,17920000000],[0,18330000000],[0,18330000000]],"524288":[[0,289000000000000],[0,298542000000000]],"112":[[0,95830000000],[0,95830000000],[0,95830000000],[0,95830000000]],"896":[[0,518330000000],[0,519580000000],[0,519580000000],[0,521250000000]],"192":[[0,132090000000],[0,132090000000],[0,132090000000],[0,132500000000]],"80":[[0,66670000000],[0,66670000000],[0,66670000000],[0,69580000000]],"24":[[0,27080000000],[0,27500000000],[0,27500000000],[0,27500000000]],"40960":[[0,22926400000000],[0,22979580000000],[0,22987080000000],[0,23264423076923]],"16":[[0,22920000000],[0,23330000000],[0,23330000000],[0,23340000000]],"3072":[[0,1706660000000],[0,1706660000000],[0,1706660000000],[0,1707080000000]],"20":[[0,25000000000],[0,25410000000],[0,25410000000],[0,25410000000]],"224":[[0,149580000000],[0,149580000000],[0,150000000000],[0,150000000000]],"2560":[[0,1429580000000],[0,1429580000000],[0,1429580000000],[0,1430000000000]],"1792":[[0,1011538461538],[0,1011670000000],[0,1011670000000],[0,1014160000000]],"1024":[[0,584000000000],[0,590410000000],[0,590830000000],[0,590840000000]],"6144":[[0,3982920000000],[0,3995830000000],[0,3997500000000],[0,3997920000000]],"56":[[0,51250000000],[0,53330000000],[0,53330000000],[0,53330000000]],"786432":[[0,426959000000000],[0,434890136363636]],"163840":[[0,90375000000000],[0,90417000000000],[0,93673330000000]],"6":[[0,17500000000],[0,17500000000],[0,17910000000],[0,17910000000]],"48":[[0,48340000000],[0,52080000000],[0,52090000000],[0,52500000000]],"32":[[0,31670000000],[0,31670000000],[0,32080000000],[0,32080000000]],"14":[[0,21670000000],[0,22080000000],[0,22080000000],[0,22500000000]],"28672":[[0,16257080000000],[0,16273857142857],[0,16337920000000],[0,16467910000000]],"512":[[0,304170000000],[0,304580000000],[0,304580000000],[0,305000000000]],"196608":[[0,109125000000000],[0,112269543209876],[0,113542000000000]],"458752":[[0,251000000000000],[0,256041000000000]],"24576":[[0,14065830000000],[0,14067500000000],[0,14068340000000],[0,14109580000000]],"2":[[0,15410000000],[0,15410000000],[0,15410000000],[0,15420000000]],"256":[[0,166666666666],[0,167080000000],[0,167080000000],[0,167500000000]],"1536":[[0,875000000000],[0,875000000000],[0,877910000000],[0,877910000000]],"64":[[0,57500000000],[0,57500000000],[0,57500000000],[0,57500000000]],"320":[[0,200000000000],[0,201660000000],[0,201670000000],[0,211670000000]],"114688":[[0,63500000000000],[0,63562090000000],[0,64402500000000]],"131072":[[0,72333000000000],[0,72625000000000],[0,72667000000000]],"16384":[[0,9610410000000],[0,9616600000000],[0,9620420000000],[0,9639170000000]],"5120":[[0,3414160000000],[0,3415000000000],[0,3415830000000],[0,3426250000000]],"229376":[[0,125834000000000],[0,126167000000000],[0,126208000000000]],"5":[[0,17080000000],[0,17080000000],[0,17090000000],[0,17500000000]],"10":[[0,20000000000],[0,20000000000],[0,20000000000],[0,20000000000]],"28":[[0,29580000000],[0,29590000000],[0,30000000000],[0,30000000000]],"655360":[[0,363042000000000],[0,368916000000000]],"7168":[[0,4541250000000],[0,4541670000000],[0,4543750000000],[0,4545840000000]],"20480":[[0,11821660000000],[0,11842487804878],[0,11867500000000],[0,11870840000000]],"65536":[[0,36263330000000],[0,36405420000000],[0,36545420000000],[0,36841936507936]],"917504":[[0,498209000000000],[0,499000000000000]],"160":[[0,114580000000],[0,114580000000],[0,115000000000],[0,115000000000]],"640":[[0,381250000000],[0,381250000000],[0,381660000000],[0,382080000000]],"40":[[0,43750000000],[0,43750000000],[0,43750000000],[0,44160000000]],"393216":[[0,214458000000000],[0,217084000000000]],"57344":[[0,31859818181818],[0,31871250000000],[0,31879590000000],[0,32380000000000]],"4":[[0,18750000000],[0,19160000000],[0,19160000000],[0,23330000000]],"1":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15000000000]],"768":[[0,451250000000],[0,451660000000],[0,451670000000],[0,452080000000]],"448":[[0,270500000000],[0,271250000000],[0,271250000000],[0,271660000000]],"8192":[[0,5099160000000],[0,5102678571428],[0,5105420000000],[0,5113330000000]],"12":[[0,20830000000],[0,20830000000],[0,20830000000],[0,20840000000]],"10240":[[0,6208000000000],[0,6231250000000],[0,6231670000000],[0,6237920000000]],"14336":[[0,8466250000000],[0,8469339622641],[0,8483062500000],[0,8499580000000]],"32768":[[0,18505830000000],[0,18512920000000],[0,18532090000000],[0,18551660000000]],"128":[[0,105000000000],[0,105410000000],[0,105830000000],[0,109170000000]],"4096":[[0,2260830000000],[0,2260840000000],[0,2261250000000],[0,2261670000000]],"49152":[[0,27422916666666],[0,27438330000000],[0,27528340000000],[0,27916000000000]],"262144":[[0,144250000000000],[0,152823000000000]],"3":[[0,18330000000],[0,18330000000],[0,18750000000],[0,18750000000]],"98304":[[0,54499170000000],[0,54583000000000],[0,55795000000000]]}},{"title":"UniqueDeque prepend, reserving capacity","results":{"2048":[[0,3900000000000],[0,3900410000000],[0,3901670000000],[0,3910000000000]],"1048576":[[0,2069041000000000],[0,2076708000000000]],"96":[[0,209580000000],[0,209580000000],[0,209590000000],[0,210000000000]],"327680":[[0,654167000000000],[0,654917000000000]],"384":[[0,744170000000],[0,744580000000],[0,744590000000],[0,745000000000]],"12288":[[0,24266600000000],[0,24292000000000],[0,24333000000000],[0,26125000000000]],"81920":[[0,158708000000000],[0,160708000000000],[0,162556016393442],[0,174977207547169]],"8":[[0,25410000000],[0,25830000000],[0,25830000000],[0,25830000000]],"1280":[[0,2445830000000],[0,2446250000000],[0,2446250000000],[0,2447080000000]],"3584":[[0,6810000000000],[0,6810410000000],[0,6811475000000],[0,6815410000000]],"7":[[0,24170000000],[0,24580000000],[0,24580000000],[0,24580000000]],"524288":[[0,1026334000000000],[0,1083546222222222]],"112":[[0,239170000000],[0,239580000000],[0,239580000000],[0,240000000000]],"896":[[0,1717920000000],[0,1718750000000],[0,1719160000000],[0,1719580000000]],"192":[[0,382500000000],[0,382500000000],[0,382500000000],[0,382910000000]],"80":[[0,167000000000],[0,179160000000],[0,179170000000],[0,179580000000]],"24":[[0,50410000000],[0,50410000000],[0,50410000000],[0,50410000000]],"40960":[[0,79083000000000],[0,79125000000000],[0,79375000000000],[0,80166000000000]],"16":[[0,36250000000],[0,36250000000],[0,36250000000],[0,36250000000]],"3072":[[0,5838750000000],[0,5839160000000],[0,5840830000000],[0,5841670000000]],"20":[[0,42910000000],[0,42910000000],[0,42910000000],[0,43330000000]],"224":[[0,441660000000],[0,442080000000],[0,442080000000],[0,442080000000]],"2560":[[0,4870000000000],[0,4870830000000],[0,4870830000000],[0,4927920000000]],"1792":[[0,3413750000000],[0,3413750000000],[0,3414170000000],[0,3425830000000]],"1024":[[0,1961250000000],[0,1961660000000],[0,1962920000000],[0,1971660000000]],"6144":[[0,12284590000000],[0,12304170000000],[0,12334000000000],[0,12392500000000]],"56":[[0,130830000000],[0,132080000000],[0,133750000000],[0,134160000000]],"786432":[[0,1559000000000000],[0,1597763833333333]],"163840":[[0,318500000000000],[0,319833000000000],[0,333709000000000]],"6":[[0,22920000000],[0,22920000000],[0,23330000000],[0,23330000000]],"48":[[0,117500000000],[0,118330000000],[0,118750000000],[0,119160000000]],"32":[[0,77500000000],[0,77910000000],[0,77910000000],[0,78330000000]],"14":[[0,33750000000],[0,33750000000],[0,33750000000],[0,34170000000]],"28672":[[0,55667000000000],[0,55792000000000],[0,56125000000000],[0,56250000000000]],"512":[[0,985000000000],[0,985000000000],[0,985410000000],[0,995420000000]],"196608":[[0,382500000000000],[0,392186680000000],[0,400889478260869]],"458752":[[0,892417000000000],[0,925716700000000]],"24576":[[0,47708000000000],[0,47708400000000],[0,47750000000000],[0,47764000000000]],"2":[[0,16250000000],[0,16660000000],[0,16660000000],[0,16660000000]],"256":[[0,501660000000],[0,502090000000],[0,502500000000],[0,526250000000]],"1536":[[0,2930830000000],[0,2931106666666],[0,2932500000000],[0,2932910000000]],"64":[[0,145750000000],[0,147080000000],[0,147090000000],[0,148750000000]],"320":[[0,622500000000],[0,623340000000],[0,623750000000],[0,627500000000]],"114688":[[0,223250000000000],[0,223555863636363],[0,223833000000000]],"131072":[[0,253833000000000],[0,256000000000000],[0,259417000000000]],"16384":[[0,31989750000000],[0,32000000000000],[0,32099170000000],[0,32167000000000]],"5120":[[0,10335000000000],[0,10335000000000],[0,10342080000000],[0,10368750000000]],"229376":[[0,446292000000000],[0,448416000000000],[0,457083000000000]],"5":[[0,21660000000],[0,21660000000],[0,21660000000],[0,21660000000]],"10":[[0,28330000000],[0,28330000000],[0,28330000000],[0,28330000000]],"28":[[0,70410000000],[0,70830000000],[0,70840000000],[0,71250000000]],"655360":[[0,1296875000000000],[0,1320875000000000]],"7168":[[0,14312500000000],[0,14330420000000],[0,14348786516853],[0,14416000000000]],"20480":[[0,39992431818181],[0,40125000000000],[0,40167000000000],[0,40209000000000]],"65536":[[0,126083000000000],[0,127258400000000],[0,127709000000000],[0,128291666666666]],"917504":[[0,1809875000000000],[0,1809958000000000]],"160":[[0,322910000000],[0,322920000000],[0,322920000000],[0,323330000000]],"640":[[0,1232920000000],[0,1235000000000],[0,1235000000000],[0,1244160000000]],"40":[[0,100830000000],[0,101250000000],[0,101250000000],[0,101670000000]],"393216":[[0,786750000000000],[0,787292000000000]],"57344":[[0,111375000000000],[0,111542000000000],[0,111583000000000],[0,112208000000000]],"4":[[0,22080000000],[0,22500000000],[0,22500000000],[0,25410000000]],"1":[[0,15000000000],[0,15000000000],[0,15000000000],[0,15410000000]],"768":[[0,1476670000000],[0,1477090000000],[0,1477500000000],[0,1486660000000]],"448":[[0,875000000000],[0,875830000000],[0,876250000000],[0,876660000000]],"8192":[[0,16334000000000],[0,16458000000000],[0,16458000000000],[0,16542000000000]],"12":[[0,30420000000],[0,30830000000],[0,30830000000],[0,31250000000]],"10240":[[0,20458000000000],[0,20500000000000],[0,20508340000000],[0,20856660000000]],"14336":[[0,28229160000000],[0,28333000000000],[0,28397500000000],[0,28458000000000]],"32768":[[0,63458000000000],[0,63916000000000],[0,64000000000000],[0,65700410000000]],"128":[[0,268909090909],[0,269580000000],[0,270410000000],[0,270410000000]],"4096":[[0,7780830000000],[0,7792000000000],[0,7825772727272],[0,7826250000000]],"49152":[[0,95000000000000],[0,95013666666666],[0,95550000000000],[0,95875000000000]],"262144":[[0,518375000000000],[0,556247529411764]],"3":[[0,20830000000],[0,20857142857],[0,21250000000],[0,21250000000]],"98304":[[0,188875000000000],[0,190305666666666],[0,195125000000000]]}},{"title":"std::deque random insertions","results":{"2048":[[0,85219466666666],[0,86039666666666],[0,87441250000000],[0,88508333333333]],"96":[[0,982500000000],[0,997920000000],[0,1012080000000],[0,1078750000000]],"327680":[[0,2071825521000000000],[0,2103164250000000000]],"384":[[0,5863750000000],[0,5909170000000],[0,5979250000000],[0,5990840000000]],"12288":[[0,2051948000000000],[0,2056052250000000],[0,2076833000000000],[0,2333375000000000]],"81920":[[0,119747041500000000],[0,120203375000000000],[0,121243500000000000],[0,121413687500000000]],"8":[[0,105410000000],[0,110420000000],[0,119160000000],[0,120000000000]],"1280":[[0,38842920000000],[0,39559027777777],[0,39650000000000],[0,39750000000000]],"3584":[[0,224708500000000],[0,229104500000000],[0,229875000000000],[0,232165589743589]],"7":[[0,75830000000],[0,77500000000],[0,104170000000],[0,104580000000]],"524288":[[0,5390294750000000000],[0,5421634791000000000]],"112":[[0,1177500000000],[0,1194580000000],[0,1284090909090],[0,1292920000000]],"896":[[0,20652311475409],[0,20771000000000],[0,21190000000000],[0,22083330000000]],"192":[[0,2284580000000],[0,2375000000000],[0,2491250000000],[0,2541250000000]],"80":[[0,819170000000],[0,838750000000],[0,866250000000],[0,870410000000]],"24":[[0,254160000000],[0,257080000000],[0,264580000000],[0,267910000000]],"40960":[[0,25262167000000000],[0,25897583000000000],[0,26060958000000000],[0,26097083000000000]],"16":[[0,168750000000],[0,182090000000],[0,188750000000],[0,193330000000]],"3072":[[0,172680333333333],[0,173732142857142],[0,175729000000000],[0,176277666666666]],"20":[[0,206250000000],[0,211670000000],[0,217080000000],[0,225830000000]],"224":[[0,2767920000000],[0,2892080000000],[0,2907920000000],[0,2948340000000]],"2560":[[0,127208500000000],[0,128791750000000],[0,129478013888888],[0,129864500000000]],"1792":[[0,68916000000000],[0,69178736842105],[0,70415830000000],[0,70491878048780]],"1024":[[0,25750000000000],[0,26375000000000],[0,27186250000000],[0,27390830000000]],"6144":[[0,581625000000000],[0,586041000000000],[0,593229187500000],[0,593828125000000]],"56":[[0,551250000000],[0,556250000000],[0,574170000000],[0,594170000000]],"163840":[[0,514239083500000000],[0,517731979000000000],[0,520127916500000000]],"6":[[0,94160000000],[0,96250000000],[0,96660000000],[0,104580000000]],"48":[[0,485410000000],[0,499580000000],[0,516250000000],[0,520000000000]],"32":[[0,336670000000],[0,342080000000],[0,360000000000],[0,363750000000]],"14":[[0,151670000000],[0,159580000000],[0,161250000000],[0,166250000000]],"28672":[[0,11367208000000000],[0,11498625000000000],[0,11506500000000000],[0,11730875000000000]],"512":[[0,8347333333333],[0,8627080000000],[0,8717285714285],[0,8982080000000]],"196608":[[0,730011375000000000],[0,758665666500000000],[0,758683292000000000]],"458752":[[0,4152893042000000000],[0,4159420791000000000]],"24576":[[0,8051750000000000],[0,8239750000000000],[0,8295583000000000],[0,8323375000000000]],"2":[[0,42910000000],[0,42910000000],[0,74160000000],[0,76250000000]],"256":[[0,3264590000000],[0,3333750000000],[0,3347090000000],[0,3638000000000]],"1536":[[0,52916500000000],[0,52984696202531],[0,53527666666666],[0,53728146341463]],"64":[[0,627080000000],[0,654170000000],[0,681250000000],[0,699170000000]],"320":[[0,4396250000000],[0,4437920000000],[0,4529580000000],[0,4771250000000]],"114688":[[0,243777312500000000],[0,245059084000000000],[0,246152333000000000]],"131072":[[0,323916000000000000],[0,325964375000000000],[0,326597562500000000]],"16384":[[0,3501584000000000],[0,3583937500000000],[0,3601584000000000],[0,3611729500000000]],"5120":[[0,426791652173913],[0,427579695652173],[0,433417000000000],[0,434240500000000]],"229376":[[0,1032004812500000000],[0,1032061125000000000],[0,1035364291000000000]],"5":[[0,55410000000],[0,88750000000],[0,92500000000],[0,95000000000]],"10":[[0,126250000000],[0,127910000000],[0,132080000000],[0,140830000000]],"28":[[0,287910000000],[0,302080000000],[0,316250000000],[0,323750000000]],"7168":[[0,768295083333333],[0,772534750000000],[0,775187500000000],[0,800958000000000]],"20480":[[0,5501791000000000],[0,5531416000000000],[0,5576916000000000],[0,5580250000000000]],"65536":[[0,73943000000000000],[0,74440375000000000],[0,74503709000000000],[0,74895333000000000]],"160":[[0,1923750000000],[0,1953320000000],[0,1965830000000],[0,1967090000000]],"640":[[0,12169642857142],[0,12312500000000],[0,12543330000000],[0,13207500000000]],"40":[[0,400830000000],[0,425000000000],[0,435830000000],[0,442910000000]],"393216":[[0,3073541271000000000],[0,3085176750000000000]],"57344":[[0,54521667000000000],[0,54942500000000000],[0,55510062500000000],[0,55707167000000000]],"4":[[0,53330000000],[0,86660000000],[0,88750000000],[0,98750000000]],"1":[[0,37080000000],[0,37080000000],[0,37080000000],[0,37111111111]],"768":[[0,16407500000000],[0,16669590000000],[0,16853330000000],[0,16888200000000]],"448":[[0,6927500000000],[0,7021000000000],[0,7231382978723],[0,7812500000000]],"8192":[[0,978292000000000],[0,980209000000000],[0,980334000000000],[0,1010203777777777]],"12":[[0,137080000000],[0,144580000000],[0,145000000000],[0,148330000000]],"10240":[[0,1471888833333333],[0,1493889000000000],[0,1495284666666666],[0,1525409666666666]],"14336":[[0,2763152666666666],[0,2767861333333333],[0,2789305666666666],[0,2793597333333333]],"32768":[[0,15368708000000000],[0,15504209000000000],[0,15535792000000000],[0,15539375000000000]],"128":[[0,1408330000000],[0,1417500000000],[0,1467080000000],[0,1483330000000]],"4096":[[0,286694454545454],[0,288927000000000],[0,295627515151515],[0,295875000000000]],"49152":[[0,38351709000000000],[0,38850437500000000],[0,38973770500000000],[0,40275666500000000]],"262144":[[0,1328818771000000000],[0,1341204041000000000]],"3":[[0,80410000000],[0,80830000000],[0,81250000000],[0,82500000000]],"98304":[[0,180338187500000000],[0,180430229000000000],[0,185341334000000000]]}},{"title":"VecDeque random insertions","results":{"2048":[[0,5022500000000],[0,5028750000000],[0,5039590000000],[0,5050000000000]],"1048576":[[0,2761875000000000],[0,3063542000000000]],"96":[[0,427920000000],[0,428750000000],[0,429160000000],[0,430840000000]],"327680":[[0,813250000000000],[0,850333363636363]],"384":[[0,1180840000000],[0,1181250000000],[0,1182090000000],[0,1189580000000]],"12288":[[0,29003330000000],[0,29163750000000],[0,29632080000000],[0,32837080000000]],"81920":[[0,181690979166666],[0,183626660000000],[0,188958000000000],[0,193958000000000]],"8":[[0,66250000000],[0,66250000000],[0,66250000000],[0,75420000000]],"1280":[[0,3373330000000],[0,3410420000000],[0,3422920000000],[0,3433750000000]],"3584":[[0,8514170000000],[0,8516250000000],[0,8518340000000],[0,8624590000000]],"7":[[0,64160000000],[0,64160000000],[0,64170000000],[0,64170000000]],"524288":[[0,1215062500000000],[0,1276298500000000]],"112":[[0,461670000000],[0,463750000000],[0,463750000000],[0,466250000000]],"896":[[0,2376670000000],[0,2378750000000],[0,2379590000000],[0,2385830000000]],"192":[[0,697500000000],[0,699580000000],[0,700000000000],[0,701250000000]],"80":[[0,389580000000],[0,389590000000],[0,390410000000],[0,392080000000]],"24":[[0,158330000000],[0,158330000000],[0,158750000000],[0,160000000000]],"40960":[[0,90687500000000],[0,92333000000000],[0,94375000000000],[0,94625000000000]],"16":[[0,111250000000],[0,111660000000],[0,111660000000],[0,111660000000]],"3072":[[0,7421250000000],[0,7425410000000],[0,7428750000000],[0,7434170000000]],"20":[[0,149580000000],[0,150000000000],[0,150420000000],[0,151660000000]],"224":[[0,766670000000],[0,769580000000],[0,770000000000],[0,770420000000]],"2560":[[0,6325000000000],[0,6329590000000],[0,6360420000000],[0,6375000000000]],"1792":[[0,4471250000000],[0,4473750000000],[0,4515000000000],[0,4525000000000]],"1024":[[0,2655272727272],[0,2657910000000],[0,2659170000000],[0,2660000000000]],"6144":[[0,15653656250000],[0,15688340000000],[0,15796250000000],[0,16008330000000]],"56":[[0,276250000000],[0,276670000000],[0,277090000000],[0,278750000000]],"786432":[[0,2255333000000000],[0,2708000000000000]],"163840":[[0,375834000000000],[0,380625000000000],[0,389125000000000]],"6":[[0,62080000000],[0,62500000000],[0,62500000000],[0,62500000000]],"48":[[0,253330000000],[0,254160000000],[0,254580000000],[0,256250000000]],"32":[[0,174580000000],[0,175000000000],[0,175410000000],[0,175420000000]],"14":[[0,107080000000],[0,107080000000],[0,107500000000],[0,107500000000]],"28672":[[0,65660410000000],[0,66500000000000],[0,66750000000000],[0,67625000000000]],"512":[[0,1452500000000],[0,1458750000000],[0,1459580000000],[0,1463330000000]],"196608":[[0,454041000000000],[0,457083000000000],[0,463625000000000]],"458752":[[0,1143625000000000],[0,1148111166666666]],"24576":[[0,56665840000000],[0,56750000000000],[0,57784042253521],[0,58821507462686]],"2":[[0,22920000000],[0,22920000000],[0,23330000000],[0,23330000000]],"256":[[0,833000000000],[0,835830000000],[0,836660000000],[0,838750000000]],"1536":[[0,3958333333333],[0,3972080000000],[0,3973750000000],[0,3975000000000]],"64":[[0,292920000000],[0,293750000000],[0,294580000000],[0,294580000000]],"320":[[0,1043750000000],[0,1044170000000],[0,1044580000000],[0,1046250000000]],"114688":[[0,260223388888888],[0,264209000000000],[0,266334000000000]],"131072":[[0,290000000000000],[0,305979000000000],[0,330584758620689]],"16384":[[0,38249580000000],[0,38709000000000],[0,38975420000000],[0,39120000000000]],"5120":[[0,13346670000000],[0,13407080000000],[0,13437500000000],[0,13470588235294]],"229376":[[0,539250000000000],[0,563026941176470],[0,572274529411764]],"5":[[0,60410000000],[0,60410000000],[0,60410000000],[0,60420000000]],"10":[[0,99580000000],[0,99580000000],[0,99590000000],[0,100410000000]],"28":[[0,166670000000],[0,166670000000],[0,167910000000],[0,168330000000]],"655360":[[0,1945933400000000],[0,1976906250000000]],"7168":[[0,17708000000000],[0,17717910000000],[0,17977080000000],[0,18062500000000]],"20480":[[0,46437500000000],[0,46510250000000],[0,46824160000000],[0,48125000000000]],"65536":[[0,146104000000000],[0,148412169230769],[0,151597888888888],[0,152834000000000]],"917504":[[0,2563458000000000],[0,2769417000000000]],"160":[[0,631660000000],[0,631670000000],[0,631670000000],[0,636250000000]],"640":[[0,1834580000000],[0,1834590000000],[0,1837080000000],[0,1838750000000]],"40":[[0,237080000000],[0,237910000000],[0,238750000000],[0,239170000000]],"393216":[[0,933500000000000],[0,966875000000000]],"57344":[[0,129602371428571],[0,131834000000000],[0,133066205479452],[0,133189044776119]],"4":[[0,27500000000],[0,31250000000],[0,32080000000],[0,32910000000]],"1":[[0,20000000000],[0,20410000000],[0,20410000000],[0,20410000000]],"768":[[0,2102920000000],[0,2107500000000],[0,2108750000000],[0,2117500000000]],"448":[[0,1318750000000],[0,1320830000000],[0,1320840000000],[0,1325420000000]],"8192":[[0,20230000000000],[0,20432500000000],[0,20435000000000],[0,20459000000000]],"12":[[0,103330000000],[0,103330000000],[0,103750000000],[0,104160000000]],"10240":[[0,24291000000000],[0,24350000000000],[0,24892500000000],[0,25088340000000]],"14336":[[0,33177080000000],[0,34039170000000],[0,34257500000000],[0,34491279069767]],"32768":[[0,73265055555555],[0,76032750000000],[0,76084000000000],[0,87833000000000]],"128":[[0,496250000000],[0,497080000000],[0,497920000000],[0,500830000000]],"4096":[[0,9610000000000],[0,9613340000000],[0,9680333333333],[0,9946250000000]],"49152":[[0,111668586206896],[0,112000000000000],[0,113583000000000],[0,113833000000000]],"262144":[[0,594209000000000],[0,626125000000000]],"3":[[0,27080000000],[0,27500000000],[0,27910000000],[0,27920000000]],"98304":[[0,224728674418604],[0,226010250000000],[0,271417000000000]]}},{"title":"UniqueDeque random insertions","results":{"2048":[[0,65245420000000],[0,65246745098039],[0,65667000000000],[0,66338550000000]],"96":[[0,940410000000],[0,947080000000],[0,965830000000],[0,974580000000]],"327680":[[0,1784625334000000000],[0,1812723041500000000]],"384":[[0,3941666666666],[0,4000840000000],[0,4439160000000],[0,23625000000000]],"12288":[[0,1832167000000000],[0,1844625000000000],[0,1868591800000000],[0,2072458500000000]],"81920":[[0,104136729000000000],[0,104443979000000000],[0,104797437500000000],[0,105185333000000000]],"8":[[0,135420000000],[0,140410000000],[0,140420000000],[0,162500000000]],"1280":[[0,28104644444444],[0,28330410000000],[0,29230830000000],[0,29368750000000]],"3584":[[0,175354000000000],[0,177583333333333],[0,178208000000000],[0,182008666666666]],"7":[[0,131250000000],[0,135410000000],[0,135830000000],[0,144580000000]],"524288":[[0,4759029937500000000],[0,4803660333000000000]],"112":[[0,1040410000000],[0,1051250000000],[0,1088330000000],[0,1117080000000]],"896":[[0,14834000000000],[0,15546660000000],[0,15551250000000],[0,15741250000000]],"192":[[0,1800420000000],[0,1808330000000],[0,1810000000000],[0,1833330000000]],"80":[[0,821250000000],[0,825410000000],[0,839580000000],[0,846670000000]],"24":[[0,291670000000],[0,301250000000],[0,301670000000],[0,307080000000]],"40960":[[0,22904875000000000],[0,23024854500000000],[0,23206104500000000],[0,23279417000000000]],"16":[[0,230830000000],[0,235000000000],[0,245840000000],[0,248330000000]],"3072":[[0,133927250000000],[0,135583250000000],[0,136262072463768],[0,139055666666666]],"20":[[0,248330000000],[0,257500000000],[0,263750000000],[0,266670000000]],"224":[[0,2155410000000],[0,2163750000000],[0,2179590000000],[0,2200000000000]],"2560":[[0,97365777777777],[0,97678000000000],[0,98346322580645],[0,99029975609756]],"1792":[[0,51128330000000],[0,51857954545454],[0,52084000000000],[0,53088750000000]],"1024":[[0,19020812500000],[0,19207910000000],[0,19837910000000],[0,20394184210526]],"6144":[[0,481843750000000],[0,483291650000000],[0,485835450000000],[0,487687500000000]],"56":[[0,580830000000],[0,602500000000],[0,615410000000],[0,624580000000]],"163840":[[0,441280542000000000],[0,441939062500000000],[0,447409604000000000]],"6":[[0,126250000000],[0,126670000000],[0,127080000000],[0,137920000000]],"48":[[0,531660000000],[0,535410000000],[0,541250000000],[0,544160000000]],"32":[[0,379160000000],[0,397500000000],[0,397910000000],[0,407080000000]],"14":[[0,192910000000],[0,195000000000],[0,200830000000],[0,201250000000]],"28672":[[0,10418542000000000],[0,10466958500000000],[0,10477625000000000],[0,10562604500000000]],"512":[[0,5820000000000],[0,5940217391304],[0,5965830000000],[0,6007500000000]],"196608":[[0,637279625000000000],[0,640841041500000000],[0,643633834000000000]],"458752":[[0,3540987709000000000],[0,3573798542000000000]],"24576":[[0,7435958000000000],[0,7487750000000000],[0,7526958000000000],[0,7575291000000000]],"2":[[0,38330000000],[0,38330000000],[0,38330000000],[0,38330000000]],"256":[[0,2491670000000],[0,2495410000000],[0,2501670000000],[0,2564580000000]],"1536":[[0,38824170000000],[0,38834000000000],[0,39003330000000],[0,40944160000000]],"64":[[0,651670000000],[0,666660000000],[0,668330000000],[0,668750000000]],"320":[[0,3198340000000],[0,3199160000000],[0,3211250000000],[0,3296250000000]],"114688":[[0,209447667000000000],[0,210372083500000000],[0,210453500000000000]],"131072":[[0,276044417000000000],[0,276632833000000000],[0,288519500000000000]],"16384":[[0,3210902666666666],[0,3246041666666666],[0,3277750000000000],[0,3278778000000000]],"5120":[[0,343958000000000],[0,348706821428571],[0,349709821428571],[0,354542000000000]],"229376":[[0,874590917000000000],[0,884354333000000000],[0,887685062500000000]],"5":[[0,88330000000],[0,90840000000],[0,95000000000],[0,100000000000]],"10":[[0,177080000000],[0,180420000000],[0,181670000000],[0,189160000000]],"28":[[0,345000000000],[0,359170000000],[0,360420000000],[0,365000000000]],"655360":[[0,7236591333000000000],[0,7330207125000000000]],"7168":[[0,653866666666666],[0,657708000000000],[0,658752800000000],[0,688098214285714]],"20480":[[0,4994250000000000],[0,5016709000000000],[0,5063458000000000],[0,5147000000000000]],"65536":[[0,64177354000000000],[0,64941000000000000],[0,65006167000000000],[0,66268042000000000]],"160":[[0,1557920000000],[0,1559160000000],[0,1570830000000],[0,1582500000000]],"640":[[0,8245000000000],[0,8450559322033],[0,8612080000000],[0,8833000000000]],"40":[[0,423330000000],[0,449580000000],[0,460840000000],[0,463340000000]],"393216":[[0,2567459959000000000],[0,2626992541500000000]],"57344":[[0,47767729000000000],[0,48259250000000000],[0,48304021000000000],[0,48635167000000000]],"4":[[0,90840000000],[0,92910000000],[0,93330000000],[0,93340000000]],"1":[[0,18330000000],[0,18340000000],[0,19170000000],[0,19170000000]],"768":[[0,11122080000000],[0,11432303571428],[0,11795830000000],[0,12317500000000]],"448":[[0,4923611111111],[0,4966670000000],[0,4979580000000],[0,5122920000000]],"8192":[[0,842292000000000],[0,845996272727272],[0,847621181818181],[0,849750000000000]],"12":[[0,176660000000],[0,188750000000],[0,190000000000],[0,193330000000]],"10240":[[0,1286839285714285],[0,1310542000000000],[0,1313654714285714],[0,1314273857142857]],"14336":[[0,2507736000000000],[0,2522486333333333],[0,2524625000000000],[0,2528958000000000]],"32768":[[0,13937333000000000],[0,14047208500000000],[0,14077125000000000],[0,14321583500000000]],"128":[[0,1216660000000],[0,1247920000000],[0,1262080000000],[0,1272920000000]],"4096":[[0,228042000000000],[0,230153000000000],[0,234010904761904],[0,234988829268292]],"49152":[[0,34225625000000000],[0,34470646000000000],[0,34523729000000000],[0,34671667000000000]],"262144":[[0,1132786542000000000],[0,1180922396000000000]],"3":[[0,62500000000],[0,65420000000],[0,65830000000],[0,65830000000]],"98304":[[0,153663833000000000],[0,153740792000000000],[0,158549583500000000]]}},{"title":"std::deque pop_front","results":{"2048":[[0,6708000000000],[0,6708000000000],[0,6708000000000],[0,6709000000000]],"1048576":[[0,3494083000000000],[0,3496958000000000]],"96":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"327680":[[0,1083042000000000],[0,1185209000000000]],"384":[[0,1250000000000],[0,1250000000000],[0,1292000000000],[0,1458000000000]],"12288":[[0,40375000000000],[0,40375000000000],[0,40375000000000],[0,46625000000000]],"81920":[[0,270334000000000],[0,270375000000000],[0,271083000000000],[0,278917000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,4166000000000],[0,4166000000000],[0,4167000000000],[0,4208000000000]],"3584":[[0,11750000000000],[0,11750000000000],[0,11792000000000],[0,12750000000000]],"7":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"524288":[[0,1784917000000000],[0,1982000000000000]],"112":[[0,333000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"896":[[0,2875000000000],[0,2916000000000],[0,2916000000000],[0,3291000000000]],"192":[[0,625000000000],[0,625000000000],[0,625000000000],[0,625000000000]],"80":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"24":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"40960":[[0,134958000000000],[0,134958000000000],[0,135000000000000],[0,135334000000000]],"16":[[0,42000000000],[0,42000000000],[0,42000000000],[0,83000000000]],"3072":[[0,10042000000000],[0,10083000000000],[0,10084000000000],[0,10084000000000]],"20":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"224":[[0,708000000000],[0,708000000000],[0,708000000000],[0,709000000000]],"2560":[[0,8416000000000],[0,8416000000000],[0,8417000000000],[0,8417000000000]],"1792":[[0,5833000000000],[0,5875000000000],[0,5875000000000],[0,5875000000000]],"1024":[[0,3333000000000],[0,3333000000000],[0,3375000000000],[0,3500000000000]],"6144":[[0,20125000000000],[0,20167000000000],[0,20208000000000],[0,22875000000000]],"56":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"786432":[[0,2622417000000000],[0,2647083000000000]],"163840":[[0,540625000000000],[0,545042000000000],[0,561542000000000]],"6":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"48":[[0,125000000000],[0,166000000000],[0,167000000000],[0,167000000000]],"32":[[0,83000000000],[0,83000000000],[0,84000000000],[0,125000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,94583000000000],[0,94583000000000],[0,94625000000000],[0,94625000000000]],"512":[[0,1666000000000],[0,1666000000000],[0,1666000000000],[0,1666000000000]],"196608":[[0,649916000000000],[0,665042000000000],[0,665834000000000]],"458752":[[0,1523709000000000],[0,1530208000000000]],"24576":[[0,81083000000000],[0,81084000000000],[0,81125000000000],[0,81166000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,833000000000],[0,833000000000],[0,833000000000],[0,833000000000]],"1536":[[0,5041000000000],[0,5041000000000],[0,5042000000000],[0,5291000000000]],"64":[[0,208000000000],[0,208000000000],[0,208000000000],[0,209000000000]],"320":[[0,1041000000000],[0,1041000000000],[0,1083000000000],[0,1417000000000]],"114688":[[0,378583000000000],[0,378875000000000],[0,379459000000000]],"131072":[[0,433166000000000],[0,437542000000000],[0,443916000000000]],"16384":[[0,53834000000000],[0,53834000000000],[0,53875000000000],[0,53916000000000]],"5120":[[0,16791000000000],[0,16791000000000],[0,16792000000000],[0,16792000000000]],"229376":[[0,758958000000000],[0,763542000000000],[0,765292000000000]],"5":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"28":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"655360":[[0,2167792000000000],[0,2170292000000000]],"7168":[[0,23500000000000],[0,23541000000000],[0,23542000000000],[0,23542000000000]],"20480":[[0,67333000000000],[0,67375000000000],[0,67375000000000],[0,74166000000000]],"65536":[[0,216542000000000],[0,216584000000000],[0,216666000000000],[0,217208000000000]],"917504":[[0,3030917000000000],[0,3034541000000000]],"160":[[0,459000000000],[0,500000000000],[0,500000000000],[0,583000000000]],"640":[[0,2083000000000],[0,2083000000000],[0,2083000000000],[0,2084000000000]],"40":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"393216":[[0,1298917000000000],[0,1302834000000000]],"57344":[[0,189125000000000],[0,189166000000000],[0,189167000000000],[0,189208000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"768":[[0,2458000000000],[0,2500000000000],[0,2500000000000],[0,2542000000000]],"448":[[0,1458000000000],[0,1458000000000],[0,1458000000000],[0,1458000000000]],"8192":[[0,26875000000000],[0,26875000000000],[0,26875000000000],[0,26917000000000]],"12":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10240":[[0,33584000000000],[0,33625000000000],[0,33625000000000],[0,33666000000000]],"14336":[[0,47083000000000],[0,47083000000000],[0,47125000000000],[0,47125000000000]],"32768":[[0,108041000000000],[0,108042000000000],[0,108084000000000],[0,108084000000000]],"128":[[0,416000000000],[0,416000000000],[0,417000000000],[0,417000000000]],"4096":[[0,13417000000000],[0,13458000000000],[0,13458000000000],[0,13458000000000]],"49152":[[0,162209000000000],[0,162291000000000],[0,162292000000000],[0,162333000000000]],"262144":[[0,865959000000000],[0,885666000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,324458000000000],[0,324792000000000],[0,328333000000000]]}},{"title":"std::deque pop_back","results":{"2048":[[0,3625000000000],[0,3667000000000],[0,3708000000000],[0,3709000000000]],"1048576":[[0,1922209000000000],[0,1930833000000000]],"96":[[0,166000000000],[0,166000000000],[0,166000000000],[0,166000000000]],"327680":[[0,596000000000000],[0,655333000000000]],"384":[[0,667000000000],[0,708000000000],[0,708000000000],[0,1000000000000]],"12288":[[0,22125000000000],[0,22125000000000],[0,22167000000000],[0,27958000000000]],"81920":[[0,148625000000000],[0,148666000000000],[0,148875000000000],[0,149125000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1280":[[0,2250000000000],[0,2291000000000],[0,2291000000000],[0,2291000000000]],"3584":[[0,6416000000000],[0,6417000000000],[0,6458000000000],[0,6959000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"524288":[[0,955375000000000],[0,1086834000000000]],"112":[[0,208000000000],[0,208000000000],[0,208000000000],[0,208000000000]],"896":[[0,1583000000000],[0,1583000000000],[0,1583000000000],[0,1791000000000]],"192":[[0,333000000000],[0,333000000000],[0,333000000000],[0,375000000000]],"80":[[0,125000000000],[0,125000000000],[0,125000000000],[0,166000000000]],"24":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"40960":[[0,74167000000000],[0,74250000000000],[0,74375000000000],[0,74458000000000]],"16":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"3072":[[0,5459000000000],[0,5500000000000],[0,5500000000000],[0,5500000000000]],"20":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"224":[[0,375000000000],[0,416000000000],[0,416000000000],[0,416000000000]],"2560":[[0,4583000000000],[0,4583000000000],[0,4583000000000],[0,4584000000000]],"1792":[[0,3167000000000],[0,3167000000000],[0,3208000000000],[0,3208000000000]],"1024":[[0,1833000000000],[0,1833000000000],[0,1833000000000],[0,1917000000000]],"6144":[[0,11042000000000],[0,11083000000000],[0,11083000000000],[0,11708000000000]],"56":[[0,83000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"786432":[[0,1432000000000000],[0,1434791000000000]],"163840":[[0,297708000000000],[0,298667000000000],[0,298875000000000]],"6":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"48":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"32":[[0,41000000000],[0,41000000000],[0,42000000000],[0,83000000000]],"14":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28672":[[0,52000000000000],[0,52125000000000],[0,52209000000000],[0,52291000000000]],"512":[[0,875000000000],[0,875000000000],[0,916000000000],[0,917000000000]],"196608":[[0,357667000000000],[0,358167000000000],[0,365167000000000]],"458752":[[0,841125000000000],[0,941458000000000]],"24576":[[0,44708000000000],[0,44750000000000],[0,44791000000000],[0,44917000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,458000000000],[0,458000000000],[0,458000000000],[0,458000000000]],"1536":[[0,2750000000000],[0,2750000000000],[0,2750000000000],[0,2875000000000]],"64":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"320":[[0,541000000000],[0,542000000000],[0,583000000000],[0,750000000000]],"114688":[[0,208625000000000],[0,208625000000000],[0,208666000000000]],"131072":[[0,238416000000000],[0,238917000000000],[0,243542000000000]],"16384":[[0,29500000000000],[0,29541000000000],[0,29542000000000],[0,29542000000000]],"5120":[[0,9167000000000],[0,9208000000000],[0,9208000000000],[0,9208000000000]],"229376":[[0,417041000000000],[0,417792000000000],[0,418667000000000]],"5":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"10":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"28":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"655360":[[0,1192041000000000],[0,1196791000000000]],"7168":[[0,12875000000000],[0,12916000000000],[0,12917000000000],[0,12917000000000]],"20480":[[0,36958000000000],[0,37000000000000],[0,37000000000000],[0,37000000000000]],"65536":[[0,119167000000000],[0,119167000000000],[0,119292000000000],[0,119333000000000]],"917504":[[0,1669958000000000],[0,1671750000000000]],"160":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"640":[[0,1125000000000],[0,1125000000000],[0,1125000000000],[0,1125000000000]],"40":[[0,83000000000],[0,83000000000],[0,83000000000],[0,83000000000]],"393216":[[0,716250000000000],[0,722667000000000]],"57344":[[0,104000000000000],[0,104083000000000],[0,104125000000000],[0,104250000000000]],"4":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,1333000000000],[0,1333000000000],[0,1375000000000],[0,1416000000000]],"448":[[0,791000000000],[0,791000000000],[0,791000000000],[0,792000000000]],"8192":[[0,14708000000000],[0,14750000000000],[0,14750000000000],[0,14791000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,18416000000000],[0,18417000000000],[0,18417000000000],[0,18458000000000]],"14336":[[0,25792000000000],[0,25833000000000],[0,25916000000000],[0,25917000000000]],"32768":[[0,59417000000000],[0,59459000000000],[0,59500000000000],[0,59583000000000]],"128":[[0,208000000000],[0,208000000000],[0,250000000000],[0,250000000000]],"4096":[[0,7333000000000],[0,7375000000000],[0,7375000000000],[0,7416000000000]],"49152":[[0,89375000000000],[0,89417000000000],[0,89500000000000],[0,89583000000000]],"262144":[[0,476541000000000],[0,481041000000000]],"3":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"98304":[[0,178708000000000],[0,178917000000000],[0,179125000000000]]}},{"title":"std::deque random removals","results":{"2048":[[0,93042000000000],[0,93584000000000],[0,94167000000000],[0,96084000000000]],"96":[[0,1000000000000],[0,1000000000000],[0,1000000000000],[0,1042000000000]],"327680":[[0,1992577250000000000],[0,2004815250000000000]],"384":[[0,6708000000000],[0,6917000000000],[0,10667000000000],[0,18666000000000]],"12288":[[0,2077125000000000],[0,2082125000000000],[0,2106666000000000],[0,2148125000000000]],"81920":[[0,115903542000000000],[0,117050542000000000],[0,117583917000000000],[0,118761875000000000]],"8":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"1280":[[0,47292000000000],[0,47750000000000],[0,49792000000000],[0,50167000000000]],"3584":[[0,238917000000000],[0,240750000000000],[0,243250000000000],[0,244708000000000]],"7":[[0,41000000000],[0,83000000000],[0,83000000000],[0,125000000000]],"524288":[[0,5238552500000000000],[0,5276722000000000000]],"112":[[0,1125000000000],[0,1209000000000],[0,1250000000000],[0,1292000000000]],"896":[[0,27625000000000],[0,28042000000000],[0,28666000000000],[0,31208000000000]],"192":[[0,2458000000000],[0,2458000000000],[0,2542000000000],[0,2666000000000]],"80":[[0,792000000000],[0,833000000000],[0,834000000000],[0,875000000000]],"24":[[0,209000000000],[0,209000000000],[0,209000000000],[0,250000000000]],"40960":[[0,25303250000000000],[0,25340000000000000],[0,25587416000000000],[0,25743125000000000]],"16":[[0,125000000000],[0,125000000000],[0,125000000000],[0,209000000000]],"3072":[[0,182083000000000],[0,182542000000000],[0,183875000000000],[0,184500000000000]],"20":[[0,166000000000],[0,167000000000],[0,208000000000],[0,208000000000]],"224":[[0,3083000000000],[0,3084000000000],[0,3166000000000],[0,3375000000000]],"2560":[[0,137500000000000],[0,138583000000000],[0,139000000000000],[0,143042000000000]],"1792":[[0,78000000000000],[0,79584000000000],[0,79916000000000],[0,80750000000000]],"1024":[[0,31375000000000],[0,31583000000000],[0,32375000000000],[0,33125000000000]],"6144":[[0,593416000000000],[0,594500000000000],[0,596416000000000],[0,601584000000000]],"56":[[0,541000000000],[0,542000000000],[0,583000000000],[0,625000000000]],"163840":[[0,493038959000000000],[0,493476166000000000],[0,500329375000000000]],"6":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,458000000000],[0,458000000000],[0,459000000000],[0,541000000000]],"32":[[0,292000000000],[0,333000000000],[0,334000000000],[0,375000000000]],"14":[[0,125000000000],[0,125000000000],[0,125000000000],[0,167000000000]],"28672":[[0,11481000000000000],[0,11481458000000000],[0,11540542000000000],[0,11603625000000000]],"512":[[0,10250000000000],[0,10333000000000],[0,10500000000000],[0,10958000000000]],"196608":[[0,710619917000000000],[0,720175000000000000],[0,726276458000000000]],"458752":[[0,3976208833000000000],[0,3989472208000000000]],"24576":[[0,8045542000000000],[0,8220542000000000],[0,8228250000000000],[0,8290083000000000]],"2":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"256":[[0,3750000000000],[0,3917000000000],[0,3959000000000],[0,5125000000000]],"1536":[[0,61750000000000],[0,62000000000000],[0,62375000000000],[0,62416000000000]],"64":[[0,625000000000],[0,625000000000],[0,667000000000],[0,667000000000]],"320":[[0,5208000000000],[0,5584000000000],[0,5625000000000],[0,6833000000000]],"114688":[[0,237708042000000000],[0,239383833000000000],[0,239488917000000000]],"131072":[[0,312269834000000000],[0,315215917000000000],[0,323288667000000000]],"16384":[[0,3496208000000000],[0,3556000000000000],[0,3574208000000000],[0,3593125000000000]],"5120":[[0,435250000000000],[0,437250000000000],[0,440416000000000],[0,440459000000000]],"229376":[[0,986884625000000000],[0,987525084000000000],[0,1003159375000000000]],"5":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,83000000000],[0,83000000000],[0,83000000000],[0,84000000000]],"28":[[0,250000000000],[0,250000000000],[0,250000000000],[0,292000000000]],"655360":[[0,7910439833000000000]],"7168":[[0,778792000000000],[0,785375000000000],[0,790958000000000],[0,808209000000000]],"20480":[[0,5454916000000000],[0,5552291000000000],[0,5560708000000000],[0,5574375000000000]],"65536":[[0,71944000000000000],[0,72166167000000000],[0,73725625000000000],[0,73876875000000000]],"160":[[0,1958000000000],[0,2000000000000],[0,2041000000000],[0,2584000000000]],"640":[[0,16791000000000],[0,17333000000000],[0,17417000000000],[0,17583000000000]],"40":[[0,375000000000],[0,375000000000],[0,417000000000],[0,417000000000]],"393216":[[0,2898900667000000000],[0,2924784500000000000]],"57344":[[0,53296542000000000],[0,53747208000000000],[0,54045833000000000],[0,54933875000000000]],"4":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"1":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"768":[[0,22375000000000],[0,22625000000000],[0,23792000000000],[0,24083000000000]],"448":[[0,8417000000000],[0,8625000000000],[0,8833000000000],[0,9083000000000]],"8192":[[0,992250000000000],[0,993000000000000],[0,1000083000000000],[0,1009542000000000]],"12":[[0,83000000000],[0,83000000000],[0,125000000000],[0,125000000000]],"10240":[[0,1485875000000000],[0,1489459000000000],[0,1500959000000000],[0,1506250000000000]],"14336":[[0,2770292000000000],[0,2777500000000000],[0,2786667000000000],[0,2839333000000000]],"32768":[[0,15326459000000000],[0,15389333000000000],[0,15573250000000000],[0,15608916000000000]],"128":[[0,1375000000000],[0,1417000000000],[0,1458000000000],[0,1500000000000]],"4096":[[0,295667000000000],[0,295750000000000],[0,296292000000000],[0,316792000000000]],"49152":[[0,37890625000000000],[0,37953833000000000],[0,38378958000000000],[0,38392250000000000]],"262144":[[0,1272504459000000000],[0,1288432416000000000]],"3":[[0,41000000000],[0,41000000000],[0,41000000000],[0,42000000000]],"98304":[[0,172334667000000000],[0,175118375000000000],[0,175305291000000000]]}},{"title":"std::deque sort","results":{"2048":[[0,48417000000000],[0,48500000000000],[0,49209000000000],[0,49792000000000]],"1048576":[[0,57343750000000000],[0,58297833000000000]],"96":[[0,542000000000],[0,542000000000],[0,584000000000],[0,584000000000]],"327680":[[0,16536667000000000],[0,16715125000000000]],"384":[[0,3042000000000],[0,3167000000000],[0,3250000000000],[0,10625000000000]],"12288":[[0,439209000000000],[0,444041000000000],[0,444875000000000],[0,456625000000000]],"81920":[[0,3660375000000000],[0,3690875000000000],[0,3703417000000000],[0,3707083000000000]],"8":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"1280":[[0,20417000000000],[0,20708000000000],[0,24791000000000],[0,25584000000000]],"3584":[[0,102041000000000],[0,104042000000000],[0,104667000000000],[0,106791000000000]],"7":[[0,41000000000],[0,41000000000],[0,41000000000],[0,41000000000]],"524288":[[0,28461375000000000],[0,29110791000000000]],"112":[[0,667000000000],[0,708000000000],[0,709000000000],[0,792000000000]],"896":[[0,9917000000000],[0,9917000000000],[0,13417000000000],[0,14500000000000]],"192":[[0,1250000000000],[0,1250000000000],[0,1291000000000],[0,1333000000000]],"80":[[0,458000000000],[0,458000000000],[0,458000000000],[0,500000000000]],"24":[[0,125000000000],[0,125000000000],[0,125000000000],[0,125000000000]],"40960":[[0,1722125000000000],[0,1726208000000000],[0,1732292000000000],[0,1742917000000000]],"16":[[0,41000000000],[0,42000000000],[0,83000000000],[0,84000000000]],"3072":[[0,85041000000000],[0,85625000000000],[0,86250000000000],[0,90541000000000]],"20":[[0,83000000000],[0,84000000000],[0,84000000000],[0,125000000000]],"224":[[0,1541000000000],[0,1584000000000],[0,1584000000000],[0,1625000000000]],"2560":[[0,67416000000000],[0,68833000000000],[0,69041000000000],[0,71292000000000]],"1792":[[0,39083000000000],[0,39583000000000],[0,39917000000000],[0,39958000000000]],"1024":[[0,13250000000000],[0,13292000000000],[0,13292000000000],[0,16084000000000]],"6144":[[0,197750000000000],[0,199667000000000],[0,200208000000000],[0,205292000000000]],"56":[[0,291000000000],[0,291000000000],[0,292000000000],[0,333000000000]],"786432":[[0,42764291000000000],[0,42883791000000000]],"163840":[[0,7982792000000000],[0,8068583000000000],[0,8134208000000000]],"6":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"48":[[0,250000000000],[0,250000000000],[0,250000000000],[0,250000000000]],"32":[[0,125000000000],[0,166000000000],[0,166000000000],[0,209000000000]],"14":[[0,41000000000],[0,42000000000],[0,83000000000],[0,83000000000]],"28672":[[0,1154083000000000],[0,1154250000000000],[0,1158000000000000],[0,1176291000000000]],"512":[[0,4458000000000],[0,4708000000000],[0,5875000000000],[0,6083000000000]],"196608":[[0,9598917000000000],[0,9662917000000000],[0,10034792000000000]],"458752":[[0,23678125000000000],[0,23887458000000000]],"24576":[[0,961291000000000],[0,976333000000000],[0,981166000000000],[0,982875000000000]],"2":[[0,42000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"256":[[0,1834000000000],[0,1875000000000],[0,1875000000000],[0,2625000000000]],"1536":[[0,29375000000000],[0,29792000000000],[0,30125000000000],[0,30375000000000]],"64":[[0,334000000000],[0,375000000000],[0,375000000000],[0,375000000000]],"320":[[0,2417000000000],[0,2541000000000],[0,2542000000000],[0,2625000000000]],"114688":[[0,5294792000000000],[0,5381666000000000],[0,5521625000000000]],"131072":[[0,6011708000000000],[0,6112125000000000],[0,6283958000000000]],"16384":[[0,608375000000000],[0,623250000000000],[0,637083000000000],[0,638000000000000]],"5120":[[0,161167000000000],[0,161834000000000],[0,162375000000000],[0,168500000000000]],"229376":[[0,11287417000000000],[0,11748166000000000],[0,11834958000000000]],"5":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"10":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"28":[[0,125000000000],[0,125000000000],[0,166000000000],[0,166000000000]],"655360":[[0,35053792000000000],[0,35118834000000000]],"7168":[[0,238625000000000],[0,241416000000000],[0,242708000000000],[0,243792000000000]],"20480":[[0,783583000000000],[0,800584000000000],[0,808542000000000],[0,821833000000000]],"65536":[[0,2886166000000000],[0,2905792000000000],[0,2911417000000000],[0,2927042000000000]],"917504":[[0,49658875000000000],[0,50835125000000000]],"160":[[0,1041000000000],[0,1042000000000],[0,1083000000000],[0,1334000000000]],"640":[[0,6958000000000],[0,7083000000000],[0,7167000000000],[0,7750000000000]],"40":[[0,208000000000],[0,208000000000],[0,208000000000],[0,250000000000]],"393216":[[0,19996916000000000],[0,21280417000000000]],"57344":[[0,2486916000000000],[0,2507208000000000],[0,2511750000000000],[0,2530125000000000]],"4":[[0,41000000000],[0,42000000000],[0,42000000000],[0,42000000000]],"1":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"768":[[0,7708000000000],[0,9625000000000],[0,10584000000000],[0,10958000000000]],"448":[[0,3750000000000],[0,4042000000000],[0,4083000000000],[0,4167000000000]],"8192":[[0,278959000000000],[0,284291000000000],[0,284875000000000],[0,287416000000000]],"12":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"10240":[[0,356792000000000],[0,361375000000000],[0,365959000000000],[0,366625000000000]],"14336":[[0,521625000000000],[0,536459000000000],[0,540417000000000],[0,545792000000000]],"32768":[[0,1322292000000000],[0,1332375000000000],[0,1337291000000000],[0,1355291000000000]],"128":[[0,792000000000],[0,833000000000],[0,833000000000],[0,833000000000]],"4096":[[0,122167000000000],[0,122667000000000],[0,124416000000000],[0,131500000000000]],"49152":[[0,2103959000000000],[0,2108958000000000],[0,2129708000000000],[0,2134334000000000]],"262144":[[0,13283041000000000],[0,13660208000000000]],"3":[[0,41000000000],[0,41000000000],[0,42000000000],[0,42000000000]],"98304":[[0,4514417000000000],[0,4582917000000000],[0,4627916000000000]]}},{"title":"VecDeque sequential iteration","results":{"2048":[[0,583000000000],[0,584000000000],[0,585410000000]],"1048576":[[0,283833000000000],[0,284042000000000]],"96":[[0,30830000000],[0,31250000000],[0,31250000000]],"327680":[[0,88833000000000],[0,97398437500000]],"384":[[0,125000000000],[0,135000000000],[0,135410000000]],"12288":[[0,3356250000000],[0,3356250000000],[0,3356670000000]],"81920":[[0,22197500000000],[0,22200830000000],[0,22230000000000]],"8":[[0,4160000000],[0,4160000000],[0,4160000000]],"1280":[[0,375000000000],[0,377910000000],[0,377920000000]],"3584":[[0,1001250000000],[0,1001250000000],[0,1001250000000]],"7":[[0,3750000000],[0,3750000000],[0,3750000000]],"524288":[[0,145166625000000],[0,151387096774193]],"112":[[0,40830000000],[0,40840000000],[0,42920000000]],"896":[[0,274160000000],[0,274160000000],[0,274580000000]],"192":[[0,65420000000],[0,65420000000],[0,65830000000]],"80":[[0,25410000000],[0,25410000000],[0,25420000000]],"24":[[0,6916666666],[0,8330000000],[0,8330000000]],"40960":[[0,11083000000000],[0,11114580000000],[0,11170000000000]],"16":[[0,6250000000],[0,6250000000],[0,6250000000]],"3072":[[0,833000000000],[0,862875000000],[0,863330000000]],"20":[[0,7500000000],[0,7500000000],[0,7500000000]],"224":[[0,77910000000],[0,78330000000],[0,78330000000]],"2560":[[0,724160000000],[0,724170000000],[0,724580000000]],"1792":[[0,516660000000],[0,516666666666],[0,516670000000]],"1024":[[0,291000000000],[0,308330000000],[0,308750000000]],"6144":[[0,1693750000000],[0,1694160000000],[0,1694170000000]],"56":[[0,16660000000],[0,17080000000],[0,17080000000]],"786432":[[0,212958000000000],[0,215857804347826]],"163840":[[0,45400000000000],[0,46583000000000]],"6":[[0,3750000000],[0,3750000000],[0,3750000000]],"48":[[0,14580000000],[0,14590000000],[0,15000000000]],"32":[[0,10410000000],[0,10420000000],[0,10830000000]],"14":[[0,5250000000],[0,5410000000],[0,5830000000]],"28672":[[0,7790410000000],[0,7790420000000],[0,7791670000000]],"512":[[0,167000000000],[0,169923076923],[0,170830000000]],"196608":[[0,53375000000000],[0,57208500000000]],"458752":[[0,124375000000000],[0,124417000000000]],"24576":[[0,6625000000000],[0,6681670000000],[0,6682500000000]],"2":[[0,2500000000],[0,2910000000],[0,2910000000]],"256":[[0,83000000000],[0,83000000000],[0,87500000000]],"1536":[[0,447347222222],[0,447500000000],[0,447500000000]],"64":[[0,19580000000],[0,19913043478],[0,20000000000]],"320":[[0,106250000000],[0,106250000000],[0,106250000000]],"114688":[[0,31070420000000],[0,31516670000000]],"131072":[[0,35666671052631],[0,35667000000000]],"16384":[[0,4458333333333],[0,4459000000000],[0,4464590000000]],"5120":[[0,1417080000000],[0,1417080000000],[0,1417500000000]],"229376":[[0,62167000000000],[0,62208000000000]],"5":[[0,3340000000],[0,3750000000],[0,3750000000]],"10":[[0,4580000000],[0,4580000000],[0,4580000000]],"28":[[0,9160000000],[0,9170000000],[0,9580000000]],"655360":[[0,177458000000000],[0,185625803921568]],"7168":[[0,1970536585365],[0,1970830000000],[0,1970830000000]],"20480":[[0,5542000000000],[0,5573340000000],[0,5574170000000]],"65536":[[0,17797500000000],[0,17798330000000],[0,17923750000000]],"917504":[[0,250916000000000],[0,262640485714285]],"160":[[0,56670000000],[0,57080000000],[0,57080000000]],"640":[[0,204580000000],[0,204580000000],[0,205000000000]],"40":[[0,12500000000],[0,12500000000],[0,12910000000]],"393216":[[0,110225000000000],[0,110322916666666]],"57344":[[0,15541000000000],[0,15542000000000],[0,15599590000000]],"4":[[0,2910000000],[0,2910000000],[0,3330000000]],"1":[[0,1250000000],[0,1250000000],[0,1660000000]],"768":[[0,229000000000],[0,239160000000],[0,239160000000]],"448":[[0,152090000000],[0,152500000000],[0,152500000000]],"8192":[[0,2248750000000],[0,2248750000000],[0,2248750000000]],"12":[[0,5000000000],[0,5000000000],[0,5410000000]],"10240":[[0,2802500000000],[0,2802500000000],[0,2802910000000]],"14336":[[0,3910830000000],[0,3910830000000],[0,3911250000000]],"32768":[[0,8897500000000],[0,8917000000000],[0,8958000000000]],"128":[[0,46660000000],[0,46670000000],[0,47080000000]],"4096":[[0,1125000000000],[0,1140000000000],[0,1292920000000]],"49152":[[0,13331670000000],[0,13332080000000],[0,13333000000000]],"262144":[[0,71166000000000],[0,74768750000000]],"3":[[0,2500000000],[0,2910000000],[0,2920000000]],"98304":[[0,26697614285714],[0,26711250000000]]}},{"title":"UniqueDeque sequential iteration","results":{"2048":[[0,1666660000000],[0,1666660000000],[0,1666670000000]],"1048576":[[0,856500000000000],[0,880143909090909]],"96":[[0,81670000000],[0,82080000000],[0,82080000000]],"327680":[[0,271792000000000],[0,286800235294117]],"384":[[0,315830000000],[0,315830000000],[0,315830000000]],"12288":[[0,9958000000000],[0,9979590000000],[0,10102920000000]],"81920":[[0,66623306122448],[0,66708000000000],[0,66721938775510]],"8":[[0,7910000000],[0,8330000000],[0,8330000000]],"1280":[[0,1042920000000],[0,1043330000000],[0,1043340000000]],"3584":[[0,2913330000000],[0,2913750000000],[0,2913750000000]],"7":[[0,7090000000],[0,7500000000],[0,7500000000]],"524288":[[0,425833000000000],[0,459373047619047]],"112":[[0,93750000000],[0,95000000000],[0,95000000000]],"896":[[0,731250000000],[0,731250000000],[0,731250000000]],"192":[[0,159580000000],[0,160000000000],[0,160000000000]],"80":[[0,68464285714],[0,68750000000],[0,69160000000]],"24":[[0,20830000000],[0,20840000000],[0,21250000000]],"40960":[[0,33257989898989],[0,33370000000000],[0,33459000000000]],"16":[[0,14160000000],[0,14580000000],[0,14580000000]],"3072":[[0,2497910000000],[0,2497920000000],[0,2497920000000]],"20":[[0,17500000000],[0,17910000000],[0,17910000000]],"224":[[0,185830000000],[0,185830000000],[0,185830000000]],"2560":[[0,2081250000000],[0,2082080000000],[0,2082080000000]],"1792":[[0,1458750000000],[0,1458750000000],[0,1459160000000]],"1024":[[0,834745762711],[0,835400000000],[0,835420000000]],"6144":[[0,4991250000000],[0,4991660000000],[0,4992080000000]],"56":[[0,41000000000],[0,49170000000],[0,49580000000]],"786432":[[0,640500000000000],[0,648958285714285]],"163840":[[0,133250000000000],[0,139583000000000]],"6":[[0,6250000000],[0,6250000000],[0,6660000000]],"48":[[0,43330000000],[0,43330000000],[0,43330000000]],"32":[[0,27500000000],[0,27500000000],[0,27500000000]],"14":[[0,12500000000],[0,12910000000],[0,12910000000]],"28672":[[0,23283000000000],[0,23284294117647],[0,23316660000000]],"512":[[0,419117647058],[0,419580000000],[0,419580000000]],"196608":[[0,163166000000000],[0,167334000000000]],"458752":[[0,373875000000000],[0,389896680000000]],"24576":[[0,19958500000000],[0,19979000000000],[0,20002500000000]],"2":[[0,3330000000],[0,3330000000],[0,3330000000]],"256":[[0,208250000000],[0,212080000000],[0,212080000000]],"1536":[[0,1250000000000],[0,1250830000000],[0,1251250000000]],"64":[[0,42000000000],[0,55830000000],[0,55830000000]],"320":[[0,263750000000],[0,263750000000],[0,264170000000]],"114688":[[0,93133200000000],[0,93375000000000]],"131072":[[0,106625000000000],[0,109350000000000]],"16384":[[0,13305000000000],[0,13305232558139],[0,13305420000000]],"5120":[[0,4160000000000],[0,4160410000000],[0,4161670000000]],"229376":[[0,186458000000000],[0,188333000000000]],"5":[[0,5420000000],[0,5830000000],[0,5830000000]],"10":[[0,9580000000],[0,9580000000],[0,9580000000]],"28":[[0,24170000000],[0,24580000000],[0,24580000000]],"655360":[[0,532583000000000],[0,543699111111111]],"7168":[[0,5822500000000],[0,5822910000000],[0,5823330000000]],"20480":[[0,16666500000000],[0,16667090000000],[0,16917000000000]],"65536":[[0,53208500000000],[0,53229000000000],[0,53459000000000]],"917504":[[0,755958000000000],[0,763310846153846]],"160":[[0,133750000000],[0,133750000000],[0,134160000000]],"640":[[0,523340000000],[0,523600000000],[0,523750000000]],"40":[[0,36250000000],[0,36250000000],[0,36660000000]],"393216":[[0,333500000000000],[0,348302071428571]],"57344":[[0,46556818181818],[0,46667000000000],[0,46750000000000]],"4":[[0,5000000000],[0,5000000000],[0,5000000000]],"1":[[0,1250000000],[0,1250000000],[0,1250000000]],"768":[[0,625000000000],[0,627210526315],[0,627500000000]],"448":[[0,367500000000],[0,367910000000],[0,367910000000]],"8192":[[0,6655000000000],[0,6687920000000],[0,6690000000000]],"12":[[0,10375000000],[0,11250000000],[0,11250000000]],"10240":[[0,8316250000000],[0,8319170000000],[0,8368330000000]],"14336":[[0,11641250000000],[0,11642920000000],[0,11750000000000]],"32768":[[0,26583000000000],[0,26669170000000],[0,26792000000000]],"128":[[0,107910000000],[0,107910000000],[0,107910000000]],"4096":[[0,3329160000000],[0,3329160000000],[0,12071500000000]],"49152":[[0,39959000000000],[0,40083000000000],[0,40125000000000]],"262144":[[0,212917000000000],[0,213167000000000]],"3":[[0,3750000000],[0,4160000000],[0,4160000000]],"98304":[[0,79842391304347],[0,81743750000000]]}}],"version":1} \ No newline at end of file diff --git a/Benchmarks/results.html b/Benchmarks/results.html deleted file mode 100644 index 708b20ce..00000000 --- a/Benchmarks/results.html +++ /dev/null @@ -1,3247 +0,0 @@ - - - - - Benchmark results - - - -

Benchmark results

-

Click to expand individual items below.

-
- Deque Benchmarks -
-
- Operations -
-
- 01 operations -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 10 ps - 10 ps - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> init from unsafe buffer - - - Deque<Int> sequential iteration (contiguous, iterator) - - - Deque<Int> subscript get, random offsets (contiguous) - - - Deque<Int> append - - - Deque<Int> append, reserving capacity - - - Deque<Int> prepend - - - Deque<Int> prepend, reserving capacity - - - Deque<Int> removeFirst (contiguous) - - - Deque<Int> removeLast (contiguous) - - - Deque<Int> sort (contiguous) - - - Deque<Int> sort (discontiguous) - - -
-
-
- 02 iteration -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> sequential iteration (contiguous, iterator) - - - Deque<Int> sequential iteration (discontiguous, iterator) - - - Deque<Int> sequential iteration (contiguous, indices) - - - Deque<Int> sequential iteration (discontiguous, indices) - - -
-
-
- 03 access -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> subscript get, random offsets (contiguous) - - - Deque<Int> subscript get, random offsets (discontiguous) - - - Deque<Int> mutate through subscript (contiguous) - - - Deque<Int> mutate through subscript (discontiguous) - - -
-
-
- 04 mutate -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> mutate through subscript (contiguous) - - - Deque<Int> mutate through subscript (discontiguous) - - - Deque<Int> random swaps (contiguous) - - - Deque<Int> random swaps (discontiguous) - - - Deque<Int> partitioning around middle (contiguous) - - - Deque<Int> partitioning around middle (discontiguous) - - - Deque<Int> sort (contiguous) - - - Deque<Int> sort (discontiguous) - - -
-
-
- 05 push -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> append - - - Deque<Int> append, reserving capacity - - - Deque<Int> prepend - - - Deque<Int> prepend, reserving capacity - - -
-
-
- 06 pop -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> removeFirst (contiguous) - - - Deque<Int> removeFirst (discontiguous) - - - Deque<Int> removeLast (contiguous) - - - Deque<Int> removeLast (discontiguous) - - -
-
-
-
-
- Deque vs Array -
-
- 01 init from buffer of integers -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 10 ps - 10 ps - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> init from unsafe buffer - - - Array<Int> init from unsafe buffer - - -
-
-
- 02 sequential iteration -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> sequential iteration (contiguous, iterator) - - - Deque<Int> sequential iteration (contiguous, indices) - - - Deque<Int> sequential iteration (discontiguous, iterator) - - - Deque<Int> sequential iteration (discontiguous, indices) - - - Array<Int> sequential iteration - - -
-
-
- 03 random-access offset lookups -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> subscript get, random offsets (contiguous) - - - Deque<Int> subscript get, random offsets (discontiguous) - - - Array<Int> subscript get, random offsets - - -
-
-
- 04 mutate through subscript -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> mutate through subscript (contiguous) - - - Deque<Int> mutate through subscript (discontiguous) - - - Array<Int> mutate through subscript - - -
-
-
- 05 random swaps -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> random swaps (contiguous) - - - Deque<Int> random swaps (discontiguous) - - - Array<Int> random swaps - - -
-
-
- 06 partitioning around middle -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> partitioning around middle (contiguous) - - - Deque<Int> partitioning around middle (discontiguous) - - - Array<Int> partitioning around middle - - -
-
-
- 07 sort -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> sort (contiguous) - - - Deque<Int> sort (discontiguous) - - - Array<Int> sort - - -
-
-
- 08 append individual integers -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> append - - - Deque<Int> append, reserving capacity - - - Array<Int> append - - - Array<Int> append, reserving capacity - - -
-
-
- 09 prepend individual integers -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - 10 µs - 10 µs - - 100 µs - 100 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> prepend - - - Deque<Int> prepend, reserving capacity - - - Array<Int> prepend - - - Array<Int> prepend, reserving capacity - - -
-
-
- 10 random insertions -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - 10 µs - 10 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> random insertions - - - Array<Int> random insertions - - -
-
-
- 11 removeFirst -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - 10 µs - 10 µs - - 100 µs - 100 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> removeFirst (contiguous) - - - Deque<Int> removeFirst (discontiguous) - - - Array<Int> removeFirst - - -
-
-
- 12 removeLast -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> removeLast (contiguous) - - - Deque<Int> removeLast (discontiguous) - - - Array<Int> removeLast - - -
-
-
- 13 random removals -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - 10 µs - 10 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deque<Int> random removals (contiguous) - - - Deque<Int> random removals (discontiguous) - - - Array<Int> random removals - - -
-
-
-
-
- Deque vs std::deque vs VecDeque vs RigidDeque vs UniqueDeque -
-
- 01 init from buffer of integers -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 10 ps - 10 ps - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> constructor from buffer - - - VecDeque<isize> constructor from buffer - - - Deque<Int> init from unsafe buffer - - -
-
-
- 02 sequential iteration -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> sequential iteration - - - VecDeque<isize> sequential iteration - - - Deque<Int> sequential iteration (contiguous, iterator) - - - Deque<Int> sequential iteration (contiguous, indices) - - - Deque<Int> sequential iteration (discontiguous, iterator) - - - Deque<Int> sequential iteration (discontiguous, indices) - - - UniqueDeque<Int> sequential iteration - - -
-
-
- 03 random-access offset lookups -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> random-access offset lookups (operator []) - - - std::deque<intptr_t> at, random offsets - - - Deque<Int> subscript get, random offsets (contiguous) - - - Deque<Int> subscript get, random offsets (discontiguous) - - -
-
-
- 04 append individual integers -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> push_back - - - VecDeque<isize> push_back - - - Deque<Int> append - - - UniqueDeque<Int> append - - -
-
-
- 05 append individual integers, reserving capacity -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 10 ps - 10 ps - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VecDeque<isize> push_back, reserving capacity - - - Deque<Int> append, reserving capacity - - - RigidDeque<Int> append, reserving capacity - - - UniqueDeque<Int> append, reserving capacity - - -
-
-
- 06 prepend individual integers -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> push_front - - - VecDeque<isize> push_front - - - Deque<Int> prepend - - - UniqueDeque<Int> prepend - - -
-
-
- 07 prepend individual integers, reserving capacity -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 100 ps - 100 ps - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VecDeque<isize> push_front, reserving capacity - - - Deque<Int> prepend, reserving capacity - - - RigidDeque<Int> prepend, reserving capacity - - - UniqueDeque<Int> prepend, reserving capacity - - -
-
-
- 08 random insertions -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - 10 µs - 10 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> random insertions - - - VecDeque<isize> random insertions - - - Deque<Int> random insertions - - - UniqueDeque<Int> random insertions - - -
-
-
- 09 removeFirst -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> pop_front - - - Deque<Int> removeFirst (contiguous) - - - Deque<Int> removeFirst (discontiguous) - - -
-
-
- 10 removeLast -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> pop_back - - - Deque<Int> removeLast (contiguous) - - - Deque<Int> removeLast (discontiguous) - - -
-
-
- 11 random removals -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - 1 µs - 1 µs - - 10 µs - 10 µs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> random removals - - - Deque<Int> random removals (contiguous) - - - Deque<Int> random removals (discontiguous) - - -
-
-
- 12 sort -
- - - Average per-element processing time over input size (bands: min, mean, mean + 2stddev) - swift-collections-benchmark - - 1 - - 2 - - 4 - - 8 - - 16 - - 32 - - 64 - - 128 - - 256 - - 512 - - 1k - - 2k - - 4k - - 8k - - 16k - - 32k - - 64k - - 128k - - 256k - - 1 ns - 1 ns - - 10 ns - 10 ns - - 100 ns - 100 ns - - - - - - - - - - - - - - - - - - - - - - - - - std::deque<intptr_t> sort - - - Deque<Int> sort (contiguous) - - - Deque<Int> sort (discontiguous) - - -
-
-
-
-
-
- - From 0c376aceb61f8169e250771a198586ebc0ad120c Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 13:05:03 -0800 Subject: [PATCH 49/75] [BasicContainers] Move array implementations into subdirectories (This sets the stage for more data structures in BasicContainers) --- Sources/BasicContainers/CMakeLists.txt | 30 ++-- .../{ => RigidArray}/RigidArray+Append.swift | 0 .../RigidArray+Container.swift | 0 .../RigidArray+Experimental.swift | 0 .../RigidArray+Initializers.swift | 0 .../RigidArray+Insertions.swift | 0 .../RigidArray+Removals.swift | 0 .../RigidArray+Replacements.swift | 0 .../{ => RigidArray}/RigidArray.swift | 0 .../UniqueArray+Append.swift | 0 .../UniqueArray+Experimental.swift | 0 .../UniqueArray+Initializers.swift | 0 .../UniqueArray+Insertions.swift | 0 .../UniqueArray+Removals.swift | 0 .../UniqueArray+Replacements.swift | 0 .../{ => UniqueArray}/UniqueArray.swift | 0 Xcode/Collections.xcodeproj/project.pbxproj | 136 ++++++++++-------- 17 files changed, 91 insertions(+), 75 deletions(-) rename Sources/BasicContainers/{ => RigidArray}/RigidArray+Append.swift (100%) rename Sources/BasicContainers/{ => RigidArray}/RigidArray+Container.swift (100%) rename Sources/BasicContainers/{ => RigidArray}/RigidArray+Experimental.swift (100%) rename Sources/BasicContainers/{ => RigidArray}/RigidArray+Initializers.swift (100%) rename Sources/BasicContainers/{ => RigidArray}/RigidArray+Insertions.swift (100%) rename Sources/BasicContainers/{ => RigidArray}/RigidArray+Removals.swift (100%) rename Sources/BasicContainers/{ => RigidArray}/RigidArray+Replacements.swift (100%) rename Sources/BasicContainers/{ => RigidArray}/RigidArray.swift (100%) rename Sources/BasicContainers/{ => UniqueArray}/UniqueArray+Append.swift (100%) rename Sources/BasicContainers/{ => UniqueArray}/UniqueArray+Experimental.swift (100%) rename Sources/BasicContainers/{ => UniqueArray}/UniqueArray+Initializers.swift (100%) rename Sources/BasicContainers/{ => UniqueArray}/UniqueArray+Insertions.swift (100%) rename Sources/BasicContainers/{ => UniqueArray}/UniqueArray+Removals.swift (100%) rename Sources/BasicContainers/{ => UniqueArray}/UniqueArray+Replacements.swift (100%) rename Sources/BasicContainers/{ => UniqueArray}/UniqueArray.swift (100%) diff --git a/Sources/BasicContainers/CMakeLists.txt b/Sources/BasicContainers/CMakeLists.txt index ce27daa1..4cd43f19 100644 --- a/Sources/BasicContainers/CMakeLists.txt +++ b/Sources/BasicContainers/CMakeLists.txt @@ -23,19 +23,19 @@ else() endif() target_sources(${module_name} PRIVATE - "RigidArray.swift" - "RigidArray+Append.swift" - "RigidArray+Container.swift" - "RigidArray+Experimental.swift" - "RigidArray+Initializers.swift" - "RigidArray+Insertions.swift" - "RigidArray+Removals.swift" - "RigidArray+Replacements.swift" - "UniqueArray.swift" - "UniqueArray+Append.swift" - "UniqueArray+Experimental.swift" - "UniqueArray+Initializers.swift" - "UniqueArray+Insertions.swift" - "UniqueArray+Removals.swift" - "UniqueArray+Replacements.swift" + "RigidArray/RigidArray.swift" + "RigidArray/RigidArray+Append.swift" + "RigidArray/RigidArray+Container.swift" + "RigidArray/RigidArray+Experimental.swift" + "RigidArray/RigidArray+Initializers.swift" + "RigidArray/RigidArray+Insertions.swift" + "RigidArray/RigidArray+Removals.swift" + "RigidArray/RigidArray+Replacements.swift" + "UniqueArray/UniqueArray.swift" + "UniqueArray/UniqueArray+Append.swift" + "UniqueArray/UniqueArray+Experimental.swift" + "UniqueArray/UniqueArray+Initializers.swift" + "UniqueArray/UniqueArray+Insertions.swift" + "UniqueArray/UniqueArray+Removals.swift" + "UniqueArray/UniqueArray+Replacements.swift" ) diff --git a/Sources/BasicContainers/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift similarity index 100% rename from Sources/BasicContainers/RigidArray+Append.swift rename to Sources/BasicContainers/RigidArray/RigidArray+Append.swift diff --git a/Sources/BasicContainers/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift similarity index 100% rename from Sources/BasicContainers/RigidArray+Container.swift rename to Sources/BasicContainers/RigidArray/RigidArray+Container.swift diff --git a/Sources/BasicContainers/RigidArray+Experimental.swift b/Sources/BasicContainers/RigidArray/RigidArray+Experimental.swift similarity index 100% rename from Sources/BasicContainers/RigidArray+Experimental.swift rename to Sources/BasicContainers/RigidArray/RigidArray+Experimental.swift diff --git a/Sources/BasicContainers/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift similarity index 100% rename from Sources/BasicContainers/RigidArray+Initializers.swift rename to Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift similarity index 100% rename from Sources/BasicContainers/RigidArray+Insertions.swift rename to Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift diff --git a/Sources/BasicContainers/RigidArray+Removals.swift b/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift similarity index 100% rename from Sources/BasicContainers/RigidArray+Removals.swift rename to Sources/BasicContainers/RigidArray/RigidArray+Removals.swift diff --git a/Sources/BasicContainers/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift similarity index 100% rename from Sources/BasicContainers/RigidArray+Replacements.swift rename to Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift diff --git a/Sources/BasicContainers/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift similarity index 100% rename from Sources/BasicContainers/RigidArray.swift rename to Sources/BasicContainers/RigidArray/RigidArray.swift diff --git a/Sources/BasicContainers/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift similarity index 100% rename from Sources/BasicContainers/UniqueArray+Append.swift rename to Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift diff --git a/Sources/BasicContainers/UniqueArray+Experimental.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Experimental.swift similarity index 100% rename from Sources/BasicContainers/UniqueArray+Experimental.swift rename to Sources/BasicContainers/UniqueArray/UniqueArray+Experimental.swift diff --git a/Sources/BasicContainers/UniqueArray+Initializers.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift similarity index 100% rename from Sources/BasicContainers/UniqueArray+Initializers.swift rename to Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift diff --git a/Sources/BasicContainers/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift similarity index 100% rename from Sources/BasicContainers/UniqueArray+Insertions.swift rename to Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift diff --git a/Sources/BasicContainers/UniqueArray+Removals.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift similarity index 100% rename from Sources/BasicContainers/UniqueArray+Removals.swift rename to Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift diff --git a/Sources/BasicContainers/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift similarity index 100% rename from Sources/BasicContainers/UniqueArray+Replacements.swift rename to Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift diff --git a/Sources/BasicContainers/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift similarity index 100% rename from Sources/BasicContainers/UniqueArray.swift rename to Sources/BasicContainers/UniqueArray/UniqueArray.swift diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 19458997..b0d55af6 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 7D2A77242F27F1B3005780C7 /* RigidArray+Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77232F27F1B3005780C7 /* RigidArray+Container.swift */; }; 7D2A77262F27F1D1005780C7 /* Span+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77252F27F1D1005780C7 /* Span+Extras.swift */; }; 7D2A77382F27F1E4005780C7 /* BorrowingSequence+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A772D2F27F1E4005780C7 /* BorrowingSequence+Utilities.swift */; }; 7D2A77392F27F1E4005780C7 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77332F27F1E4005780C7 /* Box.swift */; }; @@ -73,16 +72,6 @@ 7D48BCF02E51597200D7F6F7 /* Assertions+Containers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCEF2E51597200D7F6F7 /* Assertions+Containers.swift */; }; 7D48BCF22E51599200D7F6F7 /* CheckContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF12E51599200D7F6F7 /* CheckContainer.swift */; }; 7D48BCF42E5159A300D7F6F7 /* StaccatoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF32E5159A300D7F6F7 /* StaccatoContainer.swift */; }; - 7D6FEE252E8778F3007C1B86 /* UniqueArray+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE202E8778F3007C1B86 /* UniqueArray+Append.swift */; }; - 7D6FEE262E8778F3007C1B86 /* RigidArray+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE1E2E8778F3007C1B86 /* RigidArray+Removals.swift */; }; - 7D6FEE272E8778F3007C1B86 /* UniqueArray+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE232E8778F3007C1B86 /* UniqueArray+Removals.swift */; }; - 7D6FEE282E8778F3007C1B86 /* RigidArray+Replacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE1F2E8778F3007C1B86 /* RigidArray+Replacements.swift */; }; - 7D6FEE292E8778F3007C1B86 /* UniqueArray+Replacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE242E8778F3007C1B86 /* UniqueArray+Replacements.swift */; }; - 7D6FEE2A2E8778F3007C1B86 /* RigidArray+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE1B2E8778F3007C1B86 /* RigidArray+Append.swift */; }; - 7D6FEE2B2E8778F3007C1B86 /* RigidArray+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE1C2E8778F3007C1B86 /* RigidArray+Initializers.swift */; }; - 7D6FEE2C2E8778F3007C1B86 /* UniqueArray+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE222E8778F3007C1B86 /* UniqueArray+Insertions.swift */; }; - 7D6FEE2D2E8778F3007C1B86 /* RigidArray+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE1D2E8778F3007C1B86 /* RigidArray+Insertions.swift */; }; - 7D6FEE2E2E8778F3007C1B86 /* UniqueArray+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE212E8778F3007C1B86 /* UniqueArray+Initializers.swift */; }; 7D9748D42E9748930098631A /* BigString+Chunk+UTF16.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D32E9748930098631A /* BigString+Chunk+UTF16.swift */; }; 7D9748D52E9748930098631A /* BigString+Chunk+UnicodeScalar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D12E9748930098631A /* BigString+Chunk+UnicodeScalar.swift */; }; 7D9748D62E9748930098631A /* BigString+Chunk+Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748CF2E9748930098631A /* BigString+Chunk+Character.swift */; }; @@ -93,6 +82,21 @@ 7D9B859929E4F74400B291CD /* BitArray+LosslessStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859329E4F74400B291CD /* BitArray+LosslessStringConvertible.swift */; }; 7D9B859A29E4F74400B291CD /* BitArray+RandomBits.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859429E4F74400B291CD /* BitArray+RandomBits.swift */; }; 7D9B859B29E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859529E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift */; }; + 7DA23F462F329A2300E4C03A /* RigidArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F382F329A2300E4C03A /* RigidArray+Experimental.swift */; }; + 7DA23F472F329A2300E4C03A /* UniqueArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F3E2F329A2300E4C03A /* UniqueArray.swift */; }; + 7DA23F482F329A2300E4C03A /* RigidArray+Replacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F3C2F329A2300E4C03A /* RigidArray+Replacements.swift */; }; + 7DA23F492F329A2300E4C03A /* RigidArray+Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F372F329A2300E4C03A /* RigidArray+Container.swift */; }; + 7DA23F4A2F329A2300E4C03A /* UniqueArray+Replacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F442F329A2300E4C03A /* UniqueArray+Replacements.swift */; }; + 7DA23F4B2F329A2300E4C03A /* UniqueArray+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F432F329A2300E4C03A /* UniqueArray+Removals.swift */; }; + 7DA23F4C2F329A2300E4C03A /* RigidArray+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F362F329A2300E4C03A /* RigidArray+Append.swift */; }; + 7DA23F4D2F329A2300E4C03A /* RigidArray+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F3B2F329A2300E4C03A /* RigidArray+Removals.swift */; }; + 7DA23F4E2F329A2300E4C03A /* UniqueArray+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F412F329A2300E4C03A /* UniqueArray+Initializers.swift */; }; + 7DA23F4F2F329A2300E4C03A /* RigidArray+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F392F329A2300E4C03A /* RigidArray+Initializers.swift */; }; + 7DA23F502F329A2300E4C03A /* RigidArray+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F3A2F329A2300E4C03A /* RigidArray+Insertions.swift */; }; + 7DA23F512F329A2300E4C03A /* UniqueArray+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F3F2F329A2300E4C03A /* UniqueArray+Append.swift */; }; + 7DA23F522F329A2300E4C03A /* UniqueArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F402F329A2300E4C03A /* UniqueArray+Experimental.swift */; }; + 7DA23F532F329A2300E4C03A /* UniqueArray+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */; }; + 7DA23F542F329A2300E4C03A /* RigidArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F352F329A2300E4C03A /* RigidArray.swift */; }; 7DAD899E2E8B09C300DD5786 /* UInt+first and last set bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */; }; 7DAD899F2E8B09C300DD5786 /* UInt+reversed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899D2E8B09C300DD5786 /* UInt+reversed.swift */; }; 7DAD89A02E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */; }; @@ -466,10 +470,6 @@ 7DEBDB9029CCE44A00ADC226 /* TestContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2229CCE43600ADC226 /* TestContext.swift */; }; 7DEBDB9129CCE44A00ADC226 /* CollectionTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2429CCE43600ADC226 /* CollectionTestCase.swift */; }; 7DEBDB9229CCE44A00ADC226 /* StringConvertibleValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2B29CCE43600ADC226 /* StringConvertibleValue.swift */; }; - A93AC2152E7C841700A824DF /* RigidArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC2102E7C841700A824DF /* RigidArray.swift */; }; - A93AC2162E7C841700A824DF /* UniqueArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC2122E7C841700A824DF /* UniqueArray.swift */; }; - A93AC2172E7C841700A824DF /* RigidArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC2112E7C841700A824DF /* RigidArray+Experimental.swift */; }; - A93AC2182E7C841700A824DF /* UniqueArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC2132E7C841700A824DF /* UniqueArray+Experimental.swift */; }; A93AC21E2E7C845300A824DF /* UniqueArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC21C2E7C845300A824DF /* UniqueArrayTests.swift */; }; A93AC21F2E7C845300A824DF /* ArrayLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC21A2E7C845300A824DF /* ArrayLayout.swift */; }; A93AC2202E7C845300A824DF /* RigidArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93AC21B2E7C845300A824DF /* RigidArrayTests.swift */; }; @@ -490,7 +490,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7D2A77232F27F1B3005780C7 /* RigidArray+Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Container.swift"; sourceTree = ""; }; 7D2A77252F27F1D1005780C7 /* Span+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Span+Extras.swift"; sourceTree = ""; }; 7D2A77272F27F1E4005780C7 /* OutputSpan+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OutputSpan+Extras.swift"; sourceTree = ""; }; 7D2A77282F27F1E4005780C7 /* TemporaryAllocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemporaryAllocation.swift; sourceTree = ""; }; @@ -561,16 +560,6 @@ 7D5A64D229CCE8CC00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D329CCEE9A00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D829CCF0FE00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - 7D6FEE1B2E8778F3007C1B86 /* RigidArray+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Append.swift"; sourceTree = ""; }; - 7D6FEE1C2E8778F3007C1B86 /* RigidArray+Initializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Initializers.swift"; sourceTree = ""; }; - 7D6FEE1D2E8778F3007C1B86 /* RigidArray+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Insertions.swift"; sourceTree = ""; }; - 7D6FEE1E2E8778F3007C1B86 /* RigidArray+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Removals.swift"; sourceTree = ""; }; - 7D6FEE1F2E8778F3007C1B86 /* RigidArray+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Replacements.swift"; sourceTree = ""; }; - 7D6FEE202E8778F3007C1B86 /* UniqueArray+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Append.swift"; sourceTree = ""; }; - 7D6FEE212E8778F3007C1B86 /* UniqueArray+Initializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Initializers.swift"; sourceTree = ""; }; - 7D6FEE222E8778F3007C1B86 /* UniqueArray+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Insertions.swift"; sourceTree = ""; }; - 7D6FEE232E8778F3007C1B86 /* UniqueArray+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Removals.swift"; sourceTree = ""; }; - 7D6FEE242E8778F3007C1B86 /* UniqueArray+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Replacements.swift"; sourceTree = ""; }; 7D6FEE2F2E8880F6007C1B86 /* BasicContainers.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = BasicContainers.docc; sourceTree = ""; }; 7D6FEE312E88A4B9007C1B86 /* ContainersPreview.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = ContainersPreview.docc; sourceTree = ""; }; 7D9748CF2E9748930098631A /* BigString+Chunk+Character.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BigString+Chunk+Character.swift"; sourceTree = ""; }; @@ -584,6 +573,21 @@ 7D9B859429E4F74400B291CD /* BitArray+RandomBits.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+RandomBits.swift"; sourceTree = ""; }; 7D9B859529E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+ExpressibleByStringLiteral.swift"; sourceTree = ""; }; 7D9B859C29E4F77D00B291CD /* Collections.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Collections.xctestplan; sourceTree = ""; }; + 7DA23F352F329A2300E4C03A /* RigidArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidArray.swift; sourceTree = ""; }; + 7DA23F362F329A2300E4C03A /* RigidArray+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Append.swift"; sourceTree = ""; }; + 7DA23F372F329A2300E4C03A /* RigidArray+Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Container.swift"; sourceTree = ""; }; + 7DA23F382F329A2300E4C03A /* RigidArray+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Experimental.swift"; sourceTree = ""; }; + 7DA23F392F329A2300E4C03A /* RigidArray+Initializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Initializers.swift"; sourceTree = ""; }; + 7DA23F3A2F329A2300E4C03A /* RigidArray+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Insertions.swift"; sourceTree = ""; }; + 7DA23F3B2F329A2300E4C03A /* RigidArray+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Removals.swift"; sourceTree = ""; }; + 7DA23F3C2F329A2300E4C03A /* RigidArray+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Replacements.swift"; sourceTree = ""; }; + 7DA23F3E2F329A2300E4C03A /* UniqueArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueArray.swift; sourceTree = ""; }; + 7DA23F3F2F329A2300E4C03A /* UniqueArray+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Append.swift"; sourceTree = ""; }; + 7DA23F402F329A2300E4C03A /* UniqueArray+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Experimental.swift"; sourceTree = ""; }; + 7DA23F412F329A2300E4C03A /* UniqueArray+Initializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Initializers.swift"; sourceTree = ""; }; + 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Insertions.swift"; sourceTree = ""; }; + 7DA23F432F329A2300E4C03A /* UniqueArray+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Removals.swift"; sourceTree = ""; }; + 7DA23F442F329A2300E4C03A /* UniqueArray+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Replacements.swift"; sourceTree = ""; }; 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FixedWidthInteger+roundUpToPowerOfTwo.swift"; sourceTree = ""; }; 7DAD899B2E8B09C300DD5786 /* Integer rank.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Integer rank.swift"; sourceTree = ""; }; 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt+first and last set bit.swift"; sourceTree = ""; }; @@ -990,10 +994,6 @@ 7DEBDB9829CCE4A600ADC226 /* Shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Shared.xcconfig; sourceTree = ""; }; 7DEBDB9929CCE4A600ADC226 /* Collections.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Collections.xcconfig; sourceTree = ""; }; A93AC20F2E7C841700A824DF /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - A93AC2102E7C841700A824DF /* RigidArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidArray.swift; sourceTree = ""; }; - A93AC2112E7C841700A824DF /* RigidArray+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Experimental.swift"; sourceTree = ""; }; - A93AC2122E7C841700A824DF /* UniqueArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueArray.swift; sourceTree = ""; }; - A93AC2132E7C841700A824DF /* UniqueArray+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Experimental.swift"; sourceTree = ""; }; A93AC21A2E7C845300A824DF /* ArrayLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayLayout.swift; sourceTree = ""; }; A93AC21B2E7C845300A824DF /* RigidArrayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidArrayTests.swift; sourceTree = ""; }; A93AC21C2E7C845300A824DF /* UniqueArrayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueArrayTests.swift; sourceTree = ""; }; @@ -1136,6 +1136,35 @@ path = ContainersTests; sourceTree = ""; }; + 7DA23F3D2F329A2300E4C03A /* RigidArray */ = { + isa = PBXGroup; + children = ( + 7DA23F352F329A2300E4C03A /* RigidArray.swift */, + 7DA23F362F329A2300E4C03A /* RigidArray+Append.swift */, + 7DA23F372F329A2300E4C03A /* RigidArray+Container.swift */, + 7DA23F382F329A2300E4C03A /* RigidArray+Experimental.swift */, + 7DA23F392F329A2300E4C03A /* RigidArray+Initializers.swift */, + 7DA23F3A2F329A2300E4C03A /* RigidArray+Insertions.swift */, + 7DA23F3B2F329A2300E4C03A /* RigidArray+Removals.swift */, + 7DA23F3C2F329A2300E4C03A /* RigidArray+Replacements.swift */, + ); + path = RigidArray; + sourceTree = ""; + }; + 7DA23F452F329A2300E4C03A /* UniqueArray */ = { + isa = PBXGroup; + children = ( + 7DA23F3E2F329A2300E4C03A /* UniqueArray.swift */, + 7DA23F3F2F329A2300E4C03A /* UniqueArray+Append.swift */, + 7DA23F402F329A2300E4C03A /* UniqueArray+Experimental.swift */, + 7DA23F412F329A2300E4C03A /* UniqueArray+Initializers.swift */, + 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */, + 7DA23F432F329A2300E4C03A /* UniqueArray+Removals.swift */, + 7DA23F442F329A2300E4C03A /* UniqueArray+Replacements.swift */, + ); + path = UniqueArray; + sourceTree = ""; + }; 7DE91B1C29CA6721004483EB = { isa = PBXGroup; children = ( @@ -1999,21 +2028,8 @@ isa = PBXGroup; children = ( A93AC20F2E7C841700A824DF /* CMakeLists.txt */, - A93AC2102E7C841700A824DF /* RigidArray.swift */, - 7D6FEE1B2E8778F3007C1B86 /* RigidArray+Append.swift */, - 7D2A77232F27F1B3005780C7 /* RigidArray+Container.swift */, - A93AC2112E7C841700A824DF /* RigidArray+Experimental.swift */, - 7D6FEE1C2E8778F3007C1B86 /* RigidArray+Initializers.swift */, - 7D6FEE1D2E8778F3007C1B86 /* RigidArray+Insertions.swift */, - 7D6FEE1E2E8778F3007C1B86 /* RigidArray+Removals.swift */, - 7D6FEE1F2E8778F3007C1B86 /* RigidArray+Replacements.swift */, - A93AC2122E7C841700A824DF /* UniqueArray.swift */, - 7D6FEE202E8778F3007C1B86 /* UniqueArray+Append.swift */, - A93AC2132E7C841700A824DF /* UniqueArray+Experimental.swift */, - 7D6FEE212E8778F3007C1B86 /* UniqueArray+Initializers.swift */, - 7D6FEE222E8778F3007C1B86 /* UniqueArray+Insertions.swift */, - 7D6FEE232E8778F3007C1B86 /* UniqueArray+Removals.swift */, - 7D6FEE242E8778F3007C1B86 /* UniqueArray+Replacements.swift */, + 7DA23F3D2F329A2300E4C03A /* RigidArray */, + 7DA23F452F329A2300E4C03A /* UniqueArray */, 7D6FEE2F2E8880F6007C1B86 /* BasicContainers.docc */, ); path = BasicContainers; @@ -2256,16 +2272,11 @@ 7DE920C929CA70F4004483EB /* BitSet+BidirectionalCollection.swift in Sources */, 7DE920ED29CA70F4004483EB /* BitArray+Extras.swift in Sources */, 7DE9206829CA70F4004483EB /* BigString+Chunk+Append and Insert.swift in Sources */, - 7D2A77242F27F1B3005780C7 /* RigidArray+Container.swift in Sources */, 7DE9200E29CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift in Sources */, 7DE920D229CA70F4004483EB /* BitSet+SetAlgebra basics.swift in Sources */, 7DE9212A29CA70F4004483EB /* TreeSet+Extras.swift in Sources */, 7DE9209A29CA70F4004483EB /* Rope+Append.swift in Sources */, 7DE9203F29CA70F3004483EB /* OrderedSet+Partial SetAlgebra isDisjoint.swift in Sources */, - A93AC2152E7C841700A824DF /* RigidArray.swift in Sources */, - A93AC2162E7C841700A824DF /* UniqueArray.swift in Sources */, - A93AC2172E7C841700A824DF /* RigidArray+Experimental.swift in Sources */, - A93AC2182E7C841700A824DF /* UniqueArray+Experimental.swift in Sources */, 7DE9208629CA70F4004483EB /* BigString+LosslessStringConvertible.swift in Sources */, 7DE9204329CA70F3004483EB /* _HashTable+Bucket.swift in Sources */, 7DE9216A29CA70F4004483EB /* TreeDictionary.swift in Sources */, @@ -2386,6 +2397,21 @@ 7DE9217B29CA70F4004483EB /* Heap+Invariants.swift in Sources */, 7DE9212F29CA70F4004483EB /* TreeSet+SetAlgebra formIntersection.swift in Sources */, 7DE920A329CA70F4004483EB /* Rope+Index.swift in Sources */, + 7DA23F462F329A2300E4C03A /* RigidArray+Experimental.swift in Sources */, + 7DA23F472F329A2300E4C03A /* UniqueArray.swift in Sources */, + 7DA23F482F329A2300E4C03A /* RigidArray+Replacements.swift in Sources */, + 7DA23F492F329A2300E4C03A /* RigidArray+Container.swift in Sources */, + 7DA23F4A2F329A2300E4C03A /* UniqueArray+Replacements.swift in Sources */, + 7DA23F4B2F329A2300E4C03A /* UniqueArray+Removals.swift in Sources */, + 7DA23F4C2F329A2300E4C03A /* RigidArray+Append.swift in Sources */, + 7DA23F4D2F329A2300E4C03A /* RigidArray+Removals.swift in Sources */, + 7DA23F4E2F329A2300E4C03A /* UniqueArray+Initializers.swift in Sources */, + 7DA23F4F2F329A2300E4C03A /* RigidArray+Initializers.swift in Sources */, + 7DA23F502F329A2300E4C03A /* RigidArray+Insertions.swift in Sources */, + 7DA23F512F329A2300E4C03A /* UniqueArray+Append.swift in Sources */, + 7DA23F522F329A2300E4C03A /* UniqueArray+Experimental.swift in Sources */, + 7DA23F532F329A2300E4C03A /* UniqueArray+Insertions.swift in Sources */, + 7DA23F542F329A2300E4C03A /* RigidArray.swift in Sources */, 7DE9207329CA70F4004483EB /* BigString+RemoveSubrange.swift in Sources */, 7DE9213529CA70F4004483EB /* TreeSet+SetAlgebra symmetricDifference.swift in Sources */, 7DE920D429CA70F4004483EB /* BitSet+SetAlgebra union.swift in Sources */, @@ -2465,16 +2491,6 @@ 7DE9214329CA70F4004483EB /* _HashNode+Subtree Removals.swift in Sources */, 7DE9207929CA70F4004483EB /* BigString+UnicodeScalarView.swift in Sources */, 7DE9202429CA70F3004483EB /* OrderedSet+Invariants.swift in Sources */, - 7D6FEE252E8778F3007C1B86 /* UniqueArray+Append.swift in Sources */, - 7D6FEE262E8778F3007C1B86 /* RigidArray+Removals.swift in Sources */, - 7D6FEE272E8778F3007C1B86 /* UniqueArray+Removals.swift in Sources */, - 7D6FEE282E8778F3007C1B86 /* RigidArray+Replacements.swift in Sources */, - 7D6FEE292E8778F3007C1B86 /* UniqueArray+Replacements.swift in Sources */, - 7D6FEE2A2E8778F3007C1B86 /* RigidArray+Append.swift in Sources */, - 7D6FEE2B2E8778F3007C1B86 /* RigidArray+Initializers.swift in Sources */, - 7D6FEE2C2E8778F3007C1B86 /* UniqueArray+Insertions.swift in Sources */, - 7D6FEE2D2E8778F3007C1B86 /* RigidArray+Insertions.swift in Sources */, - 7D6FEE2E2E8778F3007C1B86 /* UniqueArray+Initializers.swift in Sources */, 7DE920A729CA70F4004483EB /* _CharacterRecognizer.swift in Sources */, 7DE920A429CA70F4004483EB /* Rope+Sequence.swift in Sources */, 7DE9201829CA70F3004483EB /* OrderedDictionary+Invariants.swift in Sources */, From 3d4423f33e7d8cc4f3f70fa5928763771319cbe8 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 13:20:09 -0800 Subject: [PATCH 50/75] [BasicContainers] RigidArray, UniqueArray: Gather all public initializers into the same source file --- .../RigidArray/RigidArray+Initializers.swift | 24 ++++++++++++++++++ .../RigidArray/RigidArray.swift | 25 ++++--------------- .../UniqueArray+Initializers.swift | 15 +++++++++++ .../UniqueArray/UniqueArray.swift | 13 +++------- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift index bd88514a..1cb76faa 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift @@ -16,6 +16,30 @@ import ContainersPreview #if compiler(>=6.2) +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + /// Initializes a new rigid array with zero capacity and no elements. + /// + /// - Complexity: O(1) + @inlinable + public init() { + unsafe _storage = .init(start: nil, count: 0) + _count = 0 + } + + /// Initializes a new rigid array with the specified capacity and no elements. + @inlinable + public init(capacity: Int) { + precondition(capacity >= 0, "Array capacity must be nonnegative") + if capacity > 0 { + unsafe _storage = .allocate(capacity: capacity) + } else { + unsafe _storage = .init(start: nil, count: 0) + } + _count = 0 + } +} + @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { /// Creates a new array with the specified capacity, directly initializing diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index 52a25a4c..3d96e798 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -91,26 +91,11 @@ public struct RigidArray: ~Copyable { unsafe _storage.extracting(0 ..< _count).deinitialize() unsafe _storage.deallocate() } - - /// Initializes a new rigid array with the specified capacity and no elements. - @inlinable - public init(capacity: Int) { - precondition(capacity >= 0, "Array capacity must be nonnegative") - if capacity > 0 { - unsafe _storage = .allocate(capacity: capacity) - } else { - unsafe _storage = .init(start: nil, count: 0) - } - _count = 0 - } - - /// Initializes a new rigid array with zero capacity and no elements. - /// - /// - Complexity: O(1) - @inlinable - public init() { - unsafe _storage = .init(start: nil, count: 0) - _count = 0 + + @_alwaysEmitIntoClient + package init(_storage: UnsafeMutableBufferPointer, count: Int) { + self._storage = _storage + self._count = count } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift index 950cbb82..106790fc 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift @@ -16,6 +16,21 @@ import ContainersPreview #if compiler(>=6.2) +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { + /// Initializes a new unique array with no elements. + @inlinable + public init() { + _storage = .init(capacity: 0) + } + + /// Initializes a new unique array with the specified capacity and no elements. + @inlinable + public init(capacity: Int) { + _storage = .init(capacity: capacity) + } +} + @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { /// Creates a new array with the specified capacity, directly initializing diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index b37c9e79..fbd711d5 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -63,16 +63,9 @@ public struct UniqueArray: ~Copyable { @usableFromInline internal var _storage: RigidArray - /// Initializes a new unique array with the specified capacity and no elements. - @inlinable - public init(capacity: Int) { - _storage = .init(capacity: capacity) - } - - /// Initializes a new unique array with no elements. - @inlinable - public init() { - _storage = .init(capacity: 0) + @_alwaysEmitIntoClient + package init(_storage: consuming RigidArray) { + self._storage = _storage } } From 1e310e2908c535c78b0e78ceb82bbb3193d65947 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 13:20:48 -0800 Subject: [PATCH 51/75] =?UTF-8?q?[BasicContainers]=20RigidArray,=20UniqueA?= =?UTF-8?q?rray:=20Rename=20copy()=20=E2=86=92=20clone()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RigidArray/RigidArray.swift | 33 +++++++++++++--- .../UniqueArray/UniqueArray.swift | 38 +++++++++++++++---- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index 3d96e798..ccc8be1d 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -470,11 +470,11 @@ extension RigidArray { /// instance with just enough capacity to hold all its elements. /// /// - Complexity: O(`count`) - @inlinable - public func copy() -> Self { - copy(capacity: count) + @_alwaysEmitIntoClient + public func clone() -> Self { + clone(capacity: self.count) } - + /// Copy the contents of this array into a newly allocated rigid array /// instance with the specified capacity. /// @@ -483,7 +483,7 @@ extension RigidArray { /// /// - Complexity: O(`count`) @inlinable - public func copy(capacity: Int) -> Self { + public func clone(capacity: Int) -> Self { precondition(capacity >= count, "RigidArray capacity overflow") var result = RigidArray(capacity: capacity) let initialized = unsafe result._storage.initialize(fromContentsOf: _items) @@ -491,6 +491,29 @@ extension RigidArray { result._count = count return result } + + /// Copy the contents of this array into a newly allocated rigid array + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone()") + @inlinable + public func copy() -> Self { + clone() + } + + /// Copy the contents of this array into a newly allocated rigid array + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting rigid array. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone(capacity:)") + @inlinable + public func copy(capacity: Int) -> Self { + clone(capacity: capacity) + } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index fbd711d5..c1957e51 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -76,8 +76,8 @@ extension UniqueArray: Sendable where Element: Sendable & ~Copyable {} @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { - /// The maximum number of elements this array can hold without reallocating - /// its storage. + /// The maximum number of elements this array can hold without having to + /// reallocate its storage. /// /// - Complexity: O(1) @inlinable @@ -387,12 +387,11 @@ extension UniqueArray { /// instance with just enough capacity to hold all its elements. /// /// - Complexity: O(`count`) - @inlinable - @inline(__always) - public func copy() -> Self { - UniqueArray(consuming: _storage.copy()) + @_alwaysEmitIntoClient + public func clone() -> Self { + UniqueArray(consuming: _storage.clone()) } - + /// Copy the contents of this array into a newly allocated unique array /// instance with the specified capacity. /// @@ -402,8 +401,31 @@ extension UniqueArray { /// - Complexity: O(`count`) @inlinable @inline(__always) + public func clone(capacity: Int) -> Self { + UniqueArray(consuming: _storage.clone(capacity: capacity)) + } + + /// Copy the contents of this array into a newly allocated unique array + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone()") + @inlinable + public func copy() -> Self { + self.clone() + } + + /// Copy the contents of this array into a newly allocated unique array + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting unique array. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone(capacity:)") + @inlinable public func copy(capacity: Int) -> Self { - UniqueArray(consuming: _storage.copy(capacity: capacity)) + clone(capacity: capacity) } } From de9a98d7aa8cbc79c4d543621aabec8e3e3b3f47 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 13:21:48 -0800 Subject: [PATCH 52/75] [DequeModule] RigidDeque, UniqueDeque: Make `clone()` methods public --- Sources/DequeModule/RigidDeque/RigidDeque.swift | 4 ++-- Sources/DequeModule/UniqueDeque/UniqueDeque.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index 42c0ac37..1f7f82d8 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -239,7 +239,7 @@ extension RigidDeque { /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient - public func _clone() -> Self { + public func clone() -> Self { RigidDeque(_handle: _handle.allocateCopy(capacity: count)) } @@ -251,7 +251,7 @@ extension RigidDeque { /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient - public func _clone(capacity: Int) -> Self { + public func clone(capacity: Int) -> Self { RigidDeque(_handle: _handle.allocateCopy(capacity: capacity)) } } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift index b0deb3ab..761eb6c5 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -231,8 +231,8 @@ extension UniqueDeque { /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient - public func _clone() -> Self { - UniqueDeque(_storage: _storage._clone()) + public func clone() -> Self { + UniqueDeque(_storage: _storage.clone()) } /// Copy the contents of this deque into a newly allocated rigid deque @@ -243,8 +243,8 @@ extension UniqueDeque { /// /// - Complexity: O(`count`) @_alwaysEmitIntoClient - public func _clone(capacity: Int) -> Self { - UniqueDeque(_storage: _storage._clone(capacity: capacity)) + public func clone(capacity: Int) -> Self { + UniqueDeque(_storage: _storage.clone(capacity: capacity)) } } From ebaef603794ab426b3d9b9aa3b4021bdf5990d98 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 13:22:00 -0800 Subject: [PATCH 53/75] [OrderedCollections] Fix doc typo --- Sources/OrderedCollections/HashTable/_HashTable+Constants.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift b/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift index 49fcf935..6086eacb 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift @@ -48,7 +48,7 @@ extension _HashTable { @inline(__always) internal static var minimumLoadFactor: Double { 1 / 4 } - /// The maximum number of items that can be held in a hash table of the given scale. + /// The minimum number of items that can be held in a hash table of the given scale. @usableFromInline @_effects(readnone) internal static func minimumCapacity(forScale scale: Int) -> Int { From 030f751515d077637313c3f0baf1be3159d0198f Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 14:06:03 -0800 Subject: [PATCH 54/75] [BasicContainers] RigidArray, UniqueArray: Fill out missing indexing APIs --- Sources/BasicContainers/CMakeLists.txt | 1 + .../RigidArray/RigidArray+Container.swift | 122 +++++++++++ .../UniqueArray/UniqueArray+Container.swift | 198 ++++++++++++++++++ .../Protocols/Container.swift | 57 ++++- .../RigidArrayTests.swift | 4 +- Xcode/Collections.xcodeproj/project.pbxproj | 4 + 6 files changed, 382 insertions(+), 4 deletions(-) create mode 100644 Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift diff --git a/Sources/BasicContainers/CMakeLists.txt b/Sources/BasicContainers/CMakeLists.txt index 4cd43f19..3b5f438c 100644 --- a/Sources/BasicContainers/CMakeLists.txt +++ b/Sources/BasicContainers/CMakeLists.txt @@ -33,6 +33,7 @@ target_sources(${module_name} PRIVATE "RigidArray/RigidArray+Replacements.swift" "UniqueArray/UniqueArray.swift" "UniqueArray/UniqueArray+Append.swift" + "UniqueArray/UniqueArray+Container.swift" "UniqueArray/UniqueArray+Experimental.swift" "UniqueArray/UniqueArray+Initializers.swift" "UniqueArray/UniqueArray+Insertions.swift" diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index 4391f2fc..d50057cf 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -42,20 +42,122 @@ extension RigidArray: Container where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { + /// Returns the position immediately after the given index. + /// + /// - Note: To improve performance, this method does not validate that the + /// index is valid before incrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be less + /// than `endIndex`. + /// - Returns: The index immediately following `i`. + /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) public func index(after index: Int) -> Int { index + 1 } + /// Returns the position immediately before the given index. + /// + /// - Note: To improve performance, this method does not validate that the + /// index is valid before decrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be greater + /// than `startIndex`. + /// - Returns: The index immediately preceding `i`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func index(before index: Int) -> Int { index - 1 } + + /// Replaces the given index with its successor. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before incrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be less + /// than `endIndex`. + /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) public func formIndex(after index: inout Int) { index += 1 } + /// Returns an index that is the specified distance from the given index. + /// + /// The value passed as `n` must not offset `index` beyond the bounds of the + /// array. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before offseting it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. + /// - Parameter n: The distance by which to offset `index`. + /// - Returns: An index offset by distance from `index`. If `n` is positive, + /// this is the same value as the result of `n` calls to `index(after:)`. + /// If `n` is negative, this is the same value as the result of `abs(n)` + /// calls to `index(before:)`. + /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) public func index(_ index: Int, offsetBy n: Int) -> Int { index + n } + /// Returns the distance between two indices. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before offseting it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter start: A valid index of the collection. + /// - Parameter end: Another valid index of the collection. If end is equal + /// to start, the result is zero. + /// - Returns: The distance between `start` and `end`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func distance(from start: Index, to end: Index) -> Int { + end - start + } + + /// Offsets the given index by the specified distance, but no further than + /// the given limiting index. + /// + /// If the operation was able to offset `index` by exactly the requested + /// number of steps without hitting `limit`, then on return `n` is set to `0`, + /// and `index` is set to the adjusted index. + /// + /// If the operation hits the limit before it can take the requested number + /// of steps, then on return `index` is set to `limit`, and `n` is set + /// to the number of steps that couldn't be taken. + /// + /// The value passed as `n` must not offset `index` beyond the bounds of the + /// container, unless the index passed as `limit` prevents offsetting beyond + /// those bounds. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before offseting it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. On return, `index` is + /// set to `limit` if + /// - Parameter n: The distance to offset `index`. + /// On return, `n` is set to zero if the operation succeeded without + /// hitting the limit; otherwise, `n` reflects the number of steps that + /// couldn't be taken. + /// - Parameter limit: A valid index of the array to use as a limit. + /// If `n > 0`, a limit that is less than `index` has no effect. + /// Likewise, if `n < 0`, a limit that is greater than `index` has no + /// effect. + /// - Complexity: O(1) @_alwaysEmitIntoClient public func formIndex( _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index @@ -63,6 +165,26 @@ extension RigidArray where Element: ~Copyable { index._advance(by: &n, limitedBy: limit) } + /// Return a span over the array's storage that begins with the element at the given index, + /// and extends to the end of the contiguous storage chunk that contains it. On return, the index + /// is updated to address the next item following the end of the returned span. + /// + /// This method can be used to efficiently process the items of a container in bulk, by + /// directly iterating over its piecewise contiguous pieces of storage: + /// + /// var index = items.startIndex + /// while true { + /// let span = items.nextSpan(after: &index) + /// if span.isEmpty { break } + /// // Process items in `span` + /// } + /// + /// - Parameter index: A valid index in the array, including the end index. On return, this + /// index is advanced by the count of the resulting span, to simplify iteration. + /// - Returns: A span over contiguous storage that starts at the given index. If the input index + /// is the end index, then this returns an empty span. Otherwise the result is non-empty, + /// with its first element matching the element at the input index. + /// - Complexity: O(1) @inlinable @_lifetime(borrow self) public func nextSpan( diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift new file mode 100644 index 00000000..7208516d --- /dev/null +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift @@ -0,0 +1,198 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension RigidArray: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = Span.BorrowingIterator + + @_alwaysEmitIntoClient + @inline(__always) + public var estimatedCount: EstimatedCount { + self._storage.estimatedCount + } + + @_alwaysEmitIntoClient + @inline(__always) + public func makeBorrowingIterator() -> BorrowingIterator { + self._storage.makeBorrowingIterator() + } +} +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension UniqueArray: Container where Element: ~Copyable { +} +#endif + +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { + /// Returns the position immediately after the given index. + /// + /// - Note: To improve performance, this method does not validate that the + /// index is valid before incrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be less + /// than `endIndex`. + /// - Returns: The index immediately following `i`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func index(after index: Int) -> Int { index + 1 } + + /// Returns the position immediately before the given index. + /// + /// - Note: To improve performance, this method does not validate that the + /// index is valid before decrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be greater + /// than `startIndex`. + /// - Returns: The index immediately preceding `i`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func index(before index: Int) -> Int { index - 1 } + + /// Replaces the given index with its successor. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before incrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be less + /// than `endIndex`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func formIndex(after index: inout Int) { index += 1 } + + /// Returns an index that is the specified distance from the given index. + /// + /// The value passed as `n` must not offset `index` beyond the bounds of the + /// array. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before offseting it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. + /// - Parameter n: The distance by which to offset `index`. + /// - Returns: An index offset by distance from `index`. If `n` is positive, + /// this is the same value as the result of `n` calls to `index(after:)`. + /// If `n` is negative, this is the same value as the result of `abs(n)` + /// calls to `index(before:)`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func index(_ index: Int, offsetBy n: Int) -> Int { + index + n + } + + /// Returns the distance between two indices. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before offseting it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter start: A valid index of the collection. + /// - Parameter end: Another valid index of the collection. If end is equal + /// to start, the result is zero. + /// - Returns: The distance between `start` and `end`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func distance(from start: Index, to end: Index) -> Int { + end - start + } + + /// Offsets the given index by the specified distance, but no further than + /// the given limiting index. + /// + /// If the operation was able to offset `index` by exactly the requested + /// number of steps without hitting `limit`, then on return `n` is set to `0`, + /// and `index` is set to the adjusted index. + /// + /// If the operation hits the limit before it can take the requested number + /// of steps, then on return `index` is set to `limit`, and `n` is set + /// to the number of steps that couldn't be taken. + /// + /// The value passed as `n` must not offset `index` beyond the bounds of the + /// container, unless the index passed as `limit` prevents offsetting beyond + /// those bounds. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before offseting it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. On return, `index` is + /// set to `limit` if + /// - Parameter n: The distance to offset `index`. + /// On return, `n` is set to zero if the operation succeeded without + /// hitting the limit; otherwise, `n` reflects the number of steps that + /// couldn't be taken. + /// - Parameter limit: A valid index of the array to use as a limit. + /// If `n > 0`, a limit that is less than `index` has no effect. + /// Likewise, if `n < 0`, a limit that is greater than `index` has no + /// effect. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + public func formIndex( + _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index + ) { + _storage.formIndex(&index, offsetBy: &n, limitedBy: limit) + } + + /// Return a span over the array's storage that begins with the element at the given index, + /// and extends to the end of the contiguous storage chunk that contains it. On return, the index + /// is updated to address the next item following the end of the returned span. + /// + /// This method can be used to efficiently process the items of a container in bulk, by + /// directly iterating over its piecewise contiguous pieces of storage: + /// + /// var index = items.startIndex + /// while true { + /// let span = items.nextSpan(after: &index) + /// if span.isEmpty { break } + /// // Process items in `span` + /// } + /// + /// - Parameter index: A valid index in the array, including the end index. On return, this + /// index is advanced by the count of the resulting span, to simplify iteration. + /// - Returns: A span over contiguous storage that starts at the given index. If the input index + /// is the end index, then this returns an empty span. Otherwise the result is non-empty, + /// with its first element matching the element at the input index. + /// - Complexity: O(1) + @inlinable + @_lifetime(borrow self) + public func nextSpan( + after index: inout Int, maximumCount: Int + ) -> Span { + _storage.nextSpan(after: &index, maximumCount: maximumCount) + } +} + +#endif diff --git a/Sources/ContainersPreview/Protocols/Container.swift b/Sources/ContainersPreview/Protocols/Container.swift index ff635855..c33df66e 100644 --- a/Sources/ContainersPreview/Protocols/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container.swift @@ -19,12 +19,65 @@ public protocol Container: BorrowingSequence, ~Copyable, ~Escapable { var startIndex: Index { get } var endIndex: Index { get } + + /// Returns the position immediately after the given index. + /// + /// - Parameter index: A valid index of the container. `i` must be less + /// than `endIndex`. + /// - Returns: The index immediately following `i`. func index(after index: Index) -> Index + + /// Replaces the given index with its successor. + /// + /// - Parameter index: A valid index of the container. `i` must be less + /// than `endIndex`. func formIndex(after index: inout Index) + + /// Returns an index that is the specified distance from the given index. + /// + /// The value passed as `n` must not offset `index` beyond the bounds of the + /// container. + /// + /// - Parameter index: A valid index of the container. + /// - Parameter n: The distance by which to offset `index`. + /// - Returns: An index offset by distance from `index`. If `n` is positive, + /// this is the same value as the result of `n` calls to `index(after:)`. + /// If `n` is negative, this is the same value as the result of `abs(n)` + /// calls to `index(before:)`. func index(_ index: Index, offsetBy n: Int) -> Index + + /// Offsets the given index by the specified distance, but no further than + /// the given limiting index. + /// + /// If the operation was able to offset `index` by exactly the requested + /// number of steps without hitting `limit`, then on return `n` is set to `0`, + /// and `index` is set to the adjusted index. + /// + /// If the operation hits the limit before it can take the requested number + /// of steps, then on return `index` is set to `limit`, and `n` is set + /// to the number of steps that couldn't be taken. + /// + /// The value passed as `n` must not offset `index` beyond the bounds of the + /// container, unless the index passed as `limit` prevents offsetting beyond + /// those bounds. + /// + /// - Parameter index: A valid index of the container. + /// - Parameter n: The distance to offset `index`. `n` must not be negative + /// unless the container conforms to the `BidirectionalContainer` protocol. + /// - Parameter limit: A valid index of the container to use as a limit. + /// If `n > 0`, a limit that is less than `index` has no effect. + /// Likewise, if `n < 0`, a limit that is greater than `index` has no + /// effect. func formIndex( _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index ) + + /// Returns the distance between two indices. + /// + /// - Parameter start: A valid index of the collection. + /// - Parameter end: Another valid index of the collection. If end is equal + /// to start, the result is zero. + /// - Returns: The distance between `start` and `end`. func distance(from start: Index, to end: Index) -> Int /// Return a span over the container's storage that begins with the element at the given index, @@ -41,11 +94,11 @@ public protocol Container: BorrowingSequence, ~Copyable, ~Escapable { /// // Process items in `span` /// } /// - /// Note: The spans returned by this method are not guaranteed to be disjunct. Some containers + /// - Note: The spans returned by this method are not guaranteed to be disjunct. Some containers /// may use the same storage chunk (or parts of a storage chunk) multiple times, to repeat their /// contents. /// - /// Note: Repeated invocations of `nextSpan` on the same container and index are not guaranteed + /// - Note: Repeated invocations of `nextSpan` on the same container and index are not guaranteed /// to return identical results. (This is particularly the case with containers that can store /// contents in their "inline" representation. Such containers may not always have /// a unique address in memory; the locations of the spans exposed by this method may vary diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index a09c6b33..ee18f8ef 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -466,7 +466,7 @@ class RigidArrayTests: CollectionTestCase { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withLifetimeTracking { tracker in let a = tracker.rigidArray(layout: layout) - let b = a.copy() + let b = a.clone() expectEqual(b.count, layout.count) expectEqual(b.capacity, layout.count) expectEqual(tracker.instances, layout.count) @@ -492,7 +492,7 @@ class RigidArrayTests: CollectionTestCase { ) { newCapacity in withLifetimeTracking { tracker in let a = tracker.rigidArray(layout: layout) - let b = a.copy(capacity: newCapacity) + let b = a.clone(capacity: newCapacity) expectEqual(b.count, layout.count) expectEqual(b.capacity, newCapacity) expectEqual(tracker.instances, layout.count) diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index b0d55af6..17064428 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -97,6 +97,7 @@ 7DA23F522F329A2300E4C03A /* UniqueArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F402F329A2300E4C03A /* UniqueArray+Experimental.swift */; }; 7DA23F532F329A2300E4C03A /* UniqueArray+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */; }; 7DA23F542F329A2300E4C03A /* RigidArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F352F329A2300E4C03A /* RigidArray.swift */; }; + 7DA23F562F329E9000E4C03A /* UniqueArray+Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F552F329E8A00E4C03A /* UniqueArray+Container.swift */; }; 7DAD899E2E8B09C300DD5786 /* UInt+first and last set bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */; }; 7DAD899F2E8B09C300DD5786 /* UInt+reversed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899D2E8B09C300DD5786 /* UInt+reversed.swift */; }; 7DAD89A02E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */; }; @@ -588,6 +589,7 @@ 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Insertions.swift"; sourceTree = ""; }; 7DA23F432F329A2300E4C03A /* UniqueArray+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Removals.swift"; sourceTree = ""; }; 7DA23F442F329A2300E4C03A /* UniqueArray+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Replacements.swift"; sourceTree = ""; }; + 7DA23F552F329E8A00E4C03A /* UniqueArray+Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Container.swift"; sourceTree = ""; }; 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FixedWidthInteger+roundUpToPowerOfTwo.swift"; sourceTree = ""; }; 7DAD899B2E8B09C300DD5786 /* Integer rank.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Integer rank.swift"; sourceTree = ""; }; 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt+first and last set bit.swift"; sourceTree = ""; }; @@ -1156,6 +1158,7 @@ children = ( 7DA23F3E2F329A2300E4C03A /* UniqueArray.swift */, 7DA23F3F2F329A2300E4C03A /* UniqueArray+Append.swift */, + 7DA23F552F329E8A00E4C03A /* UniqueArray+Container.swift */, 7DA23F402F329A2300E4C03A /* UniqueArray+Experimental.swift */, 7DA23F412F329A2300E4C03A /* UniqueArray+Initializers.swift */, 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */, @@ -2302,6 +2305,7 @@ 7DE9215329CA70F4004483EB /* _HashNode+Invariants.swift in Sources */, 7DE9209629CA70F4004483EB /* Rope+Builder.swift in Sources */, 7DE9215129CA70F4004483EB /* _HashNode+Subtree Modify.swift in Sources */, + 7DA23F562F329E9000E4C03A /* UniqueArray+Container.swift in Sources */, 7DE9204729CA70F3004483EB /* _HashTable+Testing.swift in Sources */, 7DE920E929CA70F4004483EB /* BitArray+Invariants.swift in Sources */, 7DE9215429CA70F4004483EB /* _HashNode+UnsafeHandle.swift in Sources */, From 99da8a72e061fbe01f7feb5a776aaeb30f81f43a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 15:10:11 -0800 Subject: [PATCH 55/75] [BasicContainers] RigidArray, UniqueArray: Add formIndex(before:) --- .../RigidArray/RigidArray+Append.swift | 46 +++++-- .../RigidArray/RigidArray+Container.swift | 120 ++++++++++++++++++ .../RigidArray/RigidArray.swift | 107 ---------------- .../UniqueArray/UniqueArray+Container.swift | 112 +++++++++++++++- .../UniqueArray/UniqueArray.swift | 102 --------------- 5 files changed, 262 insertions(+), 225 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index b051dabe..57e64641 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -54,6 +54,37 @@ extension RigidArray where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { + /// Append a given number of items to the end of this array by populating + /// an output span. + /// + /// If the array does not have sufficient capacity to store the new items in + /// the buffer, then this triggers a runtime error. + /// + /// - Parameters + /// - uninitializedCount: The number of items to append to the array. + /// - body: A callback that gets called precisely once to directly + /// populate newly reserved storage within the array. The function + /// is allowed to initialize fewer than `uninitializedCount` items. + /// The array is appended however many items the callback adds to + /// the output span before it returns (or before it throws an error). + /// + /// - Complexity: O(`uninitializedCount`) + @_alwaysEmitIntoClient + public mutating func append( + addingCapacity uninitializedCount: Int, + initializingWith body: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + precondition(uninitializedCount >= 0, "Negative count") + precondition(freeCapacity >= uninitializedCount, "RigidArray capacity overflow") + let buffer = _freeSpace._extracting(first: uninitializedCount) + var span = OutputSpan(buffer: buffer, initializedCount: 0) + defer { + _count &+= span.finalize(for: buffer) + span = OutputSpan() + } + return try body(&span) + } + /// Append a given number of items to the end of this array by populating /// an output span. /// @@ -69,21 +100,18 @@ extension RigidArray where Element: ~Copyable { /// before it returns (or before it throws an error). /// /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "append(addingCapacity:initializingWith:)") @_alwaysEmitIntoClient + @inline(__always) public mutating func append( count: Int, initializingWith body: (inout OutputSpan) throws(E) -> Result ) throws(E) -> Result { - // FIXME: This is extremely similar to `edit()`, except it provides a narrower span. - precondition(count >= 0, "Negative count") - precondition(freeCapacity >= count, "RigidArray capacity overflow") - let buffer = _freeSpace._extracting(first: count) - var span = OutputSpan(buffer: buffer, initializedCount: 0) - defer { - _count &+= span.finalize(for: buffer) - span = OutputSpan() + var result: Result? = nil + try append(addingCapacity: count) { target throws(E) in + result = try body(&target) } - return try body(&span) + return result.take()! } } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index d50057cf..efbc5246 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -40,6 +40,112 @@ extension RigidArray: Container where Element: ~Copyable { } #endif +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + /// A Boolean value indicating whether this array contains no elements. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var isEmpty: Bool { count == 0 } + + /// The number of elements in this array. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var count: Int { _count } +} + +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + /// A type that represents a position in the array: an integer offset from the + /// start. + /// + /// Valid indices consist of the position of every element and a "past the + /// end” position that’s not valid for use as a subscript argument. + public typealias Index = Int + + /// The position of the first element in a nonempty array. This is always zero. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var startIndex: Int { 0 } + + /// The array’s "past the end” position—that is, the position one greater than + /// the last valid subscript argument. This is always equal to the array's + /// count. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var endIndex: Int { count } + + /// The range of indices that are valid for subscripting the array. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var indices: Range { unsafe Range(uncheckedBounds: (0, count)) } +} + +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + @inlinable @inline(__always) + internal func _ptr(to index: Int) -> UnsafePointer { + precondition(index >= 0 && index < _count, "Index out of bounds") + let p = _storage.baseAddress.unsafelyUnwrapped.advanced(by: index) + return UnsafePointer(p) + } + + @inlinable @inline(__always) + internal mutating func _mutablePtr( + to index: Int + ) -> UnsafeMutablePointer { + precondition(index >= 0 && index < _count, "Index out of bounds") + return _storage.baseAddress.unsafelyUnwrapped.advanced(by: index) + } + + /// Accesses the element at the specified position. + /// + /// - Parameter position: The position of the element to access. + /// The position must be a valid index of the array that is not equal + /// to the `endIndex` property. + /// + /// - Complexity: O(1) + @inlinable + public subscript(position: Int) -> Element { + @inline(__always) + unsafeAddress { + _ptr(to: position) + } + @inline(__always) + unsafeMutableAddress { + _mutablePtr(to: position) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + /// Exchanges the values at the specified indices of the array. + /// + /// Both parameters must be valid indices of the array and not equal to + /// endIndex. Passing the same index as both `i` and `j` has no effect. + /// + /// - Parameter i: The index of the first value to swap. + /// - Parameter j: The index of the second valud to swap. + /// + /// - Complexity: O(1) + @inlinable + public mutating func swapAt(_ i: Int, _ j: Int) { + precondition( + i >= 0 && i < _count && j >= 0 && j < _count, + "Index out of bounds") + unsafe _items.swapAt(i, j) + } +} @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { /// Returns the position immediately after the given index. @@ -86,6 +192,20 @@ extension RigidArray where Element: ~Copyable { @inline(__always) public func formIndex(after index: inout Int) { index += 1 } + /// Replaces the given index with its predecessor. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before decrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be greater than + /// `startIndex`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func formIndex(before index: inout Int) { index -= 1 } + /// Returns an index that is the specified distance from the given index. /// /// The value passed as `n` must not offset `index` beyond the bounds of the diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index ccc8be1d..2c5d2b67 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -253,113 +253,6 @@ extension RigidArray where Element: ~Copyable { //MARK: - Container primitives -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - /// A Boolean value indicating whether this array contains no elements. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var isEmpty: Bool { count == 0 } - - /// The number of elements in this array. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var count: Int { _count } -} - -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - /// A type that represents a position in the array: an integer offset from the - /// start. - /// - /// Valid indices consist of the position of every element and a "past the - /// end” position that’s not valid for use as a subscript argument. - public typealias Index = Int - - /// The position of the first element in a nonempty array. This is always zero. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var startIndex: Int { 0 } - - /// The array’s "past the end” position—that is, the position one greater than - /// the last valid subscript argument. This is always equal to the array's - /// count. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var endIndex: Int { count } - - /// The range of indices that are valid for subscripting the array. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var indices: Range { unsafe Range(uncheckedBounds: (0, count)) } -} - -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - @inlinable @inline(__always) - internal func _ptr(to index: Int) -> UnsafePointer { - precondition(index >= 0 && index < _count, "Index out of bounds") - let p = _storage.baseAddress.unsafelyUnwrapped.advanced(by: index) - return UnsafePointer(p) - } - - @inlinable @inline(__always) - internal mutating func _mutablePtr( - to index: Int - ) -> UnsafeMutablePointer { - precondition(index >= 0 && index < _count, "Index out of bounds") - return _storage.baseAddress.unsafelyUnwrapped.advanced(by: index) - } - - /// Accesses the element at the specified position. - /// - /// - Parameter position: The position of the element to access. - /// The position must be a valid index of the array that is not equal - /// to the `endIndex` property. - /// - /// - Complexity: O(1) - @inlinable - public subscript(position: Int) -> Element { - @inline(__always) - unsafeAddress { - _ptr(to: position) - } - @inline(__always) - unsafeMutableAddress { - _mutablePtr(to: position) - } - } -} - -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - /// Exchanges the values at the specified indices of the array. - /// - /// Both parameters must be valid indices of the array and not equal to - /// endIndex. Passing the same index as both `i` and `j` has no effect. - /// - /// - Parameter i: The index of the first value to swap. - /// - Parameter j: The index of the second valud to swap. - /// - /// - Complexity: O(1) - @inlinable - public mutating func swapAt(_ i: Int, _ j: Int) { - precondition( - i >= 0 && i < _count && j >= 0 && j < _count, - "Index out of bounds") - unsafe _items.swapAt(i, j) - } -} - @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { /// Return a borrowing span over the maximal storage chunk following the diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift index 7208516d..99464203 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift @@ -18,15 +18,13 @@ import ContainersPreview #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension RigidArray: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = Span.BorrowingIterator +extension UniqueArray: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = RigidArray.BorrowingIterator - @_alwaysEmitIntoClient - @inline(__always) - public var estimatedCount: EstimatedCount { - self._storage.estimatedCount + public var estimatedCount: ContainersPreview.EstimatedCount { + .exactly(count) } - + @_alwaysEmitIntoClient @inline(__always) public func makeBorrowingIterator() -> BorrowingIterator { @@ -41,6 +39,92 @@ extension UniqueArray: Container where Element: ~Copyable { } #endif +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { + /// A Boolean value indicating whether this array contains no elements. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var isEmpty: Bool { _storage.isEmpty } + + /// The number of elements in this array. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var count: Int { _storage.count } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { + /// A type that represents a position in the array: an integer offset from the + /// start. + /// + /// Valid indices consist of the position of every element and a "past the + /// end” position that’s not valid for use as a subscript argument. + public typealias Index = Int + + /// The position of the first element in a nonempty array. This is always zero. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var startIndex: Int { _storage.startIndex } + + /// The array’s "past the end” position—that is, the position one greater than + /// the last valid subscript argument. This is always equal to array's count. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var endIndex: Int { _storage.count } + + /// The range of indices that are valid for subscripting the array. + /// + /// - Complexity: O(1) + @inlinable + @inline(__always) + public var indices: Range { _storage.indices } + + /// Accesses the element at the specified position. + /// + /// - Parameter position: The position of the element to access. + /// The position must be a valid index of the array that is not equal + /// to the `endIndex` property. + /// + /// - Complexity: O(1) + @inlinable + public subscript(position: Int) -> Element { + @inline(__always) + unsafeAddress { + _storage._ptr(to: position) + } + @inline(__always) + unsafeMutableAddress { + _storage._mutablePtr(to: position) + } + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { + /// Exchanges the values at the specified indices of the array. + /// + /// Both parameters must be valid indices of the array and not equal to + /// endIndex. Passing the same index as both `i` and `j` has no effect. + /// + /// - Parameter i: The index of the first value to swap. + /// - Parameter j: The index of the second valud to swap. + /// + /// - Complexity: O(1) + @inlinable + public mutating func swapAt(_ i: Int, _ j: Int) { + _storage.swapAt(i, j) + } +} + + @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { /// Returns the position immediately after the given index. @@ -87,6 +171,20 @@ extension UniqueArray where Element: ~Copyable { @inline(__always) public func formIndex(after index: inout Int) { index += 1 } + /// Replaces the given index with its predecessor. + /// + /// - Note: To improve performance, this method does not validate that the + /// given index is valid before decrementing it. Index validation is + /// deferred until the resulting index is used to access an element. + /// This optimization may be removed in future versions; do not rely on it. + /// + /// - Parameter index: A valid index of the array. `i` must be greater than + /// `startIndex`. + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func formIndex(before index: inout Int) { index -= 1 } + /// Returns an index that is the specified distance from the given index. /// /// The value passed as `n` must not offset `index` beyond the bounds of the diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index c1957e51..081e07c3 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -153,108 +153,6 @@ extension UniqueArray where Element: ~Copyable { //MARK: - Container primitives -@available(SwiftStdlib 5.0, *) -extension UniqueArray where Element: ~Copyable { - /// A Boolean value indicating whether this array contains no elements. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var isEmpty: Bool { _storage.isEmpty } - - /// The number of elements in this array. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var count: Int { _storage.count } -} - -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -@available(SwiftStdlib 5.0, *) -extension UniqueArray: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = RigidArray.BorrowingIterator - - public var estimatedCount: ContainersPreview.EstimatedCount { - .exactly(count) - } - - @_alwaysEmitIntoClient - @inline(__always) - public func makeBorrowingIterator() -> BorrowingIterator { - self._storage.makeBorrowingIterator() - } -} -#endif - -@available(SwiftStdlib 5.0, *) -extension UniqueArray where Element: ~Copyable { - /// A type that represents a position in the array: an integer offset from the - /// start. - /// - /// Valid indices consist of the position of every element and a "past the - /// end” position that’s not valid for use as a subscript argument. - public typealias Index = Int - - /// The position of the first element in a nonempty array. This is always zero. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var startIndex: Int { _storage.startIndex } - - /// The array’s "past the end” position—that is, the position one greater than - /// the last valid subscript argument. This is always equal to array's count. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var endIndex: Int { _storage.count } - - /// The range of indices that are valid for subscripting the array. - /// - /// - Complexity: O(1) - @inlinable - @inline(__always) - public var indices: Range { _storage.indices } - - /// Accesses the element at the specified position. - /// - /// - Parameter position: The position of the element to access. - /// The position must be a valid index of the array that is not equal - /// to the `endIndex` property. - /// - /// - Complexity: O(1) - @inlinable - public subscript(position: Int) -> Element { - @inline(__always) - unsafeAddress { - _storage._ptr(to: position) - } - @inline(__always) - unsafeMutableAddress { - _storage._mutablePtr(to: position) - } - } -} - -@available(SwiftStdlib 5.0, *) -extension UniqueArray where Element: ~Copyable { - /// Exchanges the values at the specified indices of the array. - /// - /// Both parameters must be valid indices of the array and not equal to - /// endIndex. Passing the same index as both `i` and `j` has no effect. - /// - /// - Parameter i: The index of the first value to swap. - /// - Parameter j: The index of the second valud to swap. - /// - /// - Complexity: O(1) - @inlinable - public mutating func swapAt(_ i: Int, _ j: Int) { - _storage.swapAt(i, j) - } -} - @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { /// Return a borrowing span over the maximal storage chunk following the From b768d2239348e68fd05406d1e8bbf8048681ae76 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 10:09:00 -0800 Subject: [PATCH 56/75] =?UTF-8?q?[BasicContainers]=20RigidArray,=20UniqueA?= =?UTF-8?q?rray:=20=E2=80=9Cprecisely=20once=E2=80=9D=20=E2=86=92=20?= =?UTF-8?q?=E2=80=9Cat=20most=20once=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Loosen guarantees about how many times closure arguments are getting called, so that e.g. insertions of zero items do not necessarily need to call their callback with an empty OutputSpan. (For these array types we can reinstate the guarantee later, if it turns out to be important/useful. However, the generalized primitives will need to allow their callbacks to get called an arbitrary number of times, and it seems useful to establish that (at least partially) with these simple array types too.) --- .../BasicContainers/RigidArray/RigidArray+Append.swift | 8 ++++++-- .../RigidArray/RigidArray+Initializers.swift | 2 +- .../RigidArray/RigidArray+Insertions.swift | 2 +- .../RigidArray/RigidArray+Replacements.swift | 2 +- Sources/BasicContainers/RigidArray/RigidArray.swift | 4 ++-- .../BasicContainers/UniqueArray/UniqueArray+Append.swift | 2 +- .../UniqueArray/UniqueArray+Initializers.swift | 2 +- .../UniqueArray/UniqueArray+Insertions.swift | 2 +- .../UniqueArray/UniqueArray+Replacements.swift | 2 +- Sources/BasicContainers/UniqueArray/UniqueArray.swift | 4 ++-- .../DequeModule/RigidDeque/RigidDeque+Insertions.swift | 2 +- 11 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index 57e64641..96608c54 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -62,7 +62,7 @@ extension RigidArray where Element: ~Copyable { /// /// - Parameters /// - uninitializedCount: The number of items to append to the array. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is allowed to initialize fewer than `uninitializedCount` items. /// The array is appended however many items the callback adds to @@ -91,9 +91,13 @@ extension RigidArray where Element: ~Copyable { /// If the array does not have sufficient capacity to store the new items in /// the buffer, then this triggers a runtime error. /// + /// If the callback fails to fully populate its output span or if + /// it throws an error, then the items that were successfully initialized + /// still get appended to the end of the array. + /// /// - Parameters /// - count: The number of items to append to the array. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is allowed to initialize fewer than `count` items. The array is /// appended however many items the callback adds to the output span diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift index 1cb76faa..4f001442 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift @@ -47,7 +47,7 @@ extension RigidArray where Element: ~Copyable { /// /// - Parameters: /// - capacity: The storage capacity of the new array. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is allowed to add fewer than `capacity` items. The array is /// initialized with however many items the callback adds to the diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index aa83b767..47018162 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -66,7 +66,7 @@ extension RigidArray where Element: ~Copyable { /// - count: The number of items to insert into the array. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the array. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is called with an empty output span of capacity matching the /// supplied count, and it must fully populate it before returning. diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 9c32a1b6..19a0744a 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -42,7 +42,7 @@ extension RigidArray where Element: ~Copyable { /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newCount: the number of items to replace the old subrange. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is called with an empty output span of capacity `newCount`, /// and it must fully populate it before returning. diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index 2c5d2b67..4f13a871 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -196,7 +196,7 @@ extension RigidArray where Element: ~Copyable { extension RigidArray where Element: ~Copyable { /// Arbitrarily edit the storage underlying this array by invoking a /// user-supplied closure with a mutable `OutputSpan` view over it. - /// This method calls its function argument precisely once, allowing it to + /// This method calls its function argument at most once, allowing it to /// arbitrarily modify the contents of the output span it is given. /// The argument is free to add, remove or reorder any items; however, /// it is not allowed to replace the span or change its capacity. @@ -207,7 +207,7 @@ extension RigidArray where Element: ~Copyable { /// /// - Parameter body: A function that edits the contents of this array through /// an `OutputSpan` argument. This method invokes this function - /// precisely once. + /// at most once. /// - Returns: This method returns the result of its function argument. /// - Complexity: Adds O(1) overhead to the complexity of the function /// argument. diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift index 6843b9ab..999c7384 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift @@ -45,7 +45,7 @@ extension UniqueArray where Element: ~Copyable { /// /// - Parameters /// - count: The number of items to append to the array. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is allowed to initialize fewer than `count` items. The array is /// appended however many items the callback adds to the output span diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift index 106790fc..fd18c8d1 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift @@ -38,7 +38,7 @@ extension UniqueArray where Element: ~Copyable { /// /// - Parameters: /// - capacity: The storage capacity of the new array. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is allowed to add fewer than `capacity` items. The array is /// initialized with however many items the callback adds to the diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift index 8180b00c..c5cd3475 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift @@ -62,7 +62,7 @@ extension UniqueArray where Element: ~Copyable { /// - count: The number of items to insert into the array. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the array. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is called with an empty output span of capacity matching the /// supplied count, and it must fully populate it before returning. diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift index f2b85f0e..3eac8b2b 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift @@ -43,7 +43,7 @@ extension UniqueArray where Element: ~Copyable { /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newCount: the number of items to replace the old subrange. - /// - body: A callback that gets called precisely once to directly + /// - body: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is called with an empty output span of capacity `newCount`, /// and it must fully populate it before returning. diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index 081e07c3..3f99cc7b 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -128,7 +128,7 @@ extension UniqueArray where Element: ~Copyable { extension UniqueArray where Element: ~Copyable { /// Arbitrarily edit the storage underlying this array by invoking a /// user-supplied closure with a mutable `OutputSpan` view over it. - /// This method calls its function argument precisely once, allowing it to + /// This method calls its function argument at most once, allowing it to /// arbitrarily modify the contents of the output span it is given. /// The argument is free to add, remove or reorder any items; however, /// it is not allowed to replace the span or change its capacity. @@ -139,7 +139,7 @@ extension UniqueArray where Element: ~Copyable { /// /// - Parameter body: A function that edits the contents of this array through /// an `OutputSpan` argument. This method invokes this function - /// precisely once. + /// at most once. /// - Returns: This method returns the result of its function argument. /// - Complexity: Adds O(1) overhead to the complexity of the function /// argument. diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 3d37b48e..e569b630 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -74,7 +74,7 @@ extension RigidDeque where Element: ~Copyable { /// times to initialize each successive chunk of storage. However, invocations /// cease if the callback fails to fully populate its output span or if /// it throws an error. In such cases, the deque keeps all items that were - /// successfully initialized before the callback terminated the prepend. + /// successfully initialized before the callback terminated the insertion. /// /// Partial insertions create a gap in ring buffer storage that needs to be /// closed by moving already inserted items to their correct positions given From 9503f8fe570eeb4a9622b5f50770861929435fb5 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 10:27:08 -0800 Subject: [PATCH 57/75] Improve consistency of precondition failure messages More uniform message strings should feel better, and they should ever so slightly reduce code size. --- .../RigidArray/RigidArray.swift | 2 +- .../BitArray/BitArray+Extras.swift | 6 ++--- .../BitCollections/BitSet/BitSet+Extras.swift | 2 +- .../Protocols/Container.swift | 8 +++---- .../ContainersPreview/Protocols/Drain.swift | 2 +- .../Protocols/Producer.swift | 2 +- .../ContainersPreview/Types/InputSpan.swift | 2 +- .../DequeModule/Deque/Deque+Collection.swift | 14 +++++------ .../RigidDeque/RigidDeque+Insertions.swift | 2 +- .../RigidDeque/RigidDeque+Removals.swift | 8 +++---- .../RigidDeque/RigidDeque+Replacements.swift | 2 +- .../UniqueDeque/UniqueDeque+Insertions.swift | 2 +- .../UniqueDeque+Replacements.swift | 4 ++-- Sources/DequeModule/_UnsafeDequeHandle.swift | 4 ++-- .../TreeDictionary+Collection.swift | 2 +- .../TreeDictionary/TreeDictionary.swift | 2 +- .../TreeSet/TreeSet+Collection.swift | 2 +- .../TreeSet/TreeSet+Extras.swift | 2 +- .../Span+Extras.swift | 4 ++-- .../UnsafeBitSet/_UnsafeBitSet.swift | 2 +- .../UnsafeBufferPointer+Extras.swift | 12 +++++----- .../UnsafeMutableBufferPointer+Extras.swift | 12 +++++----- ...y+Partial RangeReplaceableCollection.swift | 8 +++---- ...t+Partial RangeReplaceableCollection.swift | 8 +++---- .../BigString/Basics/BigString+Contents.swift | 4 ++-- ...BigString+RangeReplaceableCollection.swift | 2 +- .../Views/BigSubstring+UTF16View.swift | 4 ++-- .../Views/BigSubstring+UTF8View.swift | 4 ++-- .../BigSubstring+UnicodeScalarView.swift | 4 ++-- .../BigString/Views/BigSubstring.swift | 4 ++-- .../Rope/Conformances/Rope+Collection.swift | 4 ++-- .../OrderedSet/OrderedSetTests.swift | 2 +- .../AssertionContexts/TestContext.swift | 4 ++-- .../MinimalTypes/_MinimalCollectionCore.swift | 24 +++++++++---------- 34 files changed, 84 insertions(+), 86 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index 4f13a871..b785b573 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -460,7 +460,7 @@ extension RigidArray where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= _count, "Index range out of bounds") - precondition(newCount >= 0, "Negative count") + precondition(newCount >= 0, "Cannot add a negative number of items") precondition( newCount - subrange.count <= freeCapacity, "RigidArray capacity overflow") diff --git a/Sources/BitCollections/BitArray/BitArray+Extras.swift b/Sources/BitCollections/BitArray/BitArray+Extras.swift index 6a41c875..a96b94e6 100644 --- a/Sources/BitCollections/BitArray/BitArray+Extras.swift +++ b/Sources/BitCollections/BitArray/BitArray+Extras.swift @@ -20,7 +20,7 @@ extension BitArray { toCount count: Int, with padding: Bool = false ) { - precondition(count >= 0, "Negative count") + precondition(count >= 0, "Cannot set a negative count") if count < _count { _removeLast(self.count - count) } else if count > _count { @@ -35,7 +35,7 @@ extension BitArray { count: Int, at index: Int ) { - precondition(count >= 0, "Can't insert a negative number of values") + precondition(count >= 0, "Cannot add a negative number of items") precondition(index >= 0 && index <= count, "Index out of bounds") guard count > 0 else { return } _extend(by: count, with: false) @@ -44,7 +44,7 @@ extension BitArray { } public mutating func append(repeating value: Bool, count: Int) { - precondition(count >= 0, "Can't append a negative number of values") + precondition(count >= 0, "Cannot add a negative number of items") guard count > 0 else { return } _extend(by: count, with: value) } diff --git a/Sources/BitCollections/BitSet/BitSet+Extras.swift b/Sources/BitCollections/BitSet/BitSet+Extras.swift index 15b8a391..b4fcf3d5 100644 --- a/Sources/BitCollections/BitSet/BitSet+Extras.swift +++ b/Sources/BitCollections/BitSet/BitSet+Extras.swift @@ -66,7 +66,7 @@ extension BitSet { } set { guard let member = UInt(exactly: member) else { - precondition(!newValue, "Can't insert a negative value to a BitSet") + precondition(!newValue, "Cannot insert a negative value to a BitSet") return } if newValue { diff --git a/Sources/ContainersPreview/Protocols/Container.swift b/Sources/ContainersPreview/Protocols/Container.swift index c33df66e..9353948d 100644 --- a/Sources/ContainersPreview/Protocols/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container.swift @@ -205,7 +205,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &i, maximumCount: distance) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") distance &-= span.count } return i @@ -222,7 +222,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &j) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") guard span.count <= distance else { break } i = j distance &-= span.count @@ -261,7 +261,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &j, maximumCount: distance) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") if j > limit { break } @@ -284,7 +284,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &j) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") guard span.count <= distance, j < limit else { break } diff --git a/Sources/ContainersPreview/Protocols/Drain.swift b/Sources/ContainersPreview/Protocols/Drain.swift index 60a6d7a9..938d0d74 100644 --- a/Sources/ContainersPreview/Protocols/Drain.swift +++ b/Sources/ContainersPreview/Protocols/Drain.swift @@ -203,7 +203,7 @@ extension Drain where Self: ~Copyable & ~Escapable { public mutating func skip( upTo n: inout Int ) throws(ProducerError) -> Bool { - precondition(n >= 0, "Can't skip a negative number of elements") + precondition(n >= 0, "Cannot skip a negative number of elements") guard n > 0 else { return true } let span = drainNext(maximumCount: n) let success = span.count > 0 diff --git a/Sources/ContainersPreview/Protocols/Producer.swift b/Sources/ContainersPreview/Protocols/Producer.swift index c80ef53d..59f17608 100644 --- a/Sources/ContainersPreview/Protocols/Producer.swift +++ b/Sources/ContainersPreview/Protocols/Producer.swift @@ -200,7 +200,7 @@ extension Producer where Self: ~Copyable & ~Escapable { @inlinable @_lifetime(self: copy self) public mutating func skip(upTo n: inout Int) throws(ProducerError) -> Bool { - precondition(n > 0, "Can't skip less than 1 item") + precondition(n > 0, "Cannot skip fewer than one item") let maxBufferSize = 8 return try withTemporaryOutputSpan( of: Element.self, capacity: Swift.min(maxBufferSize, n) diff --git a/Sources/ContainersPreview/Types/InputSpan.swift b/Sources/ContainersPreview/Types/InputSpan.swift index e9bc58c6..0d9b125f 100644 --- a/Sources/ContainersPreview/Types/InputSpan.swift +++ b/Sources/ContainersPreview/Types/InputSpan.swift @@ -335,7 +335,7 @@ extension InputSpan where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(self: copy self) public mutating func removeFirst(_ k: Int) { - precondition(k >= 0, "Can't remove a negative number of elements") + precondition(k >= 0, "Cannot remove a negative number of elements") precondition(k <= _count, "InputSpan underflow") unsafe _unsafeRawAddressOfSlot( uncheckedOffset: 0 diff --git a/Sources/DequeModule/Deque/Deque+Collection.swift b/Sources/DequeModule/Deque/Deque+Collection.swift index 3c469485..1cbfcde5 100644 --- a/Sources/DequeModule/Deque/Deque+Collection.swift +++ b/Sources/DequeModule/Deque/Deque+Collection.swift @@ -757,8 +757,7 @@ extension Deque: RangeReplaceableCollection { /// this reduces the complexity to amortized O(1). @inlinable public mutating func insert(_ newElement: Element, at index: Int) { - precondition(index >= 0 && index <= count, - "Can't insert element at invalid index") + precondition(index >= 0 && index <= count, "Index out of bounds") _storage.ensureUnique(minimumCapacity: count + 1) _storage.update { target in if index == 0 { @@ -797,8 +796,7 @@ extension Deque: RangeReplaceableCollection { contentsOf newElements: __owned some Collection, at index: Int ) { - precondition(index >= 0 && index <= count, - "Can't insert elements at an invalid index") + precondition(index >= 0 && index <= count, "Index out of bounds") let newCount = newElements.count _storage.ensureUnique(minimumCapacity: count + newCount) _storage.update { target in @@ -865,8 +863,8 @@ extension Deque: RangeReplaceableCollection { @inlinable public mutating func _customRemoveLast(_ n: Int) -> Bool { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the Collection") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the Collection") _storage.ensureUnique() _storage.update { $0.uncheckedRemoveLast(n) } return true @@ -898,8 +896,8 @@ extension Deque: RangeReplaceableCollection { /// O(`count`). @inlinable public mutating func removeFirst(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the Collection") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the Collection") _storage.ensureUnique() return _storage.update { $0.uncheckedRemoveFirst(n) } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index e569b630..a402fe96 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -99,7 +99,7 @@ extension RigidDeque where Element: ~Copyable { initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(maximumCount >= 0, "Cannot insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") precondition(maximumCount <= freeCapacity, "RigidDeque capacity overflow") try _handle.uncheckedInsert( maximumCount: maximumCount, at: index, initializingWith: body) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift index ef0efb8a..a5fdf033 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift @@ -85,8 +85,8 @@ extension RigidDeque where Element: ~Copyable { /// - Complexity: O(`k`) @_alwaysEmitIntoClient public mutating func removeFirst(_ k: Int) { - precondition(k >= 0, "Can't remove a negative number of elements") - precondition(k <= count, "Can't remove more elements than there are in a RigidDeque") + precondition(k >= 0, "Cannot remove a negative number of elements") + precondition(k <= count, "Cannot remove more elements than there are in the container") _handle.uncheckedRemoveFirst(k) } @@ -103,8 +103,8 @@ extension RigidDeque where Element: ~Copyable { /// - Complexity: O(`k`) @_alwaysEmitIntoClient public mutating func removeLast(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the container") _handle.uncheckedRemoveLast(n) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 475ae2c8..174903d1 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -136,7 +136,7 @@ extension RigidDeque where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") precondition( count - subrange.count + maximumCount <= capacity, "RigidDeque capacity overflow") diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index e8c438b3..1c981db0 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -103,7 +103,7 @@ extension UniqueDeque where Element: ~Copyable { initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(maximumCount >= 0, "Cannot insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(maximumCount) try _storage._handle.uncheckedInsert( maximumCount: maximumCount, at: index, initializingWith: body) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index 186d20a3..bacfd983 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -69,7 +69,7 @@ extension UniqueDeque where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(maximumCount - subrange.count) try _storage._handle.uncheckedReplaceSubrange( subrange, @@ -136,7 +136,7 @@ extension UniqueDeque where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(maximumCount - subrange.count) try _storage._handle.uncheckedReplaceSubrange( subrange, diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index c3c4cdde..89416880 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -1385,7 +1385,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { assert( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - assert(newCount >= 0, "Negative count") + assert(newCount >= 0, "Cannot add a negative number of items") assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") self.mutableSegments(forOffsets: subrange).deinitialize() try _insertAfterReplace(subrange, newCount: newCount, initializingWith: initializer) @@ -1402,7 +1402,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { assert( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - assert(newCount >= 0, "Negative count") + assert(newCount >= 0, "Cannot add a negative number of items") assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") do { let removed = self.mutableSegments(forOffsets: subrange) diff --git a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift index a3012eb3..06ea6bcd 100644 --- a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift +++ b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift @@ -159,7 +159,7 @@ extension TreeDictionary: Collection { @inlinable public subscript(i: Index) -> Element { precondition(_isValid(i), "Invalid index") - precondition(i._path.isOnItem, "Can't get element at endIndex") + precondition(i._path.isOnItem, "Cannot get element at endIndex") return _UnsafeHandle.read(i._path.node) { $0[item: i._path.currentItemSlot] } diff --git a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift index 5152e1bf..02795f9b 100644 --- a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift +++ b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift @@ -542,7 +542,7 @@ extension TreeDictionary { @inlinable public mutating func remove(at index: Index) -> Element { precondition(_isValid(index), "Invalid index") - precondition(index._path._isItem, "Can't remove item at end index") + precondition(index._path._isItem, "Cannot remove item at end index") _invalidateIndices() let r = _root.remove(.top, at: index._path) assert(r.remainder == nil) diff --git a/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift b/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift index b0a8f72d..8e36ad51 100644 --- a/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift +++ b/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift @@ -159,7 +159,7 @@ extension TreeSet: Collection { @inlinable public subscript(position: Index) -> Element { precondition(_isValid(position), "Invalid index") - precondition(position._path.isOnItem, "Can't get element at endIndex") + precondition(position._path.isOnItem, "Cannot get element at endIndex") return _UnsafeHandle.read(position._path.node) { $0[item: position._path.currentItemSlot].key } diff --git a/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift b/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift index f02ac45f..f8325a5f 100644 --- a/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift +++ b/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift @@ -56,7 +56,7 @@ extension TreeSet { public mutating func update(_ member: Element, at index: Index) -> Element { defer { _fixLifetime(self) } precondition(_isValid(index), "Invalid index") - precondition(index._path.isOnItem, "Can't get element at endIndex") + precondition(index._path.isOnItem, "Cannot get element at endIndex") _invalidateIndices() return _UnsafeHandle.update(index._path.node) { let p = $0.itemPtr(at: index._path.currentItemSlot) diff --git a/Sources/InternalCollectionsUtilities/Span+Extras.swift b/Sources/InternalCollectionsUtilities/Span+Extras.swift index b1994564..0a94740c 100644 --- a/Sources/InternalCollectionsUtilities/Span+Extras.swift +++ b/Sources/InternalCollectionsUtilities/Span+Extras.swift @@ -16,7 +16,7 @@ extension Span where Element: ~Copyable { @_lifetime(copy self) @_alwaysEmitIntoClient package mutating func _trim(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init() } let result = self.extracting(first: cut) @@ -27,7 +27,7 @@ extension Span where Element: ~Copyable { @_lifetime(copy self) @_alwaysEmitIntoClient package mutating func _trim(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init() } let result = self.extracting(last: cut) diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift index 5fc44ca9..07d205af 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift @@ -331,7 +331,7 @@ extension _UnsafeBitSet: BidirectionalCollection { } while w.isEmpty { word -= 1 - precondition(word >= 0, "Can't advance below startIndex") + precondition(word >= 0, "Cannot advance below startIndex") w = _words[word] } return Index(word: word, bit: w.lastMember!) diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index 849dbb98..ce2e1895 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -60,7 +60,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -83,7 +83,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingFirst maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) return Self(start: baseAddress?.advanced(by: cut), count: count &- cut) } @@ -106,7 +106,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) } @@ -129,7 +129,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingLast maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = count &- Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -139,7 +139,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient package mutating func _trim(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } let oldStart = baseAddress.unsafelyUnwrapped @@ -149,7 +149,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient package mutating func _trim(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } self = .init(start: baseAddress, count: count &- cut) diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index 6c974ebc..3b0ded25 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -63,7 +63,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -86,7 +86,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingFirst maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) return Self(start: baseAddress?.advanced(by: cut), count: count &- cut) } @@ -109,7 +109,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) } @@ -132,7 +132,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingLast maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = count &- Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -142,7 +142,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package mutating func _trim(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } let oldStart = baseAddress.unsafelyUnwrapped @@ -153,7 +153,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package mutating func _trim(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } self = .init(start: baseAddress, count: count &- cut) diff --git a/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift b/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift index 603319bf..cbca5f45 100644 --- a/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift +++ b/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift @@ -121,8 +121,8 @@ extension OrderedDictionary { /// high-quality hashing. @inlinable public mutating func removeLast(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the collection") + precondition(n >= 0, "Cannot remove a negative number of items") + precondition(n <= count, "Cannot remove more elements than there are in the collection") _keys.removeLast(n) _values.removeLast(n) } @@ -152,8 +152,8 @@ extension OrderedDictionary { /// - Complexity: O(`count`). @inlinable public mutating func removeFirst(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the collection") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the collection") _keys.removeFirst(n) _values.removeFirst(n) } diff --git a/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift b/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift index bb8900f1..ea560e88 100644 --- a/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift +++ b/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift @@ -157,7 +157,7 @@ extension OrderedSet { /// high-quality hashing. @inlinable public mutating func removeLast(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") + precondition(n >= 0, "Cannot remove a negative number of items") precondition(n <= count, "Can't remove more elements than there are in the collection") removeSubrange(count - n ..< count) } @@ -171,7 +171,7 @@ extension OrderedSet { @inlinable @discardableResult public mutating func removeFirst() -> Element { - precondition(!isEmpty, "Cannot remove first element of an empty collection") + precondition(!isEmpty, "Cannot remove first item of an empty collection") return remove(at: startIndex) } @@ -187,8 +187,8 @@ extension OrderedSet { /// - Complexity: O(`count`). @inlinable public mutating func removeFirst(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the collection") + precondition(n >= 0, "Cannot remove a negative number of items") + precondition(n <= count, "Cannot remove more elements than there are in the collection") removeSubrange(0 ..< n) } diff --git a/Sources/RopeModule/BigString/Basics/BigString+Contents.swift b/Sources/RopeModule/BigString/Basics/BigString+Contents.swift index 3a998789..2553f5ab 100644 --- a/Sources/RopeModule/BigString/Basics/BigString+Contents.swift +++ b/Sources/RopeModule/BigString/Basics/BigString+Contents.swift @@ -267,7 +267,7 @@ extension BigString { } func _utf8Index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") let i = resolve(i, preferEnd: false) let ri = i._rope! var ci = i._chunkIndex @@ -299,7 +299,7 @@ extension BigString { } func _utf8Index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") let i = resolve(i, preferEnd: true) var ri = i._rope! let ci = i._chunkIndex diff --git a/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift b/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift index ed02eeac..2e6f16c9 100644 --- a/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift +++ b/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift @@ -105,7 +105,7 @@ extension BigString: RangeReplaceableCollection { } public init(repeating value: Self, count: Int) { - precondition(count >= 0, "Negative count") + precondition(count >= 0, "Cannot add a negative number of items") guard count > 0 else { self.init() return diff --git a/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift b/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift index c1750bc5..231bdb12 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift @@ -145,13 +145,13 @@ extension BigSubstring.UTF16View: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base._utf16Index(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base._utf16Index(before: i) } diff --git a/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift b/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift index 996d78b0..8a4c1e2c 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift @@ -117,13 +117,13 @@ extension BigSubstring.UTF8View: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base._utf8Index(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base._utf8Index(before: i) } diff --git a/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift b/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift index 44238691..7e3057a5 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift @@ -147,13 +147,13 @@ extension BigSubstring.UnicodeScalarView: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base._unicodeScalarIndex(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base._unicodeScalarIndex(before: i) } diff --git a/Sources/RopeModule/BigString/Views/BigSubstring.swift b/Sources/RopeModule/BigString/Views/BigSubstring.swift index 3f05920d..a69fe4ee 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring.swift @@ -174,13 +174,13 @@ extension BigSubstring: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base.index(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base.index(before: i) } diff --git a/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift b/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift index 2414baed..ea507bbe 100644 --- a/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift +++ b/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift @@ -92,7 +92,7 @@ extension Rope: BidirectionalCollection { @inlinable public func formIndex(after i: inout Index) { validate(i) - precondition(i < endIndex, "Can't move after endIndex") + precondition(i < endIndex, "Cannot advance above endIndex") if let leaf = i._leaf { let done = leaf.read { let slot = i._path[$0.height] &+ 1 @@ -110,7 +110,7 @@ extension Rope: BidirectionalCollection { @inlinable public func formIndex(before i: inout Index) { validate(i) - precondition(i > startIndex, "Can't move before startIndex") + precondition(i > startIndex, "Cannot advance below startIndex") if let leaf = i._leaf { let done = leaf.read { let slot = i._path[$0.height] diff --git a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift index e175b426..8c75cd95 100644 --- a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift +++ b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift @@ -380,7 +380,7 @@ class OrderedSetTests: CollectionTestCase { expectEqual(set[index], count) expectEqualElements(set[.. MinimalIndex { assertValidIndex(index) expectTrue(index._offset < count, - "Can't advance beyond endIndex", + "Cannot advance beyond endIndex", trapping: true) return self.index(at: index._offset + 1) } @@ -132,7 +132,7 @@ extension _MinimalCollectionCore { func index(before index: MinimalIndex) -> MinimalIndex { assertValidIndex(index) expectTrue(index._offset > 0, - "Can't advance before startIndex", + "Cannot advance before startIndex", trapping: true) return self.index(at: index._offset - 1) } @@ -140,7 +140,7 @@ extension _MinimalCollectionCore { func formIndex(after index: inout MinimalIndex) { assertValidIndex(index) expectTrue(index._offset < count, - "Can't advance beyond endIndex", + "Cannot advance beyond endIndex", trapping: true) index._offset += 1 } @@ -148,7 +148,7 @@ extension _MinimalCollectionCore { func formIndex(before index: inout MinimalIndex) { assertValidIndex(index) expectTrue(index._offset > 0, - "Can't advance before startIndex", + "Cannot advance before startIndex", trapping: true) index._offset -= 1 } @@ -165,10 +165,10 @@ extension _MinimalCollectionCore { ) -> MinimalIndex { assertValidIndex(index) expectTrue(index._offset + n >= 0, - "Can't advance before startIndex", + "Cannot advance before startIndex", trapping: true) expectTrue(index._offset + n <= count, - "Can't advance after endIndex", + "Cannot advance after endIndex", trapping: true) return self.index(at: index._offset + n) } @@ -291,7 +291,7 @@ extension _MinimalCollectionCore { mutating func removeFirst() -> Element { expectTrue( count > 0, - "Can't remove first element of an empty collection", + "Cannot remove first element of an empty collection", trapping: true) ensureUniqueState() state.remove(count: 1, at: 0) @@ -301,11 +301,11 @@ extension _MinimalCollectionCore { mutating func removeFirst(_ n: Int) { expectTrue( n >= 0, - "Can't remove a negative number of elements", + "Cannot remove a negative number of elements", trapping: true) expectTrue( n <= count, - "Can't remove more elements than there are in the collection", + "Cannot remove more elements than there are in the collection", trapping: true) ensureUniqueState() state.remove(count: n, at: 0) @@ -315,7 +315,7 @@ extension _MinimalCollectionCore { public mutating func _customRemoveLast() -> Element? { expectTrue( !isEmpty, - "Can't remove last element of an empty collection", + "Cannot remove last element of an empty collection", trapping: true) ensureUniqueState() state.remove(count: 1, at: state.count) @@ -325,11 +325,11 @@ extension _MinimalCollectionCore { public mutating func _customRemoveLast(_ n: Int) -> Bool { expectTrue( n >= 0, - "Can't remove a negative number of elements", + "Cannot remove a negative number of elements", trapping: true) expectTrue( count >= n, - "Can't remove more elements than there are in the collection", + "Cannot remove more elements than there are in the collection", trapping: true) elements.removeLast(n) ensureUniqueState() From 06f2ec073ddca0a5b3b9ca70c4660bd72962d8bc Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 14:26:57 -0800 Subject: [PATCH 58/75] Rigid, Unique types: Rework OutputSpan-based append/prepend/insert/replaceSubrange primitives --- .../RigidArray/RigidArray+Append.swift | 42 ++-- .../RigidArray/RigidArray+Initializers.swift | 4 +- .../RigidArray/RigidArray+Insertions.swift | 92 ++++++-- .../RigidArray/RigidArray+Removals.swift | 8 +- .../RigidArray/RigidArray+Replacements.swift | 211 ++++++++++++++++-- .../RigidArray/RigidArray.swift | 47 ++-- .../UniqueArray/UniqueArray+Append.swift | 44 +++- .../UniqueArray/UniqueArray+Insertions.swift | 63 +++++- .../UniqueArray/UniqueArray+Removals.swift | 6 +- .../UniqueArray+Replacements.swift | 146 +++++++++++- .../RigidDeque/RigidDeque+Consumption.swift | 129 +++++++++++ .../RigidDeque/RigidDeque+Insertions.swift | 48 ++-- .../RigidDeque/RigidDeque+Prepend.swift | 16 +- .../RigidDeque/RigidDeque+Replacements.swift | 96 ++++---- .../UniqueDeque/UniqueDeque+Insertions.swift | 44 ++-- .../UniqueDeque/UniqueDeque+Prepend.swift | 4 +- .../UniqueDeque+Replacements.swift | 83 ++++--- Sources/DequeModule/_UnsafeDequeHandle.swift | 48 ++-- Tests/DequeTests/RigidDequeTests.swift | 16 +- 19 files changed, 887 insertions(+), 260 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index 96608c54..e2bb6999 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -60,29 +60,33 @@ extension RigidArray where Element: ~Copyable { /// If the array does not have sufficient capacity to store the new items in /// the buffer, then this triggers a runtime error. /// - /// - Parameters - /// - uninitializedCount: The number of items to append to the array. - /// - body: A callback that gets called at most once to directly + /// If the callback fails to fully populate its output span or if + /// it throws an error, then the array keeps all items that were + /// successfully initialized before the callback terminated the insertion. + /// + /// - Parameters: + /// - newItemCount: The number of items to append to the array. + /// - initializer: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function - /// is allowed to initialize fewer than `uninitializedCount` items. + /// is allowed to initialize fewer than `newItemCount` items. /// The array is appended however many items the callback adds to /// the output span before it returns (or before it throws an error). /// - /// - Complexity: O(`uninitializedCount`) + /// - Complexity: O(`newItemCount`) @_alwaysEmitIntoClient public mutating func append( - addingCapacity uninitializedCount: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Void + addingCount newItemCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { - precondition(uninitializedCount >= 0, "Negative count") - precondition(freeCapacity >= uninitializedCount, "RigidArray capacity overflow") - let buffer = _freeSpace._extracting(first: uninitializedCount) + precondition(newItemCount >= 0, "Cannot add a negative number of items") + precondition(freeCapacity >= newItemCount, "RigidArray capacity overflow") + let buffer = _freeSpace._extracting(first: newItemCount) var span = OutputSpan(buffer: buffer, initializedCount: 0) defer { _count &+= span.finalize(for: buffer) span = OutputSpan() } - return try body(&span) + return try initializer(&span) } /// Append a given number of items to the end of this array by populating @@ -91,29 +95,25 @@ extension RigidArray where Element: ~Copyable { /// If the array does not have sufficient capacity to store the new items in /// the buffer, then this triggers a runtime error. /// - /// If the callback fails to fully populate its output span or if - /// it throws an error, then the items that were successfully initialized - /// still get appended to the end of the array. - /// - /// - Parameters + /// - Parameters: /// - count: The number of items to append to the array. - /// - body: A callback that gets called at most once to directly + /// - initializer: A callback that gets called at most once to directly /// populate newly reserved storage within the array. The function /// is allowed to initialize fewer than `count` items. The array is /// appended however many items the callback adds to the output span /// before it returns (or before it throws an error). /// /// - Complexity: O(`count`) - @available(*, deprecated, renamed: "append(addingCapacity:initializingWith:)") + @available(*, deprecated, renamed: "append(addingCount:initializingWith:)") @_alwaysEmitIntoClient @inline(__always) public mutating func append( count: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Result + initializingWith initializer: (inout OutputSpan) throws(E) -> Result ) throws(E) -> Result { var result: Result? = nil - try append(addingCapacity: count) { target throws(E) in - result = try body(&target) + try append(addingCount: count) { target throws(E) in + result = try initializer(&target) } return result.take()! } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift index 4f001442..59b5f8b6 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift @@ -55,10 +55,10 @@ extension RigidArray where Element: ~Copyable { @inlinable public init( capacity: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Void + initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { self.init(capacity: capacity) - try edit(body) + try edit(initializer) } } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index 47018162..1e8f9327 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -52,6 +52,69 @@ extension RigidArray where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { + /// Inserts a given number of new items into this array at the specified + /// position, using a callback to directly initialize array storage by + /// populating an output span. + /// + /// Existing elements in the array's storage are moved towards the back as + /// needed to make room for the new items. + /// + /// If the capacity of the array isn't sufficient to accommodate the specified + /// number of new elements, then this method triggers a runtime error. + /// + /// var buffer = RigidArray(capacity: 20) + /// buffer.append([-999, 999]) + /// var i = 0 + /// buffer.insert(capacity: 3, at: 1) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [-999, 0, 1, 2, 999] + /// + /// If the callback fails to fully populate its output span or if + /// it throws an error, then the array keeps all items that were + /// successfully initialized before the callback terminated the insertion. + /// + /// Partial insertions create a gap in array storage that needs to be + /// closed by moving already inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters: + /// - newItemCount: The maximum number of items to insert into the array. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the array. + /// - initializer: A callback that gets called at most once to directly + /// populate newly reserved storage within the array. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity + /// of the callback invocations. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert( + addingCount newItemCount: Int, + at index: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + precondition(index >= 0 && index <= self.count, "Index out of bounds") + precondition(newItemCount >= 0, "Cannot add a negative number of items") + precondition(newItemCount <= freeCapacity, "RigidArray capacity overflow") + let target = unsafe _openGap(at: index, count: newItemCount) + var span = OutputSpan(buffer: target, initializedCount: 0) + defer { + let c = span.finalize(for: target) + if c < newItemCount { + _closeGap(at: index &+ c, count: newItemCount &- c) + } + _count &+= c + span = OutputSpan() + } + try initializer(&span) + } + /// Inserts a given number of new items into this array at the specified /// position, using a callback to directly initialize array storage by /// populating an output span. @@ -66,31 +129,24 @@ extension RigidArray where Element: ~Copyable { /// - count: The number of items to insert into the array. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the array. - /// - body: A callback that gets called at most once to directly + /// - body: A callback that gets called exactly once to directly /// populate newly reserved storage within the array. The function /// is called with an empty output span of capacity matching the /// supplied count, and it must fully populate it before returning. /// /// - Complexity: O(`self.count` + `count`) + @available(*, deprecated, renamed: "insert(addingCount:at:initializingWith:)") @inlinable public mutating func insert( count: Int, at index: Int, initializingWith body: (inout OutputSpan) -> Result ) -> Result { - // FIXME: This does not allow `body` to throw, to prevent having to move the tail twice. Is that okay? - precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(count >= 0, "Negative count") - precondition(count <= freeCapacity, "RigidArray capacity overflow") - let target = unsafe _openGap(at: index, count: count) - var span = OutputSpan(buffer: target, initializedCount: 0) - defer { - let c = span.finalize(for: target) - precondition(c == count, "Inserted fewer items than promised") - _count &+= c - span = OutputSpan() + var result: Result? = nil + self.insert(addingCount: count, at: index) { target in + result = body(&target) } - return body(&span) + return result! } } @@ -118,7 +174,7 @@ extension RigidArray where Element: ~Copyable { moving items: UnsafeMutableBufferPointer, at index: Int ) { - insert(count: items.count, at: index) { target in + insert(addingCount: items.count, at: index) { target in target._append(moving: items) } } @@ -205,7 +261,7 @@ extension RigidArray where Element: ~Copyable { ) { // FIXME: Remove this in favor of a generic algorithm over consumable containers guard !items.isEmpty else { return } - insert(count: items.count, at: index) { target in + insert(addingCount: items.count, at: index) { target in items.edit { source in target._append(moving: &source) } @@ -270,7 +326,7 @@ extension RigidArray { copying newElements: UnsafeBufferPointer, at index: Int ) { guard newElements.count > 0 else { return } - self.insert(count: newElements.count, at: index) { target in + self.insert(addingCount: newElements.count, at: index) { target in target._append(copying: newElements) } } @@ -328,7 +384,7 @@ extension RigidArray { copying newElements: Span, at index: Int ) { guard newElements.count > 0 else { return } - self.insert(count: newElements.count, at: index) { target in + self.insert(addingCount: newElements.count, at: index) { target in target._append(copying: newElements) } } @@ -343,7 +399,7 @@ extension RigidArray { copying items: borrowing C, newCount: Int ) { - insert(count: newCount, at: index) { target in + insert(addingCount: newCount, at: index) { target in target.withUnsafeMutableBufferPointer { buffer, count in let copied = items._copyContents(intoPrefixOf: buffer) precondition( diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift b/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift index c0103111..1ff2d247 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift @@ -181,7 +181,7 @@ extension RigidArray where Element: ~Copyable { /// passing an input span to the given function to consume them in place. /// /// - Parameter bounds: The subrange of items to consume from this array. - /// - Parameter body: A function taking an input span of the removed items, + /// - Parameter consumer: A function taking an input span of the removed items, /// allowing them to be consumed straight out of the array's storage. /// The function is not required to consume all items in the span; /// however, the span's remaining items will still be removed from @@ -191,14 +191,14 @@ extension RigidArray where Element: ~Copyable { @_alwaysEmitIntoClient public mutating func consumeSubrange( _ bounds: Range, - consumingWith body: (inout InputSpan) throws(E) -> Result + consumingWith consumer: (inout InputSpan) throws(E) -> Result ) throws(E) -> Result { precondition( bounds.lowerBound >= 0 && bounds.upperBound <= _count, "Subrange out of bounds") guard !bounds.isEmpty else { var span = InputSpan() - return try body(&span) + return try consumer(&span) } let buffer = unsafe _storage.extracting(bounds) var span = InputSpan(buffer: buffer, initializedCount: buffer.count) @@ -209,7 +209,7 @@ extension RigidArray where Element: ~Copyable { _count -= bounds.count span = InputSpan() } - return try body(&span) + return try consumer(&span) } } #endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 19a0744a..c5469f43 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -18,6 +18,87 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { + /// Replaces the specified range of elements by a given count of new items, + /// using a callback to directly initialize array storage by populating + /// an output span. + /// + /// The number of new items need not match the number of elements being + /// removed. + /// + /// This method has the same overall effect as calling + /// + /// try array.removeSubrange(subrange) + /// try array.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the array twice. + /// + /// If the array does not have sufficient capacity to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If the callback fails to fully populate its output span or if + /// it throws an error, then the array keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// + /// Partial insertions create a gap in array storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newItemCount: the maximum number of items to replace the old subrange. + /// - initializer: A callback that gets called at most once to directly + /// populate newly reserved storage within the array. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity + /// of the callback invocations. + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + addingCount newItemCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= _count, + "Index range out of bounds") + precondition(newItemCount >= 0, "Cannot add a negative number of items") + precondition( + newItemCount - subrange.count <= freeCapacity, + "RigidArray capacity overflow") + try _uncheckedReplaceSubrange( + subrange, + addingCount: newItemCount, + initializingWith: initializer) + } + + @_alwaysEmitIntoClient + internal mutating func _uncheckedReplaceSubrange( + _ subrange: Range, + addingCount newItemCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + // Destroy removed items + unsafe _items.extracting(subrange).deinitialize() + let target = _resizeGap(in: subrange, to: newItemCount) + var span = OutputSpan(buffer: target, initializedCount: 0) + defer { + let c = span.finalize(for: target) + if c < newItemCount { + self._closeGap( + at: subrange.lowerBound &+ c, + count: capacity &- c) + } + span = OutputSpan() + } + try initializer(&span) + } + /// Replaces the specified range of elements by a given count of new items, /// using a callback to directly initialize array storage by populating /// an output span. @@ -42,32 +123,132 @@ extension RigidArray where Element: ~Copyable { /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newCount: the number of items to replace the old subrange. - /// - body: A callback that gets called at most once to directly + /// - body: A callback that gets called exactly once to directly /// populate newly reserved storage within the array. The function /// is called with an empty output span of capacity `newCount`, /// and it must fully populate it before returning. /// /// - Complexity: O(`self.count` + `newCount`) + @available(*, deprecated, renamed: "replaceSubrange(_:addingCapacity:initializingWith:)") @inlinable public mutating func replaceSubrange( _ subrange: Range, newCount: Int, initializingWith body: (inout OutputSpan) -> Result ) -> Result { - // FIXME: Should we allow throwing (and a partially filled output span)? - // FIXME: Should we have a version of this with two closures, to allow custom-consuming the old items? - // replaceSubrange(5..<10, newCount: 3, consumingWith: {...}, initializingWith: {...}) - let target = _gapForReplacement(of: subrange, withNewCount: newCount) - var span = OutputSpan(buffer: target, initializedCount: 0) - defer { - let c = span.finalize(for: target) - precondition(c == newCount, "Inserted fewer items than promised") - span = OutputSpan() + var result: Result? = nil + self.replaceSubrange(subrange, addingCount: newCount) { target in + result = body(&target) } - return body(&span) + return result! } } +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by a given count of new items, + /// using callbacks to consume old items, and to then insert new ones. + /// + /// The number of new items need not match the number of elements being + /// removed. + /// + /// This method has the same overall effect as calling + /// + /// try array.consume(subrange, consumingWith: consumer) + /// try array.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the deque twice. + /// + /// If the capacity of the array isn't sufficient to accommodate the specified + /// number of new elements, then this method triggers a runtime error. + /// + /// The `consumer` callback is not required to fully depopulate its input + /// span. Any items the callback leaves in the span still get removed and + /// discarded from the array before insertions begin. + /// + /// The `initializer` callback is not required to fully populate its + /// output span, and it is allowed to throw an error. In such cases, the + /// deque keeps all items that were successfully initialized before the + /// callback terminated. + /// + /// Partial insertions create a gap in array storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newItemCount: the maximum number of items to replace the old subrange. + /// - consumer: A callback that gets called at most once to consume + /// the elements to be removed directly from the deque's storage. The + /// function is always called with a non-empty input span. + /// - initializer: A callback that gets called at most once to directly + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the + /// complexity of the callback invocations. + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + addingCount newItemCount: Int, + consumingWith consumer: (inout InputSpan) -> Void, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= _count, + "Index range out of bounds") + precondition(newItemCount >= 0, "Cannot add a negative number of items") + precondition( + newItemCount - subrange.count <= freeCapacity, + "RigidArray capacity overflow") + try _uncheckedReplaceSubrange( + subrange, + addingCount: newItemCount, + consumingWith: consumer, + initializingWith: initializer) + } + + @_alwaysEmitIntoClient + internal mutating func _uncheckedReplaceSubrange( + _ subrange: Range, + addingCount newItemCount: Int, + consumingWith consumer: (inout InputSpan) -> Void, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + do { + // Consume items to be removed + let buffer = unsafe _storage.extracting(subrange) + var span = InputSpan(buffer: buffer, initializedCount: buffer.count) + consumer(&span) + _ = consume span + } + do { + // Insert new items + let target = _resizeGap(in: subrange, to: newItemCount) + var span = OutputSpan(buffer: target, initializedCount: 0) + defer { + let c = span.finalize(for: target) + if c < newItemCount { + self._closeGap( + at: subrange.lowerBound &+ c, + count: capacity &- c) + } + span = OutputSpan() + } + try initializer(&span) + } + } +#endif +} + + @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { /// Replaces the specified range of elements by moving the elements of a @@ -103,7 +284,7 @@ extension RigidArray where Element: ~Copyable { _ subrange: Range, moving newElements: UnsafeMutableBufferPointer, ) { - replaceSubrange(subrange, newCount: newElements.count) { target in + replaceSubrange(subrange, addingCount: newElements.count) { target in target._withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._moveInitializePrefix(from: newElements) } @@ -303,7 +484,7 @@ extension RigidArray { _ subrange: Range, copying newElements: UnsafeBufferPointer ) { - replaceSubrange(subrange, newCount: newElements.count) { target in + replaceSubrange(subrange, addingCount: newElements.count) { target in target._withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._initializePrefix(copying: newElements) } @@ -392,7 +573,7 @@ extension RigidArray { copyingContainer newElements: borrowing C, newCount: Int ) { - self.replaceSubrange(subrange, newCount: newCount) { target in + self.replaceSubrange(subrange, addingCapacity: newCount) { target in target.withUnsafeMutableBufferPointer { buffer, count in count = newElements._copyContents(intoPrefixOf: buffer) precondition( @@ -410,7 +591,7 @@ extension RigidArray { copyingCollection newElements: __owned some Collection, newCount: Int ) { - self.replaceSubrange(subrange, newCount: newCount) { target in + self.replaceSubrange(subrange, addingCount: newCount) { target in target._withUnsafeMutableBufferPointer { dst, dstCount in let done: Void? = newElements.withContiguousStorageIfAvailable { src in let i = unsafe dst._initializePrefix(copying: src) diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index b785b573..9fadb604 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -445,6 +445,32 @@ extension RigidArray where Element: ~Copyable { Range(uncheckedBounds: (index, index + count))) } + /// Resize the gap in the given subrange to have the specified count. + /// This operation moves elements following the gap to be at their expected + /// new location, and it adjusts the container's count to reflect the change. + /// + /// - Returns: A buffer pointer addressing the newly opened gap, to be + /// initialized by the caller. + @inlinable + @unsafe + internal mutating func _resizeGap( + in subrange: Range, to newItemCount: Int + ) -> UnsafeMutableBufferPointer { + assert(subrange.lowerBound >= 0 && subrange.upperBound <= _count) + assert(newItemCount >= 0 && newItemCount - subrange.count <= freeCapacity) + if newItemCount > subrange.count { + _ = unsafe _openGap( + at: subrange.upperBound, count: newItemCount - subrange.count) + } else if newItemCount < subrange.count { + _closeGap( + at: subrange.lowerBound + newItemCount, count: subrange.count - newItemCount) + } + _count += newItemCount - subrange.count + let gapRange = unsafe Range( + uncheckedBounds: (subrange.lowerBound, subrange.lowerBound + newItemCount)) + return unsafe _storage.extracting(gapRange) + } + /// Perform a range replacement up to populating the newly opened gap. This /// deinitializes existing elements in the specified subrange, rearranges /// following elements to be at their final location, and sets the container's @@ -452,30 +478,21 @@ extension RigidArray where Element: ~Copyable { /// /// - Returns: A buffer pointer addressing the newly opened gap, to be /// initialized by the caller. - @inlinable + @available(*, deprecated) // FIXME: Obsolete, remove this + @usableFromInline @unsafe internal mutating func _gapForReplacement( - of subrange: Range, withNewCount newCount: Int + of subrange: Range, newItemCount: Int ) -> UnsafeMutableBufferPointer { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= _count, "Index range out of bounds") - precondition(newCount >= 0, "Cannot add a negative number of items") + precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition( - newCount - subrange.count <= freeCapacity, + newItemCount - subrange.count <= freeCapacity, "RigidArray capacity overflow") unsafe _items.extracting(subrange).deinitialize() - if newCount > subrange.count { - _ = unsafe _openGap( - at: subrange.upperBound, count: newCount - subrange.count) - } else if newCount < subrange.count { - _closeGap( - at: subrange.lowerBound + newCount, count: subrange.count - newCount) - } - _count += newCount - subrange.count - let gapRange = unsafe Range( - uncheckedBounds: (subrange.lowerBound, subrange.lowerBound + newCount)) - return unsafe _storage.extracting(gapRange) + return _resizeGap(in: subrange, to: newItemCount) } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift index 999c7384..cdb73ed9 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift @@ -36,6 +36,37 @@ extension UniqueArray where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { + /// Append a given number of items to the end of this array by populating + /// an output span. + /// + /// If the array does not have sufficient capacity to hold the requested + /// number of new elements, then this reallocates the array's storage to + /// grow its capacity, using a geometric growth rate. + /// + /// If the callback fails to fully populate its output span or if + /// it throws an error, then the array keeps all items that were + /// successfully initialized before the callback terminated the insertion. + /// + /// - Parameters: + /// - newItemCount: The number of items to append to the array. + /// - initializer: A callback that gets called at most once to directly + /// populate newly reserved storage within the array. The function + /// is allowed to initialize fewer than `uninitializedCount` items. + /// The array is appended however many items the callback adds to the + /// output span before it returns (or before it throws an error). + /// + /// - Complexity: O(`uninitializedCount`) + @_alwaysEmitIntoClient + public mutating func append( + addingCount newItemCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + _ensureFreeCapacity(newItemCount) + return try _storage.append( + addingCount: newItemCount, + initializingWith: initializer) + } + /// Append a given number of items to the end of this array by populating /// an output span. /// @@ -45,20 +76,25 @@ extension UniqueArray where Element: ~Copyable { /// /// - Parameters /// - count: The number of items to append to the array. - /// - body: A callback that gets called at most once to directly + /// - initializer: A callback that gets called exactly once to directly /// populate newly reserved storage within the array. The function /// is allowed to initialize fewer than `count` items. The array is /// appended however many items the callback adds to the output span /// before it returns (or before it throws an error). /// /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "append(addingCount:initializingWith:)") @_alwaysEmitIntoClient + @inline(__always) public mutating func append( count: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Result + initializingWith initializer: (inout OutputSpan) throws(E) -> Result ) throws(E) -> Result { - _ensureFreeCapacity(count) - return try _storage.append(count: count, initializingWith: body) + var result: Result? = nil + try append(addingCount: count) { target throws(E) in + result = try initializer(&target) + } + return result.take()! } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift index c5cd3475..90dd25d4 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift @@ -51,12 +51,23 @@ extension UniqueArray where Element: ~Copyable { /// position, using a callback to directly initialize array storage by /// populating an output span. /// - /// All existing elements at or following the specified position are moved to - /// make room for the new items. + /// Existing elements in the array's storage are moved towards the back as + /// needed to make room for the new items. /// /// If the array does not have sufficient capacity to hold the new elements, - /// then this reallocates storage to extend its capacity, using a geometric - /// growth rate. + /// then this operation reallocates storage to extend its capacity, using a + /// geometric growth rate. + /// + /// var buffer = UniqueArray() + /// buffer.append([-999, 999]) + /// var i = 0 + /// buffer.insert(capacity: 3, at: 1) { target in + /// while !target.isFull { + /// target.append(i) + /// i += 1 + /// } + /// } + /// // `buffer` now contains [-999, 0, 1, 2, 999] /// /// - Parameters: /// - count: The number of items to insert into the array. @@ -68,15 +79,53 @@ extension UniqueArray where Element: ~Copyable { /// supplied count, and it must fully populate it before returning. /// /// - Complexity: O(`self.count` + `count`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert( + addingCount newItemCount: Int, + at index: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) { + _ensureFreeCapacity(newItemCount) + try _storage.insert( + addingCount: newItemCount, + at: index, + initializingWith: initializer) + } + + /// Inserts a given number of new items into this array at the specified + /// position, using a callback to directly initialize array storage by + /// populating an output span. + /// + /// All existing elements at or following the specified position are moved to + /// make room for the new items. + /// + /// If the array does not have sufficient capacity to hold the new elements, + /// then this reallocates storage to extend its capacity, using a geometric + /// growth rate. + /// + /// - Parameters: + /// - count: The number of items to insert into the array. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the array. + /// - body: A callback that gets called exactly once to directly + /// populate newly reserved storage within the array. The function + /// is called with an empty output span of capacity matching the + /// supplied count, and it must fully populate it before returning. + /// + /// - Complexity: O(`self.count` + `count`) + @available(*, deprecated, renamed: "insert(addingCount:at:initializingWith:)") @inlinable public mutating func insert( count: Int, at index: Int, initializingWith body: (inout OutputSpan) -> Result ) -> Result { - // FIXME: This does not allow `body` to throw, to prevent having to move the tail twice. Is that okay? - _ensureFreeCapacity(count) - return _storage.insert(count: count, at: index, initializingWith: body) + var result: Result? = nil + self.insert(addingCount: count, at: index) { target in + result = body(&target) + } + return result! } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift index 376cf430..619c72f4 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift @@ -157,7 +157,7 @@ extension UniqueArray where Element: ~Copyable { /// passing an input span to the given function to consume them in place. /// /// - Parameter bounds: The subrange of items to consume from this array. - /// - Parameter body: A function taking an input span of the removed items, + /// - Parameter consumer: A function taking an input span of the removed items, /// allowing them to be consumed straight out of the array's storage. /// The function is not required to consume all items in the span; /// however, the span's remaining items will still be removed from @@ -167,9 +167,9 @@ extension UniqueArray where Element: ~Copyable { @_alwaysEmitIntoClient public mutating func consumeSubrange( _ bounds: Range, - consumingWith body: (inout InputSpan) throws(E) -> Result + consumingWith consumer: (inout InputSpan) throws(E) -> Result ) throws(E) -> Result { - try _storage.consumeSubrange(bounds, consumingWith: body) + try _storage.consumeSubrange(bounds, consumingWith: consumer) } } #endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift index 3eac8b2b..8c7c0e2a 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift @@ -18,6 +18,65 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { + /// Replaces the specified range of elements by a given count of new items, + /// using a callback to directly initialize array storage by populating + /// an output span. + /// + /// The number of new items need not match the number of elements being + /// removed. + /// + /// This method has the same overall effect as calling + /// + /// try array.removeSubrange(subrange) + /// try array.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the array twice. + /// + /// If the array does not have sufficient capacity to perform the replacement, + /// then this reallocates storage to extend its capacity, using a geometric + /// growth rate. + /// + /// If the callback fails to fully populate its output span or if + /// it throws an error, then the array keeps all items that were + /// successfully initialized before the callback terminated the prepend. + /// + /// Partial insertions create a gap in array storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newItemCount: the maximum number of items to replace the old subrange. + /// - initializer: A callback that gets called at most once to directly + /// populate newly reserved storage within the array. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity + /// of the callback invocations. + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + addingCount newItemCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= self.count, + "Index range out of bounds") + precondition(newItemCount >= 0, "Cannot add a negative number of items") + // FIXME: Avoid moving the subsequent elements twice on resize. + _ensureFreeCapacity(newItemCount - subrange.count) + try _storage._uncheckedReplaceSubrange( + subrange, + addingCount: newItemCount, + initializingWith: initializer) + } + /// Replaces the specified range of elements by a given count of new items, /// using a callback to directly initialize array storage by populating /// an output span. @@ -43,28 +102,99 @@ extension UniqueArray where Element: ~Copyable { /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newCount: the number of items to replace the old subrange. - /// - body: A callback that gets called at most once to directly + /// - body: A callback that gets called exactly once to directly /// populate newly reserved storage within the array. The function /// is called with an empty output span of capacity `newCount`, /// and it must fully populate it before returning. /// /// - Complexity: O(`self.count` + `newCount`) + @available(*, deprecated, renamed: "replaceSubrange(_:addingCapacity:initializingWith:)") @inlinable public mutating func replaceSubrange( _ subrange: Range, newCount: Int, initializingWith body: (inout OutputSpan) -> Result ) -> Result { - // FIXME: Should we allow throwing (and a partially filled output span)? - // FIXME: Should we have a version of this with two closures, to allow custom-consuming the old items? - // replaceSubrange(5..<10, newCount: 3, consumingWith: {...}, initializingWith: {...}) - // FIXME: Avoid moving the subsequent elements twice. - _ensureFreeCapacity(newCount - subrange.count) - return _storage.replaceSubrange( - subrange, newCount: newCount, initializingWith: body) + var result: Result? = nil + self.replaceSubrange(subrange, addingCount: newCount) { target in + result = body(&target) + } + return result! } } +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Replaces the specified range of elements by a given count of new items, + /// using callbacks to consume old items, and to then insert new ones. + /// + /// The number of new items need not match the number of elements being + /// removed. + /// + /// This method has the same overall effect as calling + /// + /// try array.consume(subrange, consumingWith: consumer) + /// try array.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the deque twice. + /// + /// If the array does not have sufficient capacity to perform the replacement, + /// then this reallocates storage to extend its capacity, using a geometric + /// growth rate. + /// + /// The `consumer` callback is not required to fully depopulate its input + /// span. Any items the callback leaves in the span still get removed and + /// discarded from the array before insertions begin. + /// + /// The `initializer` callback is not required to fully populate its + /// output span, and it is allowed to throw an error. In such cases, the + /// deque keeps all items that were successfully initialized before the + /// callback terminated. + /// + /// Partial insertions create a gap in array storage that needs to be + /// closed by moving newly inserted items to their correct positions given + /// the adjusted count. This adds some overhead compared to adding exactly as + /// many items as promised. + /// + /// - Parameters + /// - subrange: The subrange of the deque to replace. The bounds of + /// the range must be valid indices in the deque. + /// - newItemCount: the maximum number of items to replace the old subrange. + /// - consumer: A callback that gets called at most once to consume + /// the elements to be removed directly from the deque's storage. The + /// function is always called with a non-empty input span. + /// - initializer: A callback that gets called at most once to directly + /// populate newly reserved storage within the deque. The function + /// is always called with an empty output span. + /// + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the + /// complexity of the callback invocations. + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + addingCount newItemCount: Int, + consumingWith consumer: (inout InputSpan) -> Void, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= self.count, + "Index range out of bounds") + precondition(newItemCount >= 0, "Cannot add a negative number of items") + _ensureFreeCapacity(newItemCount - subrange.count) + try _storage._uncheckedReplaceSubrange( + subrange, + addingCount: newItemCount, + consumingWith: consumer, + initializingWith: initializer) + } +#endif +} + @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { /// Replaces the specified range of elements by moving the elements of a diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift index 06f0e70b..05bc0695 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift @@ -19,12 +19,32 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Remove the specified subrange of items from this deque, + /// passing a series of input spans to a given callback function to consume + /// them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter subrange: The subrange of items to consume from this deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @inline(__always) public mutating func consume( _ subrange: Range, consumingWith consumer: (inout InputSpan) -> Void ) { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= self.count, + "Subrange out of bounds") let segments = self._handle.mutableSegments(forOffsets: subrange) var span = InputSpan(buffer: segments.first, initializedCount: segments.first.count) @@ -37,6 +57,23 @@ extension RigidDeque where Element: ~Copyable { } } + /// Remove the specified subrange of items from this deque, + /// passing a series of input spans to a given callback function to consume + /// them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter subrange: The subrange of items to consume from this deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @inline(__always) public mutating func consume>( @@ -46,6 +83,20 @@ extension RigidDeque where Element: ~Copyable { consume(subrange.relative(to: indices), consumingWith: consumer) } + /// Remove all items currently in this deque, passing a series of input + /// spans to a given callback function to consume them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// The function is called at most once. + /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @inline(__always) public mutating func consumeAll( @@ -53,6 +104,64 @@ extension RigidDeque where Element: ~Copyable { ) { consume(indices, consumingWith: consumer) } + + /// Remove the specified number of items from the end of this deque, + /// passing an input span to a given callback function to consume them in + /// place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter n: The number of items to consume from the end of the deque. + /// `n` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// - Complexity: O(`n`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consumeLast( + _ n: Int, + consumingWith consumer: (inout InputSpan) -> Void + ) { + precondition( + n >= 0 && n <= self.count, + "Count of elements to consume is out of bounds") + consume(self.count &- n ..< self.count, consumingWith: consumer) + } + + /// Remove the specified number of items from the front of this deque, + /// passing an input span to a given callback function to consume them in + /// place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter n: The number of items to consume from the front of the deque. + /// `n` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// - Complexity: O(`n`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consumeFirst( + _ n: Int, + consumingWith consumer: (inout InputSpan) -> Void + ) { + precondition( + n >= 0 && n <= self.count, + "Count of elements to consume is out of bounds") + consume(0 ..< n, consumingWith: consumer) + } #endif } @@ -81,6 +190,26 @@ extension RigidDeque where Element: ~Copyable { public mutating func consumeAll() -> SubrangeConsumer { consume(indices) } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consumeLast(_ n: Int) -> SubrangeConsumer { + precondition( + n >= 0 && n <= self.count, + "Count of elements to consume is out of bounds") + return consume(self.count - n ..< self.count) + } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consumeFirst(_ n: Int) -> SubrangeConsumer { + precondition( + n >= 0 && n <= self.count, + "Count of elements to consume is out of bounds") + return consume(0 ..< n) + } } @available(SwiftStdlib 5.0, *) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index a402fe96..aa7f72a2 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -61,7 +61,7 @@ extension RigidDeque where Element: ~Copyable { /// var buffer = RigidDeque(capacity: 20) /// buffer.append([-999, 999]) /// var i = 0 - /// buffer.insert(capacity: 3, at: 1) { target in + /// buffer.insert(addingCount: 3, at: 1) { target in /// while !target.isFull { /// target.append(i) /// i += 1 @@ -82,27 +82,27 @@ extension RigidDeque where Element: ~Copyable { /// many items as promised. /// /// - Parameters: - /// - maximumCount: The maximum number of items to insert into the deque. + /// - newItemCount: The maximum number of items to insert into the deque. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. - /// - body: A callback that gets called at most twice to directly + /// - initializer: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. /// - /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity /// of the callback invocations. @_alwaysEmitIntoClient @inline(__always) public mutating func insert( - maximumCount: Int, + addingCount newItemCount: Int, at index: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Void + initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(maximumCount >= 0, "Cannot add a negative number of items") - precondition(maximumCount <= freeCapacity, "RigidDeque capacity overflow") + precondition(newItemCount >= 0, "Cannot add a negative number of items") + precondition(newItemCount <= freeCapacity, "RigidDeque capacity overflow") try _handle.uncheckedInsert( - maximumCount: maximumCount, at: index, initializingWith: body) + addingCount: newItemCount, at: index, initializingWith: initializer) } } @@ -133,7 +133,7 @@ extension RigidDeque where Element: ~Copyable { ) { guard !items.isEmpty else { return } var remainder = items - insert(maximumCount: items.count, at: index) { target in + insert(addingCount: items.count, at: index) { target in target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) @@ -207,7 +207,7 @@ extension RigidDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension RigidDeque where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Inserts at most `maximumCount` items generated by a producer into this + /// Inserts at most `newItemCount` items generated by a producer into this /// deque, starting at the given index. /// /// Existing elements in the deque's storage are moved as needed to make room @@ -218,32 +218,32 @@ extension RigidDeque where Element: ~Copyable { /// specified number of new items, then this triggers a runtime error. /// /// This operation inserts as many items as the producer can generate before - /// either reaching `maximumCount`, or the producer hitting its end, or - /// throwing an error. If the producer has more than `maximumCount` items + /// either reaching `newItemCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `newItemCount` items /// left in its underlying sequence, then extra items remain available after /// this method returns. /// - /// If the operation inserts fewer than `maximumCount` items, then it results + /// If the operation inserts fewer than `newItemCount` items, then it results /// in a gap in ring buffer storage that needs to be closed by moving some /// items to their correct positions given the adjusted count. This adds some /// overhead compared to adding exactly as many items as promised. /// /// - Parameters: - /// - maximumCount: The maximum number of items to insert into the deque. + /// - newItemCount: The maximum number of items to insert into the deque. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`self.count` + `maximumCount`) + /// - Complexity: O(`self.count` + `newItemCount`) @_alwaysEmitIntoClient public mutating func insert< P: Producer & ~Copyable & ~Escapable >( - maximumCount: Int, + addingCount newItemCount: Int, from producer: inout P, at index: Int ) throws(P.ProducerError) { - try insert(maximumCount: maximumCount, at: index) { target throws(P.ProducerError) in + try insert(addingCount: newItemCount, at: index) { target throws(P.ProducerError) in while !target.isFull, try producer.generate(into: &target) { // Do nothing } @@ -274,14 +274,14 @@ extension RigidDeque /* where Element: Copyable */ { /// - index: The position at which to insert the new elements. It must be /// a valid index of `self`. /// - /// - Complexity: O(`count` + `newElements.count`) + /// - Complexity: O(`count` + `items.count`) @inlinable public mutating func insert( copying items: UnsafeBufferPointer, at index: Int ) { guard items.count > 0 else { return } var remainder = items - insert(maximumCount: remainder.count, at: index) { target in + insert(addingCount: remainder.count, at: index) { target in target._withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( fromContentsOf: remainder._extracting(first: buffer.count)) @@ -312,7 +312,7 @@ extension RigidDeque /* where Element: Copyable */ { /// - index: The position at which to insert the new elements. It must be /// a valid index of `self`. /// - /// - Complexity: O(`count` + `newElements.count`) + /// - Complexity: O(`count` + `items.count`) @inlinable public mutating func insert( copying items: UnsafeMutableBufferPointer, @@ -360,11 +360,11 @@ extension RigidDeque /* where Element: Copyable */ { ) { let expectedCount = self.count + newCount var it = items.makeBorrowingIterator() - insert(maximumCount: newCount, at: index) { target in + insert(addingCount: newCount, at: index) { target in it.copyContents(into: &target) } precondition( - it.nextSpan().isEmpty && count == expectedCount, + it.nextSpan().isEmpty && self.count == expectedCount, "Broken Container: count doesn't match contents") } #endif @@ -381,7 +381,7 @@ extension RigidDeque /* where Element: Copyable */ { if done != nil { return } var i = items.startIndex - self.insert(maximumCount: newCount, at: index) { target in + self.insert(addingCount: newCount, at: index) { target in while !target.isFull { target.append(items[i]) items.formIndex(after: &i) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 1fbb3c6f..402a51f5 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -97,20 +97,20 @@ extension RigidDeque where Element: ~Copyable { /// // `buffer` now contains [0, 1, 2, 3, 999] /// /// - Parameters - /// - maximumCount: The maximum number of items to prepend to the deque. + /// - newItemCount: The maximum number of items to prepend to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. /// - /// - Complexity: O(`maximumCount`) in addition to the complexity of the callback + /// - Complexity: O(`newItemCount`) in addition to the complexity of the callback /// invocations. @_alwaysEmitIntoClient public mutating func prepend( - maximumCount: Int, + addingCount newItemCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition(maximumCount >= 0, "Cannot prepend a negative number of items") - precondition(freeCapacity >= maximumCount, "RigidDeque capacity overflow") - try _handle.uncheckedPrepend(maximumCount: maximumCount, initializingWith: body) + precondition(newItemCount >= 0, "Cannot prepend a negative number of items") + precondition(freeCapacity >= newItemCount, "RigidDeque capacity overflow") + try _handle.uncheckedPrepend(addingCount: newItemCount, initializingWith: body) } } @@ -214,7 +214,7 @@ extension RigidDeque where Element: ~Copyable { from producer: inout P ) throws(P.ProducerError) { try self.prepend( - maximumCount: maximumCount ?? freeCapacity + addingCount: maximumCount ?? freeCapacity ) { target throws(P.ProducerError) in try producer.generate(into: &target) } @@ -307,7 +307,7 @@ extension RigidDeque /*where Element: Copyable*/ { exactCount: Int ) { var it = items.makeBorrowingIterator() - self.prepend(maximumCount: exactCount) { target in + self.prepend(addingCount: exactCount) { target in let span = it.nextSpan(maximumCount: target.freeCapacity) target._append(copying: span) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 174903d1..137a92f2 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -22,23 +22,21 @@ extension RigidDeque where Element: ~Copyable { /// using a callback to directly initialize deque storage by populating /// a series of output spans. /// - /// This method has the effect of removing the specified range of elements - /// from the deque and inserting room for the new elements starting at the - /// same location. The number of new elements need not match the number - /// of elements being removed. + /// This method has the same overall effect as calling + /// + /// try deque.removeSubrange(subrange) + /// try deque.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the deque twice. /// /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// If you pass a zero-length range as the `subrange` parameter, then - /// this method is equivalent to calling - /// `insert(maximumCount: newCount, at: subrange.lowerBound, initializingWith: body)`. - /// - /// Likewise, if you pass a zero for `newCount`, then this method - /// removes the elements in the given subrange without any replacement. - /// This case is more directly expressed by `removeSubrange(subrange)`. - /// - /// The newly prepended items are not guaranteed to form a single contiguous + /// The newly inserted items are not guaranteed to form a single contiguous /// storage region. Therefore, the supplied callback may be invoked multiple /// times to initialize each successive chunk of storage. However, invocations /// cease if the callback fails to fully populate its output span or if @@ -53,28 +51,29 @@ extension RigidDeque where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - maximumCount: the maximum number of items to replace the old subrange. + /// - newItemCount: the maximum number of items to replace the old subrange. /// - initializer: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. /// - /// - Complexity: O(`self.count` + `newCount`) + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity + /// of the callback invocations. @inlinable public mutating func replaceSubrange( _ subrange: Range, - maximumCount: Int, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition( - count - subrange.count + maximumCount <= capacity, + count - subrange.count + newItemCount <= capacity, "RigidDeque capacity overflow") try _handle.uncheckedReplaceSubrange( subrange, - newCount: capacity, + addingCount: newItemCount, initializingWith: initializer) } @@ -88,25 +87,34 @@ extension RigidDeque where Element: ~Copyable { /// This method has the same overall effect as calling /// /// try deque.consume(subrange, consumingWith: consumer) - /// try deque.insert(maximumCount: maximumCount, at: subrange.lowerBound, initializingWith: initializer) + /// try deque.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) /// /// Except it performs faster (by a constant factor), by avoiding moving /// some items in the deque twice. /// - /// If the capacity of the deque isn't sufficient to accommodate the specified + /// If the deque doesn't have sufficient capacity to accommodate the specified /// number of new elements, then this method triggers a runtime error. /// - /// The removed and newly inserted items are not guaranteed to form a single - /// contiguous storage region. Therefore, the supplied callbacks may be + /// Neither the removed nor the newly inserted items are guaranteed to form a + /// single contiguous storage region. Therefore, the supplied callbacks may be /// invoked multiple times to consume, then initialize successive chunks of /// storage. Calls to `consumer` do not get interleaved with calls to /// `initializer`: no new item is inserted until every replaced item has been - /// consumed. + /// fully consumed. + /// + /// The `consumer` callback is not required to fully depopulate its input + /// span. Any items the callback leaves in the span still get removed and + /// discarded from the deque before insertions begin. If there are more + /// spans to consume, the callback will get called again after such a partial + /// consumption. /// /// The `initializer` callback is not required to fully populate its /// output span, and it is allowed to throw an error. In such cases, the - /// deque keeps all items that were successfully initialized before the - /// callback terminated. + /// replacement operation ends, and the deque keeps all items that were + /// successfully initialized before the callback terminated. /// /// Partial insertions create a gap in ring buffer storage that needs to be /// closed by moving newly inserted items to their correct positions given @@ -116,7 +124,7 @@ extension RigidDeque where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - maximumCount: the maximum number of items to replace the old subrange. + /// - newItemCount: the maximum number of items to replace the old subrange. /// - consumer: A callback that gets called at most twice to consume /// the elements to be removed directly from the deque's storage. The /// function is always called with a non-empty input span. @@ -124,25 +132,25 @@ extension RigidDeque where Element: ~Copyable { /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. /// - /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity - /// of the callback invocations. + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the + /// complexity of the callback invocations. @inlinable public mutating func replaceSubrange( _ subrange: Range, - maximumCount: Int, + addingCount newItemCount: Int, consumingWith consumer: (inout InputSpan) -> Void, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Cannot add a negative number of items") + precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition( - count - subrange.count + maximumCount <= capacity, + count - subrange.count + newItemCount <= capacity, "RigidDeque capacity overflow") try _handle.uncheckedReplaceSubrange( subrange, - newCount: capacity, + addingCount: newItemCount, consumingWith: consumer, initializingWith: initializer) } @@ -185,7 +193,7 @@ extension RigidDeque where Element: ~Copyable { moving items: UnsafeMutableBufferPointer, ) { var remainder = items - replaceSubrange(subrange, maximumCount: remainder.count) { target in + replaceSubrange(subrange, addingCount: remainder.count) { target in target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) @@ -274,7 +282,7 @@ extension RigidDeque where Element: ~Copyable { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Replaces the specified range of elements by at most `maximumCount` items + /// Replaces the specified range of elements by at most `newItemCount` items /// generated by a producer. /// /// This method has the effect of removing the specified range of elements @@ -294,12 +302,12 @@ extension RigidDeque where Element: ~Copyable { /// directly expressed by calling `removeSubrange`. /// /// This operation inserts as many items as the producer can generate before - /// either reaching `maximumCount`, or the producer hitting its end, or - /// throwing an error. If the producer has more than `maximumCount` items left in + /// either reaching `newItemCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `newItemCount` items left in /// its underlying sequence, then extra items remain available after this /// method returns. /// - /// If the operation inserts fewer than `maximumCount` items, then it results in + /// If the operation inserts fewer than `newItemCount` items, then it results in /// a gap in ring buffer storage that needs to be closed by moving some /// items to their correct positions given the adjusted count. This adds some /// overhead compared to adding exactly as many items as promised. @@ -307,7 +315,7 @@ extension RigidDeque where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - maximumCount: The maximum number of items to insert into the deque. + /// - newItemCount: The maximum number of items to insert into the deque. /// - producer: A producer that generates the items to append. /// /// - Complexity: O(`self.count` + `maximumCount`) @@ -316,10 +324,10 @@ extension RigidDeque where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( _ subrange: Range, - maximumCount: Int, + addingCount newItemCount: Int, from producer: inout P ) throws(P.ProducerError) { - try replaceSubrange(subrange, maximumCount: maximumCount) { target throws(P.ProducerError) in + try replaceSubrange(subrange, addingCount: newItemCount) { target throws(P.ProducerError) in try producer.generate(into: &target) } } @@ -360,7 +368,7 @@ extension RigidDeque /* where Element: Copyable */ { copying items: UnsafeBufferPointer ) { var remainder = items - replaceSubrange(subrange, maximumCount: remainder.count) { target in + replaceSubrange(subrange, addingCount: remainder.count) { target in target._withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count @@ -453,7 +461,7 @@ extension RigidDeque /* where Element: Copyable */ { let expectedCount = self.count - subrange.count + newCount var it = items.makeBorrowingIterator() - self.replaceSubrange(subrange, maximumCount: newCount) { target in + self.replaceSubrange(subrange, addingCount: newCount) { target in it.copyContents(into: &target) } precondition( @@ -477,7 +485,7 @@ extension RigidDeque /* where Element: Copyable */ { if done != nil { return } var i = items.startIndex - self.replaceSubrange(subrange, maximumCount: newCount) { target in + self.replaceSubrange(subrange, addingCount: newCount) { target in while !target.isFull { target.append(items[i]) items.formIndex(after: &i) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index 1c981db0..bfbc626f 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025 - 2026 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 @@ -64,7 +64,7 @@ extension UniqueDeque where Element: ~Copyable { /// var buffer = UniqueDeque(capacity: 20) /// buffer.append([-999, 999]) /// var i = 0 - /// buffer.insert(capacity: 3, at: 1) { target in + /// buffer.insert(addingCount: 3, at: 1) { target in /// while !target.isFull { /// target.append(i) /// i += 1 @@ -85,28 +85,28 @@ extension UniqueDeque where Element: ~Copyable { /// many items as promised. /// /// - Parameters: - /// - maximumCount: The maximum number of items to insert into the deque. + /// - newItemCount: The maximum number of items to insert into the deque. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. - /// - body: A callback that gets called at most twice to directly + /// - initializer: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. /// - /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity /// of the callback invocations when amortized over many similar /// invocations on the same deque. @_alwaysEmitIntoClient @inline(__always) public mutating func insert( - maximumCount: Int, + addingCount newItemCount: Int, at index: Int, - initializingWith body: (inout OutputSpan) throws(E) -> Void + initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(maximumCount >= 0, "Cannot add a negative number of items") - _ensureFreeCapacity(maximumCount) + precondition(newItemCount >= 0, "Cannot add a negative number of items") + _ensureFreeCapacity(newItemCount) try _storage._handle.uncheckedInsert( - maximumCount: maximumCount, at: index, initializingWith: body) + addingCount: newItemCount, at: index, initializingWith: initializer) } } @@ -139,7 +139,7 @@ extension UniqueDeque where Element: ~Copyable { ) { guard !items.isEmpty else { return } var remainder = items - insert(maximumCount: items.count, at: index) { target in + insert(addingCount: items.count, at: index) { target in target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) @@ -217,7 +217,7 @@ extension UniqueDeque where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - /// Inserts at most `maximumCount` items generated by a producer into this + /// Inserts at most `newItemCount` items generated by a producer into this /// deque, starting at the given index. /// /// Existing elements in the deque's storage are moved as needed to make room @@ -229,33 +229,33 @@ extension UniqueDeque where Element: ~Copyable { /// geometric growth rate. /// /// This operation inserts as many items as the producer can generate before - /// either reaching `maximumCount`, or the producer hitting its end, or - /// throwing an error. If the producer has more than `maximumCount` items + /// either reaching `newItemCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `newItemCount` items /// left in its underlying sequence, then extra items remain available after /// this method returns. /// - /// If the operation inserts fewer than `maximumCount` items, then it results + /// If the operation inserts fewer than `newItemCount` items, then it results /// in a gap in ring buffer storage that needs to be closed by moving some /// items to their correct positions given the adjusted count. This adds some /// overhead compared to adding exactly as many items as promised. /// /// - Parameters: - /// - maximumCount: The maximum number of items to insert into the deque. + /// - newItemCount: The maximum number of items to insert into the deque. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the deque. /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`self.count` + `maximumCount`) when amortized over many + /// - Complexity: O(`self.count` + `newItemCount`) when amortized over many /// similar invocations on the same deque. @_alwaysEmitIntoClient public mutating func insert< P: Producer & ~Copyable & ~Escapable >( - maximumCount: Int, + addingCount newItemCount: Int, from producer: inout P, at index: Int ) throws(P.ProducerError) { - try insert(maximumCount: maximumCount, at: index) { target throws(P.ProducerError) in + try insert(addingCount: newItemCount, at: index) { target throws(P.ProducerError) in while !target.isFull, try producer.generate(into: &target) { // Do nothing } @@ -295,7 +295,7 @@ extension UniqueDeque /* where Element: Copyable */ { ) { guard items.count > 0 else { return } var remainder = items - insert(maximumCount: remainder.count, at: index) { target in + insert(addingCount: remainder.count, at: index) { target in target._withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( fromContentsOf: remainder._extracting(first: buffer.count)) @@ -378,7 +378,7 @@ extension UniqueDeque /* where Element: Copyable */ { ) { let expectedCount = self.count + newCount var it = items.makeBorrowingIterator() - insert(maximumCount: newCount, at: index) { target in + insert(addingCount: newCount, at: index) { target in it.copyContents(into: &target) } precondition( @@ -399,7 +399,7 @@ extension UniqueDeque /* where Element: Copyable */ { if done != nil { return } var i = items.startIndex - self.insert(maximumCount: newCount, at: index) { target in + self.insert(addingCount: newCount, at: index) { target in while !target.isFull { target.append(items[i]) items.formIndex(after: &i) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index 3920cb5d..6ed91d33 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -95,7 +95,7 @@ extension UniqueDeque where Element: ~Copyable { guard maximumCount > 0 else { return } _ensureFreeCapacity(maximumCount) try _storage._handle.uncheckedPrepend( - maximumCount: maximumCount, initializingWith: body) + addingCount: maximumCount, initializingWith: body) } } @@ -209,7 +209,7 @@ extension UniqueDeque where Element: ~Copyable { if let maximumCount { _ensureFreeCapacity(maximumCount) try _storage._handle.uncheckedPrepend( - maximumCount: maximumCount + addingCount: maximumCount ) { target throws(P.ProducerError) in while !target.isFull, try producer.generate(into: &target) { // Do nothing diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index bacfd983..ac319b09 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -22,29 +22,41 @@ extension UniqueDeque where Element: ~Copyable { /// using a callback to directly initialize deque storage by populating /// a series of output spans. /// - /// This method has the effect of removing the specified range of elements - /// from the deque and inserting room for the new elements starting at the - /// same location. The number of new elements need not match the number - /// of elements being removed. + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// This method has the same overall effect as calling + /// + /// try deque.consume(subrange, consumingWith: consumer) + /// try deque.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) + /// + /// Except it performs faster (by a constant factor), by avoiding moving + /// some items in the deque twice. /// /// If the deque doesn't have sufficient capacity to accommodate the new /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// If you pass a zero-length range as the `subrange` parameter, then - /// this method is equivalent to calling - /// `insert(maximumCount: newCount, at: subrange.lowerBound, initializingWith: body)`. + /// Neither the removed nor the newly inserted items are guaranteed to form a + /// single contiguous storage region. Therefore, the supplied callbacks may be + /// invoked multiple times to consume, then initialize successive chunks of + /// storage. Calls to `consumer` do not get interleaved with calls to + /// `initializer`: no new item is inserted until every replaced item has been + /// fully consumed. /// - /// Likewise, if you pass a zero for `newCount`, then this method - /// removes the elements in the given subrange without any replacement. - /// This case is more directly expressed by `removeSubrange(subrange)`. + /// The `consumer` callback is not required to fully depopulate its input + /// span. Any items the callback leaves in the span still get removed and + /// discarded from the deque before insertions begin. If there are more + /// spans to consume, the callback will get called again after such a partial + /// consumption. /// - /// The newly prepended items are not guaranteed to form a single contiguous - /// storage region. Therefore, the supplied callback may be invoked multiple - /// times to initialize each successive chunk of storage. However, invocations - /// cease if the callback fails to fully populate its output span or if - /// it throws an error. In such cases, the deque keeps all items that were - /// successfully initialized before the callback terminated the prepend. + /// The `initializer` callback is not required to fully populate its + /// output span, and it is allowed to throw an error. In such cases, the + /// replacement operation ends, and the deque keeps all items that were + /// successfully initialized before the callback terminated. /// /// Partial insertions create a gap in ring buffer storage that needs to be /// closed by moving newly inserted items to their correct positions given @@ -54,7 +66,7 @@ extension UniqueDeque where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - maximumCount: the maximum number of items to replace the old subrange. + /// - newItemCount: the maximum number of items to replace the old subrange. /// - initializer: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. @@ -63,17 +75,17 @@ extension UniqueDeque where Element: ~Copyable { @inlinable public mutating func replaceSubrange( _ subrange: Range, - maximumCount: Int, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Cannot add a negative number of items") - _ensureFreeCapacity(maximumCount - subrange.count) + precondition(newItemCount >= 0, "Cannot add a negative number of items") + _ensureFreeCapacity(newItemCount - subrange.count) try _storage._handle.uncheckedReplaceSubrange( subrange, - newCount: capacity, + addingCount: capacity, initializingWith: initializer) } @@ -87,7 +99,10 @@ extension UniqueDeque where Element: ~Copyable { /// This method has the same overall effect as calling /// /// try deque.consume(subrange, consumingWith: consumer) - /// try deque.insert(maximumCount: maximumCount, at: subrange.lowerBound, initializingWith: initializer) + /// try deque.insert( + /// addingCount: newItemCount, + /// at: subrange.lowerBound, + /// initializingWith: initializer) /// /// Except it performs faster (by a constant factor), by avoiding moving /// some items in the deque twice. @@ -116,7 +131,7 @@ extension UniqueDeque where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - maximumCount: the maximum number of items to replace the old subrange. + /// - newItemCount: the maximum number of items to replace the old subrange. /// - consumer: A callback that gets called at most twice to consume /// the elements to be removed directly from the deque's storage. The /// function is always called with a non-empty input span. @@ -124,23 +139,23 @@ extension UniqueDeque where Element: ~Copyable { /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. /// - /// - Complexity: O(`self.count` + `maximumCount`) in addition to the complexity + /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity /// of the callback invocations. @inlinable public mutating func replaceSubrange( _ subrange: Range, - maximumCount: Int, + addingCount newItemCount: Int, consumingWith consumer: (inout InputSpan) -> Void, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Cannot add a negative number of items") - _ensureFreeCapacity(maximumCount - subrange.count) + precondition(newItemCount >= 0, "Cannot add a negative number of items") + _ensureFreeCapacity(newItemCount - subrange.count) try _storage._handle.uncheckedReplaceSubrange( subrange, - newCount: capacity, + addingCount: newItemCount, consumingWith: consumer, initializingWith: initializer) } @@ -184,7 +199,7 @@ extension UniqueDeque where Element: ~Copyable { moving items: UnsafeMutableBufferPointer, ) { var remainder = items - replaceSubrange(subrange, maximumCount: remainder.count) { target in + replaceSubrange(subrange, addingCount: remainder.count) { target in target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) @@ -318,10 +333,10 @@ extension UniqueDeque where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( _ subrange: Range, - maximumCount: Int, + addingCount newItemCount: Int, from producer: inout P ) throws(P.ProducerError) { - try replaceSubrange(subrange, maximumCount: maximumCount) { target throws(P.ProducerError) in + try replaceSubrange(subrange, addingCount: newItemCount) { target throws(P.ProducerError) in while !target.isFull, try producer.generate(into: &target) { // Do nothing } @@ -365,7 +380,7 @@ extension UniqueDeque /* where Element: Copyable */ { copying items: UnsafeBufferPointer ) { var remainder = items - replaceSubrange(subrange, maximumCount: remainder.count) { target in + replaceSubrange(subrange, addingCount: remainder.count) { target in target._withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count @@ -460,7 +475,7 @@ extension UniqueDeque /* where Element: Copyable */ { let expectedCount = self.count - subrange.count + newCount var it = items.makeBorrowingIterator() - self.replaceSubrange(subrange, maximumCount: newCount) { target in + self.replaceSubrange(subrange, addingCount: newCount) { target in it.copyContents(into: &target) } precondition( @@ -484,7 +499,7 @@ extension UniqueDeque /* where Element: Copyable */ { if done != nil { return } var i = items.startIndex - self.replaceSubrange(subrange, maximumCount: newCount) { target in + self.replaceSubrange(subrange, addingCount: newCount) { target in while !target.isFull { target.append(items[i]) items.formIndex(after: &i) diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 89416880..4eb6bf20 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -740,15 +740,15 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// - Complexity: O(`count`) @_alwaysEmitIntoClient internal mutating func uncheckedPrepend( - maximumCount: Int, + addingCount newItemCount: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { - guard let gap = self._prepend(count: maximumCount) else { return } + guard let gap = self._prepend(count: newItemCount) else { return } var c = 0 defer { - if c < maximumCount { - closeGap(offsets: c ..< maximumCount) + if c < newItemCount { + closeGap(offsets: c ..< newItemCount) } } try gap.first._initialize(initializedCount: &c, initializingWith: body) @@ -1208,17 +1208,17 @@ extension _UnsafeDequeHandle where Element: ~Copyable { extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient internal mutating func uncheckedInsert( - maximumCount: Int, + addingCount newItemCount: Int, at offset: Int, initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { - guard maximumCount > 0 else { return } - let gap = self.openGap(ofSize: maximumCount, atOffset: offset) + guard newItemCount > 0 else { return } + let gap = self.openGap(ofSize: newItemCount, atOffset: offset) var c = 0 defer { - if c < maximumCount { - closeGap(offsets: offset + c ..< offset + maximumCount) + if c < newItemCount { + closeGap(offsets: offset + c ..< offset + newItemCount) } } try gap.first._initialize(initializedCount: &c, initializingWith: body) @@ -1346,12 +1346,12 @@ extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient internal mutating func _insertAfterReplace( _ subrange: Range, - newCount: Int, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { // Note: we're careful to open/close the gap in a direction that does not // lead to trying to move slots we deinitialized above. - let delta = newCount - subrange.count + let delta = newItemCount - subrange.count let left = isLeftLeaning(subrange) if delta > 0 { _ = self.openGap( @@ -1361,12 +1361,12 @@ extension _UnsafeDequeHandle where Element: ~Copyable { self.closeGap( offsets: (left ? subrange.prefix(-delta) : subrange.suffix(-delta))) } - let newRange = Range(uncheckedBounds: (subrange.lowerBound, newCount)) + let newRange = Range(uncheckedBounds: (subrange.lowerBound, newItemCount)) let gap = self.mutableSegments(forOffsets: newRange) var c = 0 defer { - if c < newCount { + if c < newItemCount { closeGap(offsets: newRange.dropFirst(c)) } } @@ -1379,31 +1379,34 @@ extension _UnsafeDequeHandle where Element: ~Copyable { @_alwaysEmitIntoClient internal mutating func uncheckedReplaceSubrange( _ subrange: Range, - newCount: Int, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { assert( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - assert(newCount >= 0, "Cannot add a negative number of items") - assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") + assert(newItemCount >= 0, "Cannot add a negative number of items") + assert(count + newItemCount - subrange.count <= capacity, "RigidDeque capacity overflow") self.mutableSegments(forOffsets: subrange).deinitialize() - try _insertAfterReplace(subrange, newCount: newCount, initializingWith: initializer) + try _insertAfterReplace( + subrange, + addingCount: newItemCount, + initializingWith: initializer) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @_alwaysEmitIntoClient internal mutating func uncheckedReplaceSubrange( _ subrange: Range, - newCount: Int, + addingCount newItemCount: Int, consumingWith consumer: (inout InputSpan) -> Void, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { assert( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - assert(newCount >= 0, "Cannot add a negative number of items") - assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") + assert(newItemCount >= 0, "Cannot add a negative number of items") + assert(count + newItemCount - subrange.count <= capacity, "RigidDeque capacity overflow") do { let removed = self.mutableSegments(forOffsets: subrange) var span = InputSpan( @@ -1415,7 +1418,10 @@ extension _UnsafeDequeHandle where Element: ~Copyable { consumer(&span) } } - try _insertAfterReplace(subrange, newCount: newCount, initializingWith: initializer) + try _insertAfterReplace( + subrange, + addingCount: newItemCount, + initializingWith: initializer) } #endif } diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests.swift index 5116dc19..a915b31f 100644 --- a/Tests/DequeTests/RigidDequeTests.swift +++ b/Tests/DequeTests/RigidDequeTests.swift @@ -612,7 +612,7 @@ final class RigidDequeTests: CollectionTestCase { data.contents.insert(contentsOf: extras, at: 0) var i = 0 - data.deque.prepend(maximumCount: prependCount) { target in + data.deque.prepend(addingCount: prependCount) { target in while !target.isFull { target.append(extras[i]) i += 1 @@ -660,7 +660,7 @@ final class RigidDequeTests: CollectionTestCase { data.contents.insert(contentsOf: extras, at: 0) var i = 0 - data.deque.prepend(maximumCount: layout.freeCapacity) { target in + data.deque.prepend(addingCount: layout.freeCapacity) { target in while !target.isFull, i < prependCount { target.append(extras[i]) i += 1 @@ -711,7 +711,7 @@ final class RigidDequeTests: CollectionTestCase { expectThrows { () throws(TestError) in var i = 0 try data.deque.prepend( - maximumCount: layout.freeCapacity + addingCount: layout.freeCapacity ) { target throws(TestError) in while !target.isFull, i < prependCount { target.append(extras[i]) @@ -1093,7 +1093,7 @@ final class RigidDequeTests: CollectionTestCase { data.contents.insert(contentsOf: extras, at: i) var j = 0 - data.deque.insert(maximumCount: c, at: i) { target in + data.deque.insert(addingCount: c, at: i) { target in expectLessThanOrEqual(target.count, extras.count - j) while !target.isFull { target.append(extras[j]) @@ -1122,7 +1122,7 @@ final class RigidDequeTests: CollectionTestCase { data.contents.insert(contentsOf: extras, at: i) var j = 0 - data.deque.insert(maximumCount: layout.freeCapacity, at: i) { target in + data.deque.insert(addingCount: layout.freeCapacity, at: i) { target in while !target.isFull, j < c { target.append(extras[j]) j += 1 @@ -1151,7 +1151,7 @@ final class RigidDequeTests: CollectionTestCase { expectThrows { () throws(TestError) in var j = 0 try data.deque.insert( - maximumCount: layout.freeCapacity, + addingCount: layout.freeCapacity, at: i ) { target throws(TestError) in while !target.isFull, j < c { @@ -1193,7 +1193,7 @@ final class RigidDequeTests: CollectionTestCase { } data.deque.insert( - maximumCount: layout.freeCapacity, + addingCount: layout.freeCapacity, from: &producer, at: i) expectEqual(extras.count, max(0, c - layout.freeCapacity)) @@ -1225,7 +1225,7 @@ final class RigidDequeTests: CollectionTestCase { expectThrows { () throws(TestError) in try data.deque.insert( - maximumCount: layout.freeCapacity, + addingCount: layout.freeCapacity, from: &producer, at: i) } From 84e99324783ca0faad6f851f3f593510281a69f3 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 17:31:47 -0800 Subject: [PATCH 59/75] Rigid/Unique types: Review consumption methods and unify their shapes Drain-returning variants will need to be added on RigidArray/UniqueArray later. --- .../RigidArray/RigidArray+Consumption.swift | 130 ++++++++++++++++++ .../RigidArray/RigidArray+Removals.swift | 79 ----------- .../UniqueArray/UniqueArray+Consumption.swift | 112 +++++++++++++++ .../UniqueArray/UniqueArray+Removals.swift | 53 ------- .../UniqueDeque/UniqueDeque+Consumption.swift | 121 ++++++++++++++++ 5 files changed, 363 insertions(+), 132 deletions(-) create mode 100644 Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift create mode 100644 Sources/BasicContainers/UniqueArray/UniqueArray+Consumption.swift diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift b/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift new file mode 100644 index 00000000..d5321cf5 --- /dev/null +++ b/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift @@ -0,0 +1,130 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + /// Remove the specified subrange of items from this array, + /// passing an input span to the given function to consume them in place. + /// + /// - Parameter subrange: The subrange of items to consume from this array. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is not required to consume all items in the span; + /// however, the span's remaining items will still be removed from + /// the array. + /// + /// - Complexity: O(`self.count`) + @_alwaysEmitIntoClient + public mutating func consume( + _ subrange: Range, + consumingWith consumer: (inout InputSpan) -> Void + ) { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= _count, + "Subrange out of bounds") + guard !subrange.isEmpty else { + var span = InputSpan() + consumer(&span) + return + } + let buffer = unsafe _storage.extracting(subrange) + var span = InputSpan(buffer: buffer, initializedCount: buffer.count) + + consumer(&span) + _ = consume span + + _closeGap(at: subrange.lowerBound, count: subrange.count) + _count -= subrange.count + } + + /// Remove the specified subrange of items from this deque, + /// passing a series of input spans to a given callback function to consume + /// them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter subrange: The subrange of items to consume from this array. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consume>( + _ subrange: R, + consumingWith consumer: (inout InputSpan) -> Void + ) { + consume(subrange.relative(to: indices), consumingWith: consumer) + } + + /// Remove all items currently in this array, passing an input + /// span to a given callback function to consume them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. + /// + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) + @_alwaysEmitIntoClient + public mutating func consumeAll( + consumingWith consumer: (inout InputSpan) -> Void + ) { + consume(indices, consumingWith: consumer) + } + + /// Remove the specified number of items from the end of this array, + /// passing an input span to a given callback function to consume them in + /// place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. + /// + /// - Parameter n: The number of items to consume from the end of the array. + /// `n` must be greater than or equal to zero and must not exceed + /// the count of the array. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is called at most once. + /// - Complexity: O(`n`) + @inline(__always) + @_alwaysEmitIntoClient + public mutating func consumeLast( + _ n: Int, + consumingWith consumer: (inout InputSpan) -> Void + ) { + precondition( + n >= 0 && n <= _count, + "Count of elements to consume is out of bounds") + self.consume(_count &- n ..< _count, consumingWith: consumer) + } +} +#endif + +#endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift b/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift index 1ff2d247..0b60b87c 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift @@ -135,83 +135,4 @@ extension RigidArray where Element: ~Copyable { } } -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - /// Remove all items currently in this array, returning an input span to - /// allow them to be consumed in place. - /// - /// The input span extends the exclusive mutating access initiated by this - /// operation to cover the span's lifetime. Once the span is destroyed, - /// the array becomes empty, but it preserves its original storage capacity. - /// - /// - Complexity: O(*n*), where *n* is the original count of the array. - @_lifetime(&self) - @_alwaysEmitIntoClient - public mutating func consumeAll() -> InputSpan { - let span = InputSpan(buffer: _items, initializedCount: self.count) - self._count = 0 - return _overrideLifetime(span, mutating: &self) - } - - /// Remove the specified number of items from the end of this array, - /// returning an input span to allow them to be consumed in place. - /// The input span extends the exclusive mutating access initiated by this - /// operation to cover the span's lifetime. - /// - /// - Parameter n: The number of items to consume from the end of the array. - /// `n` must be greater than or equal to zero and must not exceed - /// the count of the array. - /// - /// - Complexity: O(`n`) - @_lifetime(&self) - @_alwaysEmitIntoClient - public mutating func consumeLast(_ n: Int) -> InputSpan { - precondition( - n >= 0 && n <= _count, - "Count of elements to consume is out of bounds") - self._count &-= n - let span = InputSpan( - buffer: self._storage._extracting(first: n), - initializedCount: n) - return _overrideLifetime(span, mutating: &self) - } - - /// Remove the specified subrange of items from this array, - /// passing an input span to the given function to consume them in place. - /// - /// - Parameter bounds: The subrange of items to consume from this array. - /// - Parameter consumer: A function taking an input span of the removed items, - /// allowing them to be consumed straight out of the array's storage. - /// The function is not required to consume all items in the span; - /// however, the span's remaining items will still be removed from - /// the array. - /// - /// - Complexity: O(`self.count`) - @_alwaysEmitIntoClient - public mutating func consumeSubrange( - _ bounds: Range, - consumingWith consumer: (inout InputSpan) throws(E) -> Result - ) throws(E) -> Result { - precondition( - bounds.lowerBound >= 0 && bounds.upperBound <= _count, - "Subrange out of bounds") - guard !bounds.isEmpty else { - var span = InputSpan() - return try consumer(&span) - } - let buffer = unsafe _storage.extracting(bounds) - var span = InputSpan(buffer: buffer, initializedCount: buffer.count) - defer { - let remainder = span.finalize(for: buffer) - buffer._extracting(last: remainder).deinitialize() - _closeGap(at: bounds.lowerBound, count: bounds.count) - _count -= bounds.count - span = InputSpan() - } - return try consumer(&span) - } -} -#endif - #endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Consumption.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Consumption.swift new file mode 100644 index 00000000..56ce174e --- /dev/null +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Consumption.swift @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import ContainersPreview +#endif + +#if compiler(>=6.2) + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { + /// Remove the specified subrange of items from this array, + /// passing an input span to the given function to consume them in place. + /// + /// - Parameter subrange: The subrange of items to consume from this array. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is not required to consume all items in the span; + /// however, the span's remaining items will still be removed from + /// the array. + /// + /// - Complexity: O(`self.count`) + @_alwaysEmitIntoClient + public mutating func consume( + _ subrange: Range, + consumingWith consumer: (inout InputSpan) -> Void + ) { + _storage.consume(subrange, consumingWith: consumer) + } + + /// Remove the specified subrange of items from this deque, + /// passing a series of input spans to a given callback function to consume + /// them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter subrange: The subrange of items to consume from this array. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consume>( + _ subrange: R, + consumingWith consumer: (inout InputSpan) -> Void + ) { + _storage.consume(subrange.relative(to: indices), consumingWith: consumer) + } + + /// Remove all items currently in this array, passing an input + /// span to a given callback function to consume them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. + /// + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) + @_alwaysEmitIntoClient + public mutating func consumeAll( + consumingWith consumer: (inout InputSpan) -> Void + ) { + _storage.consume(indices, consumingWith: consumer) + } + + /// Remove the specified number of items from the end of this array, + /// passing an input span to a given callback function to consume them in + /// place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. + /// + /// - Parameter n: The number of items to consume from the end of the array. + /// `n` must be greater than or equal to zero and must not exceed + /// the count of the array. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the array's storage. + /// The function is called at most once. + /// - Complexity: O(`n`) + @inline(__always) + @_alwaysEmitIntoClient + public mutating func consumeLast( + _ n: Int, + consumingWith consumer: (inout InputSpan) -> Void + ) { + _storage.consumeLast(n, consumingWith: consumer) + } +} +#endif + +#endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift index 619c72f4..ac8261a5 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Removals.swift @@ -121,57 +121,4 @@ extension UniqueArray where Element: ~Copyable { } } -#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -@available(SwiftStdlib 5.0, *) -extension UniqueArray where Element: ~Copyable { - /// Remove all items currently in this array, returning an input span to - /// allow them to be consumed in place. - /// The input span extends the exclusive mutating access initiated by this - /// operation to cover the span's lifetime. Once the span is destroyed, - /// the array becomes empty, but it preserves its original storage. - /// - /// - Complexity: O(*n*), where *n* is the original count of the array. - @_lifetime(&self) - @_alwaysEmitIntoClient - public mutating func consumeAll() -> InputSpan { - _storage.consumeAll() - } - - /// Remove the specified number of items from the end of this array, - /// returning an input span to allow them to be consumed in place. - /// The input span extends the exclusive mutating access initiated by this - /// operation to cover the span's lifetime. - /// - /// - Parameter n: The number of items to consume from the end of the array. - /// `n` must be greater than or equal to zero and must not exceed - /// the count of the array. - /// - /// - Complexity: O(`n`) - @_lifetime(&self) - @_alwaysEmitIntoClient - public mutating func consumeLast(_ count: Int) -> InputSpan { - _storage.consumeLast(count) - } - - /// Remove the specified subrange of items from this array, - /// passing an input span to the given function to consume them in place. - /// - /// - Parameter bounds: The subrange of items to consume from this array. - /// - Parameter consumer: A function taking an input span of the removed items, - /// allowing them to be consumed straight out of the array's storage. - /// The function is not required to consume all items in the span; - /// however, the span's remaining items will still be removed from - /// the array. - /// - /// - Complexity: O(`self.count`) - @_alwaysEmitIntoClient - public mutating func consumeSubrange( - _ bounds: Range, - consumingWith consumer: (inout InputSpan) throws(E) -> Result - ) throws(E) -> Result { - try _storage.consumeSubrange(bounds, consumingWith: consumer) - } -} -#endif - #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift index 6a8e65d1..e0cae681 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Consumption.swift @@ -19,6 +19,23 @@ import ContainersPreview @available(SwiftStdlib 5.0, *) extension UniqueDeque where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + /// Remove the specified subrange of items from this deque, + /// passing a series of input spans to a given callback function to consume + /// them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter subrange: The subrange of items to consume from this deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @inline(__always) public mutating func consume( @@ -28,6 +45,23 @@ extension UniqueDeque where Element: ~Copyable { _storage.consume(subrange, consumingWith: consumer) } + /// Remove the specified subrange of items from this deque, + /// passing a series of input spans to a given callback function to consume + /// them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter subrange: The subrange of items to consume from this deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// The function is called at most once. + /// + /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @inline(__always) public mutating func consume>( @@ -37,6 +71,20 @@ extension UniqueDeque where Element: ~Copyable { consume(subrange.relative(to: indices), consumingWith: consumer) } + /// Remove all items currently in this deque, passing a series of input + /// spans to a given callback function to consume them in place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// The function is called at most once. + /// - Complexity: O(`self.count`) @_alwaysEmitIntoClient @inline(__always) public mutating func consumeAll( @@ -44,6 +92,59 @@ extension UniqueDeque where Element: ~Copyable { ) { consume(indices, consumingWith: consumer) } + + /// Remove the specified number of items from the end of this deque, + /// passing an input span to a given callback function to consume them in + /// place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter n: The number of items to consume from the end of the deque. + /// `n` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// - Complexity: O(`n`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consumeLast( + _ n: Int, + consumingWith consumer: (inout InputSpan) -> Void + ) { + _storage.consumeLast(n, consumingWith: consumer) + } + + /// Remove the specified number of items from the front of this deque, + /// passing an input span to a given callback function to consume them in + /// place. + /// + /// The callback is not required to fully consume the contents of its + /// argument; any items it leaves in the input span get automatically + /// consumed. The underlying storage isn't necessarily contiguous, so + /// the callback may be called more than once, whether or not it fully + /// consumes its input. If the specified range is empty, the callback + /// may not be called at all. + /// + /// - Parameter n: The number of items to consume from the front of the deque. + /// `n` must be greater than or equal to zero and must not exceed + /// the count of the deque. + /// - Parameter consumer: A function taking an input span of the removed items, + /// allowing them to be consumed straight out of the deque's storage. + /// - Complexity: O(`n`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func consumeFirst( + _ n: Int, + consumingWith consumer: (inout InputSpan) -> Void + ) { + _storage.consumeFirst(n, consumingWith: consumer) + } + #endif } @@ -76,6 +177,26 @@ extension UniqueDeque where Element: ~Copyable { public mutating func consumeAll() -> SubrangeConsumer { consume(indices) } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consumeLast(_ n: Int) -> SubrangeConsumer { + precondition( + n >= 0 && n <= self.count, + "Count of elements to consume is out of bounds") + return consume(self.count - n ..< self.count) + } + + @_alwaysEmitIntoClient + @inline(__always) + @_lifetime(&self) + public mutating func consumeFirst(_ n: Int) -> SubrangeConsumer { + precondition( + n >= 0 && n <= self.count, + "Count of elements to consume is out of bounds") + return consume(0 ..< n) + } } #endif From 2318ef4c4e220e572a27b6503ed951fabed3b62d Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 17:35:18 -0800 Subject: [PATCH 60/75] Fix random issues in single-module mode --- .../BasicContainers/UniqueArray/UniqueArray+Container.swift | 2 +- .../ConformanceCheckers/CheckContainer.swift | 4 ++++ .../_CollectionsTestSupport/MinimalTypes/CustomProducer.swift | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift index 99464203..8b5567ed 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift @@ -21,7 +21,7 @@ import ContainersPreview extension UniqueArray: BorrowingSequence where Element: ~Copyable { public typealias BorrowingIterator = RigidArray.BorrowingIterator - public var estimatedCount: ContainersPreview.EstimatedCount { + public var estimatedCount: EstimatedCount { .exactly(count) } diff --git a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift index c2920bad..7e3997cc 100644 --- a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift +++ b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift @@ -11,7 +11,11 @@ #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW import XCTest +#if COLLECTIONS_SINGLE_MODULE +import Collections +#else import ContainersPreview +#endif @available(SwiftStdlib 5.0, *) @inlinable diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift index 419a2b88..75f367f9 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/CustomProducer.swift @@ -9,7 +9,9 @@ // //===----------------------------------------------------------------------===// -#if !COLLECTIONS_SINGLE_MODULE +#if COLLECTIONS_SINGLE_MODULE +import Collections +#else import InternalCollectionsUtilities import ContainersPreview #endif From 0b8e5971d8ea92b50c5da789183d082ee2b87622 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 17:47:50 -0800 Subject: [PATCH 61/75] =?UTF-8?q?Another=20spot=20where=20we=20call=20the?= =?UTF-8?q?=20stdlib=E2=80=99s=20OutputSpan.wUMBP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContainersPreview/Protocols/BorrowingIteratorProtocol.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift index 651937d9..68cb55db 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift @@ -146,7 +146,7 @@ where Self: ~Copyable & ~Escapable, Element: Copyable @_lifetime(self: copy self) @_transparent public mutating func copyContents(into target: inout OutputSpan) { - target.withUnsafeMutableBufferPointer { dst, dstCount in + target._withUnsafeMutableBufferPointer { dst, dstCount in var tail = dst._extracting(droppingFirst: dstCount) while !tail.isEmpty { let src = nextSpan(maximumCount: tail.count) From 7692d9c4b354ef3c1512415e575af18055979ef7 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 22:41:05 -0800 Subject: [PATCH 62/75] RigidArray: Add test coverage; revive some container-based operations --- .../RigidArray/RigidArray+Append.swift | 7 +- .../RigidArray/RigidArray+Insertions.swift | 29 +- .../RigidArray/RigidArray+Replacements.swift | 28 +- .../Protocols/BorrowingSequence.swift | 2 - Tests/BasicContainersTests/ArrayLayout.swift | 39 +- .../RigidArrayTests.swift | 452 +++++++++++++++++- .../ConformanceCheckers/CheckContainer.swift | 2 - .../MinimalTypes/StaccatoContainer.swift | 156 ++++-- 8 files changed, 624 insertions(+), 91 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index e2bb6999..9ae0b3cd 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -45,7 +45,6 @@ extension RigidArray where Element: ~Copyable { /// - Complexity: O(1) @inlinable public mutating func pushLast(_ item: consuming Element) -> Element? { - // FIXME: Remove this in favor of a standard algorithm. if isFull { return item } append(item) return nil @@ -203,10 +202,8 @@ extension RigidArray where Element: ~Copyable { moving items: inout RigidArray ) { // FIXME: Remove this in favor of a generic algorithm over range-replaceable containers - unsafe items._unsafeEdit { buffer, count in - let source = buffer._extracting(first: count) - unsafe self.append(moving: source) - count = 0 + items.edit { span in + self.append(moving: &span) } } } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index 1e8f9327..d56b06ad 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -103,13 +103,14 @@ extension RigidArray where Element: ~Copyable { precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition(newItemCount <= freeCapacity, "RigidArray capacity overflow") let target = unsafe _openGap(at: index, count: newItemCount) + _count &+= newItemCount var span = OutputSpan(buffer: target, initializedCount: 0) defer { let c = span.finalize(for: target) if c < newItemCount { _closeGap(at: index &+ c, count: newItemCount &- c) + _count &-= newItemCount &- c } - _count &+= c span = OutputSpan() } try initializer(&span) @@ -261,10 +262,8 @@ extension RigidArray where Element: ~Copyable { ) { // FIXME: Remove this in favor of a generic algorithm over consumable containers guard !items.isEmpty else { return } - insert(addingCount: items.count, at: index) { target in - items.edit { source in - target._append(moving: &source) - } + items.edit { source in + self.insert(moving: &source, at: index) } } } @@ -390,8 +389,7 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. - @inlinable + @_alwaysEmitIntoClient internal mutating func _insertContainer< C: Container & ~Copyable & ~Escapable >( @@ -399,17 +397,16 @@ extension RigidArray { copying items: borrowing C, newCount: Int ) { + var it = items.makeBorrowingIterator() insert(addingCount: newCount, at: index) { target in - target.withUnsafeMutableBufferPointer { buffer, count in - let copied = items._copyContents(intoPrefixOf: buffer) - precondition( - copied == newCount, - "Broken Container: count doesn't match contents") - count = newCount + while !target.isFull { + let source = it.nextSpan(maximumCount: target.freeCapacity) + precondition(!source.isEmpty, "Broken container: mismatching count") + target._append(copying: source) } } + precondition(it.nextSpan().isEmpty, "Broken container: mismatching count") } -#endif #endif @inlinable @@ -439,7 +436,6 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -469,7 +465,6 @@ extension RigidArray { _insertContainer( at: index, copying: newElements, newCount: newElements.count) } -#endif #endif /// Copies the elements of a collection into this array at the specified @@ -501,7 +496,6 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -532,7 +526,6 @@ extension RigidArray { at: index, copying: newElements, newCount: newElements.count) } #endif -#endif } #endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index c5469f43..5b8ba7a2 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -92,7 +92,8 @@ extension RigidArray where Element: ~Copyable { if c < newItemCount { self._closeGap( at: subrange.lowerBound &+ c, - count: capacity &- c) + count: newItemCount &- c) + _count &-= newItemCount &- c } span = OutputSpan() } @@ -564,25 +565,28 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. @inlinable internal mutating func _replaceSubrange< C: Container & ~Copyable & ~Escapable >( _ subrange: Range, - copyingContainer newElements: borrowing C, + copyingContainer items: borrowing C, newCount: Int ) { - self.replaceSubrange(subrange, addingCapacity: newCount) { target in - target.withUnsafeMutableBufferPointer { buffer, count in - count = newElements._copyContents(intoPrefixOf: buffer) + var it = items.makeBorrowingIterator() + self.replaceSubrange(subrange, addingCount: newCount) { target in + while !target.isFull { + let source = it.nextSpan(maximumCount: target.freeCapacity) precondition( - count == newCount, + !source.isEmpty, "Broken Container: count doesn't match contents") + target._append(copying: source) } + precondition( + it.nextSpan().isEmpty, + "Broken Container: count doesn't match contents") } } -#endif #endif @inlinable @@ -613,7 +617,6 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -649,9 +652,10 @@ extension RigidArray { copying newElements: borrowing C ) { _replaceSubrange( - subrange, copyingContainer: newElements, newCount: newElements.count) + subrange, + copyingContainer: newElements, + newCount: newElements.count) } -#endif #endif /// Replaces the specified subrange of elements by copying the elements of @@ -691,7 +695,6 @@ extension RigidArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -731,7 +734,6 @@ extension RigidArray { subrange, copyingContainer: newElements, newCount: newElements.count) } #endif -#endif } #endif diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift index 19ece213..b7581d25 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift @@ -22,8 +22,6 @@ public protocol BorrowingSequence: ~Copyable, ~Escapable { associatedtype Element: ~Copyable associatedtype BorrowingIterator: BorrowingIteratorProtocol & ~Copyable & ~Escapable - var isEmpty: Bool { get } - var estimatedCount: EstimatedCount { get } @_lifetime(borrow self) diff --git a/Tests/BasicContainersTests/ArrayLayout.swift b/Tests/BasicContainersTests/ArrayLayout.swift index 6ae6e1dd..fc35ad2d 100644 --- a/Tests/BasicContainersTests/ArrayLayout.swift +++ b/Tests/BasicContainersTests/ArrayLayout.swift @@ -26,6 +26,10 @@ struct ArrayLayout { self.capacity = capacity self.count = count } + + var isFull: Bool { count == capacity } + var isEmpty: Bool { count == 0 } + var freeCapacity: Int { capacity - count } } func withSomeArrayLayouts( @@ -49,7 +53,7 @@ func withSomeArrayLayouts( counts.insert(2) counts.insert(capacity - 2) } - for count in counts { + for count in counts.sorted() { let layout = ArrayLayout(capacity: capacity, count: count) let entry = context.push("\(label): \(layout)", file: file, line: line) @@ -90,7 +94,7 @@ extension LifetimeTracker { ) -> RigidArray> { RigidArray(layout: layout, using: { self.instance(for: generator($0)) }) } - + func uniqueArray( layout: ArrayLayout, using generator: (Int) -> Element = { $0 } @@ -100,5 +104,36 @@ extension LifetimeTracker { } return UniqueArray(consuming: contents) } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func withInputSpan( + layout: ArrayLayout, + using generator: (Int) -> Element, + _ body: (inout InputSpan>) -> Void + ) { + let buffer = UnsafeMutableBufferPointer> + .allocate(capacity: layout.capacity) + for i in 0 ..< layout.count { + buffer.initializeElement( + at: layout.capacity - layout.count + i, + to: self.instance(for: generator(i))) + } + var span = InputSpan(buffer: buffer, initializedCount: layout.count) + body(&span) + _ = consume span + buffer.deallocate() + } +#endif + + func withOutputSpan( + layout: ArrayLayout, + using generator: (Int) -> Element, + _ body: (inout OutputSpan>) -> Void + ) { + var contents = RigidArray(layout: layout) { + self.instance(for: generator($0)) + } + contents.edit(body) + } } #endif diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index ee18f8ef..ac2887eb 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -358,7 +358,65 @@ class RigidArrayTests: CollectionTestCase { } } #endif - + + func test_equatable() { + withSomeArrayLayouts("layoutA", ofCapacities: [0, 10, 100]) { layoutA in + withSomeArrayLayouts("layoutB", ofCapacities: [0, 10, 100]) { layoutB in + withLifetimeTracking { tracker in + let a = tracker.rigidArray(layout: layoutA) + let b = tracker.rigidArray(layout: layoutB) + expectTrue(a.isTriviallyIdentical(to: a)) + expectEqual( + a.isTriviallyIdentical(to: b), + a.capacity == 0 && b.capacity == 0) + expectEqual(a == b, layoutA.count == layoutB.count) + } + } + } + } + + func test_hashable() { + withSomeArrayLayouts("layoutA", ofCapacities: [0, 10, 100]) { layoutA in + withSomeArrayLayouts("layoutB", ofCapacities: [0, 10, 100]) { layoutB in + withLifetimeTracking { tracker in + let a = tracker.rigidArray(layout: layoutA) + let b = tracker.rigidArray(layout: layoutB) + // FIXME: Use checkHashable when possible + var goodHash = false + for i in 0 ..< 10 { + var ha = Hasher() + ha.combine(i) + a.hash(into: &ha) + let hashValueA = ha.finalize() + + var hb = Hasher() + hb.combine(i) + b.hash(into: &hb) + let hashValueB = hb.finalize() + + if layoutA.count == layoutB.count { + expectEqual(hashValueA, hashValueB) + goodHash = true + } else if hashValueA != hashValueB { + goodHash = true + } + } + expectTrue(goodHash, "Hashing does not differentiate between inequal containers") + } + } + } + } + + func test_descriptions() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withLifetimeTracking { tracker in + let a = tracker.rigidArray(layout: layout) + expectEqual(a.description, "<\(layout.count) items>") + expectEqual(a.debugDescription, "<\(layout.count) items>") + } + } + } + func test_edit() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withLifetimeTracking { tracker in @@ -651,7 +709,149 @@ class RigidArrayTests: CollectionTestCase { } } } - + + func test_pushLast() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + for i in layout.count ..< layout.capacity { + expectNil(a.pushLast(tracker.instance(for: i))) + expectEqual(a.count, i + 1) + expectIterableContents( + a, + equivalentTo: 0 ..< i + 1, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + expectTrue(a.isFull) + let final = a.pushLast(tracker.instance(for: layout.capacity)) + expectNotNil(final) { value in + expectEqual(value.payload, layout.capacity) + } + } + } + } + + func test_append_addingCount_full() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + a.append(addingCount: c) { target in + expectEqual(target.freeCapacity, c) + for i in 0 ..< c { + target.append(tracker.instance(for: layout.count + i)) + } + } + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count + c, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + + func test_append_addingCount_partial() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + guard layout.freeCapacity > 0 else { return } + withEvery("c", in: 1 ..< layout.freeCapacity) { c in + withEvery("n", in: [0, 1, c / 2, c - 1] as Set) { n in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + a.append(addingCount: c) { target in + expectEqual(target.freeCapacity, c) + for i in layout.count ..< layout.count + n { + target.append(tracker.instance(for: i)) + } + } + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count + n, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + + func test_append_moving_UnsafeMutableBufferPointer() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withLifetimeTracking { tracker in + let additions = UnsafeMutableBufferPointer> + .allocate(capacity: c) + for i in 0 ..< c { + additions.initializeElement( + at: i, + to: tracker.instance(for: layout.count + i)) + } + + var a = tracker.rigidArray(layout: layout) + a.append(moving: additions) + + additions.deallocate() + + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count + c, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_append_moving_InputSpan() { + withSomeArrayLayouts("layout", ofCapacities: [0, 1, 5, 10]) { layout in + withSomeArrayLayouts("spanLayout", ofCapacities: 0 ..< layout.freeCapacity) { spanLayout in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + tracker.withInputSpan( + layout: spanLayout, + using: { layout.count + $0 } + ) { span in + a.append(moving: &span) + } + + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count + spanLayout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } +#endif + + func test_append_moving_OutputSpan() { + withSomeArrayLayouts("layout", ofCapacities: [0, 1, 5, 10]) { layout in + withSomeArrayLayouts("spanLayout", ofCapacities: 0 ..< layout.freeCapacity) { spanLayout in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + tracker.withOutputSpan( + layout: spanLayout, + using: { layout.count + $0 } + ) { span in + a.append(moving: &span) + } + + expectIterableContents( + a, + equivalentTo: 0 ..< layout.count + spanLayout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + func test_append_copying_MinimalSequence() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("isContiguous", in: [false, true]) { isContiguous in @@ -737,7 +937,166 @@ class RigidArrayTests: CollectionTestCase { } } } - + + func test_insert_addingCount_full() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 20]) { layout in + withEvery("i", in: 0 ..< layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + a.insert(addingCount: c, at: i) { target in + expectEqual(target.freeCapacity, c) + for i in 0 ..< c { + target.append(tracker.instance(for: layout.count + i)) + } + } + + var expected = Array(0 ..< layout.count) + expected.insert( + contentsOf: layout.count ..< layout.count + c, + at: i) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + + func test_insert_addingCount_partial() { + withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in + guard !layout.isFull else { return } + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 1 ..< layout.freeCapacity) { c in + withEvery("n", in: [0, 1, c / 2, c - 1] as Set) { n in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + a.insert(addingCount: c, at: i) { target in + expectTrue(target.isEmpty) + expectEqual(target.freeCapacity, c) + for i in 0 ..< n { + target.append(tracker.instance(for: layout.count + i)) + } + } + expectEqual(a.count, layout.count + n) + + var expected = Array(0 ..< layout.count) + expected.insert( + contentsOf: layout.count ..< layout.count + n, + at: i) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + } + + func test_insert_moving_UnsafeMutableBufferPointer() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withEvery("i", in: 0 ... layout.count) { i in + withEvery("c", in: 0 ..< layout.freeCapacity) { c in + withLifetimeTracking { tracker in + let additions = UnsafeMutableBufferPointer> + .allocate(capacity: c) + for i in 0 ..< c { + additions.initializeElement( + at: i, + to: tracker.instance(for: layout.count + i)) + } + + var a = tracker.rigidArray(layout: layout) + a.insert(moving: additions, at: i) + + additions.deallocate() + + var expected = Array(0 ..< layout.count) + expected.insert(contentsOf: layout.count ..< layout.count + c, at: i) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_insert_moving_InputSpan() { + withSomeArrayLayouts("layout", ofCapacities: [0, 1, 5, 10]) { layout in + withSomeArrayLayouts("spanLayout", ofCapacities: 0 ..< layout.freeCapacity) { spanLayout in + withEvery("i", in: 0 ... layout.count) { i in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + tracker.withInputSpan( + layout: spanLayout, + using: { layout.count + $0 } + ) { span in + a.insert(moving: &span, at: i) + } + + var expected = Array(0 ..< layout.count) + expected.insert( + contentsOf: layout.count ..< layout.count + spanLayout.count, + at: i) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } +#endif + + func test_insert_moving_OutputSpan() { + withSomeArrayLayouts("layout", ofCapacities: [0, 1, 5, 10]) { layout in + withSomeArrayLayouts("spanLayout", ofCapacities: 0 ..< layout.freeCapacity) { spanLayout in + withEvery("i", in: 0 ... layout.count) { i in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + tracker.withOutputSpan( + layout: spanLayout, + using: { layout.count + $0 } + ) { span in + a.insert(moving: &span, at: i) + } + + var expected = Array(0 ..< layout.count) + expected.insert( + contentsOf: layout.count ..< layout.count + spanLayout.count, + at: i) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + func test_insert_copying_Collection() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withEvery("i", in: 0 ... layout.count) { i in @@ -793,29 +1152,24 @@ class RigidArrayTests: CollectionTestCase { } } } - + #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: Update func test_insert_copying_Container() { - withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEvery("i", in: 0 ... layout.count) { i in withEvery("spanCount", in: 1 ... Swift.max(1, layout.capacity - layout.count)) { spanCount in withLifetimeTracking { tracker in - + var expected = Array(0 ..< layout.count) let addition = Array(layout.count ..< layout.capacity) expected.insert(contentsOf: addition, at: i) - + var a = tracker.rigidArray(layout: layout) let rigidAddition = StaccatoContainer( - contents: RigidArray(capacity: addition.count) { - for item in addition { - $0.append(tracker.instance(for: item)) - } - }, - spanCounts: [Swift.max(spanCount, 1)]) + contents: tracker.instances(for: addition), + spanCounts: [spanCount]) a.insert(copying: rigidAddition, at: i) - + expectIterableContents( a, equivalentTo: expected, @@ -828,7 +1182,71 @@ class RigidArrayTests: CollectionTestCase { } } #endif -#endif + + func test_replaceSubrange_addingCount_full() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 20]) { layout in + withEveryRange("subrange", in: 0 ..< layout.count) { subrange in + withEvery("c", in: 0 ..< subrange.count + layout.freeCapacity) { c in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + a.replaceSubrange(subrange, addingCount: c) { target in + expectEqual(target.freeCapacity, c) + for i in 0 ..< c { + target.append(tracker.instance(for: layout.count + i)) + } + } + + var expected = Array(0 ..< layout.count) + expected.replaceSubrange( + subrange, + with: layout.count ..< layout.count + c) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + + func test_replaceSubrange_addingCount_partial() { + withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in + guard !layout.isFull else { return } + withEveryRange("subrange", in: 0 ..< layout.count) { subrange in + withEvery("c", in: 1 ..< layout.freeCapacity) { c in + withEvery("n", in: [0, 1, c / 2, c - 1] as Set) { n in + withLifetimeTracking { tracker in + var a = tracker.rigidArray(layout: layout) + + a.replaceSubrange(subrange, addingCount: c) { target in + expectTrue(target.isEmpty) + expectEqual(target.freeCapacity, c) + for i in 0 ..< n { + target.append(tracker.instance(for: layout.count + i)) + } + } + expectEqual(a.count, layout.count - subrange.count + n) + + var expected = Array(0 ..< layout.count) + expected.replaceSubrange( + subrange, + with: layout.count ..< layout.count + n) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + } func test_replaceSubrange_Collection() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in @@ -884,7 +1302,6 @@ class RigidArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: Update func test_replaceSubrange_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in @@ -914,6 +1331,5 @@ class RigidArrayTests: CollectionTestCase { } } #endif -#endif } #endif diff --git a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift index 7e3997cc..e748975d 100644 --- a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift +++ b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift @@ -52,8 +52,6 @@ public func checkIterable< let expectedContents = Array(expectedContents) - expectEqual(iterable.isEmpty, expectedContents.isEmpty) - let estimatedCount = iterable.estimatedCount switch estimatedCount { case .exactly(let c): diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift index 6e220149..bdb9168e 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift @@ -17,74 +17,168 @@ import ContainersPreview #endif #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: Update /// A container type with user-defined contents and storage chunks. /// Useful for testing. @available(SwiftStdlib 5.0, *) public struct StaccatoContainer: ~Copyable { internal let _contents: RigidArray - internal let _spanCounts: [Int] - internal let _modulus: Int + internal let _params: _StaccatoParameters public init(contents: consuming RigidArray, spanCounts: [Int]) { // FIXME: Make this take an arbitrary consumable container - precondition(!spanCounts.isEmpty && spanCounts.allSatisfy { $0 > 0 }) self._contents = contents + self._params = _StaccatoParameters( + count: _contents.count, spanCounts: spanCounts) + } +} + +@available(SwiftStdlib 5.0, *) +extension StaccatoContainer { + public init(contents: Array, spanCounts: [Int]) { + self._contents = RigidArray(copying: contents) + self._params = _StaccatoParameters( + count: _contents.count, spanCounts: spanCounts) + } +} + +@available(SwiftStdlib 5.0, *) +package struct _StaccatoParameters { + internal let _count: Int + internal let _spanCounts: [Int] + internal let _modulus: Int + + internal init(count: Int, spanCounts: [Int]) { + precondition(!spanCounts.isEmpty && spanCounts.allSatisfy { $0 > 0 }) + self._count = count self._spanCounts = spanCounts self._modulus = spanCounts.reduce(into: 0, { $0 += $1 }) } + + internal func endOffset( + fromOffset startOffset: Int, + maximumCount: Int + ) -> Int { + precondition(maximumCount > 0) + precondition(startOffset >= 0 && startOffset <= _count) + var cycleOffset = startOffset % _modulus + var i = 0 + while i < _spanCounts.count { + let c = _spanCounts[i] + if cycleOffset < c { break } + cycleOffset -= c + i += 1 + } + let c = _spanCounts[i] + return Swift.min(_count, startOffset + Swift.min(c - cycleOffset, maximumCount)) + } } @available(SwiftStdlib 5.0, *) public struct _StaccatoBorrowingIterator: BorrowingIteratorProtocol, ~Escapable { internal let _contents: Span - internal let _spanCounts: [Int] - internal let _modulus: Int + internal let _params: _StaccatoParameters internal var _offset: Int @_lifetime(copy contents) - internal init(contents: Span, spanCounts: [Int]) { + internal init(contents: Span, params: _StaccatoParameters) { self._contents = contents - self._spanCounts = spanCounts - self._modulus = spanCounts.reduce(into: 0, { $0 += $1 }) + self._params = params self._offset = 0 } - func _spanCoordinates(atOffset offset: Int) -> (spanIndex: Int, spanOffset: Int) { - precondition(offset >= 0 && offset <= _contents.count) - var remainder = offset % _modulus - var i = 0 - while i < _spanCounts.count { - let c = _spanCounts[i] - if remainder < c { break } - remainder -= c - i += 1 - } - return (i, remainder) - } - @_lifetime(copy self) - public mutating func nextSpan(maximumCount: Int?) -> Span { - let (spanIndex, spanOffset) = _spanCoordinates(atOffset: _offset) - let c = _spanCounts[spanIndex] - spanOffset + public mutating func nextSpan(maximumCount: Int) -> Span { + let endOffset = _params.endOffset(fromOffset: _offset, maximumCount: maximumCount) let startOffset = _offset - let endOffset = Swift.min(startOffset + c, _contents.count) _offset = endOffset return _contents.extracting(startOffset ..< endOffset) - } } +@available(SwiftStdlib 5.0, *) +public struct _StaccatoIndex: Comparable { + var _offset: Int + init(_offset: Int) { + self._offset = _offset + } + + public static func ==(left: Self, right: Self) -> Bool { + left._offset == right._offset + } + + public static func <(left: Self, right: Self) -> Bool { + left._offset < right._offset + } +} + +@available(SwiftStdlib 5.0, *) +extension StaccatoContainer: BorrowingSequence where Element: ~Copyable { + public typealias BorrowingIterator = _StaccatoBorrowingIterator // FIXME rdar://150240032 + + public var estimatedCount: EstimatedCount { + .exactly(count) + } + + public func makeBorrowingIterator() -> BorrowingIterator { + BorrowingIterator(contents: _contents.span, params: _params) + } +} @available(SwiftStdlib 5.0, *) extension StaccatoContainer: Container where Element: ~Copyable { - public typealias BorrowingIterator = _StaccatoBorrowingIterator // FIXME rdar://150240032 + public typealias Index = _StaccatoIndex + public var isEmpty: Bool { _contents.isEmpty } public var count: Int { _contents.count } + + + package func _isValid(_ index: Index) -> Bool { + index._offset >= 0 && index._offset <= count + } - public func makeBorrowingIterator() -> BorrowingIterator { - BorrowingIterator(contents: _contents.span, spanCounts: _spanCounts) + public var startIndex: Index { Index(_offset: 0) } + public var endIndex: Index { Index(_offset: _contents.count) } + + public func index(after index: Index) -> Index { + precondition(index._offset >= 0 && index._offset < count) + return Index(_offset: index._offset + 1) + } + + public func index(before index: Index) -> Index { + precondition(index._offset > 0 && index._offset <= count) + return Index(_offset: index._offset - 1) + } + + public func index(_ index: Index, offsetBy n: Int) -> Index { + precondition(index._offset >= 0 && index._offset <= count) + let j = index._offset + n + precondition(j >= 0 && j <= count) + return Index(_offset: j) + } + + public func distance(from start: Index, to end: Index) -> Int { + precondition(_isValid(start) && _isValid(end)) + return end._offset - start._offset + } + + public func formIndex( + _ index: inout Index, offsetBy n: inout Int, limitedBy limit: Index + ) { + precondition(_isValid(index) && _isValid(limit)) + index._offset._advance(by: &n, limitedBy: limit._offset) + precondition(_isValid(index)) + } + + @_lifetime(borrow self) + public func nextSpan( + after index: inout Index, maximumCount: Int + ) -> Span { + precondition(_isValid(index)) + let startOffset = index._offset + let endOffset = _params.endOffset(fromOffset: index._offset, maximumCount: maximumCount) + print("\(startOffset) .-> \(endOffset)") + index._offset = endOffset + return _contents.span.extracting(startOffset ..< endOffset) } } #endif -#endif From e4a874b67af5ed1ac4b489b680aefb6db1a37605 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 22:43:18 -0800 Subject: [PATCH 63/75] Rigid & Unique types: Add Equatable, Hashable, Custom[Debug]StringConvertible operations Currently these are all conditional on copyable elements, and the types cannot conform to the actual protocols yet. --- .../RigidArray/RigidArray+Descriptions.swift | 30 ++++++++++ .../RigidArray/RigidArray+Equatable.swift | 38 ++++++++++++ .../RigidArray/RigidArray+Hashable.swift | 27 +++++++++ .../UniqueArray+Descriptions.swift | 30 ++++++++++ .../UniqueArray/UniqueArray+Equatable.swift | 29 ++++++++++ .../UniqueArray/UniqueArray+Hashable.swift | 26 +++++++++ .../BorrowingSequence+Utilities.swift | 22 ++----- .../Protocols/BorrowingSequence.swift | 14 +++++ .../Protocols/ContainerAlgorithms.swift | 58 +++++++++++++++++++ .../RigidDeque/RigidDeque+Descriptions.swift | 30 ++++++++++ .../RigidDeque/RigidDeque+Equatable.swift | 46 +++++++++++++++ .../RigidDeque/RigidDeque+Hashable.swift | 31 ++++++++++ .../UniqueDeque+Descriptions.swift | 30 ++++++++++ .../UniqueDeque/UniqueDeque+Equatable.swift | 29 ++++++++++ .../UniqueDeque/UniqueDeque+Hashable.swift | 22 +++++++ Sources/DequeModule/_UnsafeDequeHandle.swift | 10 ++++ .../Span+Extras.swift | 36 +++++++++++- 17 files changed, 489 insertions(+), 19 deletions(-) create mode 100644 Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift create mode 100644 Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift create mode 100644 Sources/BasicContainers/RigidArray/RigidArray+Hashable.swift create mode 100644 Sources/BasicContainers/UniqueArray/UniqueArray+Descriptions.swift create mode 100644 Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift create mode 100644 Sources/BasicContainers/UniqueArray/UniqueArray+Hashable.swift create mode 100644 Sources/ContainersPreview/Protocols/ContainerAlgorithms.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Descriptions.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Equatable.swift create mode 100644 Sources/DequeModule/RigidDeque/RigidDeque+Hashable.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Descriptions.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Equatable.swift create mode 100644 Sources/DequeModule/UniqueDeque/UniqueDeque+Hashable.swift diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift new file mode 100644 index 00000000..f237b812 --- /dev/null +++ b/Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidArray /*: CustomStringConvertible */ where Element: ~Copyable { + public var description: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidArray /*: CustomDebugStringConvertible */ where Element: ~Copyable { + public var debugDescription: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +#endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift b/Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift new file mode 100644 index 00000000..53d836aa --- /dev/null +++ b/Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ { + public func isTriviallyIdentical(to other: borrowing Self) -> Bool { + self._storage._isIdentical(to: other._storage) + && self._count == other._count + } +} + + +@available(SwiftStdlib 5.0, *) +extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ { + @inlinable + public static func ==( + left: borrowing Self, + right: borrowing Self + ) -> Bool { + left.span._elementsEqual(to: right.span) + } +} + +#endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Hashable.swift b/Sources/BasicContainers/RigidArray/RigidArray+Hashable.swift new file mode 100644 index 00000000..fa7d4b5f --- /dev/null +++ b/Sources/BasicContainers/RigidArray/RigidArray+Hashable.swift @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +extension RigidArray /*: Hashable */ where Element: Hashable /* & ~Copyable */ { + @inlinable + public func hash(into hasher: inout Hasher) { + hasher.combine(self.count) + self.span._hashContents(into: &hasher) + } +} + +#endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Descriptions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Descriptions.swift new file mode 100644 index 00000000..bf815ce5 --- /dev/null +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Descriptions.swift @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueArray /*: CustomStringConvertible */ where Element: ~Copyable { + public var description: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueArray /*: CustomDebugStringConvertible */ where Element: ~Copyable { + public var debugDescription: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +#endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift new file mode 100644 index 00000000..2c4753ae --- /dev/null +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +extension UniqueArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ { + @inlinable + public static func ==( + left: borrowing Self, + right: borrowing Self + ) -> Bool { + left.span._elementsEqual(to: right.span) + } +} + +#endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Hashable.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Hashable.swift new file mode 100644 index 00000000..ee93d30c --- /dev/null +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Hashable.swift @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueArray /*: Hashable */ where Element: Hashable /* & ~Copyable */ { + @inlinable + public func hash(into hasher: inout Hasher) { + hasher.combine(self.count) + let span = self.span + for i in 0 ..< count { + hasher.combine(span[unchecked: i]) + } + } +} + +#endif diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift index 4032273b..1bd60bfd 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift @@ -36,7 +36,7 @@ extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: Copyabl } } -#if true +#if true // FIXME: rdar://150228920 @available(SwiftStdlib 5.0, *) extension BorrowingSequence where Self: ~Copyable & ~Escapable { @inlinable @@ -45,12 +45,10 @@ extension BorrowingSequence where Self: ~Copyable & ~Escapable { >( _ other: borrowing Other, ) -> Bool where Element: Equatable { - switch (self.estimatedCount, other.estimatedCount) { - case let (.exactly(a), .exactly(b)): - guard a == b else { return false } - default: - break + guard self.estimatedCount._mayBeEqual(to: other.estimatedCount) else { + return false } + var it1 = self.makeBorrowingIterator() var it2 = other.makeBorrowingIterator() while true { @@ -262,18 +260,6 @@ extension BorrowingSequence where Self: ~Copyable & ~Escapable { return result } } - -@available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: Equatable { - @inlinable - public func elementsEqual< - Other: BorrowingSequence & ~Copyable & ~Escapable - >( - _ other: borrowing Other, - ) -> Bool { - self.elementsEqual(other, by: ==) - } -} #endif #endif diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift index b7581d25..16678a83 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift @@ -15,6 +15,20 @@ public enum EstimatedCount { case infinite case exactly(Int) case unknown + + @inlinable + package func _mayBeEqual(to other: EstimatedCount) -> Bool { + switch (self, other) { + case let (.exactly(a), .exactly(b)): + return a == b + case (.exactly(_), .infinite): + return false + case (.infinite, .exactly(_)): + return false + default: + return true + } + } } @available(SwiftStdlib 5.0, *) diff --git a/Sources/ContainersPreview/Protocols/ContainerAlgorithms.swift b/Sources/ContainersPreview/Protocols/ContainerAlgorithms.swift new file mode 100644 index 00000000..72fb0b41 --- /dev/null +++ b/Sources/ContainersPreview/Protocols/ContainerAlgorithms.swift @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +@available(SwiftStdlib 6.2, *) +extension Container where Self: ~Copyable & ~Escapable { + @_alwaysEmitIntoClient + internal func _spanwiseZip( + with other: borrowing Other, + by process: (Span, Span) throws(E) -> Bool + ) throws(E) -> (Index, Other.Index) { + var i = self.startIndex // End index of the current span in `self` + var j = other.startIndex // End index of the current span in `other` + var a: Span = .init() + var b: Span = .init() + var pi = i // Start index of the original span we're currently processing in `self` + var pj = j // Start index of the original span we're currently processing in `other` + var ca = 0 // Count of the original span we're currently processing in `self` + var cb = 0 // Count of the original span we're currently processing in `other` + loop: + while true { + if a.isEmpty { + pi = i + a = self.nextSpan(after: &i) + ca = a.count + } + if b.isEmpty { + pj = j + b = other.nextSpan(after: &j) + cb = b.count + } + if a.isEmpty || b.isEmpty { + return ( + (a.isEmpty ? i : self.index(pi, offsetBy: ca - a.count)), + (b.isEmpty ? j : other.index(pj, offsetBy: cb - b.count))) + } + + let c = Swift.min(a.count, b.count) + + guard try process(a._trim(first: c), b._trim(first: c)) else { + return ( + (a.isEmpty ? i : self.index(pi, offsetBy: c)), + (b.isEmpty ? j : other.index(pj, offsetBy: c))) + } + } + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Descriptions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Descriptions.swift new file mode 100644 index 00000000..5d7e53de --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Descriptions.swift @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*: CustomStringConvertible */ where Element: ~Copyable { + public var description: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*: CustomDebugStringConvertible */ where Element: ~Copyable { + public var debugDescription: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Equatable.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Equatable.swift new file mode 100644 index 00000000..747dcef1 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Equatable.swift @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ { + public func isTriviallyIdentical(to other: borrowing Self) -> Bool { + self._handle.isIdentical(to: other._handle) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ { + @inlinable + public static func ==( + left: borrowing Self, + right: borrowing Self + ) -> Bool { + guard left.count == right.count else { return false } + guard !left.isTriviallyIdentical(to: right) else { return true } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + return left.elementsEqual(right) +#else + for i in 0 ..< left.count { + guard left[i] == right[i] else { return false } + } + return true +#endif + } +} + +#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Hashable.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Hashable.swift new file mode 100644 index 00000000..5600a2b7 --- /dev/null +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Hashable.swift @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +extension RigidDeque /*: Hashable */ where Element: Hashable /* & ~Copyable */ { + @inlinable + public func hash(into hasher: inout Hasher) { + hasher.combine(self.count) + let segments = self._handle.segments() + segments.first.span._hashContents(into: &hasher) + if let second = segments.second { + second.span._hashContents(into: &hasher) + } + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Descriptions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Descriptions.swift new file mode 100644 index 00000000..5378d5ec --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Descriptions.swift @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*: CustomStringConvertible */ where Element: ~Copyable { + public var description: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*: CustomDebugStringConvertible */ where Element: ~Copyable { + public var debugDescription: String { + /// FIXME: Print the item descriptions when available. + "<\(count) items>" + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Equatable.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Equatable.swift new file mode 100644 index 00000000..7ee9fc88 --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Equatable.swift @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*: Equatable */ where Element: Equatable /* & ~Copyable */ { + @inlinable + public static func ==( + left: borrowing Self, + right: borrowing Self + ) -> Bool { + left._storage == right._storage + } +} + +#endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Hashable.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Hashable.swift new file mode 100644 index 00000000..25e0fccd --- /dev/null +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Hashable.swift @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueDeque /*: Hashable */ where Element: Hashable /* & ~Copyable */ { + @inlinable + public func hash(into hasher: inout Hasher) { + self._storage.hash(into: &hasher) + } +} + +#endif diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 4eb6bf20..f020dbaa 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -103,6 +103,16 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } } +extension _UnsafeDequeHandle where Element: ~Copyable { + @_alwaysEmitIntoClient + @_transparent + internal func isIdentical(to other: borrowing Self) -> Bool { + self._buffer._isIdentical(to: other._buffer) + && self.count == other.count + && self.startSlot == other.startSlot + } +} + // MARK: Test initializer extension _UnsafeDequeHandle where Element: ~Copyable { diff --git a/Sources/InternalCollectionsUtilities/Span+Extras.swift b/Sources/InternalCollectionsUtilities/Span+Extras.swift index 0a94740c..a1e7473c 100644 --- a/Sources/InternalCollectionsUtilities/Span+Extras.swift +++ b/Sources/InternalCollectionsUtilities/Span+Extras.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +#if compiler(>=6.2) @available(SwiftStdlib 5.0, *) extension Span where Element: ~Copyable { @@ -36,4 +36,38 @@ extension Span where Element: ~Copyable { } } +@available(SwiftStdlib 5.0, *) +extension Span where Element: Equatable /* & ~Copyable */ { + @_alwaysEmitIntoClient + package func _elementsEqual(to other: borrowing Self) -> Bool { + return self.withUnsafeBufferPointer { a in + other.withUnsafeBufferPointer { b in + guard a.count == b.count else { return false } + guard a.baseAddress != b.baseAddress else { return true } + var i = 0 + while i < self.count { + guard a[i] == b[i] else { return false } + i &+= 1 + } + return true + } + } + } +} + +@available(SwiftStdlib 5.0, *) +extension Span where Element: Hashable /* & ~Copyable */ { + @_alwaysEmitIntoClient + package func _hashContents(into hasher: inout Hasher) { + // Note: no discriminating combine call -- caller is expected to do that + // separately when needed. + var i = 0 + while i < self.count { + hasher.combine(self[unchecked: i]) + i &+= 1 + } + + } +} + #endif From 6c1d4ab9c802482387495359068a8fb450258b77 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 23:14:40 -0800 Subject: [PATCH 64/75] Update Xcode and CMake build configurations --- Sources/BasicContainers/CMakeLists.txt | 10 +++- Sources/ContainersPreview/CMakeLists.txt | 1 + Sources/DequeModule/CMakeLists.txt | 6 +++ Xcode/Collections.xcodeproj/project.pbxproj | 60 +++++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Sources/BasicContainers/CMakeLists.txt b/Sources/BasicContainers/CMakeLists.txt index 3b5f438c..f481716c 100644 --- a/Sources/BasicContainers/CMakeLists.txt +++ b/Sources/BasicContainers/CMakeLists.txt @@ -1,7 +1,7 @@ #[[ This source file is part of the Swift Collections Open Source Project -Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors +Copyright (c) 2022 - 2026 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 @@ -25,16 +25,24 @@ endif() target_sources(${module_name} PRIVATE "RigidArray/RigidArray.swift" "RigidArray/RigidArray+Append.swift" + "RigidArray/RigidArray+Consumption.swift" "RigidArray/RigidArray+Container.swift" + "RigidArray/RigidArray+Descriptions.swift" + "RigidArray/RigidArray+Equatable.swift" "RigidArray/RigidArray+Experimental.swift" + "RigidArray/RigidArray+Hashable.swift" "RigidArray/RigidArray+Initializers.swift" "RigidArray/RigidArray+Insertions.swift" "RigidArray/RigidArray+Removals.swift" "RigidArray/RigidArray+Replacements.swift" "UniqueArray/UniqueArray.swift" "UniqueArray/UniqueArray+Append.swift" + "UniqueArray/UniqueArray+Consumption.swift" "UniqueArray/UniqueArray+Container.swift" + "UniqueArray/UniqueArray+Descriptions.swift" + "UniqueArray/UniqueArray+Equatable.swift" "UniqueArray/UniqueArray+Experimental.swift" + "UniqueArray/UniqueArray+Hashable.swift" "UniqueArray/UniqueArray+Initializers.swift" "UniqueArray/UniqueArray+Insertions.swift" "UniqueArray/UniqueArray+Removals.swift" diff --git a/Sources/ContainersPreview/CMakeLists.txt b/Sources/ContainersPreview/CMakeLists.txt index 0a2eaaf3..2dedb02a 100644 --- a/Sources/ContainersPreview/CMakeLists.txt +++ b/Sources/ContainersPreview/CMakeLists.txt @@ -30,6 +30,7 @@ target_sources(${module_name} PRIVATE "Protocols/BorrowingSequence+Standard Conformances.swift" "Protocols/BorrowingSequence+Utilities.swift" "Protocols/Container.swift" + "Protocols/ContainerAlgorithms.swift" "Protocols/Drain.swift" "Protocols/Producer.swift" "Types/Borrow.swift" diff --git a/Sources/DequeModule/CMakeLists.txt b/Sources/DequeModule/CMakeLists.txt index e27d4325..8f687bcb 100644 --- a/Sources/DequeModule/CMakeLists.txt +++ b/Sources/DequeModule/CMakeLists.txt @@ -31,7 +31,10 @@ target_sources(${module_name} PRIVATE "RigidDeque/RigidDeque+Append.swift" "RigidDeque/RigidDeque+Consumption.swift" "RigidDeque/RigidDeque+Container.swift" + "RigidDeque/RigidDeque+Descriptions.swift" + "RigidDeque/RigidDeque+Equatable.swift" "RigidDeque/RigidDeque+Experimental.swift" + "RigidDeque/RigidDeque+Hashable.swift" "RigidDeque/RigidDeque+Initializers.swift" "RigidDeque/RigidDeque+Insertions.swift" "RigidDeque/RigidDeque+Prepend.swift" @@ -42,7 +45,10 @@ target_sources(${module_name} PRIVATE "UniqueDeque/UniqueDeque+Append.swift" "UniqueDeque/UniqueDeque+Consumption.swift" "UniqueDeque/UniqueDeque+Container.swift" + "UniqueDeque/UniqueDeque+Descriptions.swift" + "UniqueDeque/UniqueDeque+Equatable.swift" "UniqueDeque/UniqueDeque+Experimental.swift" + "UniqueDeque/UniqueDeque+Hashable.swift" "UniqueDeque/UniqueDeque+Initializers.swift" "UniqueDeque/UniqueDeque+Insertions.swift" "UniqueDeque/UniqueDeque+Prepend.swift" diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 17064428..98c82788 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -72,6 +72,18 @@ 7D48BCF02E51597200D7F6F7 /* Assertions+Containers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCEF2E51597200D7F6F7 /* Assertions+Containers.swift */; }; 7D48BCF22E51599200D7F6F7 /* CheckContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF12E51599200D7F6F7 /* CheckContainer.swift */; }; 7D48BCF42E5159A300D7F6F7 /* StaccatoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF32E5159A300D7F6F7 /* StaccatoContainer.swift */; }; + 7D57A2B82F33FF48002543BD /* RigidArray+Consumption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2B72F33FF48002543BD /* RigidArray+Consumption.swift */; }; + 7D57A2BA2F340B58002543BD /* UniqueArray+Consumption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2B92F340B53002543BD /* UniqueArray+Consumption.swift */; }; + 7D57A2BE2F342DEE002543BD /* UniqueArray+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2BB2F342DEE002543BD /* UniqueArray+Descriptions.swift */; }; + 7D57A2BF2F342DEE002543BD /* UniqueArray+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2BD2F342DEE002543BD /* UniqueArray+Hashable.swift */; }; + 7D57A2C02F342DEE002543BD /* UniqueArray+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2BC2F342DEE002543BD /* UniqueArray+Equatable.swift */; }; + 7D57A2C42F342F30002543BD /* RigidDeque+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C22F342F30002543BD /* RigidDeque+Equatable.swift */; }; + 7D57A2C52F342F30002543BD /* RigidDeque+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C32F342F30002543BD /* RigidDeque+Hashable.swift */; }; + 7D57A2C62F342F30002543BD /* RigidDeque+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C12F342F30002543BD /* RigidDeque+Descriptions.swift */; }; + 7D57A2CA2F342F43002543BD /* UniqueDeque+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C72F342F43002543BD /* UniqueDeque+Descriptions.swift */; }; + 7D57A2CB2F342F43002543BD /* UniqueDeque+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C82F342F43002543BD /* UniqueDeque+Equatable.swift */; }; + 7D57A2CC2F342F43002543BD /* UniqueDeque+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C92F342F43002543BD /* UniqueDeque+Hashable.swift */; }; + 7D57A2CE2F343CA9002543BD /* ContainerAlgorithms.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2CD2F343CA2002543BD /* ContainerAlgorithms.swift */; }; 7D9748D42E9748930098631A /* BigString+Chunk+UTF16.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D32E9748930098631A /* BigString+Chunk+UTF16.swift */; }; 7D9748D52E9748930098631A /* BigString+Chunk+UnicodeScalar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D12E9748930098631A /* BigString+Chunk+UnicodeScalar.swift */; }; 7D9748D62E9748930098631A /* BigString+Chunk+Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748CF2E9748930098631A /* BigString+Chunk+Character.swift */; }; @@ -98,6 +110,9 @@ 7DA23F532F329A2300E4C03A /* UniqueArray+Insertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */; }; 7DA23F542F329A2300E4C03A /* RigidArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F352F329A2300E4C03A /* RigidArray.swift */; }; 7DA23F562F329E9000E4C03A /* UniqueArray+Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F552F329E8A00E4C03A /* UniqueArray+Container.swift */; }; + 7DA23F582F32C66300E4C03A /* RigidArray+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F572F32C65900E4C03A /* RigidArray+Equatable.swift */; }; + 7DA23F5A2F32C68300E4C03A /* RigidArray+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F592F32C67D00E4C03A /* RigidArray+Hashable.swift */; }; + 7DA23F5C2F32C69100E4C03A /* RigidArray+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA23F5B2F32C68B00E4C03A /* RigidArray+Descriptions.swift */; }; 7DAD899E2E8B09C300DD5786 /* UInt+first and last set bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */; }; 7DAD899F2E8B09C300DD5786 /* UInt+reversed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899D2E8B09C300DD5786 /* UInt+reversed.swift */; }; 7DAD89A02E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */; }; @@ -558,6 +573,18 @@ 7D48BCF12E51599200D7F6F7 /* CheckContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckContainer.swift; sourceTree = ""; }; 7D48BCF32E5159A300D7F6F7 /* StaccatoContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaccatoContainer.swift; sourceTree = ""; }; 7D48BCF52E51651900D7F6F7 /* Package@swift-6.0.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Package@swift-6.0.swift"; path = "../Package@swift-6.0.swift"; sourceTree = SOURCE_ROOT; }; + 7D57A2B72F33FF48002543BD /* RigidArray+Consumption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Consumption.swift"; sourceTree = ""; }; + 7D57A2B92F340B53002543BD /* UniqueArray+Consumption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Consumption.swift"; sourceTree = ""; }; + 7D57A2BB2F342DEE002543BD /* UniqueArray+Descriptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Descriptions.swift"; sourceTree = ""; }; + 7D57A2BC2F342DEE002543BD /* UniqueArray+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Equatable.swift"; sourceTree = ""; }; + 7D57A2BD2F342DEE002543BD /* UniqueArray+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Hashable.swift"; sourceTree = ""; }; + 7D57A2C12F342F30002543BD /* RigidDeque+Descriptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Descriptions.swift"; sourceTree = ""; }; + 7D57A2C22F342F30002543BD /* RigidDeque+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Equatable.swift"; sourceTree = ""; }; + 7D57A2C32F342F30002543BD /* RigidDeque+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDeque+Hashable.swift"; sourceTree = ""; }; + 7D57A2C72F342F43002543BD /* UniqueDeque+Descriptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Descriptions.swift"; sourceTree = ""; }; + 7D57A2C82F342F43002543BD /* UniqueDeque+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Equatable.swift"; sourceTree = ""; }; + 7D57A2C92F342F43002543BD /* UniqueDeque+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Hashable.swift"; sourceTree = ""; }; + 7D57A2CD2F343CA2002543BD /* ContainerAlgorithms.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerAlgorithms.swift; sourceTree = ""; }; 7D5A64D229CCE8CC00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D329CCEE9A00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D829CCF0FE00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -590,6 +617,9 @@ 7DA23F432F329A2300E4C03A /* UniqueArray+Removals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Removals.swift"; sourceTree = ""; }; 7DA23F442F329A2300E4C03A /* UniqueArray+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Replacements.swift"; sourceTree = ""; }; 7DA23F552F329E8A00E4C03A /* UniqueArray+Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Container.swift"; sourceTree = ""; }; + 7DA23F572F32C65900E4C03A /* RigidArray+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Equatable.swift"; sourceTree = ""; }; + 7DA23F592F32C67D00E4C03A /* RigidArray+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Hashable.swift"; sourceTree = ""; }; + 7DA23F5B2F32C68B00E4C03A /* RigidArray+Descriptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Descriptions.swift"; sourceTree = ""; }; 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FixedWidthInteger+roundUpToPowerOfTwo.swift"; sourceTree = ""; }; 7DAD899B2E8B09C300DD5786 /* Integer rank.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Integer rank.swift"; sourceTree = ""; }; 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt+first and last set bit.swift"; sourceTree = ""; }; @@ -1042,6 +1072,7 @@ 7D2A772C2F27F1E4005780C7 /* BorrowingSequence+Standard Conformances.swift */, 7D2A772D2F27F1E4005780C7 /* BorrowingSequence+Utilities.swift */, 7D2A772E2F27F1E4005780C7 /* Container.swift */, + 7D57A2CD2F343CA2002543BD /* ContainerAlgorithms.swift */, 7D2A772F2F27F1E4005780C7 /* Drain.swift */, 7D2A77302F27F1E4005780C7 /* Producer.swift */, ); @@ -1088,7 +1119,10 @@ 7D2A77622F27F2BF005780C7 /* RigidDeque+Append.swift */, 7D2A77632F27F2BF005780C7 /* RigidDeque+Consumption.swift */, 7D2A77642F27F2BF005780C7 /* RigidDeque+Container.swift */, + 7D57A2C12F342F30002543BD /* RigidDeque+Descriptions.swift */, + 7D57A2C22F342F30002543BD /* RigidDeque+Equatable.swift */, 7D2A77652F27F2BF005780C7 /* RigidDeque+Experimental.swift */, + 7D57A2C32F342F30002543BD /* RigidDeque+Hashable.swift */, 7D2A77662F27F2BF005780C7 /* RigidDeque+Initializers.swift */, 7D2A77672F27F2BF005780C7 /* RigidDeque+Insertions.swift */, 7D2A77682F27F2BF005780C7 /* RigidDeque+Prepend.swift */, @@ -1106,7 +1140,10 @@ 7D2A776E2F27F2BF005780C7 /* UniqueDeque+Append.swift */, 7D2A776F2F27F2BF005780C7 /* UniqueDeque+Consumption.swift */, 7D2A77702F27F2BF005780C7 /* UniqueDeque+Container.swift */, + 7D57A2C72F342F43002543BD /* UniqueDeque+Descriptions.swift */, + 7D57A2C82F342F43002543BD /* UniqueDeque+Equatable.swift */, 7D2A77712F27F2BF005780C7 /* UniqueDeque+Experimental.swift */, + 7D57A2C92F342F43002543BD /* UniqueDeque+Hashable.swift */, 7D2A77722F27F2BF005780C7 /* UniqueDeque+Initializers.swift */, 7D2A77732F27F2BF005780C7 /* UniqueDeque+Insertions.swift */, 7D2A77742F27F2BF005780C7 /* UniqueDeque+Prepend.swift */, @@ -1143,8 +1180,12 @@ children = ( 7DA23F352F329A2300E4C03A /* RigidArray.swift */, 7DA23F362F329A2300E4C03A /* RigidArray+Append.swift */, + 7D57A2B72F33FF48002543BD /* RigidArray+Consumption.swift */, 7DA23F372F329A2300E4C03A /* RigidArray+Container.swift */, + 7DA23F5B2F32C68B00E4C03A /* RigidArray+Descriptions.swift */, + 7DA23F572F32C65900E4C03A /* RigidArray+Equatable.swift */, 7DA23F382F329A2300E4C03A /* RigidArray+Experimental.swift */, + 7DA23F592F32C67D00E4C03A /* RigidArray+Hashable.swift */, 7DA23F392F329A2300E4C03A /* RigidArray+Initializers.swift */, 7DA23F3A2F329A2300E4C03A /* RigidArray+Insertions.swift */, 7DA23F3B2F329A2300E4C03A /* RigidArray+Removals.swift */, @@ -1158,8 +1199,12 @@ children = ( 7DA23F3E2F329A2300E4C03A /* UniqueArray.swift */, 7DA23F3F2F329A2300E4C03A /* UniqueArray+Append.swift */, + 7D57A2B92F340B53002543BD /* UniqueArray+Consumption.swift */, 7DA23F552F329E8A00E4C03A /* UniqueArray+Container.swift */, + 7D57A2BB2F342DEE002543BD /* UniqueArray+Descriptions.swift */, + 7D57A2BC2F342DEE002543BD /* UniqueArray+Equatable.swift */, 7DA23F402F329A2300E4C03A /* UniqueArray+Experimental.swift */, + 7D57A2BD2F342DEE002543BD /* UniqueArray+Hashable.swift */, 7DA23F412F329A2300E4C03A /* UniqueArray+Initializers.swift */, 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */, 7DA23F432F329A2300E4C03A /* UniqueArray+Removals.swift */, @@ -2204,6 +2249,7 @@ 7D2A77852F27F2BF005780C7 /* RigidDeque+Initializers.swift in Sources */, 7D2A77862F27F2BF005780C7 /* RigidDeque+Consumption.swift in Sources */, 7D2A77872F27F2BF005780C7 /* Deque._UnsafeHandle.swift in Sources */, + 7DA23F5C2F32C69100E4C03A /* RigidArray+Descriptions.swift in Sources */, 7D2A77882F27F2BF005780C7 /* Deque+Extras.swift in Sources */, 7D2A77892F27F2BF005780C7 /* UniqueDeque+Removals.swift in Sources */, 7D2A778A2F27F2BF005780C7 /* UniqueDeque+Insertions.swift in Sources */, @@ -2215,6 +2261,9 @@ 7D2A77902F27F2BF005780C7 /* RigidDeque+Insertions.swift in Sources */, 7D2A77912F27F2BF005780C7 /* RigidDeque+Removals.swift in Sources */, 7D2A77922F27F2BF005780C7 /* _DequeBuffer.swift in Sources */, + 7D57A2BE2F342DEE002543BD /* UniqueArray+Descriptions.swift in Sources */, + 7D57A2BF2F342DEE002543BD /* UniqueArray+Hashable.swift in Sources */, + 7D57A2C02F342DEE002543BD /* UniqueArray+Equatable.swift in Sources */, 7D2A77932F27F2BF005780C7 /* _DequeBufferHeader.swift in Sources */, 7D2A77942F27F2BF005780C7 /* Deque+Collection.swift in Sources */, 7D2A77952F27F2BF005780C7 /* Deque+Codable.swift in Sources */, @@ -2237,6 +2286,8 @@ 7DE9213A29CA70F4004483EB /* TreeSet.swift in Sources */, 7DE9213829CA70F4004483EB /* TreeSet+Filter.swift in Sources */, 7DE9206D29CA70F4004483EB /* BigString+Chunk+Description.swift in Sources */, + 7D57A2B82F33FF48002543BD /* RigidArray+Consumption.swift in Sources */, + 7DA23F582F32C66300E4C03A /* RigidArray+Equatable.swift in Sources */, 7DE9208A29CA70F4004483EB /* BigString+Comparable.swift in Sources */, 7DE9213629CA70F4004483EB /* TreeSet+SetAlgebra basics.swift in Sources */, 7DE9202C29CA70F3004483EB /* OrderedSet+Initializers.swift in Sources */, @@ -2250,6 +2301,7 @@ 7DE920BD29CA70F4004483EB /* BitSet+SetAlgebra symmetricDifference.swift in Sources */, 7DE9208229CA70F4004483EB /* BigString+BidirectionalCollection.swift in Sources */, 7DE9203E29CA70F3004483EB /* OrderedSet+Partial SetAlgebra subtract.swift in Sources */, + 7D57A2CE2F343CA9002543BD /* ContainerAlgorithms.swift in Sources */, 7DE9216929CA70F4004483EB /* TreeDictionary+Filter.swift in Sources */, 7DE9203129CA70F3004483EB /* OrderedSet+Partial MutableCollection.swift in Sources */, 7DE9209B29CA70F4004483EB /* Rope+Split.swift in Sources */, @@ -2356,6 +2408,7 @@ 7DE9201929CA70F3004483EB /* OrderedDictionary+Values.swift in Sources */, 7DE9213929CA70F4004483EB /* TreeSet+SetAlgebra Initializers.swift in Sources */, 7DE9217729CA70F4004483EB /* TreeDictionary+Keys.swift in Sources */, + 7D57A2BA2F340B58002543BD /* UniqueArray+Consumption.swift in Sources */, 7DE920DA29CA70F4004483EB /* BitSet._UnsafeHandle.swift in Sources */, 7DE920D129CA70F4004483EB /* BitSet.Index.swift in Sources */, 7DAD899E2E8B09C300DD5786 /* UInt+first and last set bit.swift in Sources */, @@ -2378,6 +2431,9 @@ 7DE9203629CA70F3004483EB /* OrderedSet+ReserveCapacity.swift in Sources */, 7DE9208D29CA70F4004483EB /* Rope+Debugging.swift in Sources */, 7DE9208829CA70F4004483EB /* BigString+ExpressibleByStringLiteral.swift in Sources */, + 7D57A2C42F342F30002543BD /* RigidDeque+Equatable.swift in Sources */, + 7D57A2C52F342F30002543BD /* RigidDeque+Hashable.swift in Sources */, + 7D57A2C62F342F30002543BD /* RigidDeque+Descriptions.swift in Sources */, 7DE9202329CA70F3004483EB /* OrderedSet+UnstableInternals.swift in Sources */, 7DE9208529CA70F4004483EB /* BigString+TextOutputStream.swift in Sources */, 7DE9212829CA70F4004483EB /* TreeSet+SetAlgebra intersection.swift in Sources */, @@ -2451,6 +2507,9 @@ 7DE9209429CA70F4004483EB /* Rope+_UnmanagedLeaf.swift in Sources */, 7DE9208429CA70F4004483EB /* BigString+Equatable.swift in Sources */, 7DE9203729CA70F3004483EB /* OrderedSet+Partial SetAlgebra union.swift in Sources */, + 7D57A2CA2F342F43002543BD /* UniqueDeque+Descriptions.swift in Sources */, + 7D57A2CB2F342F43002543BD /* UniqueDeque+Equatable.swift in Sources */, + 7D57A2CC2F342F43002543BD /* UniqueDeque+Hashable.swift in Sources */, 7DE9215229CA70F4004483EB /* _HashNode+Builder.swift in Sources */, 7DE9212929CA70F4004483EB /* TreeSet+SetAlgebra formUnion.swift in Sources */, 7DE920C129CA70F4004483EB /* BitSet+SetAlgebra subtract.swift in Sources */, @@ -2517,6 +2576,7 @@ 7DE9215A29CA70F4004483EB /* _HashNode+Structural subtracting.swift in Sources */, 7DE9217E29CA70F4004483EB /* Heap+ExpressibleByArrayLiteral.swift in Sources */, 7DE448452F2D3705005853A7 /* BinaryInteger extensions.swift in Sources */, + 7DA23F5A2F32C68300E4C03A /* RigidArray+Hashable.swift in Sources */, 7DE9204029CA70F3004483EB /* OrderedSet+Partial SetAlgebra isStrictSuperset.swift in Sources */, 7DE920BF29CA70F4004483EB /* BitSet+Codable.swift in Sources */, 7DE9203329CA70F3004483EB /* OrderedSet+Testing.swift in Sources */, From 653a60b8e7485cfa0845b9090abc6d163cb56995 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 5 Feb 2026 13:26:34 -0800 Subject: [PATCH 65/75] =?UTF-8?q?`replaceSubrange(=5F:...)`=20=E2=86=92=20?= =?UTF-8?q?`replace(removing:...)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/BasicContainers/CMakeLists.txt | 2 + .../RigidArray/RigidArray+Append.swift | 29 -- .../RigidArray/RigidArray+Deprecated.swift | 390 ++++++++++++++++ .../RigidArray/RigidArray+Insertions.swift | 34 -- .../RigidArray/RigidArray+Replacements.swift | 164 +++---- .../UniqueArray/UniqueArray+Append.swift | 30 -- .../UniqueArray/UniqueArray+Deprecated.swift | 429 ++++++++++++++++++ .../UniqueArray/UniqueArray+Insertions.swift | 39 -- .../UniqueArray+Replacements.swift | 152 +++---- .../RigidDeque/RigidDeque+Replacements.swift | 105 ++--- .../UniqueDeque+Replacements.swift | 12 +- Sources/DequeModule/_UnsafeDequeHandle.swift | 15 +- .../RigidArrayTests.swift | 20 +- .../UniqueArrayTests.swift | 10 +- Tests/DequeTests/DequeInternals.swift | 8 + Tests/DequeTests/RigidDequeTests.swift | 162 +++++++ Xcode/Collections.xcodeproj/project.pbxproj | 8 + 17 files changed, 1200 insertions(+), 409 deletions(-) create mode 100644 Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift create mode 100644 Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift diff --git a/Sources/BasicContainers/CMakeLists.txt b/Sources/BasicContainers/CMakeLists.txt index f481716c..d0c1af97 100644 --- a/Sources/BasicContainers/CMakeLists.txt +++ b/Sources/BasicContainers/CMakeLists.txt @@ -27,6 +27,7 @@ target_sources(${module_name} PRIVATE "RigidArray/RigidArray+Append.swift" "RigidArray/RigidArray+Consumption.swift" "RigidArray/RigidArray+Container.swift" + "RigidArray/RigidArray+Deprecated.swift" "RigidArray/RigidArray+Descriptions.swift" "RigidArray/RigidArray+Equatable.swift" "RigidArray/RigidArray+Experimental.swift" @@ -39,6 +40,7 @@ target_sources(${module_name} PRIVATE "UniqueArray/UniqueArray+Append.swift" "UniqueArray/UniqueArray+Consumption.swift" "UniqueArray/UniqueArray+Container.swift" + "UniqueArray/UniqueArray+Deprecated.swift" "UniqueArray/UniqueArray+Descriptions.swift" "UniqueArray/UniqueArray+Equatable.swift" "UniqueArray/UniqueArray+Experimental.swift" diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index 9ae0b3cd..302ce36a 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -87,35 +87,6 @@ extension RigidArray where Element: ~Copyable { } return try initializer(&span) } - - /// Append a given number of items to the end of this array by populating - /// an output span. - /// - /// If the array does not have sufficient capacity to store the new items in - /// the buffer, then this triggers a runtime error. - /// - /// - Parameters: - /// - count: The number of items to append to the array. - /// - initializer: A callback that gets called at most once to directly - /// populate newly reserved storage within the array. The function - /// is allowed to initialize fewer than `count` items. The array is - /// appended however many items the callback adds to the output span - /// before it returns (or before it throws an error). - /// - /// - Complexity: O(`count`) - @available(*, deprecated, renamed: "append(addingCount:initializingWith:)") - @_alwaysEmitIntoClient - @inline(__always) - public mutating func append( - count: Int, - initializingWith initializer: (inout OutputSpan) throws(E) -> Result - ) throws(E) -> Result { - var result: Result? = nil - try append(addingCount: count) { target throws(E) in - result = try initializer(&target) - } - return result.take()! - } } @available(SwiftStdlib 5.0, *) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift new file mode 100644 index 00000000..1ae26624 --- /dev/null +++ b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift @@ -0,0 +1,390 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension RigidArray where Element: ~Copyable { + /// Append a given number of items to the end of this array by populating + /// an output span. + /// + /// If the array does not have sufficient capacity to store the new items in + /// the buffer, then this triggers a runtime error. + /// + /// - Parameters: + /// - count: The number of items to append to the array. + /// - initializer: A callback that gets called at most once to directly + /// populate newly reserved storage within the array. The function + /// is allowed to initialize fewer than `count` items. The array is + /// appended however many items the callback adds to the output span + /// before it returns (or before it throws an error). + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "append(addingCount:initializingWith:)") + @_alwaysEmitIntoClient + @inline(__always) + public mutating func append( + count: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Result + ) throws(E) -> Result { + var result: Result? = nil + try append(addingCount: count) { target throws(E) in + result = try initializer(&target) + } + return result.take()! + } + + /// Inserts a given number of new items into this array at the specified + /// position, using a callback to directly initialize array storage by + /// populating an output span. + /// + /// All existing elements at or following the specified position are moved to + /// make room for the new items. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters: + /// - count: The number of items to insert into the array. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the array. + /// - body: A callback that gets called exactly once to directly + /// populate newly reserved storage within the array. The function + /// is called with an empty output span of capacity matching the + /// supplied count, and it must fully populate it before returning. + /// + /// - Complexity: O(`self.count` + `count`) + @available(*, deprecated, renamed: "insert(addingCount:at:initializingWith:)") + @inlinable + public mutating func insert( + count: Int, + at index: Int, + initializingWith body: (inout OutputSpan) -> Result + ) -> Result { + var result: Result? = nil + self.insert(addingCount: count, at: index) { target in + result = body(&target) + } + return result! + } + + /// Replaces the specified range of elements by a given count of new items, + /// using a callback to directly initialize array storage by populating + /// an output span. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting room for the new elements starting at the + /// same location. The number of new elements need not match the number + /// of elements being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, then + /// this method is equivalent to calling + /// `insert(count: newCount, at: subrange.lowerbound, initializingWith: body)`. + /// + /// Likewise, if you pass a zero for `newCount`, then this method + /// removes the elements in the given subrange without any replacement. + /// This case is more directly expressed by `removeSubrange(subrange)`. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newCount: the number of items to replace the old subrange. + /// - body: A callback that gets called exactly once to directly + /// populate newly reserved storage within the array. The function + /// is called with an empty output span of capacity `newCount`, + /// and it must fully populate it before returning. + /// + /// - Complexity: O(`self.count` + `newCount`) + @available(*, deprecated, renamed: "replace(removing:addingCapacity:initializingWith:)") + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + newCount: Int, + initializingWith body: (inout OutputSpan) -> Result + ) -> Result { + var result: Result? = nil + self.replace(removing: subrange, addingCount: newCount) { target in + result = body(&target) + } + return result! + } + + /// Replaces the specified range of elements by moving the elements of a + /// fully initialized buffer into their place. On return, the buffer is left + /// in an uninitialized state. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(moving:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: A fully initialized buffer whose contents to move into + /// the array. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:moving:)") + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving newElements: UnsafeMutableBufferPointer, + ) { + replace(removing: subrange, moving: newElements) + } + + /// Replaces the specified range of elements by moving the contents of an + /// output span into their place. On return, the span is left empty. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(moving:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - items: An output span whose contents are to be moved into the array. + /// + /// - Complexity: O(`self.count` + `items.count`) + @available(*, deprecated, renamed: "replace(removing:moving:)") + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving items: inout OutputSpan + ) { + replace(removing: subrange, moving: &items) + } + + /// Replaces the specified range of elements by moving the elements of a + /// another array into their place. On return, the source array + /// becomes empty, but it is not destroyed, and it preserves its original + /// storage capacity. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: An array whose contents to move into `self`. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:moving:)") + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving newElements: inout RigidArray, + ) { + self.replace(removing: subrange, moving: &newElements) + } +} + +@available(SwiftStdlib 5.0, *) +extension RigidArray { + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: UnsafeBufferPointer + ) { + self.replace(removing: subrange, copying: newElements) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: UnsafeMutableBufferPointer + ) { + self.replace(removing: subrange, copying: newElements) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given span. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length span as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: Span + ) { + self.replace(removing: subrange, copying: newElements) + } + + @available(*, unavailable) + @usableFromInline + internal mutating func _replaceSubrange( + _ subrange: Range, + copyingCollection newElements: __owned some Collection, + newCount: Int + ) { + self._replace( + removing: subrange, + copyingCollection: newElements, + newCount: newCount) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given collection. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length collection as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + @inline(__always) + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: __owned some Collection + ) { + self.replace(removing: subrange, copying: newElements) + } +} + +#endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index d56b06ad..d924fee9 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -115,40 +115,6 @@ extension RigidArray where Element: ~Copyable { } try initializer(&span) } - - /// Inserts a given number of new items into this array at the specified - /// position, using a callback to directly initialize array storage by - /// populating an output span. - /// - /// All existing elements at or following the specified position are moved to - /// make room for the new items. - /// - /// If the capacity of the array isn't sufficient to accommodate the new - /// elements, then this method triggers a runtime error. - /// - /// - Parameters: - /// - count: The number of items to insert into the array. - /// - index: The position at which to insert the new items. - /// `index` must be a valid index in the array. - /// - body: A callback that gets called exactly once to directly - /// populate newly reserved storage within the array. The function - /// is called with an empty output span of capacity matching the - /// supplied count, and it must fully populate it before returning. - /// - /// - Complexity: O(`self.count` + `count`) - @available(*, deprecated, renamed: "insert(addingCount:at:initializingWith:)") - @inlinable - public mutating func insert( - count: Int, - at index: Int, - initializingWith body: (inout OutputSpan) -> Result - ) -> Result { - var result: Result? = nil - self.insert(addingCount: count, at: index) { target in - result = body(&target) - } - return result! - } } @available(SwiftStdlib 5.0, *) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 5b8ba7a2..511b0aa5 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -59,8 +59,8 @@ extension RigidArray where Element: ~Copyable { /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity /// of the callback invocations. @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { @@ -71,15 +71,15 @@ extension RigidArray where Element: ~Copyable { precondition( newItemCount - subrange.count <= freeCapacity, "RigidArray capacity overflow") - try _uncheckedReplaceSubrange( - subrange, + try _uncheckedReplace( + removing: subrange, addingCount: newItemCount, initializingWith: initializer) } @_alwaysEmitIntoClient - internal mutating func _uncheckedReplaceSubrange( - _ subrange: Range, + internal mutating func _uncheckedReplace( + removing subrange: Range, addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { @@ -99,50 +99,6 @@ extension RigidArray where Element: ~Copyable { } try initializer(&span) } - - /// Replaces the specified range of elements by a given count of new items, - /// using a callback to directly initialize array storage by populating - /// an output span. - /// - /// This method has the effect of removing the specified range of elements - /// from the array and inserting room for the new elements starting at the - /// same location. The number of new elements need not match the number - /// of elements being removed. - /// - /// If the capacity of the array isn't sufficient to accommodate the new - /// elements, then this method triggers a runtime error. - /// - /// If you pass a zero-length range as the `subrange` parameter, then - /// this method is equivalent to calling - /// `insert(count: newCount, at: subrange.lowerbound, initializingWith: body)`. - /// - /// Likewise, if you pass a zero for `newCount`, then this method - /// removes the elements in the given subrange without any replacement. - /// This case is more directly expressed by `removeSubrange(subrange)`. - /// - /// - Parameters - /// - subrange: The subrange of the array to replace. The bounds of - /// the range must be valid indices in the array. - /// - newCount: the number of items to replace the old subrange. - /// - body: A callback that gets called exactly once to directly - /// populate newly reserved storage within the array. The function - /// is called with an empty output span of capacity `newCount`, - /// and it must fully populate it before returning. - /// - /// - Complexity: O(`self.count` + `newCount`) - @available(*, deprecated, renamed: "replaceSubrange(_:addingCapacity:initializingWith:)") - @inlinable - public mutating func replaceSubrange( - _ subrange: Range, - newCount: Int, - initializingWith body: (inout OutputSpan) -> Result - ) -> Result { - var result: Result? = nil - self.replaceSubrange(subrange, addingCount: newCount) { target in - result = body(&target) - } - return result! - } } @available(SwiftStdlib 5.0, *) @@ -196,10 +152,10 @@ extension RigidArray where Element: ~Copyable { /// - Complexity: O(`self.count` + `newItemCount`) in addition to the /// complexity of the callback invocations. @inlinable - public mutating func replaceSubrange( - _ subrange: Range, - addingCount newItemCount: Int, + public mutating func replace( + removing subrange: Range, consumingWith consumer: (inout InputSpan) -> Void, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( @@ -209,18 +165,18 @@ extension RigidArray where Element: ~Copyable { precondition( newItemCount - subrange.count <= freeCapacity, "RigidArray capacity overflow") - try _uncheckedReplaceSubrange( - subrange, - addingCount: newItemCount, + try _uncheckedReplace( + removing: subrange, consumingWith: consumer, + addingCount: newItemCount, initializingWith: initializer) } @_alwaysEmitIntoClient - internal mutating func _uncheckedReplaceSubrange( - _ subrange: Range, - addingCount newItemCount: Int, + internal mutating func _uncheckedReplace( + removing subrange: Range, consumingWith consumer: (inout InputSpan) -> Void, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { do { @@ -281,11 +237,11 @@ extension RigidArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `newElements.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving newElements: UnsafeMutableBufferPointer, ) { - replaceSubrange(subrange, addingCount: newElements.count) { target in + replace(removing: subrange, addingCount: newElements.count) { target in target._withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._moveInitializePrefix(from: newElements) } @@ -320,13 +276,13 @@ extension RigidArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving items: inout InputSpan ) { items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(last: count) - unsafe self.replaceSubrange(subrange, moving: source) + unsafe self.replace(removing: subrange, moving: source) count = 0 } } @@ -359,13 +315,13 @@ extension RigidArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving items: inout OutputSpan ) { items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) - unsafe self.replaceSubrange(subrange, moving: source) + unsafe self.replace(removing: subrange, moving: source) count = 0 } } @@ -399,14 +355,14 @@ extension RigidArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `newElements.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving newElements: inout RigidArray, ) { // FIXME: Remove this in favor of a generic algorithm over consumable containers unsafe newElements._unsafeEdit { buffer, count in let source = buffer._extracting(first: count) - unsafe self.replaceSubrange(subrange, moving: source) + unsafe self.replace(removing: subrange, moving: source) count = 0 } } @@ -442,12 +398,12 @@ extension RigidArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `newElements.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, consuming newElements: consuming RigidArray, ) { // FIXME: Remove this in favor of a generic algorithm over consumable containers - replaceSubrange(subrange, moving: &newElements) + replace(removing: subrange, moving: &newElements) } #endif } @@ -481,11 +437,11 @@ extension RigidArray { /// /// - Complexity: O(`self.count` + `newElements.count`) @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: UnsafeBufferPointer ) { - replaceSubrange(subrange, addingCount: newElements.count) { target in + replace(removing: subrange, addingCount: newElements.count) { target in target._withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._initializePrefix(copying: newElements) } @@ -519,12 +475,12 @@ extension RigidArray { /// /// - Complexity: O(`self.count` + `newElements.count`) @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: UnsafeMutableBufferPointer ) { - unsafe self.replaceSubrange( - subrange, + unsafe self.replace( + removing: subrange, copying: UnsafeBufferPointer(newElements)) } @@ -555,26 +511,26 @@ extension RigidArray { /// /// - Complexity: O(`self.count` + `newElements.count`) @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: Span ) { unsafe newElements.withUnsafeBufferPointer { buffer in - unsafe self.replaceSubrange(subrange, copying: buffer) + unsafe self.replace(removing: subrange, copying: buffer) } } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @inlinable - internal mutating func _replaceSubrange< + internal mutating func _replace< C: Container & ~Copyable & ~Escapable >( - _ subrange: Range, + removing subrange: Range, copyingContainer items: borrowing C, newCount: Int ) { var it = items.makeBorrowingIterator() - self.replaceSubrange(subrange, addingCount: newCount) { target in + self.replace(removing: subrange, addingCount: newCount) { target in while !target.isFull { let source = it.nextSpan(maximumCount: target.freeCapacity) precondition( @@ -590,12 +546,12 @@ extension RigidArray { #endif @inlinable - internal mutating func _replaceSubrange( - _ subrange: Range, + internal mutating func _replace( + removing subrange: Range, copyingCollection newElements: __owned some Collection, newCount: Int ) { - self.replaceSubrange(subrange, addingCount: newCount) { target in + self.replace(removing: subrange, addingCount: newCount) { target in target._withUnsafeMutableBufferPointer { dst, dstCount in let done: Void? = newElements.withContiguousStorageIfAvailable { src in let i = unsafe dst._initializePrefix(copying: src) @@ -645,14 +601,14 @@ extension RigidArray { /// - Complexity: O(`self.count` + `newElements.count`) @inlinable @inline(__always) - public mutating func replaceSubrange< + public mutating func replace< C: Container & ~Copyable & ~Escapable >( - _ subrange: Range, + removing subrange: Range, copying newElements: borrowing C ) { - _replaceSubrange( - subrange, + _replace( + removing: subrange, copyingContainer: newElements, newCount: newElements.count) } @@ -686,12 +642,14 @@ extension RigidArray { /// - Complexity: O(`self.count` + `newElements.count`) @inlinable @inline(__always) - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: __owned some Collection ) { - _replaceSubrange( - subrange, copyingCollection: newElements, newCount: newElements.count) + _replace( + removing: subrange, + copyingCollection: newElements, + newCount: newElements.count) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @@ -724,14 +682,16 @@ extension RigidArray { /// *m* is the count of `newElements`. @inlinable @inline(__always) - public mutating func replaceSubrange< + public mutating func replace< C: Container & Collection >( - _ subrange: Range, + removing subrange: Range, copying newElements: C ) { - _replaceSubrange( - subrange, copyingContainer: newElements, newCount: newElements.count) + _replace( + removing: subrange, + copyingContainer: newElements, + newCount: newElements.count) } #endif } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift index cdb73ed9..1cc82d2c 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift @@ -66,36 +66,6 @@ extension UniqueArray where Element: ~Copyable { addingCount: newItemCount, initializingWith: initializer) } - - /// Append a given number of items to the end of this array by populating - /// an output span. - /// - /// If the array does not have sufficient capacity to hold the requested - /// number of new elements, then this reallocates the array's storage to - /// grow its capacity, using a geometric growth rate. - /// - /// - Parameters - /// - count: The number of items to append to the array. - /// - initializer: A callback that gets called exactly once to directly - /// populate newly reserved storage within the array. The function - /// is allowed to initialize fewer than `count` items. The array is - /// appended however many items the callback adds to the output span - /// before it returns (or before it throws an error). - /// - /// - Complexity: O(`count`) - @available(*, deprecated, renamed: "append(addingCount:initializingWith:)") - @_alwaysEmitIntoClient - @inline(__always) - public mutating func append( - count: Int, - initializingWith initializer: (inout OutputSpan) throws(E) -> Result - ) throws(E) -> Result { - var result: Result? = nil - try append(addingCount: count) { target throws(E) in - result = try initializer(&target) - } - return result.take()! - } } @available(SwiftStdlib 5.0, *) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift new file mode 100644 index 00000000..bde410a4 --- /dev/null +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift @@ -0,0 +1,429 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2026 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 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) + +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: ~Copyable { + /// Append a given number of items to the end of this array by populating + /// an output span. + /// + /// If the array does not have sufficient capacity to hold the requested + /// number of new elements, then this reallocates the array's storage to + /// grow its capacity, using a geometric growth rate. + /// + /// - Parameters + /// - count: The number of items to append to the array. + /// - initializer: A callback that gets called exactly once to directly + /// populate newly reserved storage within the array. The function + /// is allowed to initialize fewer than `count` items. The array is + /// appended however many items the callback adds to the output span + /// before it returns (or before it throws an error). + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "append(addingCount:initializingWith:)") + @_alwaysEmitIntoClient + @inline(__always) + public mutating func append( + count: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Result + ) throws(E) -> Result { + var result: Result? = nil + try append(addingCount: count) { target throws(E) in + result = try initializer(&target) + } + return result.take()! + } + + /// Inserts a given number of new items into this array at the specified + /// position, using a callback to directly initialize array storage by + /// populating an output span. + /// + /// All existing elements at or following the specified position are moved to + /// make room for the new items. + /// + /// If the array does not have sufficient capacity to hold the new elements, + /// then this reallocates storage to extend its capacity, using a geometric + /// growth rate. + /// + /// - Parameters: + /// - count: The number of items to insert into the array. + /// - index: The position at which to insert the new items. + /// `index` must be a valid index in the array. + /// - body: A callback that gets called exactly once to directly + /// populate newly reserved storage within the array. The function + /// is called with an empty output span of capacity matching the + /// supplied count, and it must fully populate it before returning. + /// + /// - Complexity: O(`self.count` + `count`) + @available(*, deprecated, renamed: "insert(addingCount:at:initializingWith:)") + @inlinable + public mutating func insert( + count: Int, + at index: Int, + initializingWith body: (inout OutputSpan) -> Result + ) -> Result { + var result: Result? = nil + self.insert(addingCount: count, at: index) { target in + result = body(&target) + } + return result! + } + + /// Replaces the specified range of elements by a given count of new items, + /// using a callback to directly initialize array storage by populating + /// an output span. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting room for the new elements starting at the + /// same location. The number of new elements need not match the number + /// of elements being removed. + /// + /// If the array does not have sufficient capacity to perform the replacement, + /// then this reallocates storage to extend its capacity, using a geometric + /// growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, then + /// this method is equivalent to calling + /// `insert(count: newCount, initializingWith: body)`. + /// + /// Likewise, if you pass a zero for `newCount`, then this method + /// removes the elements in the given subrange without any replacement. + /// Calling `removeSubrange(subrange)` is preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newCount: the number of items to replace the old subrange. + /// - body: A callback that gets called exactly once to directly + /// populate newly reserved storage within the array. The function + /// is called with an empty output span of capacity `newCount`, + /// and it must fully populate it before returning. + /// + /// - Complexity: O(`self.count` + `newCount`) + @available(*, deprecated, renamed: "replace(removing:addingCount:initializingWith:)") + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + newCount: Int, + initializingWith body: (inout OutputSpan) -> Result + ) -> Result { + var result: Result? = nil + self.replace(removing: subrange, addingCount: newCount) { target in + result = body(&target) + } + return result! + } + + /// Replaces the specified range of elements by moving the elements of a + /// fully initialized buffer into their place. On return, the buffer is left + /// in an uninitialized state. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the array does not have sufficient capacity to perform the replacement, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: A fully initialized buffer whose contents to move into + /// the array. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:moving:)") + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving newElements: UnsafeMutableBufferPointer, + ) { + self.replace(removing: subrange, moving: newElements) + } + + /// Replaces the specified range of elements by moving the contents of an + /// output span into their place. On return, the span is left empty. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the array does not have sufficient capacity to perform the replacement, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(moving:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - items: An output span whose contents are to be moved into the array. + /// + /// - Complexity: O(`self.count` + `items.count`) + @available(*, deprecated, renamed: "replace(removing:moving:)") + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving items: inout OutputSpan + ) { + self.replace(removing: subrange, moving: &items) + } + + /// Replaces the specified range of elements by moving the elements of a + /// another array into their place. On return, the source array + /// becomes empty, but it is not destroyed, and it preserves its original + /// storage capacity. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the array does not have sufficient capacity to hold enough elements, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: An array whose contents to move into `self`. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:moving:)") + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + moving newElements: inout RigidArray, + ) { + self.replace(removing: subrange, moving: &newElements) + } + + /// Replaces the specified range of elements by moving the elements of a + /// given array into their place, consuming it in the process. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the array does not have sufficient capacity to perform the replacement, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: An array whose contents to move into `self`. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @available(*, deprecated, renamed: "replace(removing:consuming:)") + @_alwaysEmitIntoClient + public mutating func replaceSubrange( + _ subrange: Range, + consuming newElements: consuming RigidArray, + ) { + self.replace(removing: subrange, consuming: newElements) + } +} + +@available(SwiftStdlib 5.0, *) +extension UniqueArray { + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same location. + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// If the capacity of the array isn't sufficient to perform the replacement, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + @inline(__always) + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: UnsafeBufferPointer + ) { + self.replace(removing: subrange, copying: newElements) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given buffer pointer, which must be fully initialized. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same location. + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// If the capacity of the array isn't sufficient to perform the replacement, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length buffer as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + @inline(__always) + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: UnsafeMutableBufferPointer + ) { + self.replace(removing: subrange, copying: newElements) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given span. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same location. + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// If the capacity of the array isn't sufficient to perform the replacement, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length span as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: Span + ) { + self.replace(removing: subrange, copying: newElements) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given collection. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same location. + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// If the capacity of the array isn't sufficient to perform the replacement, + /// then this reallocates the array's storage to extend its capacity, using a + /// geometric growth rate. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length collection as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(*, deprecated, renamed: "replace(removing:copying:)") + @inlinable + @inline(__always) + public mutating func replaceSubrange( + _ subrange: Range, + copying newElements: __owned some Collection + ) { + self.replace(removing: subrange, copying: newElements) + } +} + +#endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift index 90dd25d4..0da21c28 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift @@ -92,41 +92,6 @@ extension UniqueArray where Element: ~Copyable { at: index, initializingWith: initializer) } - - /// Inserts a given number of new items into this array at the specified - /// position, using a callback to directly initialize array storage by - /// populating an output span. - /// - /// All existing elements at or following the specified position are moved to - /// make room for the new items. - /// - /// If the array does not have sufficient capacity to hold the new elements, - /// then this reallocates storage to extend its capacity, using a geometric - /// growth rate. - /// - /// - Parameters: - /// - count: The number of items to insert into the array. - /// - index: The position at which to insert the new items. - /// `index` must be a valid index in the array. - /// - body: A callback that gets called exactly once to directly - /// populate newly reserved storage within the array. The function - /// is called with an empty output span of capacity matching the - /// supplied count, and it must fully populate it before returning. - /// - /// - Complexity: O(`self.count` + `count`) - @available(*, deprecated, renamed: "insert(addingCount:at:initializingWith:)") - @inlinable - public mutating func insert( - count: Int, - at index: Int, - initializingWith body: (inout OutputSpan) -> Result - ) -> Result { - var result: Result? = nil - self.insert(addingCount: count, at: index) { target in - result = body(&target) - } - return result! - } } @available(SwiftStdlib 5.0, *) @@ -350,7 +315,6 @@ extension UniqueArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -384,7 +348,6 @@ extension UniqueArray { _ensureFreeCapacity(c) _storage._insertContainer(at: index, copying: newElements, newCount: c) } -#endif #endif /// Copies the elements of a collection into this array at the specified @@ -419,7 +382,6 @@ extension UniqueArray { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. /// Copies the elements of a container into this array at the specified /// position. /// @@ -454,7 +416,6 @@ extension UniqueArray { _storage._insertContainer(at: index, copying: newElements, newCount: c) } #endif -#endif } #endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift index 8c7c0e2a..56be6e92 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift @@ -60,8 +60,8 @@ extension UniqueArray where Element: ~Copyable { /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity /// of the callback invocations. @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { @@ -71,55 +71,10 @@ extension UniqueArray where Element: ~Copyable { precondition(newItemCount >= 0, "Cannot add a negative number of items") // FIXME: Avoid moving the subsequent elements twice on resize. _ensureFreeCapacity(newItemCount - subrange.count) - try _storage._uncheckedReplaceSubrange( - subrange, - addingCount: newItemCount, - initializingWith: initializer) - } - - /// Replaces the specified range of elements by a given count of new items, - /// using a callback to directly initialize array storage by populating - /// an output span. - /// - /// This method has the effect of removing the specified range of elements - /// from the array and inserting room for the new elements starting at the - /// same location. The number of new elements need not match the number - /// of elements being removed. - /// - /// If the array does not have sufficient capacity to perform the replacement, - /// then this reallocates storage to extend its capacity, using a geometric - /// growth rate. - /// - /// If you pass a zero-length range as the `subrange` parameter, then - /// this method is equivalent to calling - /// `insert(count: newCount, initializingWith: body)`. - /// - /// Likewise, if you pass a zero for `newCount`, then this method - /// removes the elements in the given subrange without any replacement. - /// Calling `removeSubrange(subrange)` is preferred in this case. - /// - /// - Parameters - /// - subrange: The subrange of the array to replace. The bounds of - /// the range must be valid indices in the array. - /// - newCount: the number of items to replace the old subrange. - /// - body: A callback that gets called exactly once to directly - /// populate newly reserved storage within the array. The function - /// is called with an empty output span of capacity `newCount`, - /// and it must fully populate it before returning. - /// - /// - Complexity: O(`self.count` + `newCount`) - @available(*, deprecated, renamed: "replaceSubrange(_:addingCapacity:initializingWith:)") - @inlinable - public mutating func replaceSubrange( - _ subrange: Range, - newCount: Int, - initializingWith body: (inout OutputSpan) -> Result - ) -> Result { - var result: Result? = nil - self.replaceSubrange(subrange, addingCount: newCount) { target in - result = body(&target) - } - return result! + try _storage._uncheckedReplace( + removing: subrange, + addingCount: newItemCount, + initializingWith: initializer) } } @@ -164,10 +119,10 @@ extension UniqueArray where Element: ~Copyable { /// - Parameters /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. - /// - newItemCount: the maximum number of items to replace the old subrange. /// - consumer: A callback that gets called at most once to consume /// the elements to be removed directly from the deque's storage. The /// function is always called with a non-empty input span. + /// - newItemCount: the maximum number of items to replace the old subrange. /// - initializer: A callback that gets called at most once to directly /// populate newly reserved storage within the deque. The function /// is always called with an empty output span. @@ -175,10 +130,10 @@ extension UniqueArray where Element: ~Copyable { /// - Complexity: O(`self.count` + `newItemCount`) in addition to the /// complexity of the callback invocations. @inlinable - public mutating func replaceSubrange( - _ subrange: Range, - addingCount newItemCount: Int, + public mutating func replace( + removing subrange: Range, consumingWith consumer: (inout InputSpan) -> Void, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( @@ -186,10 +141,10 @@ extension UniqueArray where Element: ~Copyable { "Index range out of bounds") precondition(newItemCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(newItemCount - subrange.count) - try _storage._uncheckedReplaceSubrange( - subrange, - addingCount: newItemCount, + try _storage._uncheckedReplace( + removing: subrange, consumingWith: consumer, + addingCount: newItemCount, initializingWith: initializer) } #endif @@ -227,13 +182,13 @@ extension UniqueArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `newElements.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving newElements: UnsafeMutableBufferPointer, ) { // FIXME: Avoid moving the subsequent elements twice. _ensureFreeCapacity(newElements.count - subrange.count) - _storage.replaceSubrange(subrange, moving: newElements) + _storage.replace(removing: subrange, moving: newElements) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @@ -265,13 +220,13 @@ extension UniqueArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving items: inout InputSpan ) { // FIXME: Avoid moving the subsequent elements twice. _ensureFreeCapacity(items.count - subrange.count) - _storage.replaceSubrange(subrange, moving: &items) + _storage.replace(removing: subrange, moving: &items) } #endif @@ -303,13 +258,13 @@ extension UniqueArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving items: inout OutputSpan ) { // FIXME: Avoid moving the subsequent elements twice. _ensureFreeCapacity(items.count - subrange.count) - _storage.replaceSubrange(subrange, moving: &items) + _storage.replace(removing: subrange, moving: &items) } /// Replaces the specified range of elements by moving the elements of a @@ -342,13 +297,13 @@ extension UniqueArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `newElements.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving newElements: inout RigidArray, ) { // FIXME: Avoid moving the subsequent elements twice. _ensureFreeCapacity(newElements.count - subrange.count) - _storage.replaceSubrange(subrange, moving: &newElements) + _storage.replace(removing: subrange, moving: &newElements) } } @@ -382,11 +337,11 @@ extension UniqueArray where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `newElements.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, consuming newElements: consuming RigidArray, ) { - replaceSubrange(subrange, moving: &newElements) + replace(removing: subrange, moving: &newElements) } } @@ -422,13 +377,13 @@ extension UniqueArray { /// *m* is the count of `newElements`. @inlinable @inline(__always) - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: UnsafeBufferPointer ) { // FIXME: Avoid moving the subsequent elements twice. _ensureFreeCapacity(newElements.count) - unsafe _storage.replaceSubrange(subrange, copying: newElements) + unsafe _storage.replace(removing: subrange, copying: newElements) } /// Replaces the specified subrange of elements by copying the elements of @@ -461,12 +416,13 @@ extension UniqueArray { /// *m* is the count of `newElements`. @inlinable @inline(__always) - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: UnsafeMutableBufferPointer ) { - unsafe self.replaceSubrange( - subrange, copying: UnsafeBufferPointer(newElements)) + unsafe self.replace( + removing: subrange, + copying: UnsafeBufferPointer(newElements)) } /// Replaces the specified subrange of elements by copying the elements of @@ -498,17 +454,16 @@ extension UniqueArray { /// - Complexity: O(*n* + *m*), where *n* is count of this array and /// *m* is the count of `newElements`. @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: Span ) { // FIXME: Avoid moving the subsequent elements twice. _ensureFreeCapacity(newElements.count) - _storage.replaceSubrange(subrange, copying: newElements) + _storage.replace(removing: subrange, copying: newElements) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -539,19 +494,20 @@ extension UniqueArray { /// *m* is the count of `newElements`. @inlinable @inline(__always) - public mutating func replaceSubrange< + public mutating func replace< C: Container & ~Copyable & ~Escapable >( - _ subrange: Range, + removing subrange: Range, copying newElements: borrowing C ) { // FIXME: Avoid moving the subsequent elements twice. let c = newElements.count _ensureFreeCapacity(c - subrange.count) - _storage._replaceSubrange( - subrange, copyingContainer: newElements, newCount: c) + _storage._replace( + removing: subrange, + copyingContainer: newElements, + newCount: c) } -#endif #endif /// Replaces the specified subrange of elements by copying the elements of @@ -584,19 +540,20 @@ extension UniqueArray { /// *m* is the count of `newElements`. @inlinable @inline(__always) - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying newElements: __owned some Collection ) { // FIXME: Avoid moving the subsequent elements twice. let c = newElements.count _ensureFreeCapacity(c) - _storage._replaceSubrange( - subrange, copyingCollection: newElements, newCount: c) + _storage._replace( + removing: subrange, + copyingCollection: newElements, + newCount: c) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // FIXME: This needs a container with an exact count. /// Replaces the specified subrange of elements by copying the elements of /// the given container. /// @@ -636,10 +593,11 @@ extension UniqueArray { // FIXME: Avoid moving the subsequent elements twice. let c = newElements.count _ensureFreeCapacity(c - subrange.count) - _storage._replaceSubrange( - subrange, copyingContainer: newElements, newCount: c) + _storage._replace( + removing: subrange, + copyingContainer: newElements, + newCount: c) } #endif -#endif } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 137a92f2..aee4d20c 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -59,8 +59,8 @@ extension RigidDeque where Element: ~Copyable { /// - Complexity: O(`self.count` + `newItemCount`) in addition to the complexity /// of the callback invocations. @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { @@ -71,8 +71,8 @@ extension RigidDeque where Element: ~Copyable { precondition( count - subrange.count + newItemCount <= capacity, "RigidDeque capacity overflow") - try _handle.uncheckedReplaceSubrange( - subrange, + try _handle.uncheckedReplace( + removing: subrange, addingCount: newItemCount, initializingWith: initializer) } @@ -135,10 +135,10 @@ extension RigidDeque where Element: ~Copyable { /// - Complexity: O(`self.count` + `newItemCount`) in addition to the /// complexity of the callback invocations. @inlinable - public mutating func replaceSubrange( - _ subrange: Range, - addingCount newItemCount: Int, + public mutating func replace( + removing subrange: Range, consumingWith consumer: (inout InputSpan) -> Void, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( @@ -148,10 +148,10 @@ extension RigidDeque where Element: ~Copyable { precondition( count - subrange.count + newItemCount <= capacity, "RigidDeque capacity overflow") - try _handle.uncheckedReplaceSubrange( - subrange, - addingCount: newItemCount, + try _handle.uncheckedReplace( + removing: subrange, consumingWith: consumer, + addingCount: newItemCount, initializingWith: initializer) } #endif @@ -188,12 +188,12 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving items: UnsafeMutableBufferPointer, ) { var remainder = items - replaceSubrange(subrange, addingCount: remainder.count) { target in + replace(removing: subrange, addingCount: remainder.count) { target in target._withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) @@ -231,13 +231,13 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving items: inout InputSpan ) { items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(last: count) - unsafe self.replaceSubrange(subrange, moving: source) + unsafe self.replace(removing: subrange, moving: source) count = 0 } } @@ -270,13 +270,13 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `items.count`) @_alwaysEmitIntoClient - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, moving items: inout OutputSpan ) { items._withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) - unsafe self.replaceSubrange(subrange, moving: source) + unsafe self.replace(removing: subrange, moving: source) count = 0 } } @@ -320,14 +320,17 @@ extension RigidDeque where Element: ~Copyable { /// /// - Complexity: O(`self.count` + `maximumCount`) @_alwaysEmitIntoClient - public mutating func replaceSubrange< + public mutating func replace< P: Producer & ~Copyable & ~Escapable >( - _ subrange: Range, + removing subrange: Range, addingCount newItemCount: Int, from producer: inout P ) throws(P.ProducerError) { - try replaceSubrange(subrange, addingCount: newItemCount) { target throws(P.ProducerError) in + try replace( + removing: subrange, + addingCount: newItemCount + ) { target throws(P.ProducerError) in try producer.generate(into: &target) } } @@ -363,12 +366,12 @@ extension RigidDeque /* where Element: Copyable */ { /// /// - Complexity: O(`self.count` + `items.count`) @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying items: UnsafeBufferPointer ) { var remainder = items - replaceSubrange(subrange, addingCount: remainder.count) { target in + replace(removing: subrange, addingCount: remainder.count) { target in target._withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count @@ -404,12 +407,12 @@ extension RigidDeque /* where Element: Copyable */ { /// /// - Complexity: O(`self.count` + `items.count`) @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying items: UnsafeMutableBufferPointer ) { - unsafe self.replaceSubrange( - subrange, + unsafe self.replace( + removing: subrange, copying: UnsafeBufferPointer(items)) } @@ -440,28 +443,28 @@ extension RigidDeque /* where Element: Copyable */ { /// /// - Complexity: O(`self.count` + `items.count`) @inlinable - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying items: Span ) { unsafe items.withUnsafeBufferPointer { buffer in - unsafe self.replaceSubrange(subrange, copying: buffer) + unsafe self.replace(removing: subrange, copying: buffer) } } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @inlinable - internal mutating func _replaceSubrange< + internal mutating func _replace< C: Container & ~Copyable & ~Escapable >( - _ subrange: Range, + removing subrange: Range, copyingContainer items: borrowing C, newCount: Int ) { let expectedCount = self.count - subrange.count + newCount var it = items.makeBorrowingIterator() - self.replaceSubrange(subrange, addingCount: newCount) { target in + self.replace(removing: subrange, addingCount: newCount) { target in it.copyContents(into: &target) } precondition( @@ -471,8 +474,8 @@ extension RigidDeque /* where Element: Copyable */ { #endif @inlinable - internal mutating func _replaceSubrange( - _ subrange: Range, + internal mutating func _replace( + removing subrange: Range, copyingCollection items: __owned some Collection, newCount: Int ) { @@ -480,12 +483,12 @@ extension RigidDeque /* where Element: Copyable */ { precondition( src.count == newCount, "Broken Collection: count doesn't match contents") - self.replaceSubrange(subrange, copying: src) + self.replace(removing: subrange, copying: src) } if done != nil { return } var i = items.startIndex - self.replaceSubrange(subrange, addingCount: newCount) { target in + self.replace(removing: subrange, addingCount: newCount) { target in while !target.isFull { target.append(items[i]) items.formIndex(after: &i) @@ -522,14 +525,14 @@ extension RigidDeque /* where Element: Copyable */ { /// - Complexity: O(`self.count` + `items.count`) @inlinable @inline(__always) - public mutating func replaceSubrange< + public mutating func replace< C: Container & ~Copyable & ~Escapable >( - _ subrange: Range, + removing subrange: Range, copying items: borrowing C ) { - _replaceSubrange( - subrange, copyingContainer: items, newCount: items.count) + _replace( + removing: subrange, copyingContainer: items, newCount: items.count) } #endif @@ -561,12 +564,12 @@ extension RigidDeque /* where Element: Copyable */ { /// - Complexity: O(`self.count` + `items.count`) @inlinable @inline(__always) - public mutating func replaceSubrange( - _ subrange: Range, + public mutating func replace( + removing subrange: Range, copying items: __owned some Collection ) { - _replaceSubrange( - subrange, copyingCollection: items, newCount: items.count) + _replace( + removing: subrange, copyingCollection: items, newCount: items.count) } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @@ -599,14 +602,14 @@ extension RigidDeque /* where Element: Copyable */ { /// *m* is the count of `items`. @inlinable @inline(__always) - public mutating func replaceSubrange< + public mutating func replace< C: Container & Collection >( - _ subrange: Range, + removing subrange: Range, copying items: C ) { - _replaceSubrange( - subrange, copyingContainer: items, newCount: items.count) + _replace( + removing: subrange, copyingContainer: items, newCount: items.count) } #endif } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index ac319b09..a2ca9d54 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -83,8 +83,8 @@ extension UniqueDeque where Element: ~Copyable { "Subrange out of bounds") precondition(newItemCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(newItemCount - subrange.count) - try _storage._handle.uncheckedReplaceSubrange( - subrange, + try _storage._handle.uncheckedReplace( + removing: subrange, addingCount: capacity, initializingWith: initializer) } @@ -144,8 +144,8 @@ extension UniqueDeque where Element: ~Copyable { @inlinable public mutating func replaceSubrange( _ subrange: Range, - addingCount newItemCount: Int, consumingWith consumer: (inout InputSpan) -> Void, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { precondition( @@ -153,10 +153,10 @@ extension UniqueDeque where Element: ~Copyable { "Subrange out of bounds") precondition(newItemCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(newItemCount - subrange.count) - try _storage._handle.uncheckedReplaceSubrange( - subrange, - addingCount: newItemCount, + try _storage._handle.uncheckedReplace( + removing: subrange, consumingWith: consumer, + addingCount: newItemCount, initializingWith: initializer) } #endif diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index f020dbaa..05853add 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -1371,7 +1371,10 @@ extension _UnsafeDequeHandle where Element: ~Copyable { self.closeGap( offsets: (left ? subrange.prefix(-delta) : subrange.suffix(-delta))) } - let newRange = Range(uncheckedBounds: (subrange.lowerBound, newItemCount)) + let newRange = Range( + uncheckedBounds: ( + subrange.lowerBound, + subrange.lowerBound &+ newItemCount)) let gap = self.mutableSegments(forOffsets: newRange) var c = 0 @@ -1387,8 +1390,8 @@ extension _UnsafeDequeHandle where Element: ~Copyable { } @_alwaysEmitIntoClient - internal mutating func uncheckedReplaceSubrange( - _ subrange: Range, + internal mutating func uncheckedReplace( + removing subrange: Range, addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { @@ -1406,10 +1409,10 @@ extension _UnsafeDequeHandle where Element: ~Copyable { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @_alwaysEmitIntoClient - internal mutating func uncheckedReplaceSubrange( - _ subrange: Range, - addingCount newItemCount: Int, + internal mutating func uncheckedReplace( + removing subrange: Range, consumingWith consumer: (inout InputSpan) -> Void, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { assert( diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index ac2887eb..bed56314 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -1183,14 +1183,14 @@ class RigidArrayTests: CollectionTestCase { } #endif - func test_replaceSubrange_addingCount_full() { + func test_replace_addingCount_full() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 20]) { layout in withEveryRange("subrange", in: 0 ..< layout.count) { subrange in withEvery("c", in: 0 ..< subrange.count + layout.freeCapacity) { c in withLifetimeTracking { tracker in var a = tracker.rigidArray(layout: layout) - a.replaceSubrange(subrange, addingCount: c) { target in + a.replace(removing: subrange, addingCount: c) { target in expectEqual(target.freeCapacity, c) for i in 0 ..< c { target.append(tracker.instance(for: layout.count + i)) @@ -1213,7 +1213,7 @@ class RigidArrayTests: CollectionTestCase { } } - func test_replaceSubrange_addingCount_partial() { + func test_replace_addingCount_partial() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in guard !layout.isFull else { return } withEveryRange("subrange", in: 0 ..< layout.count) { subrange in @@ -1222,7 +1222,7 @@ class RigidArrayTests: CollectionTestCase { withLifetimeTracking { tracker in var a = tracker.rigidArray(layout: layout) - a.replaceSubrange(subrange, addingCount: c) { target in + a.replace(removing: subrange, addingCount: c) { target in expectTrue(target.isEmpty) expectEqual(target.freeCapacity, c) for i in 0 ..< n { @@ -1248,7 +1248,7 @@ class RigidArrayTests: CollectionTestCase { } } - func test_replaceSubrange_Collection() { + func test_replace_Collection() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in withEvery("isContiguous", in: [false, true]) { isContiguous in @@ -1262,7 +1262,7 @@ class RigidArrayTests: CollectionTestCase { addition.map { tracker.instance(for: $0) }, isContiguous: isContiguous) var a = tracker.rigidArray(layout: layout) - a.replaceSubrange(range, copying: trackedAddition) + a.replace(removing: range, copying: trackedAddition) expectIterableContents( a, @@ -1276,7 +1276,7 @@ class RigidArrayTests: CollectionTestCase { } } } - func test_replaceSubrange_Span() { + func test_replace_Span() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in withEvery("c", in: 0 ..< layout.capacity - layout.count + range.count) { c in @@ -1287,7 +1287,7 @@ class RigidArrayTests: CollectionTestCase { var a = tracker.rigidArray(layout: layout) let trackedAddition = RigidArray(copying: addition.map { tracker.instance(for: $0) }) - a.replaceSubrange(range, copying: trackedAddition.span) + a.replace(removing: range, copying: trackedAddition.span) expectIterableContents( a, @@ -1302,7 +1302,7 @@ class RigidArrayTests: CollectionTestCase { } #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW - func test_replaceSubrange_Container() { + func test_replace_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in withEvery("c", in: 0 ..< layout.capacity - layout.count + range.count) { c in @@ -1316,7 +1316,7 @@ class RigidArrayTests: CollectionTestCase { let trackedAddition = StaccatoContainer( contents: RigidArray(copying: addition.map { tracker.instance(for: $0) }), spanCounts: [spanCount]) - a.replaceSubrange(range, copying: trackedAddition) + a.replace(removing: range, copying: trackedAddition) expectIterableContents( a, diff --git a/Tests/BasicContainersTests/UniqueArrayTests.swift b/Tests/BasicContainersTests/UniqueArrayTests.swift index 6ae8d9d8..26ca3a1f 100644 --- a/Tests/BasicContainersTests/UniqueArrayTests.swift +++ b/Tests/BasicContainersTests/UniqueArrayTests.swift @@ -868,7 +868,7 @@ class UniqueArrayTests: CollectionTestCase { #endif #endif - func test_replaceSubrange_copying_Collection() { + func test_replace_copying_Collection() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in withEvery("c", in: [0, 1, 10, 100]) { c in @@ -879,7 +879,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) let trackedAddition = addition.map { tracker.instance(for: $0) } - a.replaceSubrange(range, copying: trackedAddition) + a.replace(removing: range, copying: trackedAddition) expectIterableContents( a, @@ -893,7 +893,7 @@ class UniqueArrayTests: CollectionTestCase { } } - func test_replaceSubrange_copying_Span() { + func test_replace_copying_Span() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in withEvery("c", in: [0, 1, 10, 100]) { c in @@ -905,7 +905,7 @@ class UniqueArrayTests: CollectionTestCase { var a = tracker.uniqueArray(layout: layout) let trackedAddition = RigidArray( copying: addition.map { tracker.instance(for: $0) }) - a.replaceSubrange(range, copying: trackedAddition.span) + a.replace(removing: range, copying: trackedAddition.span) expectIterableContents( a, @@ -921,7 +921,7 @@ class UniqueArrayTests: CollectionTestCase { #if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW #if false // FIXME: Update - func test_replaceSubrange_copying_Container() { + func test_replace_copying_Container() { withSomeArrayLayouts("layout", ofCapacities: [0, 5, 10]) { layout in withEveryRange("range", in: 0 ..< layout.count) { range in withEvery("c", in: [0, 1, 10, 100]) { c in diff --git a/Tests/DequeTests/DequeInternals.swift b/Tests/DequeTests/DequeInternals.swift index 8bf76c0a..cb38992d 100644 --- a/Tests/DequeTests/DequeInternals.swift +++ b/Tests/DequeTests/DequeInternals.swift @@ -26,6 +26,14 @@ internal struct RigidTestData: ~Copyable { self.deque = deque self.contents = contents } + + mutating func take() -> RigidDeque { + exchange(&self.deque, with: .init()) + } + + consuming func consume() -> RigidDeque { + exchange(&self.deque, with: .init()) + } } @available(SwiftStdlib 5.0, *) diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests.swift index a915b31f..d1b4ed43 100644 --- a/Tests/DequeTests/RigidDequeTests.swift +++ b/Tests/DequeTests/RigidDequeTests.swift @@ -1284,6 +1284,168 @@ final class RigidDequeTests: CollectionTestCase { } #endif + func test_replace_addingCount_full() { + withEveryDeque("layout", ofCapacities: [0, 5, 10]) { layout in + withEveryRange("subrange", in: 0 ..< layout.count) { subrange in + withEvery("c", in: 0 ..< subrange.count + layout.freeCapacity) { c in + withLifetimeTracking { tracker in + var a = tracker.rigidDeque(with: layout).consume() + + var i = 0 + a.replace(removing: subrange, addingCount: c) { target in + while !target.isFull { + target.append(tracker.instance(for: layout.count + i)) + i += 1 + } + } + expectEqual(i, c) + + var expected = Array(0 ..< layout.count) + expected.replaceSubrange( + subrange, + with: layout.count ..< layout.count + c) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + + func test_replace_addingCount_partial() { + withEveryDeque("layout", ofCapacities: [0, 5, 10]) { layout in + withEveryRange("subrange", in: 0 ..< layout.count) { subrange in + guard layout.freeCapacity - subrange.count > 0 else { return } + withEvery("c", in: 1 ..< subrange.count + layout.freeCapacity) { c in + withEvery("n", in: 0 ..< c - 1) { n in + withLifetimeTracking { tracker in + var a = tracker.rigidDeque(with: layout).consume() + + var i = 0 + a.replace(removing: subrange, addingCount: c) { target in + while !target.isFull, i < n { + target.append(tracker.instance(for: layout.count + i)) + i += 1 + } + } + expectEqual(i, n) + + var expected = Array(0 ..< layout.count) + expected.replaceSubrange( + subrange, + with: layout.count ..< layout.count + n) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + } + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_replace_consuming_addingCount_full() { + withEveryDeque("layout", ofCapacities: [0, 5, 10]) { layout in + withEveryRange("subrange", in: 0 ..< layout.count) { subrange in + withEvery("c", in: 0 ..< subrange.count + layout.freeCapacity) { c in + withLifetimeTracking { tracker in + var a = tracker.rigidDeque(with: layout).consume() + + var i = subrange.lowerBound + var j = 0 + a.replace( + removing: subrange, + consumingWith: { source in + while let next = source.popFirst() { + expectEqual(next.payload, i) + i += 1 + } + }, + addingCount: c, + initializingWith: { target in + expectEqual(i, subrange.upperBound) + while !target.isFull { + target.append(tracker.instance(for: layout.count + j)) + j += 1 + } + }) + expectEqual(i, subrange.upperBound) + expectEqual(j, c) + + var expected = Array(0 ..< layout.count) + expected.replaceSubrange( + subrange, + with: layout.count ..< layout.count + c) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } +#endif + +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + func test_replace_consuming_addingCount_partial() { + withEveryDeque("layout", ofCapacities: [0, 5, 10]) { layout in + withEveryRange("subrange", in: 0 ..< layout.count) { subrange in + guard layout.freeCapacity - subrange.count > 0 else { return } + withEvery("c", in: 1 ..< subrange.count + layout.freeCapacity) { c in + withEvery("n", in: 0 ..< c - 1) { n in + withLifetimeTracking { tracker in + var a = tracker.rigidDeque(with: layout).consume() + + var i = subrange.lowerBound + var j = 0 + a.replace( + removing: subrange, + consumingWith: { source in + while let next = source.popFirst() { + expectEqual(next.payload, i) + i += 1 + } + }, + addingCount: c, + initializingWith: { target in + expectEqual(i, subrange.upperBound) + while !target.isFull, j < n { + target.append(tracker.instance(for: layout.count + j)) + j += 1 + } + }) + expectEqual(i, subrange.upperBound) + expectEqual(j, n) + + var expected = Array(0 ..< layout.count) + expected.replaceSubrange( + subrange, + with: layout.count ..< layout.count + n) + + expectIterableContents( + a, + equivalentTo: expected, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + } + } + } +#endif + func test_removeOne() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in withEvery("offset", in: 0 ..< layout.count) { offset in diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 98c82788..b24fe715 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -84,6 +84,8 @@ 7D57A2CB2F342F43002543BD /* UniqueDeque+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C82F342F43002543BD /* UniqueDeque+Equatable.swift */; }; 7D57A2CC2F342F43002543BD /* UniqueDeque+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2C92F342F43002543BD /* UniqueDeque+Hashable.swift */; }; 7D57A2CE2F343CA9002543BD /* ContainerAlgorithms.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2CD2F343CA2002543BD /* ContainerAlgorithms.swift */; }; + 7D57A2D02F353946002543BD /* RigidArray+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2CF2F35393E002543BD /* RigidArray+Deprecated.swift */; }; + 7D57A2D22F353CA5002543BD /* UniqueArray+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D57A2D12F353CA1002543BD /* UniqueArray+Deprecated.swift */; }; 7D9748D42E9748930098631A /* BigString+Chunk+UTF16.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D32E9748930098631A /* BigString+Chunk+UTF16.swift */; }; 7D9748D52E9748930098631A /* BigString+Chunk+UnicodeScalar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D12E9748930098631A /* BigString+Chunk+UnicodeScalar.swift */; }; 7D9748D62E9748930098631A /* BigString+Chunk+Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748CF2E9748930098631A /* BigString+Chunk+Character.swift */; }; @@ -585,6 +587,8 @@ 7D57A2C82F342F43002543BD /* UniqueDeque+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Equatable.swift"; sourceTree = ""; }; 7D57A2C92F342F43002543BD /* UniqueDeque+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Hashable.swift"; sourceTree = ""; }; 7D57A2CD2F343CA2002543BD /* ContainerAlgorithms.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerAlgorithms.swift; sourceTree = ""; }; + 7D57A2CF2F35393E002543BD /* RigidArray+Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Deprecated.swift"; sourceTree = ""; }; + 7D57A2D12F353CA1002543BD /* UniqueArray+Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueArray+Deprecated.swift"; sourceTree = ""; }; 7D5A64D229CCE8CC00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D329CCEE9A00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D829CCF0FE00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -1190,6 +1194,7 @@ 7DA23F3A2F329A2300E4C03A /* RigidArray+Insertions.swift */, 7DA23F3B2F329A2300E4C03A /* RigidArray+Removals.swift */, 7DA23F3C2F329A2300E4C03A /* RigidArray+Replacements.swift */, + 7D57A2CF2F35393E002543BD /* RigidArray+Deprecated.swift */, ); path = RigidArray; sourceTree = ""; @@ -1209,6 +1214,7 @@ 7DA23F422F329A2300E4C03A /* UniqueArray+Insertions.swift */, 7DA23F432F329A2300E4C03A /* UniqueArray+Removals.swift */, 7DA23F442F329A2300E4C03A /* UniqueArray+Replacements.swift */, + 7D57A2D12F353CA1002543BD /* UniqueArray+Deprecated.swift */, ); path = UniqueArray; sourceTree = ""; @@ -2498,6 +2504,7 @@ 7D2A773D2F27F1E4005780C7 /* BorrowingSequence.swift in Sources */, 7D2A773E2F27F1E4005780C7 /* BorrowingSequence+Standard Conformances.swift in Sources */, 7D2A773F2F27F1E4005780C7 /* Borrow.swift in Sources */, + 7D57A2D02F353946002543BD /* RigidArray+Deprecated.swift in Sources */, 7D2A77402F27F1E4005780C7 /* BorrowingIteratorProtocol.swift in Sources */, 7D2A77412F27F1E4005780C7 /* Inout.swift in Sources */, 7D2A77422F27F1E4005780C7 /* OutputSpan+Extras.swift in Sources */, @@ -2520,6 +2527,7 @@ 7DE9208029CA70F4004483EB /* BigString+Hashing.swift in Sources */, 7DE920F829CA70F4004483EB /* BitArray+Testing.swift in Sources */, 7DE920D629CA70F4004483EB /* BitSet+Equatable.swift in Sources */, + 7D57A2D22F353CA5002543BD /* UniqueArray+Deprecated.swift in Sources */, 7DE9217A29CA70F4004483EB /* Heap+Descriptions.swift in Sources */, 7DE9216429CA70F4004483EB /* _HashNode.swift in Sources */, 7DAD89A52E8B09D900DD5786 /* _UnsafeBitSet+_Word.swift in Sources */, From e6d67311245aae11960a8e6cd024b7e1c642b496 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 5 Feb 2026 14:33:41 -0800 Subject: [PATCH 66/75] =?UTF-8?q?Don=E2=80=99t=20flood=20Xcode=20with=20a?= =?UTF-8?q?=20million=20unit=20test=20failures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssertionContexts/Assertions.swift | 1 + .../AssertionContexts/TestContext.swift | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift index dbdc70fc..8390202d 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift @@ -34,6 +34,7 @@ public func _expectFailure( file: StaticString, line: UInt ) { + guard TestContext.incrementFailureCount() else { return } let message = message() XCTFail( TestContext.currentTrace( diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/TestContext.swift b/Tests/_CollectionsTestSupport/AssertionContexts/TestContext.swift index cab8f766..22df2600 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/TestContext.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/TestContext.swift @@ -14,6 +14,7 @@ import XCTest public final class TestContext { internal var _nextStateId = 0 internal var _nextIndexId = 0 + internal var _failureCount = 0 /// Stack of labels with associated source positions. /// Useful for tracking failed cases in combinatorial tests. @@ -32,6 +33,10 @@ extension TestContext { } return current } + + /// Don't report more than this number of failures per test, to avoid + /// overwhelming Xcode's display engine. + public static var maximumFailureCount: Int { 100 } public static func pushNew() -> TestContext { let context = TestContext() @@ -191,6 +196,16 @@ extension TestContext { for trace in _trace { result += " - \(trace.label)\n" } + if _failureCount == Self.maximumFailureCount { + result += "*** Failure limit reached; additional failures will be suppressed ***" + } + return result + } + + public static func incrementFailureCount() -> Bool { + guard let context = _current else { return true } + let result = context._failureCount < maximumFailureCount + context._failureCount += 1 return result } From b9fd3ed56e97a3dc6cdcf70b01e39c72f7b217f7 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 5 Feb 2026 16:46:14 -0800 Subject: [PATCH 67/75] RigidArray, UniqueArray: Move remaining deprecations to dedicated file --- .../RigidArray/RigidArray+Deprecated.swift | 53 ++++++++++++++++++- .../RigidArray/RigidArray.swift | 47 ---------------- .../UniqueArray/UniqueArray+Deprecated.swift | 23 ++++++++ .../UniqueArray/UniqueArray.swift | 26 --------- 4 files changed, 74 insertions(+), 75 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift index 1ae26624..459d1341 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift @@ -41,7 +41,7 @@ extension RigidArray where Element: ~Copyable { } return result.take()! } - + /// Inserts a given number of new items into this array at the specified /// position, using a callback to directly initialize array storage by /// populating an output span. @@ -75,7 +75,7 @@ extension RigidArray where Element: ~Copyable { } return result! } - + /// Replaces the specified range of elements by a given count of new items, /// using a callback to directly initialize array storage by populating /// an output span. @@ -228,10 +228,59 @@ extension RigidArray where Element: ~Copyable { ) { self.replace(removing: subrange, moving: &newElements) } + + + /// Perform a range replacement up to populating the newly opened gap. This + /// deinitializes existing elements in the specified subrange, rearranges + /// following elements to be at their final location, and sets the container's + /// new count. + /// + /// - Returns: A buffer pointer addressing the newly opened gap, to be + /// initialized by the caller. + @available(*, deprecated) // FIXME: Obsolete, remove this + @usableFromInline + @unsafe + internal mutating func _gapForReplacement( + of subrange: Range, newItemCount: Int + ) -> UnsafeMutableBufferPointer { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= _count, + "Index range out of bounds") + precondition(newItemCount >= 0, "Cannot add a negative number of items") + precondition( + newItemCount - subrange.count <= freeCapacity, + "RigidArray capacity overflow") + unsafe _items.extracting(subrange).deinitialize() + return _resizeGap(in: subrange, to: newItemCount) + } } @available(SwiftStdlib 5.0, *) extension RigidArray { + /// Copy the contents of this array into a newly allocated rigid array + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone()") + @inlinable + public func copy() -> Self { + clone() + } + + + /// Copy the contents of this array into a newly allocated rigid array + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting rigid array. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone(capacity:)") + @inlinable + public func copy(capacity: Int) -> Self { + clone(capacity: capacity) + } + /// Replaces the specified subrange of elements by copying the elements of /// the given buffer pointer, which must be fully initialized. /// diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index 9fadb604..2ef88c48 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -384,29 +384,6 @@ extension RigidArray { result._count = count return result } - - /// Copy the contents of this array into a newly allocated rigid array - /// instance with just enough capacity to hold all its elements. - /// - /// - Complexity: O(`count`) - @available(*, deprecated, renamed: "clone()") - @inlinable - public func copy() -> Self { - clone() - } - - /// Copy the contents of this array into a newly allocated rigid array - /// instance with the specified capacity. - /// - /// - Parameter capacity: The desired capacity of the resulting rigid array. - /// `capacity` must be greater than or equal to `count`. - /// - /// - Complexity: O(`count`) - @available(*, deprecated, renamed: "clone(capacity:)") - @inlinable - public func copy(capacity: Int) -> Self { - clone(capacity: capacity) - } } @@ -470,30 +447,6 @@ extension RigidArray where Element: ~Copyable { uncheckedBounds: (subrange.lowerBound, subrange.lowerBound + newItemCount)) return unsafe _storage.extracting(gapRange) } - - /// Perform a range replacement up to populating the newly opened gap. This - /// deinitializes existing elements in the specified subrange, rearranges - /// following elements to be at their final location, and sets the container's - /// new count. - /// - /// - Returns: A buffer pointer addressing the newly opened gap, to be - /// initialized by the caller. - @available(*, deprecated) // FIXME: Obsolete, remove this - @usableFromInline - @unsafe - internal mutating func _gapForReplacement( - of subrange: Range, newItemCount: Int - ) -> UnsafeMutableBufferPointer { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= _count, - "Index range out of bounds") - precondition(newItemCount >= 0, "Cannot add a negative number of items") - precondition( - newItemCount - subrange.count <= freeCapacity, - "RigidArray capacity overflow") - unsafe _items.extracting(subrange).deinitialize() - return _resizeGap(in: subrange, to: newItemCount) - } } #endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift index bde410a4..bfda4f1c 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift @@ -274,6 +274,29 @@ extension UniqueArray where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension UniqueArray { + /// Copy the contents of this array into a newly allocated unique array + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone()") + @inlinable + public func copy() -> Self { + self.clone() + } + + /// Copy the contents of this array into a newly allocated unique array + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting unique array. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone(capacity:)") + @inlinable + public func copy(capacity: Int) -> Self { + clone(capacity: capacity) + } + /// Replaces the specified subrange of elements by copying the elements of /// the given buffer pointer, which must be fully initialized. /// diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index 3f99cc7b..17cfaae3 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -302,31 +302,5 @@ extension UniqueArray { public func clone(capacity: Int) -> Self { UniqueArray(consuming: _storage.clone(capacity: capacity)) } - - /// Copy the contents of this array into a newly allocated unique array - /// instance with just enough capacity to hold all its elements. - /// - /// - Complexity: O(`count`) - @available(*, deprecated, renamed: "clone()") - @inlinable - public func copy() -> Self { - self.clone() - } - - /// Copy the contents of this array into a newly allocated unique array - /// instance with the specified capacity. - /// - /// - Parameter capacity: The desired capacity of the resulting unique array. - /// `capacity` must be greater than or equal to `count`. - /// - /// - Complexity: O(`count`) - @available(*, deprecated, renamed: "clone(capacity:)") - @inlinable - public func copy(capacity: Int) -> Self { - clone(capacity: capacity) - } } - - - #endif From 35e09984f5893a317e7a42d2ffe20a2aff1c63e3 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 5 Feb 2026 16:48:05 -0800 Subject: [PATCH 68/75] =?UTF-8?q?[doc]=20Add=20missing=20colon=20after=20?= =?UTF-8?q?=E2=80=9CParameters=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RigidArray/RigidArray+Append.swift | 22 +++++++-------- .../RigidArray/RigidArray+Deprecated.swift | 8 +++--- .../RigidArray/RigidArray+Insertions.swift | 22 +++++++-------- .../RigidArray/RigidArray+Replacements.swift | 14 +++++----- .../UniqueArray/UniqueArray+Append.swift | 22 +++++++-------- .../UniqueArray/UniqueArray+Deprecated.swift | 12 ++++---- .../UniqueArray/UniqueArray+Insertions.swift | 22 +++++++-------- .../UniqueArray+Replacements.swift | 14 +++++----- .../RigidDeque/RigidDeque+Append.swift | 22 +++++++-------- .../RigidDeque/RigidDeque+Initializers.swift | 2 +- .../RigidDeque/RigidDeque+Insertions.swift | 18 ++++++------ .../RigidDeque/RigidDeque+Prepend.swift | 28 +++++++++---------- .../RigidDeque/RigidDeque+Replacements.swift | 12 ++++---- .../UniqueDeque/UniqueDeque+Append.swift | 22 +++++++-------- .../UniqueDeque+Initializers.swift | 2 +- .../UniqueDeque/UniqueDeque+Insertions.swift | 18 ++++++------ .../UniqueDeque/UniqueDeque+Prepend.swift | 28 +++++++++---------- .../UniqueDeque+Replacements.swift | 12 ++++---- Sources/DequeModule/_UnsafeDequeHandle.swift | 8 +++--- 19 files changed, 154 insertions(+), 154 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index 302ce36a..bda586e3 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -97,7 +97,7 @@ extension RigidArray where Element: ~Copyable { /// If the array does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the array. /// @@ -120,7 +120,7 @@ extension RigidArray where Element: ~Copyable { /// If the array does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents need to be appended to this array. /// /// - Complexity: O(`items.count`) @@ -142,7 +142,7 @@ extension RigidArray where Element: ~Copyable { /// If the array does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents need to be appended to this array. /// /// - Complexity: O(`items.count`) @@ -164,7 +164,7 @@ extension RigidArray where Element: ~Copyable { /// If the target array does not have sufficient capacity to hold all items /// in the source array, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An array whose items to move to the end of this array. /// /// - Complexity: O(`items.count`) @@ -188,7 +188,7 @@ extension RigidArray where Element: ~Copyable { /// If the target array does not have sufficient capacity to hold all items /// in the source array, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A container whose contents to move into this array. /// /// - Complexity: O(`items.count`) @@ -210,7 +210,7 @@ extension RigidArray { /// If the array does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: A fully initialized buffer whose contents to copy into /// the array. /// @@ -233,7 +233,7 @@ extension RigidArray { /// If the array does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: A fully initialized buffer whose contents to copy into /// the array. /// @@ -250,7 +250,7 @@ extension RigidArray { /// If the array does not have sufficient capacity to hold all items in the /// span, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: A span whose contents to copy into the array. /// /// - Complexity: O(`newElements.count`) @@ -289,7 +289,7 @@ extension RigidArray { /// If the array does not have sufficient capacity to hold all items in the /// source sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: A container whose contents to copy into the array. /// /// - Complexity: O(`newElements.count`) @@ -309,7 +309,7 @@ extension RigidArray { /// If the array does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to copy into the array. /// /// - Complexity: O(*m*), where *m* is the length of `newElements`. @@ -331,7 +331,7 @@ extension RigidArray { /// If the array does not have sufficient capacity to hold all items in the /// source sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to copy into the array. /// /// - Complexity: O(*m*), where *m* is the length of `newElements`. diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift index 459d1341..8f84a257 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift @@ -96,7 +96,7 @@ extension RigidArray where Element: ~Copyable { /// removes the elements in the given subrange without any replacement. /// This case is more directly expressed by `removeSubrange(subrange)`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newCount: the number of items to replace the old subrange. @@ -141,7 +141,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: A fully initialized buffer whose contents to move into @@ -177,7 +177,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - items: An output span whose contents are to be moved into the array. @@ -214,7 +214,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: An array whose contents to move into `self`. diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index d924fee9..722dc2b9 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -129,7 +129,7 @@ extension RigidArray where Element: ~Copyable { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the array. /// - index: The position at which to insert the new items. @@ -156,7 +156,7 @@ extension RigidArray where Element: ~Copyable { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents to move into /// the array. /// - index: The position at which to insert the new items. @@ -185,7 +185,7 @@ extension RigidArray where Element: ~Copyable { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents to move into /// the array. /// - index: The position at which to insert the new items. @@ -215,7 +215,7 @@ extension RigidArray where Element: ~Copyable { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An array whose contents to move into `self`. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the array. @@ -246,7 +246,7 @@ extension RigidArray where Element: ~Copyable { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The array whose contents to move into `self`. /// - index: The position at which to insert the new items. /// `index` must be a valid index in the array. @@ -279,7 +279,7 @@ extension RigidArray { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -309,7 +309,7 @@ extension RigidArray { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -337,7 +337,7 @@ extension RigidArray { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. @@ -415,7 +415,7 @@ extension RigidArray { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. @@ -446,7 +446,7 @@ extension RigidArray { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. @@ -475,7 +475,7 @@ extension RigidArray { /// If the capacity of the array isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 511b0aa5..7b833944 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -48,7 +48,7 @@ extension RigidArray where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newItemCount: the maximum number of items to replace the old subrange. @@ -138,7 +138,7 @@ extension RigidArray where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - newItemCount: the maximum number of items to replace the old subrange. @@ -229,7 +229,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: A fully initialized buffer whose contents to move into @@ -269,7 +269,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - items: An input span whose contents are to be moved into the array. @@ -308,7 +308,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - items: An output span whose contents are to be moved into the array. @@ -348,7 +348,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: An array whose contents to move into `self`. @@ -391,7 +391,7 @@ extension RigidArray where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: An array whose contents to move into `self`. diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift index 1cc82d2c..55275d1c 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift @@ -77,7 +77,7 @@ extension UniqueArray where Element: ~Copyable { /// buffer, then this reallocates the array's storage to grow its capacity, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the array. /// @@ -98,7 +98,7 @@ extension UniqueArray where Element: ~Copyable { /// then this reallocates the array's storage to grow its capacity, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents need to be appended to this array. /// /// - Complexity: O(`items.count`) @@ -118,7 +118,7 @@ extension UniqueArray where Element: ~Copyable { /// then this reallocates the array's storage to grow its capacity, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents need to be appended to this array. /// /// - Complexity: O(`items.count`) @@ -138,7 +138,7 @@ extension UniqueArray where Element: ~Copyable { /// in the source array, then this automatically grows the target array's /// capacity, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An array whose items to move to the end of this array. /// /// - Complexity: O(`items.count`) when amortized over many invocations on @@ -163,7 +163,7 @@ extension UniqueArray where Element: ~Copyable { /// in the source array, then this automatically grows the target array's /// capacity, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An array whose items to move to the end of this array. /// /// - Complexity: O(`items.count`) @@ -186,7 +186,7 @@ extension UniqueArray { /// in the source buffer, then this automatically grows the array's /// capacity, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: A fully initialized buffer whose contents to copy into /// the array. /// @@ -206,7 +206,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using /// a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: A fully initialized buffer whose contents to copy into /// the array. /// @@ -225,7 +225,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: A span whose contents to copy into the array. /// /// - Complexity: O(`newElements.count`) when amortized over many @@ -264,7 +264,7 @@ extension UniqueArray { /// estimate of its count, then the array's storage may need to be resized /// more than once. /// - /// - Parameters + /// - Parameters: /// - newElements: A container whose contents to copy into the array. /// /// - Complexity: O(`newElements.count`), when amortized over many invocations @@ -289,7 +289,7 @@ extension UniqueArray { /// estimate of its count, then the array's storage may need to be resized /// more than once. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to copy into the array. /// /// - Complexity: O(*m*), where *m* is the length of `newElements`, when @@ -318,7 +318,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: A container whose contents to copy into the array. /// /// - Complexity: O(`newElements.count`), when amortized over many invocations diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift index bfda4f1c..552da64d 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift @@ -20,7 +20,7 @@ extension UniqueArray where Element: ~Copyable { /// number of new elements, then this reallocates the array's storage to /// grow its capacity, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - count: The number of items to append to the array. /// - initializer: A callback that gets called exactly once to directly /// populate newly reserved storage within the array. The function @@ -99,7 +99,7 @@ extension UniqueArray where Element: ~Copyable { /// removes the elements in the given subrange without any replacement. /// Calling `removeSubrange(subrange)` is preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newCount: the number of items to replace the old subrange. @@ -145,7 +145,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: A fully initialized buffer whose contents to move into @@ -182,7 +182,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - items: An output span whose contents are to be moved into the array. @@ -220,7 +220,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: An array whose contents to move into `self`. @@ -256,7 +256,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: An array whose contents to move into `self`. diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift index 0da21c28..55e936b2 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift @@ -104,7 +104,7 @@ extension UniqueArray where Element: ~Copyable { /// then this reallocates storage to extend its capacity, using a geometric /// growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the array. /// @@ -130,7 +130,7 @@ extension UniqueArray where Element: ~Copyable { /// then this reallocates storage to extend its capacity, using a geometric /// growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents to move into /// the array. /// - index: The position at which to insert the new items. @@ -157,7 +157,7 @@ extension UniqueArray where Element: ~Copyable { /// then this reallocates storage to extend its capacity, using a geometric /// growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents to move into /// the array. /// - index: The position at which to insert the new items. @@ -182,7 +182,7 @@ extension UniqueArray where Element: ~Copyable { /// then this reallocates storage to extend its capacity, using a geometric /// growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An array whose contents to move into `self`. /// /// - Complexity: O(`self.count` + `items.count`) @@ -207,7 +207,7 @@ extension UniqueArray where Element: ~Copyable { /// then this reallocates storage to extend its capacity, using a geometric /// growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the array. /// @@ -241,7 +241,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -271,7 +271,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -299,7 +299,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. @@ -329,7 +329,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. @@ -364,7 +364,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. @@ -396,7 +396,7 @@ extension UniqueArray { /// then this reallocates the array's storage to extend its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the array. /// - index: The position at which to insert the new elements. It must be /// a valid index of the array. diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift index 56be6e92..5d5c977e 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift @@ -49,7 +49,7 @@ extension UniqueArray where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newItemCount: the maximum number of items to replace the old subrange. @@ -116,7 +116,7 @@ extension UniqueArray where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - consumer: A callback that gets called at most once to consume @@ -174,7 +174,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: A fully initialized buffer whose contents to move into @@ -213,7 +213,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - items: An input span whose contents are to be moved into the array. @@ -251,7 +251,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - items: An output span whose contents are to be moved into the array. @@ -290,7 +290,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: An array whose contents to move into `self`. @@ -330,7 +330,7 @@ extension UniqueArray where Element: ~Copyable { /// without replacement. Calling the `removeSubrange(_:)` method instead is /// preferred in this case. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the array. /// - newElements: An array whose contents to move into `self`. diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 8a9c1392..a79bd23e 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -91,7 +91,7 @@ extension RigidDeque where Element: ~Copyable { /// } /// // `buffer` now contains [999, 0, 1, 2, 3] /// - /// - Parameters + /// - Parameters: /// - maximumCount: The maximum number of items to append to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. @@ -119,7 +119,7 @@ extension RigidDeque where Element: ~Copyable { /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// @@ -139,7 +139,7 @@ extension RigidDeque where Element: ~Copyable { /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents need to be appended to this deque. /// /// - Complexity: O(`items.count`) @@ -161,7 +161,7 @@ extension RigidDeque where Element: ~Copyable { /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents need to be appended to this deque. /// /// - Complexity: O(`items.count`) @@ -189,7 +189,7 @@ extension RigidDeque where Element: ~Copyable { /// producer; if the producer has more, then they remain available after this /// method returns. /// - /// - Parameters + /// - Parameters: /// - maximumCount: The maximum number of items to append to the deque, or /// nil to use all available capacity. /// - producer: A producer that generates the items to append. @@ -219,7 +219,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -240,7 +240,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -257,7 +257,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// span, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A span whose contents to copy into the deque. /// /// - Complexity: O(`items.count`) @@ -287,7 +287,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `newElements`. @@ -305,7 +305,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `newElements`. @@ -327,7 +327,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`. diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index c6e34f97..ec8d79c1 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -78,7 +78,7 @@ extension RigidDeque where Element: ~Copyable { /// previously produced items are discarded and the initializer rethrows the /// error. /// - /// - Parameters + /// - Parameters: /// - producer: A producer that generates the items to append to the new /// deque. /// diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index aa7f72a2..238e974f 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -119,7 +119,7 @@ extension RigidDeque where Element: ~Copyable { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// - index: The position at which to insert the new items. @@ -154,7 +154,7 @@ extension RigidDeque where Element: ~Copyable { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents to move into /// the deque. /// - index: The position at which to insert the new items. @@ -184,7 +184,7 @@ extension RigidDeque where Element: ~Copyable { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents to move into /// the deque. /// - index: The position at which to insert the new items. @@ -268,7 +268,7 @@ extension RigidDeque /* where Element: Copyable */ { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -306,7 +306,7 @@ extension RigidDeque /* where Element: Copyable */ { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -334,7 +334,7 @@ extension RigidDeque /* where Element: Copyable */ { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. @@ -406,7 +406,7 @@ extension RigidDeque /* where Element: Copyable */ { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. @@ -438,7 +438,7 @@ extension RigidDeque /* where Element: Copyable */ { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. @@ -468,7 +468,7 @@ extension RigidDeque /* where Element: Copyable */ { /// If the capacity of the deque isn't sufficient to accommodate the new /// elements, then this method triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 402a51f5..5f26171d 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -96,7 +96,7 @@ extension RigidDeque where Element: ~Copyable { /// } /// // `buffer` now contains [0, 1, 2, 3, 999] /// - /// - Parameters + /// - Parameters: /// - newItemCount: The maximum number of items to prepend to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. @@ -122,7 +122,7 @@ extension RigidDeque where Element: ~Copyable { /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// @@ -143,7 +143,7 @@ extension RigidDeque where Element: ~Copyable { /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents need to be prepended to this deque. /// /// - Complexity: O(`items.count`) @@ -165,7 +165,7 @@ extension RigidDeque where Element: ~Copyable { /// If the deque does not have sufficient capacity to hold all items in its /// storage, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents need to be prepended to this deque. /// /// - Complexity: O(`items.count`) @@ -198,7 +198,7 @@ extension RigidDeque where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - maximumCount: The maximum number of items to prepend to the deque, or /// nil to use all available capacity. @@ -230,7 +230,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -252,7 +252,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// buffer, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -270,7 +270,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// span, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A span whose contents to copy into the deque. /// /// - Complexity: O(`items.count`) @@ -323,7 +323,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// operation works by first appending the items, then finalizing the /// prepend by rotating them in place as a postprocessing step. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`. @@ -340,7 +340,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// container, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(`items.count`) @@ -427,7 +427,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`. @@ -443,7 +443,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`. @@ -459,7 +459,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`. @@ -475,7 +475,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`. diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index aee4d20c..8c6a1df5 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -48,7 +48,7 @@ extension RigidDeque where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - newItemCount: the maximum number of items to replace the old subrange. @@ -121,7 +121,7 @@ extension RigidDeque where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - newItemCount: the maximum number of items to replace the old subrange. @@ -180,7 +180,7 @@ extension RigidDeque where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - items: A fully initialized buffer whose contents to move into @@ -224,7 +224,7 @@ extension RigidDeque where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - items: An input span whose contents are to be moved into the deque. @@ -263,7 +263,7 @@ extension RigidDeque where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the deque. /// - items: An output span whose contents are to be moved into the deque. @@ -312,7 +312,7 @@ extension RigidDeque where Element: ~Copyable { /// items to their correct positions given the adjusted count. This adds some /// overhead compared to adding exactly as many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - newItemCount: The maximum number of items to insert into the deque. diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift index b00f8f01..b9cc56a2 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -74,7 +74,7 @@ extension UniqueDeque where Element: ~Copyable { /// } /// // `buffer` now contains [999, 0, 1, 2, 3] /// - /// - Parameters + /// - Parameters: /// - maximumCount: The maximum number of items to append to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. @@ -104,7 +104,7 @@ extension UniqueDeque where Element: ~Copyable { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// @@ -126,7 +126,7 @@ extension UniqueDeque where Element: ~Copyable { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents need to be appended to this deque. /// /// - Complexity: O(`items.count`) when amortized over many similar @@ -150,7 +150,7 @@ extension UniqueDeque where Element: ~Copyable { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents need to be appended to this deque. /// /// - Complexity: O(`items.count`) when amortized over many similar @@ -181,7 +181,7 @@ extension UniqueDeque where Element: ~Copyable { /// producer; if the producer has more, then they remain available after this /// method returns. /// - /// - Parameters + /// - Parameters: /// - maximumCount: The maximum number of items to append to the deque, or /// nil to append every item the producer generates. /// - producer: A producer that generates the items to append. @@ -231,7 +231,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// number of new elements, then this method reallocates the deque's storage /// to grow it, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -251,7 +251,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// number of new elements, then this method reallocates the deque's storage /// to grow it, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -270,7 +270,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// number of new elements, then this method reallocates the deque's storage /// to grow it, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A span whose contents to copy into the deque. /// /// - Complexity: O(`items.count`) when amortized over many similar @@ -301,7 +301,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`, when amortized @@ -322,7 +322,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// estimate of its count, then the deque's storage may need to be resized /// more than once. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`, when @@ -351,7 +351,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`, when diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift index 273c25b0..3d7d50bf 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift @@ -71,7 +71,7 @@ extension UniqueDeque where Element: ~Copyable { /// Creates a new unique deque of the specified capacity, populating it with /// all items generated by a given producer. /// - /// - Parameters + /// - Parameters: /// - producer: A producer that generates the items to append to the new /// deque. /// diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index bfbc626f..bdb014e7 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -124,7 +124,7 @@ extension UniqueDeque where Element: ~Copyable { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// - index: The position at which to insert the new items. @@ -161,7 +161,7 @@ extension UniqueDeque where Element: ~Copyable { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents to move into /// the deque. /// - index: The position at which to insert the new items. @@ -193,7 +193,7 @@ extension UniqueDeque where Element: ~Copyable { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents to move into /// the deque. /// - index: The position at which to insert the new items. @@ -281,7 +281,7 @@ extension UniqueDeque /* where Element: Copyable */ { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -321,7 +321,7 @@ extension UniqueDeque /* where Element: Copyable */ { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. The buffer /// must be fully initialized. /// - index: The position at which to insert the new elements. It must be @@ -351,7 +351,7 @@ extension UniqueDeque /* where Element: Copyable */ { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. @@ -426,7 +426,7 @@ extension UniqueDeque /* where Element: Copyable */ { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. @@ -460,7 +460,7 @@ extension UniqueDeque /* where Element: Copyable */ { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. @@ -492,7 +492,7 @@ extension UniqueDeque /* where Element: Copyable */ { /// then this reallocates the deque's storage to grow its capacity, using a /// geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to insert into the deque. /// - index: The position at which to insert the new elements. It must be /// a valid index of the deque. diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index 6ed91d33..90611346 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -79,7 +79,7 @@ extension UniqueDeque where Element: ~Copyable { /// } /// // `buffer` now contains [0, 1, 2, 3, 999] /// - /// - Parameters + /// - Parameters: /// - maximumCount: The maximum number of items to prepend to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. @@ -108,7 +108,7 @@ extension UniqueDeque where Element: ~Copyable { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// @@ -131,7 +131,7 @@ extension UniqueDeque where Element: ~Copyable { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An input span whose contents need to be prepended to this deque. /// /// - Complexity: O(`items.count`) when amortized over many similar @@ -155,7 +155,7 @@ extension UniqueDeque where Element: ~Copyable { /// elements, then this method reallocates the deque's storage to grow it, /// using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: An output span whose contents need to be prepended to this deque. /// /// - Complexity: O(`items.count`) when amortized over many similar @@ -191,7 +191,7 @@ extension UniqueDeque where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - maximumCount: The maximum number of items to prepend to the deque, or /// nil to use all available capacity. /// - producer: A producer that generates the items to prepend. @@ -241,7 +241,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// number of new elements, then this method reallocates the deque's storage /// to grow it, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -263,7 +263,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// number of new elements, then this method reallocates the deque's storage /// to grow it, using a geometric growth rate. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to copy into /// the deque. /// @@ -282,7 +282,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// span, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: A span whose contents to copy into the deque. /// /// - Complexity: O(`items.count`) when amortized over many similar @@ -336,7 +336,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// operation works by first appending the items, then finalizing the /// prepend by rotating them in place as a postprocessing step. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`, as amortized @@ -354,7 +354,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// container, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(`items.count`) when amortized over many similar @@ -444,7 +444,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items`, as amortized @@ -461,7 +461,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - newElements: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items` when amortized @@ -478,7 +478,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items` when amortized @@ -495,7 +495,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// If the deque does not have sufficient capacity to hold all items in the /// sequence, then this triggers a runtime error. /// - /// - Parameters + /// - Parameters: /// - items: The new elements to copy into the deque. /// /// - Complexity: O(*m*), where *m* is the length of `items` when amortized diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index a2ca9d54..bec74b5b 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -63,7 +63,7 @@ extension UniqueDeque where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - newItemCount: the maximum number of items to replace the old subrange. @@ -128,7 +128,7 @@ extension UniqueDeque where Element: ~Copyable { /// the adjusted count. This adds some overhead compared to adding exactly as /// many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - newItemCount: the maximum number of items to replace the old subrange. @@ -186,7 +186,7 @@ extension UniqueDeque where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - items: A fully initialized buffer whose contents to move into @@ -231,7 +231,7 @@ extension UniqueDeque where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - items: An input span whose contents are to be moved into the deque. @@ -271,7 +271,7 @@ extension UniqueDeque where Element: ~Copyable { /// without replacement. This case is more directly expressed by calling /// `removeSubrange`. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the array to replace. The bounds of /// the range must be valid indices in the deque. /// - items: An output span whose contents are to be moved into the deque. @@ -321,7 +321,7 @@ extension UniqueDeque where Element: ~Copyable { /// items to their correct positions given the adjusted count. This adds some /// overhead compared to adding exactly as many items as promised. /// - /// - Parameters + /// - Parameters: /// - subrange: The subrange of the deque to replace. The bounds of /// the range must be valid indices in the deque. /// - maximumCount: The maximum number of items to insert into the deque. diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index 05853add..b9546237 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -679,7 +679,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// it throws an error. In such cases, the deque keeps all items that were /// successfully initialized before the callback terminated. /// - /// - Parameters + /// - Parameters: /// - capacity: The maximum number of items to append to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function @@ -739,7 +739,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// } /// // `buffer` now contains [0, 1, 2, 3, 4, 5, 10] /// - /// - Parameters + /// - Parameters: /// - count: The number of items to append to the deque. /// - body: A callback that gets called at most twice to directly /// populate newly reserved storage within the deque. The function @@ -777,7 +777,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// This unchecked routine does not verify that the deque has sufficient /// capacity to store the new items. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// @@ -804,7 +804,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { /// This unchecked routine does not verify that the deque has sufficient /// capacity to store the new items. /// - /// - Parameters + /// - Parameters: /// - items: A fully initialized buffer whose contents to move into /// the deque. /// From 8ef702c8a5635656666f079839d063832c6cdd49 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 5 Feb 2026 17:07:03 -0800 Subject: [PATCH 69/75] Remove workaround for OutputSpan.wUMBP bug --- .../RigidArray/RigidArray+Append.swift | 2 +- .../RigidArray/RigidArray+Insertions.swift | 2 +- .../RigidArray/RigidArray+Replacements.swift | 8 ++-- .../Extensions/OutputSpan+Extras.swift | 43 ++----------------- .../Protocols/BorrowingIteratorProtocol.swift | 2 +- .../RigidDeque/RigidDeque+Append.swift | 2 +- .../RigidDeque/RigidDeque+Insertions.swift | 6 +-- .../RigidDeque/RigidDeque+Prepend.swift | 2 +- .../RigidDeque/RigidDeque+Replacements.swift | 6 +-- .../UniqueDeque/UniqueDeque+Append.swift | 2 +- .../UniqueDeque/UniqueDeque+Insertions.swift | 6 +-- .../UniqueDeque/UniqueDeque+Prepend.swift | 2 +- .../UniqueDeque+Replacements.swift | 6 +-- 13 files changed, 27 insertions(+), 62 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index bda586e3..0d4d58f1 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -150,7 +150,7 @@ extension RigidArray where Element: ~Copyable { public mutating func append( moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.append(moving: source) count = 0 diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index 722dc2b9..c27a1743 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -197,7 +197,7 @@ extension RigidArray where Element: ~Copyable { moving items: inout OutputSpan, at index: Int ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.insert(moving: source, at: index) count = 0 diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 7b833944..ed195185 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -242,7 +242,7 @@ extension RigidArray where Element: ~Copyable { moving newElements: UnsafeMutableBufferPointer, ) { replace(removing: subrange, addingCount: newElements.count) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._moveInitializePrefix(from: newElements) } } @@ -319,7 +319,7 @@ extension RigidArray where Element: ~Copyable { removing subrange: Range, moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.replace(removing: subrange, moving: source) count = 0 @@ -442,7 +442,7 @@ extension RigidArray { copying newElements: UnsafeBufferPointer ) { replace(removing: subrange, addingCount: newElements.count) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in count = unsafe buffer._initializePrefix(copying: newElements) } } @@ -552,7 +552,7 @@ extension RigidArray { newCount: Int ) { self.replace(removing: subrange, addingCount: newCount) { target in - target._withUnsafeMutableBufferPointer { dst, dstCount in + target.withUnsafeMutableBufferPointer { dst, dstCount in let done: Void? = newElements.withContiguousStorageIfAvailable { src in let i = unsafe dst._initializePrefix(copying: src) precondition( diff --git a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift index 045f7ec2..77318a9c 100644 --- a/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift +++ b/Sources/ContainersPreview/Extensions/OutputSpan+Extras.swift @@ -41,7 +41,7 @@ extension OutputSpan where Element: ~Copyable { @inlinable package mutating func _popLast() -> Element? { // FIXME: This needs to be in the stdlib. - _withUnsafeMutableBufferPointer { buffer, count in + withUnsafeMutableBufferPointer { buffer, count in guard count > 0 else { return nil } count &-= 1 return buffer.moveElement(from: count) @@ -59,7 +59,7 @@ extension OutputSpan where Element: ~Copyable { ) { // FIXME: This needs to be in the stdlib. guard source.count > 0 else { return } - self._withUnsafeMutableBufferPointer { dst, dstCount in + self.withUnsafeMutableBufferPointer { dst, dstCount in let dstEnd = dstCount + source.count precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") dst @@ -92,7 +92,7 @@ extension OutputSpan where Element: ~Copyable { @_lifetime(self: copy self) package mutating func _append(moving source: inout OutputSpan) { // FIXME: This needs to be in the stdlib. - source._withUnsafeMutableBufferPointer { src, srcCount in + source.withUnsafeMutableBufferPointer { src, srcCount in let items = src._extracting(uncheckedFrom: 0, to: srcCount) self._append(moving: items) srcCount = 0 @@ -106,7 +106,7 @@ extension OutputSpan /*where Element: Copyable*/ { @_lifetime(self: copy self) package mutating func _append(copying source: UnsafeBufferPointer) { // FIXME: This needs to be in the stdlib. - self._withUnsafeMutableBufferPointer { dst, dstCount in + self.withUnsafeMutableBufferPointer { dst, dstCount in let dstEnd = dstCount + source.count precondition(dstEnd <= dst.count, "OutputSpan capacity overflow") dst @@ -126,39 +126,4 @@ extension OutputSpan /*where Element: Copyable*/ { } } -@available(SwiftStdlib 5.0, *) -extension OutputSpan where Element: ~Copyable { - @_alwaysEmitIntoClient - @inlinable // FIXME: This should be implied by @_aeic - @_lifetime(self: copy self) - package mutating func _withUnsafeMutableBufferPointer( - _ body: ( - UnsafeMutableBufferPointer, - _ initializedCount: inout Int - ) throws(E) -> R - ) throws(E) -> R { - // FIXME: Work around https://github.com/apple/swift-collections/issues/561 / rdar://169036911 - let capacity = self.capacity - let r = try self.withUnsafeMutableBufferPointer { buffer, initializedCount throws(E) -> R? in - if buffer.count == capacity { - return try body(buffer, &initializedCount) - } - return nil - } - if let r { return r } - - let start = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow. - let correctedBuffer = UnsafeMutableRawBufferPointer( - start: .init(mutating: start), // Wow, wow. - count: self.capacity &* MemoryLayout.stride) - return try correctedBuffer.withMemoryRebound(to: Element.self) { correctBuffer throws(E) in - precondition(correctBuffer.count == self.capacity) - return try self.withUnsafeMutableBufferPointer { badBuffer, count throws(E) in - precondition(badBuffer.baseAddress == correctBuffer.baseAddress) - return try body(correctBuffer, &count) - } - } - } -} - #endif diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift index 68cb55db..651937d9 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift @@ -146,7 +146,7 @@ where Self: ~Copyable & ~Escapable, Element: Copyable @_lifetime(self: copy self) @_transparent public mutating func copyContents(into target: inout OutputSpan) { - target._withUnsafeMutableBufferPointer { dst, dstCount in + target.withUnsafeMutableBufferPointer { dst, dstCount in var tail = dst._extracting(droppingFirst: dstCount) while !tail.isEmpty { let src = nextSpan(maximumCount: tail.count) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index a79bd23e..0997dec7 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -169,7 +169,7 @@ extension RigidDeque where Element: ~Copyable { public mutating func append( moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.append(moving: source) count = 0 diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 238e974f..f731f276 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -134,7 +134,7 @@ extension RigidDeque where Element: ~Copyable { guard !items.isEmpty else { return } var remainder = items insert(addingCount: items.count, at: index) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -196,7 +196,7 @@ extension RigidDeque where Element: ~Copyable { moving items: inout OutputSpan, at index: Int ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.insert(moving: source, at: index) count = 0 @@ -282,7 +282,7 @@ extension RigidDeque /* where Element: Copyable */ { guard items.count > 0 else { return } var remainder = items insert(addingCount: remainder.count, at: index) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( fromContentsOf: remainder._extracting(first: buffer.count)) remainder = remainder._extracting(droppingFirst: buffer.count) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 5f26171d..7ace8d56 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -173,7 +173,7 @@ extension RigidDeque where Element: ~Copyable { public mutating func prepend( moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.prepend(moving: source) count = 0 diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 8c6a1df5..8b7758e0 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -194,7 +194,7 @@ extension RigidDeque where Element: ~Copyable { ) { var remainder = items replace(removing: subrange, addingCount: remainder.count) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -274,7 +274,7 @@ extension RigidDeque where Element: ~Copyable { removing subrange: Range, moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.replace(removing: subrange, moving: source) count = 0 @@ -372,7 +372,7 @@ extension RigidDeque /* where Element: Copyable */ { ) { var remainder = items replace(removing: subrange, addingCount: remainder.count) { target in - target._withUnsafeMutableBufferPointer { dst, dstCount in + target.withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift index b9cc56a2..7302dde2 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -159,7 +159,7 @@ extension UniqueDeque where Element: ~Copyable { public mutating func append( moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.append(moving: source) count = 0 diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index bdb014e7..3bd676b1 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -140,7 +140,7 @@ extension UniqueDeque where Element: ~Copyable { guard !items.isEmpty else { return } var remainder = items insert(addingCount: items.count, at: index) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -206,7 +206,7 @@ extension UniqueDeque where Element: ~Copyable { moving items: inout OutputSpan, at index: Int ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.insert(moving: source, at: index) count = 0 @@ -296,7 +296,7 @@ extension UniqueDeque /* where Element: Copyable */ { guard items.count > 0 else { return } var remainder = items insert(addingCount: remainder.count, at: index) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in buffer.initializeAll( fromContentsOf: remainder._extracting(first: buffer.count)) remainder = remainder._extracting(droppingFirst: buffer.count) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index 90611346..de4408fb 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -164,7 +164,7 @@ extension UniqueDeque where Element: ~Copyable { public mutating func prepend( moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.prepend(moving: source) count = 0 diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index bec74b5b..3f565945 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -200,7 +200,7 @@ extension UniqueDeque where Element: ~Copyable { ) { var remainder = items replaceSubrange(subrange, addingCount: remainder.count) { target in - target._withUnsafeMutableBufferPointer { buffer, count in + target.withUnsafeMutableBufferPointer { buffer, count in buffer.moveInitializeAll( fromContentsOf: remainder._trim(first: buffer.count)) count = buffer.count @@ -282,7 +282,7 @@ extension UniqueDeque where Element: ~Copyable { _ subrange: Range, moving items: inout OutputSpan ) { - items._withUnsafeMutableBufferPointer { buffer, count in + items.withUnsafeMutableBufferPointer { buffer, count in let source = buffer._extracting(first: count) unsafe self.replaceSubrange(subrange, moving: source) count = 0 @@ -381,7 +381,7 @@ extension UniqueDeque /* where Element: Copyable */ { ) { var remainder = items replaceSubrange(subrange, addingCount: remainder.count) { target in - target._withUnsafeMutableBufferPointer { dst, dstCount in + target.withUnsafeMutableBufferPointer { dst, dstCount in dst.initializeAll(fromContentsOf: remainder._trim(first: dst.count)) dstCount += dst.count } From b21316ea08ae9380b1aac0937bd112017c752f2a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 9 Feb 2026 17:28:31 -0800 Subject: [PATCH 70/75] [DequeModule] Add some top-level RigidDeque/UniqueDeque docs --- .../UniqueArray/UniqueArray.swift | 10 ++- .../DequeModule/RigidDeque/RigidDeque.swift | 81 ++++++++++++++++++- .../DequeModule/UniqueDeque/UniqueDeque.swift | 71 ++++++++++++++++ 3 files changed, 157 insertions(+), 5 deletions(-) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index 17cfaae3..404c7c15 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -37,26 +37,28 @@ public struct UniqueArray: ~Copyable { /// /// `UniqueArray` instances automatically resize their underlying storage as /// needed to accommodate newly inserted items, using a geometric growth curve. -/// This frees code using `UniqueArray` from having to allocate enough +/// This lets code using `UniqueArray` avoid having to allocate enough /// capacity in advance; on the other hand, it makes it difficult to tell /// when and where such reallocations may happen. /// -/// For example, appending an element to a dynamic array has highly variable +/// For example, appending an element to a `UniqueArray` has highly variable /// complexity; often, it runs at a constant cost, but if the operation has to /// resize storage, then the cost of an individual append suddenly becomes /// proportional to the size of the whole array. /// /// The geometric growth curve allows the cost of such latency spikes to /// get amortized across repeated invocations, bringing the average cost back -/// to O(1); but they make this construct less suitable for use cases that +/// to O(1); but the spikes make this construct less suitable for use cases that /// expect predictable, consistent performance on every operation. /// /// Implicit growth also makes it more difficult to predict/analyze the amount /// of memory an algorithm would need. Developers targeting environments with /// stringent limits on heap allocations may prefer to avoid using dynamically -/// resizing array types as a matter of policy. The type `RigidArray` provides +/// resizing container types as a matter of policy. The type `RigidArray` provides /// a fixed-capacity array variant that caters specifically for these use cases, /// trading ease-of-use for more consistent/predictable execution. +/// For copyable elements, the copy-on-write `Array` type is an +/// even more convenient and expressive choice. @available(SwiftStdlib 5.0, *) @frozen public struct UniqueArray: ~Copyable { diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index 1f7f82d8..caace267 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -29,7 +29,86 @@ public struct RigidDeque: ~Copyable { #else /// A fixed capacity, heap allocated, noncopyable double-ended queue of -/// potentially noncopyable elements. +/// potentially noncopyable elements. A deque (pronounced "deck") +/// is an ordered random-access container that supports efficient +/// insertions and removals from both ends. +/// +/// Deques implement the same indexing semantics as arrays: they use integer +/// indices, and the first element of a nonempty deque is always at logical +/// index zero. +/// +/// var colors = RigidDeque(capacity: 5) +/// colors.append("red") +/// colors.prepend("yellow") +/// colors.append("blue") +/// // `colors` now contains "yellow", "red", "blue" +/// +/// print(colors[0]) // prints "yellow" +/// print(colors[1]) // prints "red" +/// +/// print(colors.removeFirst()) // prints "yellow" +/// print(colors.removeLast()) // prints "blue" +/// // `colors` now contains "red" +/// +/// This double-ended nature makes deques particularly well-suited for +/// representing first-in-first-out (FIFO) buffers, where new items are +/// inserted at one end, and old items are retrieved from the other. +/// For example, they are ideal for modeling buffered data streams, such as +/// networking channels, or other producer/consumer scenarios. +/// +/// ### Implementation Notes +/// +/// `RigidDeque` implements a ring buffer. It stores its elements in a +/// single heap-allocated buffer, and to allow fast insertions and removals +/// from both ends, the buffer behaves as if its ends were glued together into +/// a ring shape. This comes at the cost of potentially discontiguous storage, as +/// the contents of the ring buffer sometimes wrap around the edges. +/// +/// While the first item in the deque is always addressed by the logical index +/// zero, its physical location can be anywhere in the underlying ring buffer. +/// Compare this with `RigidArray`'s contiguous storage, where the first item +/// is always stored at the start of the buffer, so new data can always be +/// efficiently appended to the end, but inserting at the front is relatively +/// slow, as existing elements need to be shifted to make room. +/// +/// ### Fixed Storage Capacity +/// +/// `RigidDeque` instances are created with a specific maximum capacity. +/// Elements can be added to the deque up to that capacity, but no more: trying +/// to add an item to a full deque results in a runtime trap. +/// +/// var items = RigidDeque(capacity: 2) +/// items.prepend(1) +/// items.prepend(2) +/// items.prepend(3) // Runtime error: RigidDeque capacity overflow +/// +/// Rigid deques provide convenience properties to help verify that it has +/// enough available capacity: `isFull` and `freeCapacity`. +/// +/// guard items.freeCapacity >= 4 else { throw CapacityOverflow() } +/// items.append(copying: newItems) +/// +/// It is possible to extend or shrink the capacity of a rigid deque instance, +/// but this needs to be done explicitly, with operations dedicated to this +/// purpose (such as ``reserveCapacity`` and ``reallocate(capacity:)``). +/// The deque never resizes itself automatically. +/// +/// Therefore, it is necessary to perform careful manual analysis (or up front +/// runtime capacity checks) to prevent the deque from overflowing its storage. +/// This makes this type more difficult to use than a dynamically resizing +/// container. However, it allows this construct to provide predictably stable +/// performance. +/// +/// This trading of usability in favor of stable performance limits `RigidDeque` +/// to the most resource-constrained of use cases, such as space-constrained +/// environments that require carefully accounting of every heap allocation, or +/// time-constrained applications that cannot accommodate unexpected latency +/// spikes due to a reallocation getting triggered at an inopportune moment. +/// +/// For use cases outside of these narrow domains, we generally recommmend +/// to use the dynamically resizing ``UniqueDeque`` type rather than +/// `RigidDeque`. For copyable elements, the copy-on-write `Deque` type is an +/// even more convenient and expressive choice. @available(SwiftStdlib 5.0, *) @frozen @safe diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift index 761eb6c5..ab52644c 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque.swift @@ -16,6 +16,10 @@ import ContainersPreview #if compiler(<6.2) +/// A dynamically self-resizing, heap allocated, noncopyable double-ended +/// queue of potentially noncopyable elements. A deque (pronounced "deck") +/// is an ordered random-access container that supports efficient +/// insertions and removals from both ends. @frozen @available(*, unavailable, message: "UniqueDeque requires a Swift 6.2 toolchain") public struct UniqueDeque: ~Copyable { @@ -26,6 +30,73 @@ public struct UniqueDeque: ~Copyable { #else +/// A dynamically self-resizing, heap allocated, noncopyable double-ended +/// queue of potentially noncopyable elements. A deque (pronounced "deck") +/// is an ordered random-access container that supports efficient +/// insertions and removals from both ends. +/// +/// Deques implement the same indexing semantics as arrays: they use integer +/// indices, and the first element of a nonempty deque is always at logical +/// index zero. +/// +/// var colors = UniqueDeque() +/// colors.append("red") +/// colors.prepend("yellow") +/// colors.append("blue") +/// // `colors` now contains "yellow", "red", "blue" +/// +/// print(colors[0]) // prints "yellow" +/// print(colors[1]) // prints "red" +/// +/// print(colors.removeFirst()) // prints "yellow" +/// print(colors.removeLast()) // prints "blue" +/// // `colors` now contains "red" +/// +/// This double-ended nature makes deques particularly well-suited for +/// representing first-in-first-out (FIFO) buffers, where new items are +/// inserted at one end, and old items are retrieved from the other. +/// For example, they are ideal for modeling buffered data streams, such as +/// networking channels, or other producer/consumer scenarios. +/// +/// ### Implementation Notes +/// +/// `UniqueDeque` implements a ring buffer. It stores its elements in a +/// single heap-allocated buffer, and to allow fast insertions and removals +/// from both ends, the buffer behaves as if its ends were glued together into +/// a ring shape. This comes at the cost of potentially discontiguous storage, as +/// the contents of the ring buffer sometimes wrap around the edges. +/// +/// While the first item in the deque is always addressed by the logical index +/// zero, its physical location can be anywhere in the underlying ring buffer. +/// Compare this with `UniqueArray`'s contiguous storage, where the first item +/// is always stored at the start of the buffer, so new data can always be +/// efficiently appended to the end, but inserting at the front is relatively +/// slow, as existing elements need to be shifted to make room. +/// +/// ### Dynamic Storage Sizing +/// +/// `UniqueDeque` instances automatically resize their underlying storage as +/// needed to accommodate newly inserted items, using a geometric growth curve. +/// This lets code using `UniqueDeque` avoid having to carefully allocate enough +/// capacity in advance; on the other hand, it makes it difficult to tell +/// when and where such reallocations may happen. +/// +/// For example, appending an element to a `UniqueDeque` has highly variable +/// complexity; often, it runs at a constant cost, but if the operation has to +/// resize storage, then the cost of an individual append suddenly becomes +/// proportional to the size of the whole container. +/// +/// The geometric growth curve allows the cost of such latency spikes to +/// get amortized across repeated invocations, bringing the average cost back +/// to O(1); but the spikes make this construct less suitable for use cases that +/// expect predictable, consistent performance on every operation. +/// +/// Implicit growth also makes it more difficult to predict/analyze the amount +/// of memory an algorithm would need. Developers targeting environments with +/// stringent limits on heap allocations may prefer to avoid using dynamically +/// resizing container types as a matter of policy. The type `RigidDeque` +/// provides a fixed-capacity deque variant that caters specifically for these +/// use cases, trading ease-of-use for more consistent/predictable execution. @available(SwiftStdlib 5.0, *) @frozen @safe From 5b05a1b42ba6ae82684f099bbbe25fab06821537 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 9 Feb 2026 17:40:18 -0800 Subject: [PATCH 71/75] Update README in preparation of the 1.4.0 release --- README.md | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 10de447b..c357f14b 100644 --- a/README.md +++ b/README.md @@ -10,25 +10,28 @@ Read more about the package, and the intent behind it, in the [announcement on s The package currently provides the following implementations: -- [`BitSet`][BitSet] and [`BitArray`][BitArray], dynamic bit collections. +- [`UniqueArray`][UniqueArray] and [`RigidArray`][RigidArray], noncopyable array variants trading some of `Array`'s flexibility for more predictable performance. -- [`Deque`][Deque], a double-ended queue backed by a ring buffer. Deques are range-replaceable, mutable, random-access collections. - -- [`Heap`][Heap], a min-max heap backed by an array, suitable for use as a priority queue. +- [`Deque`][Deque], [`UniqueDeque`][UniqueDeque] and [`RigidDeque`][RigidDeque], variants of a double-ended queue type backed by a ring buffer. Deques are range-replaceable, mutable, random-access collections. - [`OrderedSet`][OrderedSet], a variant of the standard `Set` where the order of items is well-defined and items can be arbitrarily reordered. Uses a `ContiguousArray` as its backing store, augmented by a separate hash table of bit packed offsets into it. - [`OrderedDictionary`][OrderedDictionary], an ordered variant of the standard `Dictionary`, providing similar benefits. -- [`TreeSet`][TreeSet] and [`TreeDictionary`][TreeDictionary], persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements. +- [`BitSet`][BitSet] and [`BitArray`][BitArray], dynamic bit collections. -- [`UniqueArray`][UniqueArray] and [`RigidArray`][RigidArray], noncopyable array variants trading some of `Array`'s flexibility for more predictable performance. +- [`Heap`][Heap], a min-max heap backed by an array, suitable for use as a priority queue. + +- [`TreeSet`][TreeSet] and [`TreeDictionary`][TreeDictionary], persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements. - [`TrailingArray`][TrailingArray], a low-level, ownership-aware variant of `ManagedBuffer`, for interoperability with C constructs that consist of a fixed-size header directly followed by variable-size storage buffer. [BitSet]: https://swiftpackageindex.com/apple/swift-collections/documentation/bitcollections/bitset [BitArray]: https://swiftpackageindex.com/apple/swift-collections/documentation/bitcollections/bitarray [Deque]: https://swiftpackageindex.com/apple/swift-collections/documentation/dequemodule/deque +[RigidDeque]: https://swiftpackageindex.com/apple/swift-collections/documentation/dequemodule/rigiddeque +[UniqueDeque]: https://swiftpackageindex.com/apple/swift-collections/documentation/dequemodule/uniquedeque +[Deque]: https://swiftpackageindex.com/apple/swift-collections/documentation/dequemodule/deque [Heap]: https://swiftpackageindex.com/apple/swift-collections/documentation/heapmodule/heap [OrderedSet]: https://swiftpackageindex.com/apple/swift-collections/documentation/orderedcollections/orderedset [OrderedDictionary]: https://swiftpackageindex.com/apple/swift-collections/documentation/orderedcollections/ordereddictionary @@ -57,7 +60,7 @@ The Swift Collections package is source stable. The version numbers follow [Sema ### Public API -The public API of version 1.3 of the `swift-collections` package consists of non-underscored declarations that are marked `public` in the `Collections`, `BitCollections`, `DequeModule`, `HeapModule`, `OrderedCollections` and `HashTreeCollections` modules. +The public API of version 1.4 of the `swift-collections` package consists of non-underscored declarations that are marked `public` in the `Collections`, `BasicContainers`, `BitCollections`, `DequeModule`, `HeapModule`, `OrderedCollections` and `HashTreeCollections` modules. Interfaces that aren't part of the public API may continue to change in any release, including patch releases. @@ -68,9 +71,11 @@ By "underscored declarations" we mean declarations that have a leading underscor - `_FooModule.Bar` (underscored module) - `FooModule.Bar.init(_value:)` (underscored initializer) +Interfaces that get enabled by opting into either of the `UnstableContainersPreview` or `UnstableSortedCollections` package traits are not part of the public API; those interfaces may get removed or changed in any release. + If you have a use case that requires using underscored (or otherwise non-public) APIs, please [submit a Feature Request][enhancement] describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution. -This source compatibility promise only applies to swift-collection when built as a Swift package. (The repository also contains unstable configurations for building swift-collections using CMake and Xcode. These configurations are provided for internal Swift project use only -- such as for building the (private) swift-collections binaries that ship within Swift toolchains.) +This source compatibility promise only applies to swift-collections when built as a Swift package. (The repository also contains unstable configurations for building swift-collections using CMake and Xcode. These configurations are provided for internal Swift project use only -- such as for building the (private) swift-collections binaries that ship within Swift toolchains.) Note that the files in the `Tests`, `Utils`, `Documentation`, `Xcode`, `cmake` and `Benchmarks` subdirectories may change at whim; they may be added, modified or removed in any new release. Do not rely on anything about them. @@ -88,6 +93,7 @@ The following table maps package releases to their minimum required Swift toolch | swift-collections 1.1.x | >= Swift 5.7.2 | >= Xcode 14.2 | | swift-collections 1.2.x | >= Swift 5.10.0 | >= Xcode 15.3 | | swift-collections 1.3.x | >= Swift 6.0.3 | >= Xcode 16.2 | +| swift-collections 1.4.x | >= Swift 6.0.3 | >= Xcode 16.2 | (Note: the package has no minimum deployment target, so while it does require clients to use a recent Swift toolchain to build it, the code itself is able to run on any OS release that supports running Swift code.) @@ -104,7 +110,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/apple/swift-collections.git", - .upToNextMinor(from: "1.3.0") // or `.upToNextMajor + .upToNextMinor(from: "1.4.0") // or `.upToNextMajor ) ], targets: [ @@ -134,15 +140,16 @@ We maintain separate branches for each minor version of the package: | ----------------------- | ----------- | -------- | | swift-collections 1.0.x | release/1.0 | Obsolete | | swift-collections 1.1.x | release/1.1 | Obsolete | -| swift-collections 1.2.x | release/1.2 | Bugfixes only | +| swift-collections 1.2.x | release/1.2 | Obsolete | | swift-collections 1.3.x | release/1.3 | Bugfixes only | +| swift-collections 1.4.x | release/1.4 | Bugfixes only | | n.a. | main | Feature work towards next minor release | Changes must land on the branch corresponding to the earliest release that they will need to ship on. They are periodically propagated to subsequent branches, in the following direction: -`release/1.1` → `release/1.2` → `release/1.3` → `main` +`release/1.3` → `release/1.4` → `main` -For example, anything landing on `release/1.2` will eventually appear on `release/1.3` and then `main` too; there is no need to file standalone PRs for each release line. Change propagation is not instantaneous, as it currently requires manual work -- it is performed by project maintainers. +For example, anything landing on `release/1.3` will eventually appear on `release/1.4` and then `main` too; there is no need to file standalone PRs for each release line. Change propagation is not instantaneous, as it currently requires manual work -- it is performed by project maintainers. ### Working on the package @@ -172,7 +179,7 @@ By submitting a pull request, you represent that you have the right to license y #### Proposing the addition of a new data structure -**Note:** As of 2025, we are fully preoccupied with refactoring our existing data structures to support noncopyable and/or nonescapable element types; this includes designing new container protocols around them. I don't expect we'll have capacity to work on any major new data structure implementations until this effort is complete. +**Note:** We are currently fully preoccupied with refactoring our existing data structures to support noncopyable and/or nonescapable element types; this includes designing new container protocols around them. I don't expect we'll have capacity to work on any major new data structure implementations until this effort is complete. ### Code of Conduct From 3bf8de6e2b719e65cbc3d04a08703b27623ca648 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 12 Feb 2026 11:01:30 -0800 Subject: [PATCH 72/75] Add new span taking copying initializers to Rigid and UniqueArray --- .../RigidArray/RigidArray+Initializers.swift | 18 +++++++++++++++ .../UniqueArray+Initializers.swift | 17 ++++++++++++++ .../RigidArrayTests.swift | 23 +++++++++++++++++++ .../UniqueArrayTests.swift | 22 ++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift index 59b5f8b6..c850ba47 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift @@ -171,6 +171,24 @@ extension RigidArray /*where Element: Copyable*/ { self.init(capacity: capacity ?? contents.count) self.append(copying: contents) } + + /// Creates a new array with the specified capacity, holding a copy + /// of the contents of the given span. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new array, or nil to allocate + /// just enough capacity to store the contents of the span. + /// - span: The span whose contents to copy into the new array. + /// The span must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init( + capacity: Int? = nil, + copying span: Span + ) { + self.init(capacity: capacity ?? span.count) + self.append(copying: span) + } } // FIXME: Add init(moving:), init(consuming:) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift index fd18c8d1..5706f5e8 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift @@ -139,6 +139,23 @@ extension UniqueArray /*where Element: Copyable*/ { } #endif + /// Creates a new array with the specified capacity, holding a copy + /// of the contents of the given span. + /// + /// - Parameters: + /// - capacity: The storage capacity of the new array, or nil to allocate + /// just enough capacity to store the contents of the span. + /// - span: The span whose contents to copy into the new array. + /// The span must not contain more than `capacity` elements. + @_alwaysEmitIntoClient + @inline(__always) + public init( + capacity: Int? = nil, + copying span: Span + ) { + self.init(capacity: capacity ?? span.count) + self.append(copying: span) + } } #endif diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index bed56314..46a40fbe 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -191,6 +191,29 @@ class RigidArrayTests: CollectionTestCase { #endif #endif + func test_init_copying_Span() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withLifetimeTracking { tracker in + let a = tracker.rigidArray(layout: layout) + let b = RigidArray(capacity: layout.capacity, copying: a.span) + expectEqual(tracker.instances, layout.count) + expectEqual(b.capacity, layout.capacity) + expectEqual(b.count, layout.count) + expectEqual(b.freeCapacity, layout.capacity - layout.count) + expectEqual(b.isEmpty, layout.count == 0) + expectEqual(b.isFull, layout.count == layout.capacity) + for i in 0 ..< layout.count { + expectEqual(b[i].payload, i) + } + expectIterableContents( + b, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + func test_span() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withLifetimeTracking { tracker in diff --git a/Tests/BasicContainersTests/UniqueArrayTests.swift b/Tests/BasicContainersTests/UniqueArrayTests.swift index 26ca3a1f..65e0752d 100644 --- a/Tests/BasicContainersTests/UniqueArrayTests.swift +++ b/Tests/BasicContainersTests/UniqueArrayTests.swift @@ -227,6 +227,28 @@ class UniqueArrayTests: CollectionTestCase { #endif #endif + func test_init_copying_Span() { + withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in + withLifetimeTracking { tracker in + let a = tracker.uniqueArray(layout: layout) + let b = UniqueArray(capacity: layout.capacity, copying: a.span) + expectEqual(tracker.instances, layout.count) + expectEqual(b.capacity, layout.capacity) + expectEqual(b.count, layout.count) + expectEqual(b.freeCapacity, layout.capacity - layout.count) + expectEqual(b.isEmpty, layout.count == 0) + for i in 0 ..< layout.count { + expectEqual(b[i].payload, i) + } + expectIterableContents( + b, + equivalentTo: 0 ..< layout.count, + by: { $0.payload == $1 }, + printer: { "\($0.payload)" }) + } + } + } + func test_span() { withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in withLifetimeTracking { tracker in From 5a4ee8be669ac603e58f9033485d7500fbf0a8aa Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 16 Feb 2026 15:49:22 -0800 Subject: [PATCH 73/75] Update docs for Container.nextSpan(after:maximumCount:) Oops, the docs did not explain `maximumCount`. --- .../RigidArray/RigidArray+Container.swift | 70 +++++++++-- .../UniqueArray/UniqueArray+Container.swift | 70 +++++++++-- .../Protocols/Container.swift | 110 +++++++++++++++--- 3 files changed, 209 insertions(+), 41 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index efbc5246..2d99e10a 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -285,25 +285,73 @@ extension RigidArray where Element: ~Copyable { index._advance(by: &n, limitedBy: limit) } - /// Return a span over the array's storage that begins with the element at the given index, - /// and extends to the end of the contiguous storage chunk that contains it. On return, the index - /// is updated to address the next item following the end of the returned span. + /// Return a span over the array's storage that begins with the element at + /// the given index, and extends to the end of the contiguous storage chunk + /// that contains it, but no more than `maximumCount` items. /// - /// This method can be used to efficiently process the items of a container in bulk, by - /// directly iterating over its piecewise contiguous pieces of storage: + /// On return, the index is updated to address the next item following the + /// end of the returned span. + /// + /// This method can be used to efficiently process the items of a container in + /// bulk, by directly iterating over its piecewise contiguous pieces of + /// storage: /// /// var index = items.startIndex /// while true { - /// let span = items.nextSpan(after: &index) + /// let span = items.nextSpan(after: &index, maximumCount: 4) /// if span.isEmpty { break } /// // Process items in `span` /// } /// - /// - Parameter index: A valid index in the array, including the end index. On return, this - /// index is advanced by the count of the resulting span, to simplify iteration. - /// - Returns: A span over contiguous storage that starts at the given index. If the input index - /// is the end index, then this returns an empty span. Otherwise the result is non-empty, - /// with its first element matching the element at the input index. + /// The `maximumCount` argument gives the caller control over the number of + /// items it receives from the iterator. This lets the caller avoid getting + /// more elements than it would be able to immediately process, which would + /// significantly complicate container use. + /// + /// If the caller is able to process any number available items, it can signal + /// that by passing `Int.max` as the `maximumCount`, or simply by calling the + /// `nexSpan(after:)` method, which does precisely that. This is frequently + /// the case when the caller simply wants to iterate over the entire + /// container in a single loop. + /// + /// `maximumCount` sets an upper bound. To read a specific number of items, + /// the caller usually needs to invoke `nextSpan` in a loop: + /// + /// var items: some Container + /// var index = items.startIndex + /// var remainder = numberOfItemsToRead + /// while remainder > 0 { + /// let next = items.nextSpan(after: &index, maximumCount: remainder) + /// guard !next.isEmpty else { + /// // Container does not have enough items + /// break + /// } + /// remainder -= next.count + /// // Process items in `next` + /// } + /// + /// - Note: The spans returned by this method are not guaranteed to be + /// disjunct. Some containers may use the same storage chunk (or parts of a + /// storage chunk) multiple times, to repeat their contents. + /// + /// - Note: Repeated invocations of `nextSpan` on the same container and index + /// are not guaranteed to return identical results. (This is particularly + /// the case with containers that can store contents in their "inline" + /// representation. Such containers may not always have a unique address + /// in memory; the locations of the spans exposed by this method may vary + /// between different borrows of the same container.) + /// + /// - Parameter index: A valid index in the container, including the end + /// index. On return, this index is advanced by the count of the resulting + /// span, to simplify iteration. + /// - Parameter maximumCount: The maximum number of items the caller is able + /// to process immediately. `maximumCount` must be greater than zero. + /// If you are able to process an arbitrary number of items, set + /// `maximumCount` to `Int.max`, or call the `nextSpan(after:)` method. + /// - Returns: A span over contiguous storage that starts at the given index. + /// If the input index is the end index, then this returns an empty span. + /// Otherwise the result is non-empty, with its first element matching the + /// element at the input index. /// - Complexity: O(1) @inlinable @_lifetime(borrow self) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift index 8b5567ed..789a2fdb 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift @@ -264,25 +264,73 @@ extension UniqueArray where Element: ~Copyable { _storage.formIndex(&index, offsetBy: &n, limitedBy: limit) } - /// Return a span over the array's storage that begins with the element at the given index, - /// and extends to the end of the contiguous storage chunk that contains it. On return, the index - /// is updated to address the next item following the end of the returned span. + /// Return a span over the array's storage that begins with the element at + /// the given index, and extends to the end of the contiguous storage chunk + /// that contains it, but no more than `maximumCount` items. /// - /// This method can be used to efficiently process the items of a container in bulk, by - /// directly iterating over its piecewise contiguous pieces of storage: + /// On return, the index is updated to address the next item following the + /// end of the returned span. + /// + /// This method can be used to efficiently process the items of a container in + /// bulk, by directly iterating over its piecewise contiguous pieces of + /// storage: /// /// var index = items.startIndex /// while true { - /// let span = items.nextSpan(after: &index) + /// let span = items.nextSpan(after: &index, maximumCount: 4) /// if span.isEmpty { break } /// // Process items in `span` /// } /// - /// - Parameter index: A valid index in the array, including the end index. On return, this - /// index is advanced by the count of the resulting span, to simplify iteration. - /// - Returns: A span over contiguous storage that starts at the given index. If the input index - /// is the end index, then this returns an empty span. Otherwise the result is non-empty, - /// with its first element matching the element at the input index. + /// The `maximumCount` argument gives the caller control over the number of + /// items it receives from the iterator. This lets the caller avoid getting + /// more elements than it would be able to immediately process, which would + /// significantly complicate container use. + /// + /// If the caller is able to process any number available items, it can signal + /// that by passing `Int.max` as the `maximumCount`, or simply by calling the + /// `nexSpan(after:)` method, which does precisely that. This is frequently + /// the case when the caller simply wants to iterate over the entire + /// container in a single loop. + /// + /// `maximumCount` sets an upper bound. To read a specific number of items, + /// the caller usually needs to invoke `nextSpan` in a loop: + /// + /// var items: some Container + /// var index = items.startIndex + /// var remainder = numberOfItemsToRead + /// while remainder > 0 { + /// let next = items.nextSpan(after: &index, maximumCount: remainder) + /// guard !next.isEmpty else { + /// // Container does not have enough items + /// break + /// } + /// remainder -= next.count + /// // Process items in `next` + /// } + /// + /// - Note: The spans returned by this method are not guaranteed to be + /// disjunct. Some containers may use the same storage chunk (or parts of a + /// storage chunk) multiple times, to repeat their contents. + /// + /// - Note: Repeated invocations of `nextSpan` on the same container and index + /// are not guaranteed to return identical results. (This is particularly + /// the case with containers that can store contents in their "inline" + /// representation. Such containers may not always have a unique address + /// in memory; the locations of the spans exposed by this method may vary + /// between different borrows of the same container.) + /// + /// - Parameter index: A valid index in the container, including the end + /// index. On return, this index is advanced by the count of the resulting + /// span, to simplify iteration. + /// - Parameter maximumCount: The maximum number of items the caller is able + /// to process immediately. `maximumCount` must be greater than zero. + /// If you are able to process an arbitrary number of items, set + /// `maximumCount` to `Int.max`, or call the `nextSpan(after:)` method. + /// - Returns: A span over contiguous storage that starts at the given index. + /// If the input index is the end index, then this returns an empty span. + /// Otherwise the result is non-empty, with its first element matching the + /// element at the input index. /// - Complexity: O(1) @inlinable @_lifetime(borrow self) diff --git a/Sources/ContainersPreview/Protocols/Container.swift b/Sources/ContainersPreview/Protocols/Container.swift index 9353948d..6a380909 100644 --- a/Sources/ContainersPreview/Protocols/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container.swift @@ -80,35 +80,73 @@ public protocol Container: BorrowingSequence, ~Copyable, ~Escapable { /// - Returns: The distance between `start` and `end`. func distance(from start: Index, to end: Index) -> Int - /// Return a span over the container's storage that begins with the element at the given index, - /// and extends to the end of the contiguous storage chunk that contains it. On return, the index - /// is updated to address the next item following the end of the returned span. + /// Return a span over the container's storage that begins with the element at + /// the given index, and extends to the end of the contiguous storage chunk + /// that contains it, but no more than `maximumCount` items. /// - /// This method can be used to efficiently process the items of a container in bulk, by - /// directly iterating over its piecewise contiguous pieces of storage: + /// On return, the index is updated to address the next item following the + /// end of the returned span. + /// + /// This method can be used to efficiently process the items of a container in + /// bulk, by directly iterating over its piecewise contiguous pieces of + /// storage: /// /// var index = items.startIndex /// while true { - /// let span = items.nextSpan(after: &index) + /// let span = items.nextSpan(after: &index, maximumCount: 4) /// if span.isEmpty { break } /// // Process items in `span` /// } /// - /// - Note: The spans returned by this method are not guaranteed to be disjunct. Some containers - /// may use the same storage chunk (or parts of a storage chunk) multiple times, to repeat their - /// contents. + /// The `maximumCount` argument gives the caller control over the number of + /// items it receives from the iterator. This lets the caller avoid getting + /// more elements than it would be able to immediately process, which would + /// significantly complicate container use. /// - /// - Note: Repeated invocations of `nextSpan` on the same container and index are not guaranteed - /// to return identical results. (This is particularly the case with containers that can store - /// contents in their "inline" representation. Such containers may not always have - /// a unique address in memory; the locations of the spans exposed by this method may vary - /// between different borrows of the same container.) + /// If the caller is able to process any number available items, it can signal + /// that by passing `Int.max` as the `maximumCount`, or simply by calling the + /// `nexSpan(after:)` method, which does precisely that. This is frequently + /// the case when the caller simply wants to iterate over the entire + /// container in a single loop. /// - /// - Parameter index: A valid index in the container, including the end index. On return, this - /// index is advanced by the count of the resulting span, to simplify iteration. - /// - Returns: A span over contiguous storage that starts at the given index. If the input index - /// is the end index, then this returns an empty span. Otherwise the result is non-empty, - /// with its first element matching the element at the input index. + /// `maximumCount` sets an upper bound. To read a specific number of items, + /// the caller usually needs to invoke `nextSpan` in a loop: + /// + /// var items: some Container + /// var index = items.startIndex + /// var remainder = numberOfItemsToRead + /// while remainder > 0 { + /// let next = items.nextSpan(after: &index, maximumCount: remainder) + /// guard !next.isEmpty else { + /// // Container does not have enough items + /// break + /// } + /// remainder -= next.count + /// // Process items in `next` + /// } + /// + /// - Note: The spans returned by this method are not guaranteed to be + /// disjunct. Some containers may use the same storage chunk (or parts of a + /// storage chunk) multiple times, to repeat their contents. + /// + /// - Note: Repeated invocations of `nextSpan` on the same container and index + /// are not guaranteed to return identical results. (This is particularly + /// the case with containers that can store contents in their "inline" + /// representation. Such containers may not always have a unique address + /// in memory; the locations of the spans exposed by this method may vary + /// between different borrows of the same container.) + /// + /// - Parameter index: A valid index in the container, including the end + /// index. On return, this index is advanced by the count of the resulting + /// span, to simplify iteration. + /// - Parameter maximumCount: The maximum number of items the caller is able + /// to process immediately. `maximumCount` must be greater than zero. + /// If you are able to process an arbitrary number of items, set + /// `maximumCount` to `Int.max`, or call the `nextSpan(after:)` method. + /// - Returns: A span over contiguous storage that starts at the given index. + /// If the input index is the end index, then this returns an empty span. + /// Otherwise the result is non-empty, with its first element matching the + /// element at the input index. @_lifetime(borrow self) func nextSpan(after index: inout Index, maximumCount: Int) -> Span @@ -121,6 +159,40 @@ public protocol Container: BorrowingSequence, ~Copyable, ~Escapable { @available(SwiftStdlib 5.0, *) extension Container where Self: ~Copyable & ~Escapable { + /// Return a span over the container's storage that begins with the element at + /// the given index, and extends to the end of the contiguous storage chunk + /// that contains it. On return, the index is updated to address the next item + /// following the end of the returned span. + /// + /// This method can be used to efficiently process the items of a container in + /// bulk, by directly iterating over its piecewise contiguous pieces of + /// storage: + /// + /// var index = items.startIndex + /// while true { + /// let span = items.nextSpan(after: &index) + /// if span.isEmpty { break } + /// // Process items in `span` + /// } + /// + /// - Note: The spans returned by this method are not guaranteed to be + /// disjunct. Some containers may use the same storage chunk (or parts of a + /// storage chunk) multiple times, to repeat their contents. + /// + /// - Note: Repeated invocations of `nextSpan` on the same container and index + /// are not guaranteed to return identical results. (This is particularly + /// the case with containers that can store contents in their "inline" + /// representation. Such containers may not always have a unique address + /// in memory; the locations of the spans exposed by this method may vary + /// between different borrows of the same container.) + /// + /// - Parameter index: A valid index in the container, including the end + /// index. On return, this index is advanced by the count of the resulting + /// span, to simplify iteration. + /// - Returns: A span over contiguous storage that starts at the given index. + /// If the input index is the end index, then this returns an empty span. + /// Otherwise the result is non-empty, with its first element matching the + /// element at the input index. @inlinable @_lifetime(borrow self) public func nextSpan(after index: inout Index) -> Span { From ac7a8bf61b3a10d847df487b3ae30e8fcbfbb988 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 16 Feb 2026 15:52:43 -0800 Subject: [PATCH 74/75] [RigidArray, RigidDeque].nextSpan: Validate `maximumCount` `nextSpan(after:,maximumCount:)` failed to validate that `maximumCount > 0`, potentially allowing out-of-bounds access. --- Sources/BasicContainers/RigidArray/RigidArray+Container.swift | 3 ++- Sources/DequeModule/RigidDeque/RigidDeque+Container.swift | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index efbc5246..3e389e63 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -310,7 +310,8 @@ extension RigidArray where Element: ~Copyable { public func nextSpan( after index: inout Int, maximumCount: Int ) -> Span { - precondition(index >= 0 && index <= _count, "Index out of bounds") + precondition(UInt(bitPattern: index) <= _count, "Index out of bounds") + precondition(maximumCount > 0, "maximumCount must be positive") let start = index index = start &+ Swift.min(maximumCount, _count &- start) return _span(in: Range(uncheckedBounds: (start, index))) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift index 7a61bd8e..92810ed6 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift @@ -94,6 +94,7 @@ extension RigidDeque where Element: ~Copyable { @_lifetime(borrow self) public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") + precondition(maximumCount > 0, "maximumCount must be positive") let segment = self._handle .nextSegment(from: index) ._extracting(first: maximumCount) From 621374557ce25cc915c656ced3e0da8a71fe3627 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 16 Feb 2026 17:05:36 -0800 Subject: [PATCH 75/75] Array, Deque types: Introduce _checkItemIndex, _checkValidIndex, _checkValidBounds --- .../RigidArray/RigidArray+Consumption.swift | 4 +-- .../RigidArray/RigidArray+Container.swift | 35 +++++++++++++++---- .../RigidArray/RigidArray+Experimental.swift | 4 +-- .../RigidArray/RigidArray+Insertions.swift | 6 ++-- .../RigidArray/RigidArray+Removals.swift | 6 ++-- .../RigidArray/RigidArray+Replacements.swift | 8 ++--- .../UniqueArray+Replacements.swift | 8 ++--- .../RigidDeque/RigidDeque+Consumption.swift | 5 ++- .../RigidDeque/RigidDeque+Container.swift | 2 +- .../RigidDeque/RigidDeque+Experimental.swift | 4 +-- .../RigidDeque/RigidDeque+Insertions.swift | 4 +-- .../RigidDeque/RigidDeque+Removals.swift | 2 +- .../RigidDeque/RigidDeque+Replacements.swift | 8 ++--- .../DequeModule/RigidDeque/RigidDeque.swift | 33 ++++++++++++++--- .../UniqueDeque/UniqueDeque+Insertions.swift | 4 +-- .../UniqueDeque+Replacements.swift | 8 ++--- 16 files changed, 83 insertions(+), 58 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift b/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift index d5321cf5..39ff9bb9 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift @@ -35,9 +35,7 @@ extension RigidArray where Element: ~Copyable { _ subrange: Range, consumingWith consumer: (inout InputSpan) -> Void ) { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= _count, - "Subrange out of bounds") + _checkValidBounds(subrange) guard !subrange.isEmpty else { var span = InputSpan() consumer(&span) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index 3e389e63..be5fc946 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -88,13 +88,37 @@ extension RigidArray where Element: ~Copyable { @inlinable @inline(__always) public var indices: Range { unsafe Range(uncheckedBounds: (0, count)) } + + @_alwaysEmitIntoClient + @_transparent + package func _checkItemIndex(_ index: Int) { + precondition( + UInt(bitPattern: index) < UInt(bitPattern: _count), + "Index out of bounds") + } + + @_alwaysEmitIntoClient + @_transparent + package func _checkValidIndex(_ index: Int) { + precondition( + UInt(bitPattern: index) <= UInt(bitPattern: _count), + "Index out of bounds") + } + + @_alwaysEmitIntoClient + @_transparent + package func _checkValidBounds(_ subrange: Range) { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= _count, + "Index range out of bounds") + } } @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { @inlinable @inline(__always) internal func _ptr(to index: Int) -> UnsafePointer { - precondition(index >= 0 && index < _count, "Index out of bounds") + _checkItemIndex(index) let p = _storage.baseAddress.unsafelyUnwrapped.advanced(by: index) return UnsafePointer(p) } @@ -103,7 +127,7 @@ extension RigidArray where Element: ~Copyable { internal mutating func _mutablePtr( to index: Int ) -> UnsafeMutablePointer { - precondition(index >= 0 && index < _count, "Index out of bounds") + _checkItemIndex(index) return _storage.baseAddress.unsafelyUnwrapped.advanced(by: index) } @@ -140,9 +164,8 @@ extension RigidArray where Element: ~Copyable { /// - Complexity: O(1) @inlinable public mutating func swapAt(_ i: Int, _ j: Int) { - precondition( - i >= 0 && i < _count && j >= 0 && j < _count, - "Index out of bounds") + _checkItemIndex(i) + _checkItemIndex(j) unsafe _items.swapAt(i, j) } } @@ -310,7 +333,7 @@ extension RigidArray where Element: ~Copyable { public func nextSpan( after index: inout Int, maximumCount: Int ) -> Span { - precondition(UInt(bitPattern: index) <= _count, "Index out of bounds") + _checkValidIndex(index) precondition(maximumCount > 0, "maximumCount must be positive") let start = index index = start &+ Swift.min(maximumCount, _count &- start) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Experimental.swift b/Sources/BasicContainers/RigidArray/RigidArray+Experimental.swift index 214e0b44..cdfcd455 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Experimental.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Experimental.swift @@ -22,7 +22,7 @@ extension RigidArray where Element: ~Copyable { @inlinable @_lifetime(borrow self) public func borrowElement(at index: Int) -> Borrow { - precondition(index >= 0 && index < _count, "Index out of bounds") + _checkItemIndex(index) return unsafe Borrow( unsafeAddress: _storage.baseAddress.unsafelyUnwrapped.advanced(by: index), borrowing: self @@ -37,7 +37,7 @@ extension RigidArray where Element: ~Copyable { @inlinable @_lifetime(&self) public mutating func mutateElement(at index: Int) -> Mut { - precondition(index >= 0 && index < _count) + _checkItemIndex(index) return unsafe Mut( unsafeAddress: _storage.baseAddress.unsafelyUnwrapped.advanced(by: index), mutating: &self diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index 722dc2b9..55b505fb 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -37,7 +37,7 @@ extension RigidArray where Element: ~Copyable { /// - Complexity: O(`self.count`) @inlinable public mutating func insert(_ item: consuming Element, at index: Int) { - precondition(index >= 0 && index <= count, "Index out of bounds") + _checkValidIndex(index) precondition(!isFull, "RigidArray capacity overflow") if index < count { let source = unsafe _storage.extracting(index ..< count) @@ -99,7 +99,7 @@ extension RigidArray where Element: ~Copyable { at index: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { - precondition(index >= 0 && index <= self.count, "Index out of bounds") + _checkValidIndex(index) precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition(newItemCount <= freeCapacity, "RigidArray capacity overflow") let target = unsafe _openGap(at: index, count: newItemCount) @@ -381,7 +381,7 @@ extension RigidArray { copying items: some Collection, newCount: Int ) { - precondition(index >= 0 && index <= _count, "Index out of bounds") + _checkValidIndex(index) precondition(newCount <= freeCapacity, "RigidArray capacity overflow") let gap = unsafe _openGap(at: index, count: newCount) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift b/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift index 0b60b87c..4ee28a3f 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Removals.swift @@ -31,7 +31,7 @@ extension RigidArray where Element: ~Copyable { @inlinable @discardableResult public mutating func remove(at index: Int) -> Element { - precondition(index >= 0 && index < _count, "Index out of bounds") + _checkItemIndex(index) let old = unsafe _storage.moveElement(from: index) _closeGap(at: index, count: 1) _count -= 1 @@ -97,9 +97,7 @@ extension RigidArray where Element: ~Copyable { /// - Complexity: O(`count`) @inlinable public mutating func removeSubrange(_ bounds: Range) { - precondition( - bounds.lowerBound >= 0 && bounds.upperBound <= _count, - "Subrange out of bounds") + _checkValidBounds(bounds) guard !bounds.isEmpty else { return } unsafe _storage.extracting(bounds).deinitialize() _closeGap(at: bounds.lowerBound, count: bounds.count) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 7b833944..4b4da101 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -64,9 +64,7 @@ extension RigidArray where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= _count, - "Index range out of bounds") + _checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition( newItemCount - subrange.count <= freeCapacity, @@ -158,9 +156,7 @@ extension RigidArray where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= _count, - "Index range out of bounds") + _checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition( newItemCount - subrange.count <= freeCapacity, diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift index 5d5c977e..aa6af999 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift @@ -65,9 +65,7 @@ extension UniqueArray where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= self.count, - "Index range out of bounds") + _storage._checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") // FIXME: Avoid moving the subsequent elements twice on resize. _ensureFreeCapacity(newItemCount - subrange.count) @@ -136,9 +134,7 @@ extension UniqueArray where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= self.count, - "Index range out of bounds") + _storage._checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(newItemCount - subrange.count) try _storage._uncheckedReplace( diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift index 05bc0695..0a19a35f 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift @@ -42,9 +42,7 @@ extension RigidDeque where Element: ~Copyable { _ subrange: Range, consumingWith consumer: (inout InputSpan) -> Void ) { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= self.count, - "Subrange out of bounds") + _checkValidBounds(subrange) let segments = self._handle.mutableSegments(forOffsets: subrange) var span = InputSpan(buffer: segments.first, initializedCount: segments.first.count) @@ -232,6 +230,7 @@ extension RigidDeque where Element: ~Copyable { @inline(__always) @_lifetime(&_base) internal init(_base: inout RigidDeque, offsetRange: Range) { + _base._checkValidBounds(subrange) let segments = _base._handle.mutableSegments(forOffsets: offsetRange) self._buffer1 = segments.first self._buffer2 = segments.second ?? .init(start: nil, count: 0) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift index 92810ed6..16ed1ee5 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift @@ -93,7 +93,7 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { - precondition(index >= 0 && index <= count, "Index out of bounds") + _checkValidIndex(index) precondition(maximumCount > 0, "maximumCount must be positive") let segment = self._handle .nextSegment(from: index) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift index cea19d9d..250ab5d3 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Experimental.swift @@ -23,7 +23,7 @@ extension RigidDeque where Element: ~Copyable { @_transparent @_lifetime(borrow self) public func borrowElement(at index: Int) -> Borrow { - precondition(index >= 0 && index < count, "Index out of bounds") + _checkItemIndex(index) let slot = _handle.slot(forOffset: index) return Borrow(unsafeAddress: _handle.ptr(at: slot), borrowing: self) } @@ -32,7 +32,7 @@ extension RigidDeque where Element: ~Copyable { @_transparent @_lifetime(&self) public mutating func mutateElement(at index: Int) -> Inout { - precondition(index >= 0 && index < count, "Index out of bounds") + _checkItemIndex(index) let slot = _handle.slot(forOffset: index) return Inout(unsafeAddress: _handle.mutablePtr(at: slot), mutating: &self) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 238e974f..bb530f91 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -40,7 +40,7 @@ extension RigidDeque where Element: ~Copyable { @inline(__always) public mutating func insert(_ item: consuming Element, at index: Int) { precondition(!isFull, "RigidDeque capacity overflow") - precondition(index >= 0 && index <= count, "Index out of bounds") + _checkValidIndex(index) _handle.uncheckedInsert(item, at: index) } } @@ -98,7 +98,7 @@ extension RigidDeque where Element: ~Copyable { at index: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { - precondition(index >= 0 && index <= self.count, "Index out of bounds") + _checkValidIndex(index) precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition(newItemCount <= freeCapacity, "RigidDeque capacity overflow") try _handle.uncheckedInsert( diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift index a5fdf033..38f3048b 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift @@ -32,7 +32,7 @@ extension RigidDeque where Element: ~Copyable { @discardableResult @_alwaysEmitIntoClient public mutating func remove(at index: Int) -> Element { - precondition(index >= 0 && index < count, "Index out of bounds") + _checkItemIndex(index) return _handle.uncheckedRemove(at: index) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 8c6a1df5..cc789a05 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -64,9 +64,7 @@ extension RigidDeque where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= count, - "Subrange out of bounds") + _checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition( count - subrange.count + newItemCount <= capacity, @@ -141,9 +139,7 @@ extension RigidDeque where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= count, - "Subrange out of bounds") + _checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") precondition( count - subrange.count + newItemCount <= capacity, diff --git a/Sources/DequeModule/RigidDeque/RigidDeque.swift b/Sources/DequeModule/RigidDeque/RigidDeque.swift index caace267..d92efbb3 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque.swift @@ -234,20 +234,44 @@ extension RigidDeque where Element: ~Copyable { @inline(__always) public var indices: Range { unsafe Range(uncheckedBounds: (0, count)) } + @_alwaysEmitIntoClient + @_transparent + package func _checkItemIndex(_ index: Int) { + precondition( + UInt(bitPattern: index) < UInt(bitPattern: _handle.count), + "Index out of bounds") + } + + @_alwaysEmitIntoClient + @_transparent + package func _checkValidIndex(_ index: Int) { + precondition( + UInt(bitPattern: index) <= UInt(bitPattern: _handle.count), + "Index out of bounds") + } + + @_alwaysEmitIntoClient + @_transparent + package func _checkValidBounds(_ subrange: Range) { + precondition( + subrange.lowerBound >= 0 && subrange.upperBound <= _handle.count, + "Index range out of bounds") + } + @_alwaysEmitIntoClient public subscript(position: Int) -> Element { // FIXME: Replace with borrow/mutate accessors @inline(__always) @_transparent unsafeAddress { - precondition(position >= 0 && position < count, "Index out of bounds") + _checkItemIndex(position) let slot = _handle.slot(forOffset: position) return _handle.ptr(at: slot) } @inline(__always) @_transparent unsafeMutableAddress { - precondition(position >= 0 && position < count, "Index out of bounds") + _checkItemIndex(position) let slot = _handle.slot(forOffset: position) return _handle.mutablePtr(at: slot) } @@ -267,9 +291,8 @@ extension RigidDeque where Element: ~Copyable { /// - Complexity: O(1) @inlinable public mutating func swapAt(_ i: Int, _ j: Int) { - precondition( - i >= 0 && i < count && j >= 0 && j < count, - "Index out of bounds") + _checkItemIndex(i) + _checkItemIndex(j) _handle.uncheckedSwapAt(i, j) } } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index bdb014e7..f0723b3a 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -41,7 +41,7 @@ extension UniqueDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_transparent public mutating func insert(_ item: consuming Element, at index: Int) { - precondition(index >= 0 && index <= self.count, "Index out of bounds") + _storage._checkValidIndex(index) _ensureFreeCapacity(1) _storage._handle.uncheckedInsert(item, at: index) } @@ -102,7 +102,7 @@ extension UniqueDeque where Element: ~Copyable { at index: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { - precondition(index >= 0 && index <= self.count, "Index out of bounds") + _storage._checkValidIndex(index) precondition(newItemCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(newItemCount) try _storage._handle.uncheckedInsert( diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index bec74b5b..82963e7a 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -78,9 +78,7 @@ extension UniqueDeque where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= count, - "Subrange out of bounds") + _storage._checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(newItemCount - subrange.count) try _storage._handle.uncheckedReplace( @@ -148,9 +146,7 @@ extension UniqueDeque where Element: ~Copyable { addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition( - subrange.lowerBound >= 0 && subrange.upperBound <= count, - "Subrange out of bounds") + _storage._checkValidBounds(subrange) precondition(newItemCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(newItemCount - subrange.count) try _storage._handle.uncheckedReplace(