Repository navigation
馃敡 Functional Interfaces
1. bisect_left
bisect_left<T>(
arr: [T],
x: T,
lo_opt: ?Nat,
hi_opt: ?Nat,
fcmp: (T, T) -> Order.Order
) : Nat- Purpose: Finds the leftmost insertion point for
xin the sorted arrayarr. - Use Case: Inserts
xbefore any existing entries of the same value. - Returns: Index where
xshould be inserted.
2. bisect_right
bisect_right<T>(
arr: [T],
x: T,
lo_opt: ?Nat,
hi_opt: ?Nat,
fcmp: (T, T) -> Order.Order
) : Nat- Purpose: Finds the rightmost insertion point for
x. - Use Case: Inserts
xafter existing entries of the same value. - Returns: Index where
xshould be inserted.
3. insort_left
insort_left<T>(
arr: [T],
x: T,
lo_opt: ?Nat,
hi_opt: ?Nat,
fcmp: (T, T) -> Order.Order
) : [T]- Purpose: Inserts
xat the position returned bybisect_left. - Returns: A new array with
xinserted, maintaining order.
4. insort_right
insort_right<T>(
arr: [T],
x: T,
lo_opt: ?Nat,
hi_opt: ?Nat,
fcmp: (T, T) -> Order.Order
) : [T]- Purpose: Inserts
xat the position returned bybisect_right. - Returns: A new array with
xinserted, maintaining order.
馃 Parameters
| Name | Type | Description |
|---|---|---|
arr |
[T] |
Sorted array of elements |
x |
T |
Element to insert or search |
lo_opt |
?Nat |
(Optional) Start index for the search |
hi_opt |
?Nat |
(Optional) End index for the search |
fcmp |
(T, T) -> Order |
Comparator function between two elements |
馃攷 If
lo_optandhi_optarenull, the entire array is searched by default.