N
Nick
I have a dictionary and I am trying to trim it down to the N smallest
items. For example, myDict usually contains around 3500 to 5500 items,
and I only want the smallest 10 (usually). The code I'm using now is :
'// loop, removing largest distance until we're down to the number of
points we want
Do Until myDict.Count = N
maxDist = -1
For Each i In myDict.Keys
If myDict.Item(i) > maxDist Then
maxDist = myDict.Item(i)
mx = i
End If
Next i
myDict.Remove mx
Loop
The problem is that this is super slow; it loops through thousands of
times, and this snippet of code is used thousands of times too. Is
there a faster way to get the smallest N items?
items. For example, myDict usually contains around 3500 to 5500 items,
and I only want the smallest 10 (usually). The code I'm using now is :
'// loop, removing largest distance until we're down to the number of
points we want
Do Until myDict.Count = N
maxDist = -1
For Each i In myDict.Keys
If myDict.Item(i) > maxDist Then
maxDist = myDict.Item(i)
mx = i
End If
Next i
myDict.Remove mx
Loop
The problem is that this is super slow; it loops through thousands of
times, and this snippet of code is used thousands of times too. Is
there a faster way to get the smallest N items?