Skip to main content



partition[type: AnyRegType, cmp_fn: fn[AnyRegType]($0, $0, /) capturing -> Bool](buff: LegacyPointer[type, 0], k: Int, size: Int)

Partition the input vector inplace such that first k elements are the largest (or smallest if cmp_fn is <= operator) elements. The ordering of the first k elements is undefined.


  • type (AnyRegType): DType of the underlying data.
  • cmp_fn (fn[AnyRegType]($0, $0, /) capturing -> Bool): Comparison functor of type, type) capturing -> Bool type.


  • buff (LegacyPointer[type, 0]): Input buffer.
  • k (Int): Index of the partition element.
  • size (Int): The length of the buffer.