3个版本 (破坏性更新)
0.3.0 | 2020年3月30日 |
---|---|
0.2.0 | 2019年6月7日 |
0.1.0 | 2017年10月7日 |
#625 在 嵌入式开发
每月 30 次下载
在 2 crate 中使用
24KB
222 行
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);
}
依赖
~2.5MB
~55K SLoC