Skip to main content

Crate funcperm

Crate funcperm 

Source
Expand description

§FuncPerm

A no_std Rust library for cycle-walking functional permutations on [0 . . n).

The FuncPerm structure provides, given nm, a pseudorandom permutation of [0 . . n) by taking a bijection on [0 . . m) and applying cycle walking to restrict the result to [0 . . n), that is, by applying the bijection repeatedly until the result is in [0 . . n).

The library provides built-in bijections based on MurmurHash3-like mixing functions.

§Examples

use funcperm::murmur;

// Create a permutation of [0..100) with seeds (0, 0)
let perm = murmur(100, 0, 0);

// Every element maps to a unique element in [0..100)
let y = perm.get(42);
assert!(y < 100);

You can also supply a custom bijection:

use funcperm::FuncPerm;

let perm = FuncPerm::new(10, |x: u64| x ^ 0b1010);
assert!(perm.get(0) < 10);

Structs§

FuncPerm
Cycle-walking functional permutation on [0 . . n), given a bijection on [0 . . m), where mn.

Functions§

murmur
MurmurHash3-based functional permutations.