Re:Binary Search Reconsidered (2018)
by TedShiller on Friday December 25, 2020 @02:47PM
(#25538552)
That’s considered clean?
[ Parent
| on HN ]
Re:Binary Search Reconsidered (2018)
by tsimionescu on Friday December 25, 2020 @03:48PM
(#25538920)
What do you consider not to be clean? I dislike the fact that it returns a copy of the key, but otherwise it seems quite explicit code that doesn't needlessly get bogged down in error prone integer arithmetic.
As I've pointed out in another comment, this implementation loses track of the index. It looks clean enough to my un-rusty eye, but it sacrifices functionality in favor of hiding the arithmetic behind a slice.
And __s's comment does it best: use the standard library. And that's a nice implementation (despite the unsafe stuff), which tracks the basepoint and size to keep the arithmetic clean.