Cursor.FindSingleValue

Ruslan Zasukhin ruslan_zasukhin at valentina-db.com
Tue Dec 29 12:58:41 CST 2009


On 12/29/09 6:29 PM, "Thomas Flemming" <tf at ttqv.com> wrote:

Hi Thomas,

>> And you have cursor ordered by field 1.
>> So binary search can be used on this field1.
>> Binary search is FAST. Even for million record this is only 20 steps.
> In c++, but also in vb.net?
> Maybe you can give a short example, on how this could work.

1) binary search do even children in game
        Guess a number.

I have choose number from 1 to 1M.
Thomas, please guess this number!

I think you first guess will be 500,000. Yes
Then I say bigger.

You say - 750,000, yes?
I say smaller

You say 625,000
And so on.

Algorithm itself I think you can easy find in Google

BINARY SEARCH works on ANY SORTED ARRAY.

You say that you have
    "select * from table order by field1"

This means that your cursor is SORTED BY FIELD field1, right?
This means that you have SORTED ARRAY of fields in fact.


2) and your task solution is:

cursor2 find single record.
You extract for this record value field1

And now do binary search in the cursor1.
10 steps only for 1K records.
20 steps only for 1M records
30 steps only for 1 billion recs

If field1 is not unique field, then you can find GROUP of recs with the same
value in field1. Right? But this group will be small. And here you can do
linear search using RecID value from curs2.

I hope this is very clear and detailed description :)

-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list