@@ -181,29 +181,29 @@ public class RadixTree {
181
181
else if shared == e. label {
182
182
currEdge = e
183
183
var tempIndex = searchStr. startIndex
184
- for _ in 1 ... shared. characters . count {
185
- tempIndex = searchStr. characters . index ( after: tempIndex)
184
+ for _ in 1 ... shared. count {
185
+ tempIndex = searchStr. index ( after: tempIndex)
186
186
}
187
- searchStr = searchStr . substring ( from : tempIndex)
187
+ searchStr = String ( searchStr [ tempIndex... ] )
188
188
found = true
189
189
break
190
190
}
191
191
192
192
// If the child's label and the search string share a partial prefix,
193
193
// then both the label and the search string need to be substringed
194
194
// and a new branch needs to be created
195
- else if shared. characters . count > 0 {
196
- var labelIndex = e. label. characters . startIndex
195
+ else if shared. count > 0 {
196
+ var labelIndex = e. label. startIndex
197
197
198
198
// Create index objects and move them to after the shared prefix
199
- for _ in 1 ... shared. characters . count {
200
- index = searchStr. characters . index ( after: index)
201
- labelIndex = e. label. characters . index ( after: labelIndex)
199
+ for _ in 1 ... shared. count {
200
+ index = searchStr. index ( after: index)
201
+ labelIndex = e. label. index ( after: labelIndex)
202
202
}
203
203
204
204
// Substring both the search string and the label from the shared prefix
205
- searchStr = searchStr . substring ( from : index)
206
- e. label = e. label. substring ( from : labelIndex)
205
+ searchStr = String ( searchStr [ index... ] )
206
+ e. label = String ( e. label [ labelIndex... ] )
207
207
208
208
// Create 2 new edges and update parent/children values
209
209
let newEdge = Edge ( e. label)
@@ -266,16 +266,16 @@ public class RadixTree {
266
266
if shared == c. label {
267
267
currEdge = c
268
268
var tempIndex = searchStr. startIndex
269
- for _ in 1 ... shared. characters . count {
270
- tempIndex = searchStr. characters . index ( after: tempIndex)
269
+ for _ in 1 ... shared. count {
270
+ tempIndex = searchStr. index ( after: tempIndex)
271
271
}
272
- searchStr = searchStr . substring ( from : tempIndex)
272
+ searchStr = String ( searchStr [ tempIndex... ] )
273
273
found = true
274
274
break
275
275
}
276
276
277
277
// If the shared string is empty, go to the next child
278
- else if shared. characters . count == 0 {
278
+ else if shared. count == 0 {
279
279
continue
280
280
}
281
281
@@ -287,7 +287,7 @@ public class RadixTree {
287
287
// If the search string and the child's label only share some characters,
288
288
// the string is not in the tree, return false
289
289
else if shared [ shared. startIndex] == c. label [ c. label. startIndex] &&
290
- shared. characters . count < c. label. characters . count {
290
+ shared. count < c. label. count {
291
291
return false
292
292
}
293
293
}
@@ -340,10 +340,10 @@ public class RadixTree {
340
340
if shared == currEdge. children [ c] . label {
341
341
currEdge = currEdge. children [ c]
342
342
var tempIndex = searchStr. startIndex
343
- for _ in 1 ... shared. characters . count {
344
- tempIndex = searchStr. characters . index ( after: tempIndex)
343
+ for _ in 1 ... shared. count {
344
+ tempIndex = searchStr. index ( after: tempIndex)
345
345
}
346
- searchStr = searchStr . substring ( from : tempIndex)
346
+ searchStr = String ( searchStr [ tempIndex... ] )
347
347
found = true
348
348
break
349
349
}
@@ -366,13 +366,13 @@ public class RadixTree {
366
366
// i.e. sharedPrefix("court", "coral") -> "co"
367
367
public func sharedPrefix( _ str1: String , _ str2: String ) -> String {
368
368
var temp = " "
369
- var c1 = str1. characters . startIndex
370
- var c2 = str2. characters . startIndex
371
- for _ in 0 ... min ( str1. characters . count- 1 , str2. characters . count- 1 ) {
369
+ var c1 = str1. startIndex
370
+ var c2 = str2. startIndex
371
+ for _ in 0 ... min ( str1. count- 1 , str2. count- 1 ) {
372
372
if str1 [ c1] == str2 [ c2] {
373
373
temp. append ( str1 [ c1] )
374
- c1 = str1. characters . index ( after: c1)
375
- c2 = str2. characters . index ( after: c2)
374
+ c1 = str1. index ( after: c1)
375
+ c2 = str2. index ( after: c2)
376
376
} else {
377
377
return temp
378
378
}
0 commit comments