Well, to apply any search algorithm, first make sure that the table is appropriately sorted, that is, the column that needs to be searched, has to be sorted.
ED does not have a builtin, off the shelf, functionality that applyes the binary search but you can easily make your own method. Here is the code:
BinarySearch(e1, e2, e3)
where
e1: Atom containing the table
e2: Column number where the value should be searched
e3: The value that should be searched for
Code: Select all
Do(
var([atmTable], vbAtom, p(1)),
var([valColumn], vbValue, p(2)),
var([valValueToSearchFor], vbValue, p(3)),
var([valLowerBoundary], vbValue),
var([valUpperBoundary], vbValue),
var([valMiddlePoint], vbValue),
var([valFound], vbValue),
valFound := False,
valLowerBoundary := 0,
valUpperBoundary := nRows(atmTable),
if(
Cell(valUpperBoundary, valColumn, atmTable) = valValueToSearchFor,
Do(
valMiddlePoint := valUpperBoundary,
valFound := True
)
),
LoopUntil(
Or(
valFound,
valLowerBoundary + 1 >= valUpperBoundary
),
Do(
valMiddlePoint := Trunc((valLowerBoundary + valUpperBoundary )/2),
if(
Cell(valMiddlePoint, valColumn, atmTable) = valValueToSearchFor,
valFound := True,
if(
Cell(valMiddlePoint, valColumn, atmTable) < valValueToSearchFor,
valLowerBoundary := valMiddlePoint,
valUpperBoundary := valMiddlePoint
)
)
)
),
if(
valFound,
valMiddlePoint,
0
)
)