mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
58 lines
1.7 KiB
Swift
58 lines
1.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if UnstableSortedCollections
|
|
|
|
extension _Node {
|
|
/// Represents the result of a overfilled node's split.
|
|
@usableFromInline
|
|
package struct Splinter {
|
|
@inlinable
|
|
@inline(__always)
|
|
internal init(element: Element, rightChild: _Node<Key, Value>) {
|
|
self.element = element
|
|
self.rightChild = rightChild
|
|
}
|
|
|
|
/// The former median element which should be propagated upward.
|
|
@usableFromInline
|
|
internal let element: Element
|
|
|
|
/// The right product of the node split.
|
|
@usableFromInline
|
|
internal var rightChild: _Node<Key, Value>
|
|
|
|
/// Converts the splinter object to a node.
|
|
/// - Parameters:
|
|
/// - leftChild: The node generating the splinter. Becomes the returned
|
|
/// node's left child.
|
|
/// - capacity: The desired capacity of the new node.
|
|
/// - Returns: A new node of `capacity` with a single element.
|
|
@inlinable
|
|
@inline(__always)
|
|
internal __consuming func toNode(
|
|
leftChild: _Node<Key, Value>,
|
|
capacity: Int
|
|
) -> _Node {
|
|
return _Node(
|
|
leftChild: leftChild,
|
|
separator: element,
|
|
rightChild: rightChild,
|
|
capacity: capacity
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|