'Builds the index and returns an object which you can store as a process global variable
'in order to avoid rebuilding the index when the device orientation changes.
Public Sub SetItems(Items As List) As Object
Dim startTime As Long
startTime = DateTime.Now
ProgressDialogShow2("Building index...", False)
Dim noDuplicates As Map
noDuplicates.Initialize
prefixList.Clear
substringList.Clear
Dim m As Map
Dim li As List
For i = 0 To Items.Size - 1
If i Mod 100 = 0 Then DoEvents
Dim item As String
item = Items.Get(i)
item = item.ToLowerCase
noDuplicates.Clear
For start = 0 To item.Length
Dim count As Int
count = MIN_LIMIT
Do While count <= MAX_LIMIT AND start + count <= item.Length
Dim str As String
str = item.SubString2(start, start + count)
If noDuplicates.ContainsKey(str) = False Then
noDuplicates.Put(str, "")
If start = 0 Then m = prefixList Else m = substringList
li = m.Get(str)
If li.IsInitialized = False Then
li.Initialize
m.Put(str, li)
End If
li.Add(Items.Get(i)) 'Preserve the original case
End If
count = count + 1
Loop
Next
Next
ProgressDialogHide
Log("Index time: " & (DateTime.Now - startTime) & " ms (" & Items.Size & " Items)")
Return Array As Object(prefixList, substringList)
End Sub