-
-
Save franleplant/20dde8cf5d7dd59d788d987c28e31c83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{BTreeMap, BTreeSet}; | |
type State = String; | |
type DeltaValue = BTreeMap<char, BTreeSet<State>>; | |
type Delta = BTreeMap<State, DeltaValue>; | |
fn main() { | |
let mut delta: Delta = BTreeMap::new(); | |
let rules = [ | |
(("q0".to_string(), 'a'), "q1".to_string()), | |
(("q0".to_string(), 'a'), "q2".to_string()) | |
]; | |
for &((ref s,a), ref ns) in rules.iter() { | |
let mut delta_value = match delta.get(s) { | |
Some(value) => value.clone(), | |
None => BTreeMap::new() | |
}; | |
let mut next_states = match delta_value.get(&a) { | |
Some(states) => states.clone(), | |
None => BTreeSet::new() | |
}; | |
next_states.insert(ns.clone()); | |
delta_value.insert(a, next_states); | |
delta.insert(s.clone(), delta_value); | |
println!("{:?}", delta); | |
} | |
let mut delta_value: DeltaValue = BTreeMap::new(); | |
let mut next_states: BTreeSet<State>= BTreeSet::new(); | |
next_states.insert("q1".to_string()); | |
delta_value.insert('a', next_states); | |
delta.insert("q0".to_string(), delta_value); | |
println!("{:?}", delta); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment