Skip to content

Commit 2f209a3

Browse files
committed
Added more inline comments
1 parent bcf9ade commit 2f209a3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Radix-Tree/RadixTree.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ class RadixTree {
251251
var currEdge = root
252252
while (true) {
253253
var found = false
254+
//Loop through currEdge's children
254255
for c in currEdge.children {
255256
//First check if the search string and the child's label are equal
256257
// if so the string is in the tree, return true
@@ -260,8 +261,8 @@ class RadixTree {
260261
//If that is not true, find the shared string b/t the search string
261262
// and the label
262263
var shared = sharedPrefix(searchStr, c.label)
263-
//If the shared string is equal to the label, update the curent node
264-
// and run it back
264+
//If the shared string is equal to the label, update the curent node,
265+
// break the loop, and run it back
265266
if shared == c.label {
266267
currEdge = c
267268
var tempIndex = searchStr.startIndex
@@ -272,7 +273,7 @@ class RadixTree {
272273
found = true
273274
break
274275
}
275-
//If the shared string is empty, go to the next children
276+
//If the shared string is empty, go to the next child
276277
else if shared.characters.count == 0 {
277278
continue
278279
}
@@ -287,14 +288,16 @@ class RadixTree {
287288
return false
288289
}
289290
}
291+
//If nothing was found, return false
290292
if !found {
291293
return false
292294
}
293295
}
294296
}
295297

298+
//Removes a string from the tree
296299
func remove(_ str: String) -> Bool {
297-
//You cannot remove the empty string from the tree
300+
//Removing the empty string removes everything in the tree
298301
if str == "" {
299302
for c in root.children {
300303
c.erase()
@@ -306,6 +309,7 @@ class RadixTree {
306309
else if root.children.count == 0 {
307310
return false
308311
}
312+
//searchStr and currEdge have the same functionality as in insert() and find()
309313
var searchStr = str
310314
var currEdge = root
311315
while (true) {
@@ -314,6 +318,7 @@ class RadixTree {
314318
if currEdge.children.count == 0 {
315319
return false
316320
}
321+
//Loop through the children
317322
for c in 0...currEdge.children.count-1 {
318323
//If the child's label matches the search string, remove that child
319324
// and everything below it in the tree
@@ -343,6 +348,7 @@ class RadixTree {
343348
}
344349
}
345350

351+
//Prints the tree by calling the root's print function
346352
func printTree() {
347353
root.printRoot()
348354
}

0 commit comments

Comments
 (0)