mixed_radix_counter

Crates.iomixed_radix_counter
lib.rsmixed_radix_counter
version0.1.0
sourcesrc
created_at2024-01-31 18:31:45.768271
updated_at2024-01-31 18:31:45.768271
descriptionA no_std crate for counting in a mixed radix system.
homepage
repositoryhttps://github.com/tsatke/mixed_radix_counter
max_upload_size
id1122045
size8,708
Tim Satke (tsatke)

documentation

README

Mixed Radix Counter

A counter for a mixed radix system.

The counter consists of values and limits.
values overflow at their limit (exclusive).

Given values of [0, 1, 4] and limits of [3, 4, 5], adding 1 to the counter results in the values [0, 2, 0].

Usage

let mut mrc = MixedRadixCounter::try_from_limits([u64::MAX, 365, 24, 60, 60]).expect("default values don't fit the limits");
assert_eq!(*mrc, [0, 0, 0, 0, 0]);

mrc.add(69_413_798); // or call `mrc.increment()` in a loop 69_413_798 times, but beware, that's a lot slower
assert_eq!(*mrc, [2, 73, 9, 36, 38]);

Although numbers are the most obvious element types, this is not restricted to numbers. Look at the generic bounds af you want to see more.

How to contribute

Feel free to send PRs for anything that comes to your mind.

Commit count: 0

cargo fmt