janet-lang / spork

Various Janet utility modules - the official "Contrib" library.
MIT License
122 stars 35 forks source link

add binary-search macros #143

Closed primo-ppcg closed 1 year ago

primo-ppcg commented 1 year ago

No new tests have been added, the current tests for insert-sorted and insert-sorted-by are likely sufficient.

sogaiu commented 1 year ago

I tried it out a bit. In my limited testing it seemed fine :+1:

I wondered a bit about the case where one might want to know if some element is present. I guess once a value is returned, one could inspect the array using the returned index (taking into account the case where the index lies outside the currently valid indices).

primo-ppcg commented 1 year ago

one could inspect the array using the returned index

Seems sufficient to me, although a separate implementation could implement short circuiting. Worst and average runtime complexity would remain unchanged, though.