# Add lowerBound/upperBound/equalRange · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/664c18544c2622352a4e38254496a349006d331b)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 664c18544c2622352a4e38254496a349006d331b

Requested commit: 664c18544c2622352a4e38254496a349006d331b

Commit: 664c18544c2622352a4e38254496a349006d331b

Tree: 16af022be1c0ac38ff5135183f759d5c25372110

Author: Craig O'Connor

Committer: John Schmidt

## Message

```
Add lowerBound/upperBound/equalRange

Authored by https://github.com/CraigglesO

Original Discussion: #9890

I already had to create these functions and test cases for my own
project so I decided to contribute to the main code base in hopes it
would simplify my own.

I realize this is still under discussion but this was a trivial amount
of work so I thought I could help nudge the discussion towards a
decision.

Why add these to the standard library

To better illustrate and solidify their value, the standard library's
"sort" module already contains several binary search queries on arrays
such as binarySearch and internal functions binaryFirst & binaryLast. A
final example of its use: the Zig code itself created and used a
bounding search in the linker.

There still lacks the ability to allow the programmer themselves to
search the array for a rough position and find an index to read &/
update.

Adding these functions would also help to complement dynamic structures
like ArrayList with it's insert function.

Example Case

I'm building a library in Zig for GIS geometry. To store points, lines,
and polygons each 3D point is first translated into what's called an
S2CellId. This is a fancy way of saying I reduce the Earth's spherical
data into a 1D Hilbert Curve with cm precision. This gives me 2
convenient truths:

    Hilbert Curves have locality of reference.
    All points can be stored inside a 1D array

Since lowerBound and upperBound to find data inside a radius for
instance. If I'm interested in a specific cell at a specific "level" and
want to iterate all duplicates, equalRange is a best fit.

```

## Parents

- [ee36131e6a8bf8611f8a6fd55116e98eae2ed63c](https://git.cafe/gitcafe/zig/commit/ee36131e6a8bf8611f8a6fd55116e98eae2ed63c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/664c18544c2622352a4e38254496a349006d331b?format=markdown)
