deterministic-finite-automaton

Crates.iodeterministic-finite-automaton
lib.rsdeterministic-finite-automaton
version0.1.1
sourcesrc
created_at2022-04-19 18:40:43.326768
updated_at2022-04-19 18:43:00.385868
descriptionSimple generic implementation of a deterministic finite automaton
homepage
repository
max_upload_size
id570557
size4,943
Sean DiGirolamo (s-digiro)

documentation

README

deterministic-finite-automaton

Rust implementation of a deterministic finite automaton

Wikipedia Link

usage:

// Accepts strings that contain 1 twice
let states = [0, 1, 2];
let alphabet = [0, 1];
let transition_fn = |s, c| match (s, c) {
    (0, 0) => 0,
    (0, 1) => 1,
    (1, 0) => 1,
    (1, 1) => 2,
    (2, 0) => 2,
    (2, 1) => 2,
    _ => panic!("Invalid (state, char)"),
};
let start_state = 0
let accept_states = [2];

let dfa = DFA::new(
    states,
    alphabet,
    transition_fn,
    start_state,
    accept_states,
);

assert!(dfa.input([1, 1, 0]) State::Accept(2));
assert!(dfa.input([0]) State::Reject(0));
Commit count: 0

cargo fmt