Skip to content

Commit

Permalink
Cleanup some NodeLeaf generic boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh committed Aug 19, 2023
1 parent f9a5452 commit 2e56de5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Sources/ARTreeModule/ARTree+insert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions Sources/ARTreeModule/ARTree+utils.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 0 additions & 2 deletions Sources/ARTreeModule/NodeLeaf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//===----------------------------------------------------------------------===//

struct NodeLeaf {
typealias Storage = NodeStorage<Self>

var storage: Storage
}

Expand Down

0 comments on commit 2e56de5

Please sign in to comment.