New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

big_lehmer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

big_lehmer

Source
crates.io
Version
0.1.1
Version published
Total downloads
2.7K
Maintainers
1
Created
Source

Big Lehmer

Big Lehmer is a lib for converting between arbitrarily sized sequence permutations into compact Lehmer codes and back to their uncompressed representation.

The number sequence must have similar properties as [0.N].shuffle. Basically sequential numbers in random order, starting at zero. The lib technically supports up to u32::MAX numbers, but performance will be the main issue beforehand.

Usage

fn main() {
    let sequence = [7, 2, 0, 6, 5, 1, 4, 3];
    let lehmer_code = big_lehmer::encode(&sequence).unwrap();
    let mut roundtrip = [0; 8];
    big_lehmer::decode(&lehmer_code, &mut roundtrip).unwrap();
    assert_eq!(sequence, roundtrip);
}

Benchmarks:

Measured on my "old system" (i7- 6700k). Not very accurate, just to showcase performance expectations.

Sequence lengthLehmer code sizeencode timedecode time
5124485 bytes470.70µs107.40µs
10_00014808 bytes = 15 KB2.40ms4.11ms
100_000189588 bytes = ~190 KB61.21ms205.44ms
1_000_0002311111 bytes = ~2.2 MiB2.15s11.39s

The crate is mainly optimized for large sequences.

Performance for large sequences is dominated by the big integer math. A possible optimization is to replace Dashu with rug. Apparently rug (=GMP) is extremely well optimized, but it's not native rust and not trivial to get working.

FAQs

Package last updated on 05 Jun 2024

Related posts