mod2k 0.1.1

Fast arithmetic modulo `2^k`, `2^k - 1`, and `2^k - d`.
Documentation
  • Coverage
  • 100%
    35 out of 35 items documented1 out of 17 items with examples
  • Size
  • Source code size: 105.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 51.92 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 25s Average build duration of successful builds.
  • all releases: 26s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • purplesyringa/mod2k
    18 2 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • purplesyringa

mod2k

License Version docs.rs Tests

A #![no_std] Rust crate for fast arithmetic modulo 2^k, 2^k - 1, and 2^k - d.

Modular arithmetic is useful for fast hashing, verification of polynomial operations, and as a ring balancing the cost of division with the cost of other operations. Different moduli make different quality vs performance tradeoffs. This crate provides a uniform interface for fast implementations of multiple moduli, allowing you to tune the balance without rewriting your code to adopt faster algorithms:

  • "Big" primes: 2^8 - 5, 2^16 - 15, 2^32 - 5, 2^64 - 59. Slowest (~12 insn per multiplication, ~7 insn per addition, slow shifts and inversions), excellent quality.
  • Primes: 2^7 - 1, 2^13 - 1, 2^31 - 1, 2^61 - 1. Medium performance (~10 insn per multiplication, ~5 insn per addition), excellent quality (but slightly fewer bits of precision compared to "big" primes).
  • "Fast": 2^8 - 1, 2^16 - 1, 2^32 - 1, 2^64 - 1. Great performance (~4 insn per multiplication, ~2 insn per addition), medium quality (the moduli have relatively big prime factors).
  • Powers of two: 2^8, 2^16, 2^32, 2^64. Fastest (1 insn per multiplication and addition), but have seed-independent collisions and do not support division by 2.

mod2k is estimated to be ~2x faster than general-purpose modular arithmetic libraries on average, and more specific performance information is available.

Check the docs for more information.