Stdlib module math/sort.vitl

This page is a wiki-style reference for one concrete stdlib file. It explains what the file owns, where it fits in the family, and how to decide whether this is the right surface to depend on.

Visual portrait of math/sort.vitl
Wiki-style portrait for math/sort.vitl.

Family: math

Kind: public stdlib surface

Page style: this reference follows the same “encyclopedic card + portrait + usage contract” logic as the keyword pages, but for stdlib modules.

Summary

Overview

FieldValue
Pathmath/sort.vitl
Familymath
Kindpublic stdlib surface
Line count347
Declared procedures48
Declared forms/picks0

`math/sort.vitl` is a public stdlib surface inside the `math` family. It should be read as one focused slice of the broader family responsibility: Arithmetic, algebra, comparison, calculus, geometry, modular arithmetic, number theory, probability, statistics, matrix, and vector helpers.

Purpose

This file should be chosen because of responsibility, not because its name “sounds close enough”. Inside the math family, it carries one focused part of the contract and keeps that responsibility separate from neighboring concerns.

  • A scoring engine can compute aggregates in `math` while keeping I/O and transport elsewhere.
  • A statistics or matrix chapter should explain the workflow around the computation, not just a single formula.

Taxonomy

Think of this page as a generated encyclopedia entry rather than a hand-written tutorial. The goal is to show what kind of module this is, how dense it is, and what reading strategy makes sense before depending on it.

  • Large algorithm surface: this file exposes many procedures and likely acts as a domain toolkit rather than a single thin wrapper.
  • Has tuning constants: part of the module behavior is controlled by named constants that document default precision, limits, or policy.
  • Minimal top-level dependencies: the module reads as mostly self-contained from its opening declarations.
  • Explicit export surface: the file ends with visible export declarations instead of relying only on implicit namespace discovery.

Implementation profile

This profile is inferred directly from the source text. It does not replace reading the file, but it tells you quickly whether the module is mostly declarative, loop-heavy, branch-heavy, or organized around many small exits.

SignalCountWhat it suggests
if14Branching density and local decision-making.
while16Loop-heavy or iterative implementation style.
for0Collection-style traversal at source level.
match0Variant-driven branching or grammar-style decoding.
let61Local state and intermediate value density.
give57Number of explicit exit points and result shaping.

Top-level API inventory

SurfaceItems
Procedurescopy_range, reverse_copy, swap, floor_log2_int, median3_index, is_sorted, is_strictly_sorted, insertion_sort_range, insertion_sort_inplace, insertion_sort, sift_down, heapify
Formsnone declared at top level
Picksnone declared at top level
ConstantsINSERTION_THRESHOLD
Exports*

Imported surfaces

This file does not advertise a top-level `use` surface in its opening declarations. That often means it is either self-contained or an aggregation layer.

Position in family

This file is module 17 of 21 in the math family when ordered by path. By procedure count it ranks 13, and by line count it ranks 15. Those ranks are useful as rough signals of breadth, not as quality judgments.

Declaration map

The declaration map turns raw source into a scan-friendly catalog. It is useful when the file is large enough that a reader wants to orient by kinds of surfaces first.

LineNameKindRole
1vitte/stdlib/math/sortspaceDeclares the namespace that anchors this file in the stdlib tree.
3INSERTION_THRESHOLDconstDefines a named constant reused across the module.
5copy_rangeprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
15reverse_copyprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
25swapprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
33floor_log2_intprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
43median3_indexprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
62is_sortedprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
73is_strictly_sortedprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
84insertion_sort_rangeprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
100insertion_sort_inplaceprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
104insertion_sortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
108sift_downprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
112heapifyprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
116sort_inplaceprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
134heapsort_inplaceprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
138heapsortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
142partitionprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
157heapsort_rangeprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
161introsort_recprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
165quicksort_inplaceprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
169quicksortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
173introsortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
177mergeprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
196mergesortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
206stable_sortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
210reverseprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
214reverse_inplaceprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
218sort_descprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
223sort_desc_inplaceprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
227nth_elementprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
235partial_sortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
240top_kprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
245bottom_kprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
250lower_boundprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
262upper_boundprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
274binary_searchprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
294contains_sortedprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
298sort_intprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
299sort_i32procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
300sort_i64procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
301sort_u32procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
302sort_u64procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
304sort_f64procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
322stable_sort_intprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
323stable_sort_f64procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
324sortprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
326sort_versionprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
330sort_readyprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
334sort_selftestprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.

The table is exhaustive for top-level declarations of the selected kinds. This file declares 50 matching surfaces.

Representative signatures

