Files
swift-collections/Sources/SortedCollections/BTree/_Node.Splinter.swift
T
Franz Busch 3c373b900c Use the defines from traits directly
Package traits already pass defines with their trait name when building. Instead of adding our own conditional defines based on the traits we can use the trait provided defines directly. I observed that various tooling behaves better with the trait provided defines.
2026-05-06 07:41:02 -07:00

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
internal 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:
/// - node: 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