-
Notifications
You must be signed in to change notification settings - Fork 217
Open
Description
Motivation
-
Other programming languages support high-level APIs like
- Get next smaller value (or item)
- Get floor value (or item)
- Get ceil value (or item)
- Get next larger value (or item)
In Tree data structure.
-
We can achieve this by using bisect method + index range check, but providing higher-level API would help users to avoid writing wrapper code every time.
API Definition
SortedList
- def next_smaller(self, value: object) -> Optional[object]
- def floor (self, value: object) -> Optional[object]
- def ceil (self, value: object) -> Optional[object]
- def next_greater(self, value: object) -> Optional[object]
SortedSet
- def next_smaller(self, value: Hashable) -> Optional[object]
- def floor (self, value: Hashable) -> Optional[object]
- def ceil (self, value: Hashable) -> Optional[object]
- def next_greater(self, value: Hashable) -> Optional[object]
SortedDict
- def next_smaller_item(self, key: Hashable) -> tuple[Optional[Hashable], Optional[object]]
- def floor_item (self, key: Hashable) -> tuple[Optional[Hashable], Optional[object]]
- def ceil_item (self, key: Hashable) -> tuple[Optional[Hashable], Optional[object]]
- def next_greater_item(self, key: Hashable) -> tuple[Optional[Hashable], Optional[object]]
Prototype Code (Implementation / Tests)
P.S
- If this idea sounds good to you, I'd love to discuss API design (including naming), testing strategy, etc.
- Thank you so much for your attention and participation.
tr1ten
Metadata
Metadata
Assignees
Labels
No labels