syndicate-rs/src/skeleton.rs

74 lines
1.3 KiB
Rust
Raw Normal View History

use std::collections::BTreeMap;
use std::collections::BTreeSet;
use super::bag::BTreeBag;
use preserves::value::AValue;
2018-12-09 13:28:01 +00:00
pub enum Event {
Removed,
Message,
Added,
}
type Path = Vec<usize>;
type Paths = Vec<Path>;
type Captures = Vec<AValue>;
2018-12-09 13:28:01 +00:00
trait HandleEvent {
fn handle_event<'a>(self, captures: &Captures);
}
2018-12-09 13:28:01 +00:00
pub enum Skeleton {
2018-12-09 13:28:01 +00:00
Blank,
Guarded(Guard, Vec<Skeleton>)
2018-12-09 13:28:01 +00:00
}
pub struct AnalysisResults {
skeleton: Skeleton,
const_paths: Paths,
const_vals: Vec<AValue>,
capture_paths: Paths,
assertion: AValue,
2018-12-09 13:28:01 +00:00
}
pub struct Index {
all_assertions: BTreeBag<AValue>,
2018-12-09 13:28:01 +00:00
}
impl Index {
2018-12-09 13:28:01 +00:00
pub fn new() -> Self {
Index{ all_assertions: BTreeBag::new() }
2018-12-09 13:28:01 +00:00
}
// pub fn add_handler(analysis_results: AnalysisResults,
2018-12-09 13:28:01 +00:00
}
struct Node {
continuation: Continuation,
edges: BTreeMap<Selector, BTreeMap<Guard, Node>>,
2018-12-09 13:28:01 +00:00
}
struct Continuation {
cached_assertions: BTreeSet<AValue>,
leaf_map: BTreeMap<Paths, BTreeMap<Vec<AValue>, Leaf>>,
2018-12-09 13:28:01 +00:00
}
struct Selector {
pop_count: usize,
index: usize,
}
enum Guard {
Rec(AValue, usize),
2018-12-09 13:28:01 +00:00
Seq(usize),
}
struct Leaf { // aka Topic
cached_assertions: BTreeSet<AValue>,
handler_map: BTreeMap<Paths, Handler>,
2018-12-09 13:28:01 +00:00
}
struct Handler {
cached_captures: BTreeBag<Captures>,
callbacks: BTreeSet<Box<dyn HandleEvent>>,
2018-12-09 13:28:01 +00:00
}