Closed
Description
TreeMap (and TreeSet) should provide a variant of find
that returns an iterator instead of the value, for finding the start (or end) of a range of values in O(log n). It would probably make sense to expose lower_bound
and upper_bound
like C++ does in std::map
too.
The basic functionality is pretty simple, it's just the same process as find
but each node along the way is pushed onto an iterator's stack, which is then returned. However, it would be nice to get values in the reverse direction too, especially without needing to walk down the tree twice. In C++, the lazy iterators are bidirectional - but that's because they have pointers to walk (which really wouldn't work for an owned tree in Rust, and is likely slower).