@@ -28,8 +28,6 @@ class Root {
28
28
}
29
29
30
30
func printRoot( ) {
31
- //print("children: \(children.count)")
32
- //print("split at: \(children.count/2-1)")
33
31
if ( children. count > 1 ) {
34
32
for c in 0 ... children. count/ 2 - 1 {
35
33
children [ c] . printEdge ( )
@@ -40,7 +38,6 @@ class Root {
40
38
children [ 0 ] . printEdge ( )
41
39
}
42
40
print ( " ROOT " )
43
- //print("second half starts at: \(children.count/2)")
44
41
if children. count > 1 {
45
42
for c in children. count/ 2 ... children. count- 1 {
46
43
children [ c] . printEdge ( )
@@ -72,15 +69,13 @@ class Edge: Root {
72
69
}
73
70
74
71
func erase( ) {
75
- print ( " Testing erase on: \( label) " )
76
72
self . parent = nil
77
73
if children. count > 0 {
78
74
for _ in 0 ... children. count- 1 {
79
75
children [ 0 ] . erase ( )
80
76
children. remove ( at: 0 )
81
77
}
82
78
}
83
- print ( " Removed: \( label) " )
84
79
}
85
80
86
81
func printEdge( ) {
@@ -268,10 +263,13 @@ class RadixTree {
268
263
}
269
264
270
265
func remove( _ str: String ) -> Bool {
271
- print ( " Tryna remove: \( str) " )
272
266
//You cannot remove the empty string from the tree
273
267
if str == " " {
274
- return false
268
+ for c in root. children {
269
+ c. erase ( )
270
+ root. children. remove ( at: 0 )
271
+ }
272
+ return true
275
273
}
276
274
//If the tree is empty, you cannot remove anything
277
275
else if root. children. count == 0 {
@@ -281,21 +279,16 @@ class RadixTree {
281
279
var currEdge = root
282
280
while ( true ) {
283
281
var found = false
284
- print ( " Search string: \( searchStr) " )
285
282
//If currEdge has no children, then the searchStr is not in the tree
286
283
if currEdge. children. count == 0 {
287
284
return false
288
285
}
289
286
for c in 0 ... currEdge. children. count- 1 {
290
287
//If the child's label matches the search string, remove that child
291
288
// and everything below it in the tree
292
- print ( " Looking at: \( currEdge. children [ c] . label) " )
293
289
if currEdge. children [ c] . label == searchStr {
294
- print ( " MATCH FOUND " )
295
290
currEdge. children [ c] . erase ( )
296
- print ( " ERASED WORKED " )
297
291
currEdge. children. remove ( at: c)
298
- print ( " EDGE LABEL MATCH REMOVE " )
299
292
return true
300
293
}
301
294
//Find the shared string
0 commit comments