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