c3_lang_linearization/
lib.rs

1mod c3;
2mod c3_linearization;
3mod id;
4mod sets;
5
6pub use crate::c3::{Class, Fn, Var, C3};
7pub use c3_linearization::c3_linearization;
8use sets::Sets;
9
10#[derive(Debug)]
11pub enum C3Error {
12    BaseClassDoesNotExists(String),
13    EmptySet,
14    PushingEmptySet,
15    NoMoreCandidates,
16}
17
18/// Parse coma separated list of parents.
19/// TODO: Implement using regexp
20pub fn split_coma(s: &str) -> Vec<String> {
21    s.split(", ")
22        .map(String::from)
23        .filter(|x| !x.is_empty())
24        .collect()
25}
26
27/// Check if element is in the tail of the list.
28fn in_tail<T: Eq>(element: &T, list: &[T]) -> Result<bool, C3Error> {
29    match list.split_first() {
30        Some((_, tail)) => Ok(tail.contains(element)),
31        None => Err(C3Error::EmptySet),
32    }
33}
34
35/// Check if is `smaller` is subset of `larger`.
36pub fn is_subset<T: Eq>(larger: &[T], smaller: &[T]) -> bool {
37    smaller.iter().all(|item| larger.contains(item))
38}