Skip to content

v1.0.0

Latest

Choose a tag to compare

@nirvana369 nirvana369 released this 19 Jun 04:09
· 1 commit to main since this release

馃敡 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 x in the sorted array arr.
  • Use Case: Inserts x before any existing entries of the same value.
  • Returns: Index where x should 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 x after existing entries of the same value.
  • Returns: Index where x should 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 x at the position returned by bisect_left.
  • Returns: A new array with x inserted, 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 x at the position returned by bisect_right.
  • Returns: A new array with x inserted, 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_opt and hi_opt are null, the entire array is searched by default.