diff --git a/Sources/ARTreeModule/ARTree+insert.swift b/Sources/ARTreeModule/ARTree+insert.swift index c871e3303..f69cff06c 100644 --- a/Sources/ARTreeModule/ARTree+insert.swift +++ b/Sources/ARTreeModule/ARTree+insert.swift @@ -28,7 +28,7 @@ extension ARTree { fatalError("replace not supported") } - let newLeaf = NodeLeaf.allocate(key: key, value: value, of: Value.self) + let newLeaf = Self.allocateLeaf(key: key, value: value) var longestPrefix = leaf.longestCommonPrefix(with: newLeaf, fromIndex: depth) var newNode = Node4.allocate() @@ -76,7 +76,7 @@ extension ARTree { node.partialBytes.shiftLeft(toIndex: prefixDiff + 1) node.partialLength -= prefixDiff + 1 - let newLeaf = NodeLeaf.allocate(key: key, value: value, of: Value.self) + let newLeaf = Self.allocateLeaf(key: key, value: value) newNode.addChild(forKey: key[depth + prefixDiff], node: newLeaf) ref?.pointee = newNode.rawNode return true @@ -86,7 +86,7 @@ extension ARTree { // Find next child to continue. guard let next = node.child(forKey: key[depth], ref: &ref) else { // No child, insert leaf within us. - let newLeaf = NodeLeaf.allocate(key: key, value: value, of: Value.self) + let newLeaf = Self.allocateLeaf(key: key, value: value) node.addChild(forKey: key[depth], node: newLeaf, ref: ref) return true } diff --git a/Sources/ARTreeModule/ARTree+utils.swift b/Sources/ARTreeModule/ARTree+utils.swift new file mode 100644 index 000000000..85a518745 --- /dev/null +++ b/Sources/ARTreeModule/ARTree+utils.swift @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +extension ARTree { + static func allocateLeaf(key: Key, value: Value) -> NodeLeaf { + return NodeLeaf.allocate(key: key, value: value, of: Value.self) + } +} diff --git a/Sources/ARTreeModule/NodeLeaf.swift b/Sources/ARTreeModule/NodeLeaf.swift index 6d789da86..970fb4eed 100644 --- a/Sources/ARTreeModule/NodeLeaf.swift +++ b/Sources/ARTreeModule/NodeLeaf.swift @@ -10,8 +10,6 @@ //===----------------------------------------------------------------------===// struct NodeLeaf { - typealias Storage = NodeStorage - var storage: Storage }