3 releases (breaking)
0.3.0 | Mar 30, 2020 |
---|---|
0.2.0 | Jun 7, 2019 |
0.1.0 | Oct 7, 2017 |
#394 in Embedded development
3,812 downloads per month
Used in 2 crates
24KB
222 lines
use lfsr::lfsr_lookup;
use lfsr::galois;
use lfsr::LFSR;
searching_lfsr_lookup!(galois32_lookup, galois::Galois32, 10, 20, 5);
searching_lfsr_lookup!(galois32_lookup_big, galois::Galois32, 99_999_000, 100_001_000, 100);
direct_lfsr_lookup!(galois16_direct_lookup, galois::Galois16);
fn main() {
// Searching lookup
let mut lfsr = galois::Galois32::default();
assert_eq!(galois32_lookup(&lfsr), None);
for _ in 0..9 {
lfsr.inc();
}
assert_eq!(galois32_lookup(&lfsr), None);
for _ in 9..10 {
lfsr.inc();
}
assert_eq!(galois32_lookup(&lfsr), Some(10));
for _ in 10..17 {
lfsr.inc();
}
assert_eq!(galois32_lookup(&lfsr), Some(17));
for _ in 9..20 {
lfsr.inc();
}
assert_eq!(galois32_lookup(&lfsr), None);
// Direct lookup
let mut lfsr = galois::Galois16::default();
assert_eq!(galois16_direct_lookup(&lfsr), 0);
for _ in 0..10 {
lfsr.inc();
}
assert_eq!(galois16_direct_lookup(&lfsr), 10);
for _ in 10..11 {
lfsr.inc();
}
assert_eq!(galois16_direct_lookup(&lfsr), 11);
for _ in 11..65534 {
lfsr.inc();
}
assert_eq!(galois16_direct_lookup(&lfsr), 65534);
// wrap around
lfsr.inc();
assert_eq!(galois16_direct_lookup(&lfsr), 0);
}
Dependencies
~2.5MB
~56K SLoC