4 ms·
You misunderstood! In my code, all arithmetic is performed with 64-bit unsigned integers. The "trick" is a type whose size is zero bytes. If T is size zero, Ve
by ridiculous_fish 5y ago
You misunderstood! In my code, all arithmetic is performed with 64-bit unsigned integers.
The "trick" is a type whose size is zero bytes. If T is size zero, Vec<T> does not allocate any memory: it just keeps a count. You can make a Vec<()> with usize::max() for free, if you can finesse the compiler.
The binary search itself does not access any memory: it's just pure arithmetic, and it overflows.
- kazinator 5y agoHow do you use this object in an application, such that it's useful to do a binary_search on it and part of the application? Would that be just to prototype something before going to other data structures, or in production too?