Crates.io | mixed_radix_counter |
lib.rs | mixed_radix_counter |
version | 0.1.0 |
source | src |
created_at | 2024-01-31 18:31:45.768271 |
updated_at | 2024-01-31 18:31:45.768271 |
description | A no_std crate for counting in a mixed radix system. |
homepage | |
repository | https://github.com/tsatke/mixed_radix_counter |
max_upload_size | |
id | 1122045 |
size | 8,708 |
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]
.
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.
Feel free to send PRs for anything that comes to your mind.