Kwker

Use Kwker from Rust

The kwker crate is the library itself: a safe API over the engines, chosen at run time. Its build compiles the C++ engines, so it needs a C++ compiler (GCC or Clang; CXX picks one).

The project file

TOMLRuns on your machine.
[package]
name = "latency"
version = "0.1.0"
edition = "2021"

[dependencies]
kwker = "0.1"

The program

The three slowest requests, without sorting the whole array:

RustAdd kwker to Cargo.toml, then cargo run.
use kwker::Order;

fn main() {
    let latency_ms = [12.1, 250.4, 8.9, 97.0, 310.2, 15.5, 260.0];
    let (values, positions): (Vec<f64>, Vec<usize>) = kwker::top_k(&latency_ms, 3, Order::DESCENDING, true);
    println!("{values:?}");
    println!("{positions:?}");
}
Output
[310.2, 260.0, 250.4]
[4, 6, 1]

Build and run

ShellOn your machine.
cargo run --release

Features

The default features are std and engines. --no-default-features gives a no_std + alloc build of the portable engine for embedded and bare-metal targets. To shrink the binary, leave out operation groups you don't use: arrow, sparse, strings, dist, window, int4, group and float16.

Errors

Functions panic only on the contract violations each one documents, such as k larger than the slice. The file sorts return std::io::Error.

Next steps