mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
This sanitizes the semantics of _Node.Builder, removing the (unneccessary) need to pass around hash paths. It also slightly refactors removal operations, but stops short of implementing node shrinking. # Conflicts: # Sources/PersistentCollections/Node/_Node+Builder.swift # Sources/PersistentCollections/Node/_Node+Initializers.swift # Sources/PersistentCollections/Node/_Node+Structural intersection.swift # Sources/PersistentCollections/Node/_Node+Structural subtracting.swift # Sources/PersistentCollections/Node/_Node+Subtree Modify.swift # Sources/PersistentCollections/Node/_Node+Subtree Removals.swift # Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Initializers.swift # Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra Initializers.swift # Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra intersection.swift # Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtracting.swift
36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2022 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension PersistentSet {
|
|
@inlinable
|
|
public func inserting(_ newMember: __owned Element) -> Self {
|
|
let hash = _Hash(newMember)
|
|
let r = _root.inserting(.top, (newMember, ()), hash)
|
|
return PersistentSet(_new: r.node)
|
|
}
|
|
|
|
@inlinable
|
|
public func removing(_ member: Element) -> Self {
|
|
let hash = _Hash(member)
|
|
let r = _root.removing(.top, member, hash)
|
|
guard let r = r else { return self }
|
|
let root = r.replacement.finalize(.top)
|
|
return PersistentSet(_new: root)
|
|
}
|
|
|
|
@inlinable
|
|
public func updating(with newMember: __owned Element) -> Self {
|
|
var copy = self
|
|
copy.update(with: newMember)
|
|
return copy
|
|
}
|
|
}
|