@@ -85,7 +85,7 @@ public class Edge: Root {
85
85
// For each child, erase it, then remove it from the children array.
86
86
for _ in 0 ... children. count- 1 {
87
87
children [ 0 ] . erase ( )
88
- children. removeAtIndex ( 0 )
88
+ children. remove ( at : 0 )
89
89
}
90
90
}
91
91
}
@@ -137,7 +137,7 @@ public class RadixTree {
137
137
}
138
138
139
139
// Inserts a string into the tree.
140
- public func insert( str: String ) -> Bool {
140
+ public func insert( _ str: String ) -> Bool {
141
141
//Account for a blank input. The empty string is already in the tree.
142
142
if str == " " {
143
143
return false
@@ -182,9 +182,9 @@ public class RadixTree {
182
182
currEdge = e
183
183
var tempIndex = searchStr. startIndex
184
184
for _ in 1 ... shared. characters. count {
185
- tempIndex = tempIndex . successor ( )
185
+ tempIndex = searchStr . characters . index ( after : tempIndex )
186
186
}
187
- searchStr = searchStr. substringFromIndex ( tempIndex)
187
+ searchStr = searchStr. substring ( from : tempIndex)
188
188
found = true
189
189
break
190
190
}
@@ -197,13 +197,13 @@ public class RadixTree {
197
197
198
198
// Create index objects and move them to after the shared prefix
199
199
for _ in 1 ... shared. characters. count {
200
- index = index . successor ( )
201
- labelIndex = labelIndex . successor ( )
200
+ index = searchStr . characters . index ( after : index )
201
+ labelIndex = e . label . characters . index ( after : labelIndex )
202
202
}
203
203
204
204
// Substring both the search string and the label from the shared prefix
205
- searchStr = searchStr. substringFromIndex ( index)
206
- e. label = e. label. substringFromIndex ( labelIndex)
205
+ searchStr = searchStr. substring ( from : index)
206
+ e. label = e. label. substring ( from : labelIndex)
207
207
208
208
// Create 2 new edges and update parent/children values
209
209
let newEdge = Edge ( e. label)
@@ -236,7 +236,7 @@ public class RadixTree {
236
236
}
237
237
238
238
// Tells you if a string is in the tree
239
- public func find( str: String ) -> Bool {
239
+ public func find( _ str: String ) -> Bool {
240
240
// A radix tree always contains the empty string
241
241
if str == " " {
242
242
return true
@@ -267,9 +267,9 @@ public class RadixTree {
267
267
currEdge = c
268
268
var tempIndex = searchStr. startIndex
269
269
for _ in 1 ... shared. characters. count {
270
- tempIndex = tempIndex . successor ( )
270
+ tempIndex = searchStr . characters . index ( after : tempIndex )
271
271
}
272
- searchStr = searchStr. substringFromIndex ( tempIndex)
272
+ searchStr = searchStr. substring ( from : tempIndex)
273
273
found = true
274
274
break
275
275
}
@@ -300,12 +300,12 @@ public class RadixTree {
300
300
}
301
301
302
302
// Removes a string from the tree
303
- public func remove( str: String ) -> Bool {
303
+ public func remove( _ str: String ) -> Bool {
304
304
// Removing the empty string removes everything in the tree
305
305
if str == " " {
306
306
for c in root. children {
307
307
c. erase ( )
308
- root. children. removeAtIndex ( 0 )
308
+ root. children. remove ( at : 0 )
309
309
}
310
310
return true
311
311
}
@@ -329,7 +329,7 @@ public class RadixTree {
329
329
// and everything below it in the tree
330
330
if currEdge. children [ c] . label == searchStr {
331
331
currEdge. children [ c] . erase ( )
332
- currEdge. children. removeAtIndex ( c)
332
+ currEdge. children. remove ( at : c)
333
333
return true
334
334
}
335
335
@@ -341,9 +341,9 @@ public class RadixTree {
341
341
currEdge = currEdge. children [ c]
342
342
var tempIndex = searchStr. startIndex
343
343
for _ in 1 ... shared. characters. count {
344
- tempIndex = tempIndex . successor ( )
344
+ tempIndex = searchStr . characters . index ( after : tempIndex )
345
345
}
346
- searchStr = searchStr. substringFromIndex ( tempIndex)
346
+ searchStr = searchStr. substring ( from : tempIndex)
347
347
found = true
348
348
break
349
349
}
@@ -364,15 +364,15 @@ public class RadixTree {
364
364
365
365
// Returns the prefix that is shared between the two input strings
366
366
// i.e. sharedPrefix("court", "coral") -> "co"
367
- public func sharedPrefix( str1: String , _ str2: String ) -> String {
367
+ public func sharedPrefix( _ str1: String , _ str2: String ) -> String {
368
368
var temp = " "
369
369
var c1 = str1. characters. startIndex
370
370
var c2 = str2. characters. startIndex
371
371
for _ in 0 ... min ( str1. characters. count- 1 , str2. characters. count- 1 ) {
372
372
if str1 [ c1] == str2 [ c2] {
373
373
temp. append ( str1 [ c1] )
374
- c1 = c1 . successor ( )
375
- c2 = c2 . successor ( )
374
+ c1 = str1 . characters . index ( after : c1 )
375
+ c2 = str2 . characters . index ( after : c2 )
376
376
} else {
377
377
return temp
378
378
}
0 commit comments