Skip to main content
Log in

Mojo function

partition

partition[type: CollectionElement, lifetime: MutableLifetime, //, cmp_fn: fn($0, $0) capturing -> Bool](span: Span[1, type, lifetime], k: Int)

Partition the input buffer 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.

Parameters:

  • type (CollectionElement): Type of the underlying data.
  • lifetime (MutableLifetime): Lifetime of span.
  • cmp_fn (fn($0, $0) capturing -> Bool): Comparison functor of (type, type) capturing -> Bool type.

Args:

  • span (Span[1, type, lifetime]): Input buffer.
  • k (Int): Index of the partition element.

partition[lifetime: MutableLifetime, //, cmp_fn: fn(Int, Int) capturing -> Bool](span: Span[1, Int, lifetime], k: Int)

Partition the input buffer 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.

Parameters:

  • lifetime (MutableLifetime): Lifetime of span.
  • cmp_fn (fn(Int, Int) capturing -> Bool): Comparison functor of (type, type) capturing -> Bool type.

Args:

  • span (Span[1, Int, lifetime]): Input buffer.
  • k (Int): Index of the partition element.

partition[type: DType, lifetime: MutableLifetime, //, cmp_fn: fn(SIMD[$0, 1], SIMD[$0, 1]) capturing -> Bool](span: Span[1, SIMD[type, 1], lifetime], k: Int)

Partition the input buffer 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.

Parameters:

  • type (DType): DType of the underlying data.
  • lifetime (MutableLifetime): Lifetime of span.
  • cmp_fn (fn(SIMD[$0, 1], SIMD[$0, 1]) capturing -> Bool): Comparison functor of (type, type) capturing -> Bool type.

Args:

  • span (Span[1, SIMD[type, 1], lifetime]): Input buffer.
  • k (Int): Index of the partition element.

Was this page helpful?