Skip to content

Efficient way to find the next smaller element than a given key in a TreeMap/TreeSet #8621

@scabug

Description

@scabug

Given a Set with elements (10,20,30,40,...) we need to find the next smallest and next largest element (both inclusive), e.g. nextSmallest(25) = 20, nextLargest(25) = 30.

Given a TreeMap this can be quickly done by traversing the tree. Sadly to achieve this in Scala 2.11 you have to copy the code of the TreeMap and RedBlack-classes.

On the other hand the next largest element can now be efficiently found using iteratorFrom introduced by #6642.

There should be a simple way to find the next smallest element, for example by introducing a reverseIteratorFrom.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions