Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/source_map/lib/binary-search.js>search

Port of mozilla / source-map to deno.
Latest
function search
import { search } from "https://deno.land/x/source_map@0.8.0-beta.1/lib/binary-search.js";

This is an implementation of binary search which will always try and return the index of the closest element if there is no exact hit. This is because mappings between original and generated line/col pairs are single points, and there is an implicit region between each of them, so a miss just means that you aren't on the very start of a region.

Parameters

aNeedle

The element you are looking for.

aHaystack

The array that is being searched.

aCompare

A function which takes the needle and an element in the array and returns -1, 0, or 1 depending on whether the needle is less than, equal to, or greater than the element, respectively.

aBias

Either 'binarySearch.GREATEST_LOWER_BOUND' or 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the closest element that is smaller than or greater than the one we are searching for, respectively, if the exact element cannot be found. Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.