Skip to content

New lookup functions on BTreeMap/Set #49638

Open
@parsonsmatt

Description

@parsonsmatt

The current function get attempts to find an exact key match; if it fails, it returns None. I propose the addition of four variants:

  • get_lt finds the greatest (key, element) in the map/set that is less than the given key.
  • get_lte returns the lookup key and element in the map if present, otherwise returning the next smallest key and element.
  • get_gt finds the smallest (key, element) in the map/set that is greater than the given key.
  • get_gte looks up the key; if present, returns it and the element, if not, returns the next largest key and element.

The specific use case that prompted this:

I'm working on a toy Smalltalk implementation. One of the implementation methods is "given an object pointer, find the next object pointer that is an instance of of the class." Given a value instances: BTreeSet<Pointer>, the implementation is simply get_gt(obj_ptr).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions