ts-ds / traceSearch
Function: traceSearch()
ts
function traceSearch<T>(
algorithm,
array,
target,
compareFn?
): SearchTrace<T>;Defined in: trace/search.ts:28
Records which elements a search algorithm looks at (probe) and every call of the comparator (compare). Like trace, the algorithm is not changed: the array is wrapped in a Proxy.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
algorithm | (array, target, compareFn?) => number | Search function, e.g. binarySearch. |
array | readonly T[] | Array to search. |
target | T | Value to find. |
compareFn? | CompareFn<T> | Comparator passed to the algorithm. |
Returns
SearchTrace<T>
The result, the steps and the counters.
Example
ts
traceSearch(binarySearch, [1, 3, 5, 7], 5).stats; // { probes: 3, comparisons: 3 }