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

partition[T: Copyable, origin: MutOrigin, //, cmp_fn: def(T, T) capturing -> Bool](span: Span[T, origin], 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:

  • T (Copyable): Type of the underlying data.
  • origin (MutOrigin): Origin of span.
  • cmp_fn (def(T, T) capturing -> Bool): Comparison functor of (T, T) capturing [_] -> Bool type.

Args: