kpermute

Top-level

Types

Link copied to clipboard
class BoundedIntPermutation(val size: Int, rng: Random = Random.Default, rounds: Int = 3, const: UInt) : IntPermutation

Permutation over [0, size) that mixes within the enclosing power-of-two block and cycle-walks until the output lands in range. size is read as unsigned, so -1 means 2^32 - 1 values. const must be odd.

Link copied to clipboard
class BoundedLongPermutation(val size: Long, rng: Random = Random.Default, rounds: Int = 3, const: ULong) : LongPermutation

Permutation over [0, size) that mixes within the enclosing power-of-two block and cycle-walks until the output lands in range. size is read as unsigned, so -1 means 2^64 - 1 values. const must be odd.

Link copied to clipboard
class FullIntPermutation(rng: Random = Random.Default, rounds: Int = 2, c1: Int = -2048144789, c2: Int = -1028477387) : IntPermutation

Permutation over all 32-bit values using keyed xor-shift-multiply rounds. The multipliers c1 and c2 must be odd.

Link copied to clipboard
class FullLongPermutation(rng: Random = Random.Default, rounds: Int = 2, c1: Long = -4658895280553007687, c2: Long = -7723592293110705685) : LongPermutation

Permutation over all 64-bit values using keyed xor-shift-multiply rounds. The multipliers c1 and c2 must be odd.

Link copied to clipboard

Bijection on [0, size), or on all 32-bit values when size == -1. size is read as unsigned. decode is the exact inverse of encode.

Link copied to clipboard

Bijection on [0, size), or on all 64-bit values when size == -1L. size is read as unsigned. decode is the exact inverse of encode.

Link copied to clipboard
class SmallIntPermutation(val size: Int, rng: Random) : IntPermutation

Permutation over [0, size) backed by shuffled lookup tables.

Link copied to clipboard

Permutation over [0, size) backed by shuffled lookup tables.

Functions

Link copied to clipboard
fun intPermutation(size: Int = Int.MAX_VALUE, seed: Long, rounds: Int = 0): IntPermutation

Seeded variant of intPermutation; deterministic for a given size, seed and rounds.

fun intPermutation(size: Int = Int.MAX_VALUE, rng: Random = Random.Default, rounds: Int = 0): IntPermutation

Creates an IntPermutation over [0, size).

fun intPermutation(range: IntRange, seed: Long, rounds: Int = 0): IntPermutation

Seeded variant of intPermutation over range.

fun intPermutation(range: IntRange, rng: Random = Random.Default, rounds: Int = 0): IntPermutation

Creates an IntPermutation whose domain is the non-empty range. Implementation and default rounds are chosen from the range length.

Link copied to clipboard
fun longPermutation(size: Long = Long.MAX_VALUE, seed: Long, rounds: Int = 0): LongPermutation

Seeded variant of longPermutation; deterministic for a given size, seed and rounds.

fun longPermutation(size: Long = Long.MAX_VALUE, rng: Random = Random.Default, rounds: Int = 0): LongPermutation

Creates a LongPermutation over [0, size).

Seeded variant of longPermutation over range.

fun longPermutation(range: LongRange, rng: Random = Random.Default, rounds: Int = 0): LongPermutation

Creates a LongPermutation whose domain is the non-empty range. Implementation and default rounds are chosen from the range length.

Link copied to clipboard
fun <T> List<T>.permuted(perm: IntPermutation = intPermutation(size)): List<T>

Returns a read-only view of this list reordered by perm, whose domain must be [0, size). The view does not copy, so the source must not change size.

Link copied to clipboard

Returns a view of this permutation shifted onto range, which must hold exactly IntPermutation.size values. On an existing range view, replaces its range.

Returns a view of this permutation shifted onto range, which must hold exactly LongPermutation.size values. On an existing range view, replaces its range.

Link copied to clipboard

Inverse of permuted.