
If not, the following start could help - because on a constant word table, also the pointer table also have after do be done only one time. To speed up everything, a fourth character could be included in the pointer list and a binary search in the find routine would to the rest...
Code: Select all
#Words=1234567
#Pointer=26*26*26
Global Dim abc.s(#Words)
Global Dim ptr(#Pointer)
Debug "Create sorted word list..."
RandomSeed(0)
Dim aaa(3)
init.s="aaa"
z=0
more=1
While z<#Words
z+1
abc(z)=init
n=Random(15)
For i=1 To n
abc(z)+Chr('a'+Random(25))
Next i
If more And Random(50)=0
n=0
m=3
Repeat
If aaa(m)<25
aaa(m)+1
n=1
;If m=1
; Debug Chr(aaa(1)+'a')
;EndIf
Else
aaa(m)=0
m-1
If m=0
n=1
more=0
EndIf
EndIf
Until n
If more
init=Chr('a'+aaa(1))+Chr('a'+aaa(2))+Chr('a'+aaa(3))
EndIf
EndIf
Wend
Debug "Create pointer..."
z=#Words
While z>0
ptr((PeekA(@abc(z))-'a')*576+(PeekA(@abc(z)+SizeOf(Character))-'a')*26+(PeekA(@abc(z)+SizeOf(Character)<<1)-'a'))=z
z-1
Wend
z=#Pointer
ptr(#Pointer)=#Words
While z>0
z-1
If ptr(z)=0
ptr(z)=-Abs(ptr(z+1))
EndIf
Wend
Procedure find(s.s)
Protected pointer,n
pointer=(PeekA(@s)-'a')*576+(PeekA(@s+SizeOf(Character))-'a')*26+(PeekA(@s+SizeOf(Character)<<1)-'a')
If pointer>=0 And pointer<#Pointer
n=Abs(ptr(pointer+1))
pointer=ptr(pointer)
If pointer>0
While pointer<n
If abc(pointer)=s
Debug "Found '"+s+"' at position "+Str(pointer)
ProcedureReturn pointer
EndIf
pointer+1
Wend
EndIf
EndIf
ProcedureReturn #Null
EndProcedure
Debug "Search..."
Debug find("ahedtymjfcszty")
Debug find("cvhnvwzssyrkfmpzsa")
Debug find("zzzdacknjkxghp")