These signatures are shown in source order so the page keeps the feel of a reference manual, not just a keyword cloud.

  • const INSERTION_THRESHOLD: int = 16 (line 3)
  • proc copy_range(values: [int], start: int, end: int) -> [int] { (line 5)
  • proc reverse_copy(values: [int]) -> [int] { (line 15)
  • proc swap(values: [int], i: int, j: int) -> [int] { (line 25)
  • proc floor_log2_int(value: int) -> int { (line 33)
  • proc median3_index(values: [int], a: int, b: int, c: int) -> int { (line 43)
  • proc is_sorted(values: [int]) -> bool { (line 62)
  • proc is_strictly_sorted(values: [int]) -> bool { (line 73)
  • proc insertion_sort_range(values: [int], start: int, end: int) -> [int] { (line 84)
  • proc insertion_sort_inplace(values: [int]) -> [int] { (line 100)
  • proc insertion_sort(values: [int]) -> [int] { (line 104)
  • proc sift_down(values: [int], start: int, end: int) -> [int] { (line 108)
  • proc heapify(values: [int]) -> [int] { (line 112)
  • proc sort_inplace(values: [int]) -> [int] { (line 116)
  • proc heapsort_inplace(values: [int]) -> [int] { (line 134)
  • proc heapsort(values: [int]) -> [int] { (line 138)
  • proc partition(values: [int], pivot: int) -> [[int]] { (line 142)
  • proc heapsort_range(values: [int], start: int, end: int) -> [int] { (line 157)

The list is intentionally capped here; the source file declares 49 matching signatures in total.

How to use this module

Start by reading the file as an ownership boundary. Ask three questions: what enters this module, what stable types or procedures it exports, and what adjacent module should stay outside of it.

  1. Read space and top-level imports first so the ownership boundary of math/sort.vitl is explicit.
  2. Scan constants before procedures; they often encode precision, limits, or policy assumptions that explain later behavior.
  3. Traverse procedures in source order; the early helpers usually explain the naming and numeric conventions used later.
  4. Only after that compare neighbor modules, because the right boundary choice matters more than memorizing one helper name.

User example

This example is generated from the actual stdlib module surface. Its job is not to be the smallest snippet possible; its job is to show a realistic consumer-shaped file that exercises the module and mirrors the language keywords the module itself relies on.

space demo/math_sort
const SAMPLE_LABEL: string = "demo"
proc run_example() -> string {
  let entries = copy_range([1, 2, 3], 1, 1)
  let ready: bool = is_sorted([1, 2, 3])
  let failed: bool = false
  let stable: bool = ready and true
  let fallback: bool = ready or false
  let idx: int = 0
  let count: int = 0
  while idx < entries.len {
    set count = count + 1
    set idx = idx + 1
  }
  if ready {
    give "not-ready"
  } else {
    give "ok"
  }
}
export run_example

Keyword coverage

This table makes the “all keywords of the module” requirement auditable. It compares the detected Vitte keywords in the source file with the generated consumer example above.

KeywordPresent in module sourceUsed in generated user example
spaceyesyes
constyesyes
procyesyes
letyesyes
setyesyes
ifyesyes
elseyesyes
whileyesyes
giveyesyes
exportyesyes
trueyesyes
falseyesyes
andyesyes
oryesyes

The generated snippet exercises every detected Vitte keyword used by this module.

Source shape

space vitte/stdlib/math/sort
const INSERTION_THRESHOLD: int = 16
proc copy_range(values: [int], start: int, end: int) -> [int] {
  let out: [int] = []
  let i: int = start
  while i < values.len and i < end {
    set out = out + [values[i]]
    set i = i + 1
  }
  give out

The excerpt is not meant to replace the file. It exists to make the module recognizable at first glance, the same way a Wikipedia infobox helps the reader orient before reading the whole article.

Source landmarks

Large files are easier to retain when they have visible landmarks. When the source contains explicit section banners, they are surfaced here; otherwise the first major declarations are used as anchors.

  • Line 1: space vitte/stdlib/math/sort
  • Line 3: const INSERTION_THRESHOLD: int = 16
  • Line 5: proc copy_range(values: [int], start: int, end: int) -> [int] {
  • Line 15: proc reverse_copy(values: [int]) -> [int] {
  • Line 25: proc swap(values: [int], i: int, j: int) -> [int] {
  • Line 33: proc floor_log2_int(value: int) -> int {
  • Line 43: proc median3_index(values: [int], a: int, b: int, c: int) -> int {
  • Line 62: proc is_sorted(values: [int]) -> bool {

Source organization

When a file carries its own internal chaptering, those chapters usually reveal the intended reading order better than a flat symbol list. This section reconstructs that organization from the source itself.

File surfaces

Top-level items: 51. Procedures: 48. Data surfaces: 0. Constants: 1.

First visible names: vitte/stdlib/math/sort, INSERTION_THRESHOLD, copy_range, reverse_copy, swap, floor_log2_int, median3_index, is_sorted, is_strictly_sorted, insertion_sort_range

Complete API catalog

This catalog is the exhaustive file-level index for the module. It is intentionally closer to a generated encyclopedia appendix than to a tutorial summary.

Constants

LineNameSignatureRole
3INSERTION_THRESHOLDconst INSERTION_THRESHOLD: int = 16Defines a named constant reused across the module.

Procedures

LineNameSignatureRole
5copy_rangeproc copy_range(values: [int], start: int, end: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
15reverse_copyproc reverse_copy(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
25swapproc swap(values: [int], i: int, j: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
33floor_log2_intproc floor_log2_int(value: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
43median3_indexproc median3_index(values: [int], a: int, b: int, c: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
62is_sortedproc is_sorted(values: [int]) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
73is_strictly_sortedproc is_strictly_sorted(values: [int]) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
84insertion_sort_rangeproc insertion_sort_range(values: [int], start: int, end: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
100insertion_sort_inplaceproc insertion_sort_inplace(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
104insertion_sortproc insertion_sort(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
108sift_downproc sift_down(values: [int], start: int, end: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
112heapifyproc heapify(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
116sort_inplaceproc sort_inplace(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
134heapsort_inplaceproc heapsort_inplace(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
138heapsortproc heapsort(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
142partitionproc partition(values: [int], pivot: int) -> [[int]] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
157heapsort_rangeproc heapsort_range(values: [int], start: int, end: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
161introsort_recproc introsort_rec(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
165quicksort_inplaceproc quicksort_inplace(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
169quicksortproc quicksort(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
173introsortproc introsort(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
177mergeproc merge(a: [int], b: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
196mergesortproc mergesort(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
206stable_sortproc stable_sort(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
210reverseproc reverse(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
214reverse_inplaceproc reverse_inplace(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
218sort_descproc sort_desc(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
223sort_desc_inplaceproc sort_desc_inplace(values: [int]) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
227nth_elementproc nth_element(values: [int], index: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
235partial_sortproc partial_sort(values: [int], count0: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
240top_kproc top_k(values: [int], k: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
245bottom_kproc bottom_k(values: [int], k: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
250lower_boundproc lower_bound(values: [int], needle: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
262upper_boundproc upper_bound(values: [int], needle: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
274binary_searchproc binary_search(values: [int], needle: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
294contains_sortedproc contains_sorted(values: [int], needle: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
298sort_intproc sort_int(values: [int]) -> [int] { give sort_inplace(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
299sort_i32proc sort_i32(values: [int]) -> [int] { give sort_inplace(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
300sort_i64proc sort_i64(values: [int]) -> [int] { give sort_inplace(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
301sort_u32proc sort_u32(values: [int]) -> [int] { give sort_inplace(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
302sort_u64proc sort_u64(values: [int]) -> [int] { give sort_inplace(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
304sort_f64proc sort_f64(values: [f64]) -> [f64] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
322stable_sort_intproc stable_sort_int(values: [int]) -> [int] { give stable_sort(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
323stable_sort_f64proc stable_sort_f64(values: [f64]) -> [f64] { give sort_f64(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
324sortproc sort(values: [int]) -> [int] { give sort_inplace(values) }Represents one top-level surface in the file contract and should be read as part of the module boundary.
326sort_versionproc sort_version() -> string {Represents one top-level surface in the file contract and should be read as part of the module boundary.
330sort_readyproc sort_ready() -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
334sort_selftestproc sort_selftest() -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.

Exports

LineNameSignatureRole
347*export *Re-exports surfaces that the module wants to expose as part of its public boundary.

Integration boundaries

Within math, this file should remain focused. If a future helper changes the host boundary, scheduling boundary, or data-shape boundary, it probably belongs in a neighbor module instead of being added here by convenience.

  • Family responsibility: Arithmetic, algebra, comparison, calculus, geometry, modular arithmetic, number theory, probability, statistics, matrix, and vector helpers.
  • Family architecture role: Use `math` when the transformation itself is the feature. This family exists so algorithmic intent stays visible and testable.

Composition guidance

Choose this module when

  • Choose math/sort.vitl when the main question is owned by this module rather than by transport, storage, orchestration, or user-interface code.
  • A scoring engine can compute aggregates in `math` while keeping I/O and transport elsewhere.
  • A statistics or matrix chapter should explain the workflow around the computation, not just a single formula.

Pause before extending it when

  • Avoid extending this file when the new helper mostly changes the boundary to host I/O, runtime coordination, or foreign integration instead of staying inside math.
  • Check nearby modules such as math/algebra.vitl, math/arithmetic.vitl, math/arrays.vitl before adding convenience wrappers here.

Relationship table

This table keeps the page closer to a real encyclopedia entry: a module is easier to understand when compared with its nearest alternatives in the same family.

NeighborProceduresData surfacesWhy compare it
math/algebra.vitl140Shares the same family boundary but carries a distinct slice of responsibility.
math/arithmetic.vitl722Shares the same family boundary but carries a distinct slice of responsibility.
math/arrays.vitl832Shares the same family boundary but carries a distinct slice of responsibility.
math/calculus.vitl563Shares the same family boundary but carries a distinct slice of responsibility.
math/comparison.vitl470Shares the same family boundary but carries a distinct slice of responsibility.
math/complex.vitl490Shares the same family boundary but carries a distinct slice of responsibility.
math/geometry.vitl720Shares the same family boundary but carries a distinct slice of responsibility.
math/logic.vitl200Shares the same family boundary but carries a distinct slice of responsibility.

Neighbor modules