Skip to content

Commit c59f475

Browse files
committed
Removed debug prints
1 parent 42e259f commit c59f475

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

Radix-Tree/RadixTree.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class Root {
2828
}
2929

3030
func printRoot() {
31-
//print("children: \(children.count)")
32-
//print("split at: \(children.count/2-1)")
3331
if (children.count > 1) {
3432
for c in 0...children.count/2-1 {
3533
children[c].printEdge()
@@ -40,7 +38,6 @@ class Root {
4038
children[0].printEdge()
4139
}
4240
print("ROOT")
43-
//print("second half starts at: \(children.count/2)")
4441
if children.count > 1 {
4542
for c in children.count/2...children.count-1 {
4643
children[c].printEdge()
@@ -72,15 +69,13 @@ class Edge: Root {
7269
}
7370

7471
func erase() {
75-
print("Testing erase on: \(label)")
7672
self.parent = nil
7773
if children.count > 0 {
7874
for _ in 0...children.count-1 {
7975
children[0].erase()
8076
children.remove(at: 0)
8177
}
8278
}
83-
print("Removed: \(label)")
8479
}
8580

8681
func printEdge() {
@@ -268,10 +263,13 @@ class RadixTree {
268263
}
269264

270265
func remove(_ str: String) -> Bool {
271-
print("Tryna remove: \(str)")
272266
//You cannot remove the empty string from the tree
273267
if str == "" {
274-
return false
268+
for c in root.children {
269+
c.erase()
270+
root.children.remove(at: 0)
271+
}
272+
return true
275273
}
276274
//If the tree is empty, you cannot remove anything
277275
else if root.children.count == 0 {
@@ -281,21 +279,16 @@ class RadixTree {
281279
var currEdge = root
282280
while (true) {
283281
var found = false
284-
print("Search string: \(searchStr)")
285282
//If currEdge has no children, then the searchStr is not in the tree
286283
if currEdge.children.count == 0 {
287284
return false
288285
}
289286
for c in 0...currEdge.children.count-1 {
290287
//If the child's label matches the search string, remove that child
291288
// and everything below it in the tree
292-
print("Looking at: \(currEdge.children[c].label)")
293289
if currEdge.children[c].label == searchStr {
294-
print("MATCH FOUND")
295290
currEdge.children[c].erase()
296-
print("ERASED WORKED")
297291
currEdge.children.remove(at: c)
298-
print("EDGE LABEL MATCH REMOVE")
299292
return true
300293
}
301294
//Find the shared string

Radix-Tree/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ radixWiki.printTree()
4747
print(radixWiki.remove("rub"))
4848
radixWiki.printTree()
4949

50-
print(radixWiki.remove("stevenson"))
50+
print(radixWiki.remove("stevenson"))
51+
52+
print(radixWiki.remove(""))
53+
radixWiki.printTree()

0 commit comments

Comments
 (0)