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

Download history 1/week @ 2024-07-29 1/week @ 2024-08-05 18/week @ 2024-08-12 55/week @ 2024-08-26 136/week @ 2024-09-09 203/week @ 2024-09-16 39/week @ 2024-09-23 111/week @ 2024-10-07 3412/week @ 2024-10-14 1726/week @ 2024-10-21 1268/week @ 2024-10-28 64/week @ 2024-11-04 227/week @ 2024-11-11

3,812 downloads per month
Used in 2 crates

MIT/Apache

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