aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Random.zig
diff options
context:
space:
mode:
authorCraig O'Connor <craigoconnor@Craigs-MacBook-Pro.local>2024-01-27 22:42:56 +0100
committerJohn Schmidt <john.schmidt.h@gmail.com>2024-02-07 21:00:24 +0100
commit664c18544c2622352a4e38254496a349006d331b (patch)
tree16af022be1c0ac38ff5135183f759d5c25372110 /lib/std/Random.zig
parentee36131e6a8bf8611f8a6fd55116e98eae2ed63c (diff)
downloadzig-664c18544c2622352a4e38254496a349006d331b.tar.gz
zig-664c18544c2622352a4e38254496a349006d331b.zip
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.
Diffstat (limited to 'lib/std/Random.zig')
0 files changed, 0 insertions, 0 deletions