Skip to content

Add range searches to TreeMap/TreeSet #4604

Closed
@thestinger

Description

@thestinger

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions