Skip to content

Commit 55f8ca8

Browse files
committed
refactor!: ♻️ rename the Add API to Insert
I have renamed the `Add` API to `Insert` to make the APIs of my K-D Tree library consistent with those of existing ones written in Go. BREAKING CHANGE: With the removal of the `Add` API in this commit, any code that uses the `Add` API will no longer work with future releases of this library created after this commit. Affected codebases must migrate to the `Insert` API to be compatible with future releases of this library.
1 parent 338cf5c commit 55f8ca8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

kdtree.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ func (t *KDTree[T]) Values() []T {
112112
return res
113113
}
114114

115-
func (t *KDTree[T]) Add(value T) bool {
115+
func (t *KDTree[T]) Insert(value T) bool {
116116
if t.root == nil {
117117
t.root = NewKDNode(value)
118118
return true
119119
}
120-
res := add(t.dimensions, value, 0, t.root)
120+
res := insert(t.dimensions, value, 0, t.root)
121121
if res {
122122
t.size++
123123
}
@@ -359,7 +359,7 @@ func deleteNode[T Comparable[T]](d int, value T, cd int, r *kdNode[T]) (*kdNode[
359359
return r, ok
360360
}
361361

362-
func add[T Comparable[T]](d int, value T, cd int, r *kdNode[T]) bool {
362+
func insert[T Comparable[T]](d int, value T, cd int, r *kdNode[T]) bool {
363363
if value.Dist(r.value) == 0 {
364364
return false
365365
}
@@ -370,13 +370,13 @@ func add[T Comparable[T]](d int, value T, cd int, r *kdNode[T]) bool {
370370
if r.left == nil {
371371
r.left = NewKDNode(value)
372372
} else {
373-
return add(d, value, ncd, r.left)
373+
return insert(d, value, ncd, r.left)
374374
}
375375
} else {
376376
if r.right == nil {
377377
r.right = NewKDNode(value)
378378
} else {
379-
return add(d, value, ncd, r.right)
379+
return insert(d, value, ncd, r.right)
380380
}
381381
}
382382
return true

tests/kdtree_2d_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func Test2DNodeAddition1(t *testing.T) {
249249
}
250250
tree := kdtree.NewKDTreeWithValues(dimensions, ps)
251251
v := types.Tensor2D{48, 38}
252-
tree.Add(v)
252+
tree.Insert(v)
253253
testTable := []struct {
254254
input, expected types.Tensor2D
255255
}{
@@ -292,7 +292,7 @@ func Test2DNodeAddition2(t *testing.T) {
292292
{879, 810},
293293
}
294294
for _, v := range ps {
295-
tree.Add(v)
295+
tree.Insert(v)
296296
}
297297
testTable := []struct {
298298
input, expected types.Tensor2D

0 commit comments

Comments
 (0)