IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

partition

def partition[T: Copyable, origin: MutOrigin, //](span: Span[T, origin], k: Int, cmp_fn: T)

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:

  • ​T (Copyable): Type of the underlying data.
  • ​origin (MutOrigin): Origin of span.

Args:

  • ​span (Span[T, origin]): Input buffer.
  • ​k (Int): Index of the partition element.
  • ​cmp_fn (T): The comparison function.