Schmidt
8/29/2011 3:32:00 PM
Am 28.08.2011 21:05, schrieb BeeJ:
> Thanks for the feedback!
> Fast but I am looking for code ...
Ah, but since in your first post you were asking:
"I need fastest String Store and Exists Check."
I thought that the RC4s cSortedDictionary would
worth mentioning.
> ... I can get into and modify as needed.
Ok, but in this case you should perhaps also
refrain from the usage of the Scripting.Dictionary,
since you cannot modify its sourcecode either. ;-)
Just in case, these your planned modifications are
related to Sorting and a following binary-search
on the sorted contents: this already comes "for free"
in cSortedDictionary.
For example, if you want to achieve something like
the VB-IDE does with Intellisense (up-popping areas,
which give you the "nearest entry within a sorted list"
whilst typing the beginning of the searchterm).
If that's what you're after, then there's another
method of the cSortedDictionary (.IndexByKey), you
maybe should know about (before you throw it away ;-).
The following example scans "c:\windows\system32"
for all dlls, puts the results sorted into a listbox -
and then allows you in a textbox, to type the beginnings
of the entry you're searching for - the listbox is updating
its contents then appropriately (listing/filtering only the
entries, which start with the sequence you're typing.
The "binary chop" is done in this case by the
SortedDictionarys .IndexByKey-method, which offers
a second (optional) parameter, which you would need
to turn on - but look at the example...
(needs RichClient4 for the new cDirList-stuff, which
the older version 3 does not have)
'*** Into a Form
'*** with a TextBox named: txtStartsWith
'*** and a ListBox name: lstFiles
Option Explicit
Const FolderToScan$ = "c:\windows\system32"
Private New_c As New cConstructor
Private SD As cSortedDictionary, DL As cDirList
Private Sub Form_Load()
'perform a FolderScan, and store the results in our DL-Object
Dim Flt As String
Flt = "*.dll"
With New_c.FSO
Set DL = .GetDirList(FolderToScan, dlSortNone, Flt, True, True)
End With
'copy the filenames (from the already filled DL) over into
'our sorting Dictionary for faster Filtering later on
Set SD = GetNamesFromDirList(DL)
Caption = SD.Count & " (" & Flt & ") Files found in " & FolderToScan
FillListFromSD lstFiles, SD
End Sub
Function GetNamesFromDirList(DL As cDirList) As cSortedDictionary
Dim i As Long
Set GetNamesFromDirList = New_c.SortedDictionary(TextCompare, True)
For i = 0 To DL.FilesCount - 1
GetNamesFromDirList.Add DL.FileName(i)
Next i
End Function
Private Sub FillListFromSD(LB As ListBox, SD As cSortedDictionary, _
Optional ByVal StartsWith As String)
Dim i As Long, LenSW As Long, Idx As Long
StartsWith = LCase$(StartsWith)
LenSW = Len(StartsWith)
LB.Clear
If SD.Count = 0 Then Exit Sub
If LenSW = 0 Then 'copy everything over into the LB
For i = 0 To SD.Count - 1
LB.AddItem SD.KeyByIndex(i)
Next i
Else 'the SortedDictionaries "StartsWith-scan-feature", forced by...
Idx = SD.IndexByKey(StartsWith, True) '<- ..the Optional Param here
If Idx >= SD.Count Then Exit Sub
Do While LCase$(Left$(SD.KeyByIndex(Idx), LenSW)) = StartsWith
LB.AddItem SD.KeyByIndex(Idx)
Idx = Idx + 1
If Idx = SD.Count Then Exit Do
Loop
End If
End Sub
Private Sub txtStartsWith_Change()
FillListFromSD lstFiles, SD, txtStartsWith.Text
End Sub
Olaf