kpermute

LongPermutation

Reversible permutation over a 64-bit integer domain.

A LongPermutation defines a bijection on either:

  • a finite domain [0, size) when size >= 0L, or

  • the full signed 64-bit space when size == -1L.

Implementations are deterministic: the same instance always maps the same input to the same output, and decode is the exact inverse of encode. They are suitable for repeatable shuffling, masking, and index remapping without full lookup tables.

Security note: These permutations are not cryptographic. They are not PRPs and are not intended to resist adversarial inversion or analysis.

Contract:

Use longPermutation to construct concrete implementations.

Inheritors

Properties

Link copied to clipboard
abstract val size: Long

Domain size of the permutation.

Functions

Link copied to clipboard
open fun decode(encoded: Long): Long

Decodes a previously encoded long back to its original value.

Link copied to clipboard
abstract fun decodeUnchecked(encoded: Long): Long

Decodes a previously encoded value without range checks.

Link copied to clipboard
open fun encode(value: Long): Long

Encodes a long in the permutation domain into its permuted value.

Link copied to clipboard
abstract fun encodeUnchecked(value: Long): Long

Encodes a value without range checks.

Link copied to clipboard
open operator override fun iterator(): LongIterator

Returns an iterator over encode(i) for all i in [0, size) for finite domains, or over the full 64-bit space when size == -1L.

abstract fun iterator(offset: Long): LongIterator

Returns an iterator over encode(i) for indices in [offset, size).

Link copied to clipboard

Returns a view of this permutation that operates on range instead of [0, size). Only valid for finite domains where range.count() == size.

decodeUnchecked

abstract fun decodeUnchecked(encoded: Long): Long(source)

Decodes a previously encoded value without range checks.

decode

open fun decode(encoded: Long): Long(source)

Decodes a previously encoded long back to its original value.

For finite domains (size >= 0L), encoded must be in [0, size).

encodeUnchecked

abstract fun encodeUnchecked(value: Long): Long(source)

Encodes a value without range checks.

encode

open fun encode(value: Long): Long(source)

Encodes a long in the permutation domain into its permuted value.

For finite domains (size >= 0L), value must be in [0, size).

iterator

open operator override fun iterator(): LongIterator(source)

Returns an iterator over encode(i) for all i in [0, size) for finite domains, or over the full 64-bit space when size == -1L.


abstract fun iterator(offset: Long): LongIterator(source)

Returns an iterator over encode(i) for indices in [offset, size).

For finite domains, offset is an index in 0..size. For full-domain implementations, semantics are defined by the implementation.

size

abstract val size: Long(source)

Domain size of the permutation.

  • size >= 0L: finite domain [0, size).

  • size == -1L: full signed 64-bit domain.