leaderboard 0.1.2

Provides leaderboard functions for Vec such as ranking with ex aequos
Documentation
  • Coverage
  • 0%
    0 out of 8 items documented0 out of 0 items with examples
  • Size
  • Source code size: 7.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 206.48 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Inspirateur/leaderboard
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Inspirateur

leaderboard

A rust crate providing 2 functions for Vec useful in leaderboards:

  • vec.iter_ranked(): iterates on a sorted vec and group Equal elements together (ex aequos)
  • vec.iter_sections(ranges): iterate over the vec on the domain defined by a vec of ranges

Example

Here's how the 2 functions can be used together to display top and bottom 3 ranks with ex aequos:

fn test() {
    let scores = vec![
        150, 142, 138, 138, 135, 120, 101, 83, 66, 61, 61
    ];
    let ranking: Vec<_> = scores.iter_ranked().collect();
    let last = ranking.len();
    let mut rank = 1;
    for view in ranking.iter_sections(vec![0..3, last-3..last]) {
        if let View::Skipped(offset) = view {
            println!("...");
            rank += offset
        } else {
            println!("{rank}. {view:?}");
            rank += 1
        };
    }
}

Output:

1. Item([150])
2. Item([142])
3. Item([138, 138])
...
7. Item([83])
8. Item([66])
9. Item([61, 61])