Files
obitools4/autodoc/docmd/pkg/obiutils/ranks.md
T
Eric Coissac 8c7017a99d ⬆️ version bump to v4.5
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5"
- Update version.txt from 4.29 → .30
(automated by Makefile)
2026-04-13 13:34:53 +02:00

36 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# `obiutils` — Semantic Description of Core Functionality
This Go package provides generic and type-specific utilities for **ranking** and **ordering** data without modifying the original slice. It leverages Gos `sort` package to compute index permutations that reflect sorted order.
## Key Components
- **IntOrder(data []int) []int**
Returns indices that would sort a slice of integers in *ascending* order. The original data remains unchanged.
- **ReverseIntOrder(data []int) []int**
Same as `IntOrder`, but returns indices for *descending* order.
- **Order[T sort.Interface](data T) []int**
Generic version accepting any type implementing `sort.Interface`. Returns stable sorted indices.
## Internal Design
- **intRanker** and **Ranker[T]**: Helper types wrapping data + index list (`r`).
They implement `sort.Interface` *indirectly*—sorting indices instead of mutating data.
- **Index-based sorting**:
By permuting a list of indices (`r = [0,1,...]`), the original data is never copied or altered—ideal for large datasets or immutable inputs.
- **Stability**: `Order` uses `sort.Stable`, preserving relative order of equal elements.
## Use Cases
- Sorting metadata (e.g., sorting labels by associated scores).
- Preparing orderings for downstream operations (plots, ranking metrics).
- Efficiently tracking original positions after sort.
## Constraints
- Requires `sort.Interface` for generic version (e.g., custom structs with methods).
- Returns empty slice (`nil`) on zero-length input.