pub struct KTuples { /* private fields */ }
Expand description
A type representing a set of terminal strings (i.e. terminal sequences) (called k-tuples)
Implementations§
source§impl KTuples
impl KTuples
sourcepub fn union(&self, other: &Self) -> (Self, bool)
pub fn union(&self, other: &Self) -> (Self, bool)
Creates a union with another KTuples and self
sourcepub fn intersection(&self, other: &Self) -> Self
pub fn intersection(&self, other: &Self) -> Self
Creates a intersection with another KTuples and self
sourcepub fn is_disjoint(&self, other: &Self) -> bool
pub fn is_disjoint(&self, other: &Self) -> bool
Checks if self and other are disjoint
sourcepub fn k_concat(self, other: &Self, k: usize) -> Self
pub fn k_concat(self, other: &Self, k: usize) -> Self
Creates a new object from a slice of KTuple objects.
use parol::{KTuple, KTuplesBuilder, CompiledTerminal};
use parol::analysis::k_tuple::TerminalMappings;
use parol::analysis::compiled_terminal::EPS;
{
let tuples1 = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[EPS]]).build().unwrap();
let tuples2 = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[EPS]]).build().unwrap();
let result = tuples1.k_concat(&tuples2, 1);
let expected = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[EPS]]).build().unwrap();
assert_eq!(expected, result, "[ε] + [ε] = [ε]");
}
{
let tuples1 = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[1]]).build().unwrap();
let tuples2 = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[EPS]]).build().unwrap();
let result = tuples1.k_concat(&tuples2, 1);
let expected = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[1]]).build().unwrap();
assert_eq!(expected, result, "[a] + [ε] = [a]");
}
{
let tuples1 = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[EPS]]).build().unwrap();
let tuples2 = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[1]]).build().unwrap();
let result = tuples1.k_concat(&tuples2, 1);
let expected = KTuplesBuilder::new().k(1).max_terminal_index(1).terminal_indices(&[&[1]]).build().unwrap();
assert_eq!(expected, result, "[ε] + [a] = [a]");
}
{
let tuples1 = KTuplesBuilder::new().k(1).max_terminal_index(2).terminal_indices(&[&[1]]).build().unwrap();
let tuples2 = KTuplesBuilder::new().k(1).max_terminal_index(2).terminal_indices(&[&[2]]).build().unwrap();
let result = tuples1.k_concat(&tuples2, 1);
let expected = KTuplesBuilder::new().k(1).max_terminal_index(2).terminal_indices(&[&[1]]).build().unwrap();
assert_eq!(expected, result, "1: [a] + [b] = [a]");
}
{
let tuples1 = KTuplesBuilder::new().k(2).max_terminal_index(2).terminal_indices(&[&[1]]).build().unwrap();
let tuples2 = KTuplesBuilder::new().k(2).max_terminal_index(2).terminal_indices(&[&[2]]).build().unwrap();
let result = tuples1.k_concat(&tuples2, 2);
let expected = KTuplesBuilder::new().k(2).max_terminal_index(2).terminal_indices(&[&[1, 2]]).build().unwrap();
assert_eq!(expected, result, "2: [a] + [b] = [ab]");
}
Trait Implementations§
source§impl PartialEq for KTuples
impl PartialEq for KTuples
impl Eq for KTuples
impl StructuralPartialEq for KTuples
Auto Trait Implementations§
impl Freeze for KTuples
impl RefUnwindSafe for KTuples
impl Send for KTuples
impl Sync for KTuples
impl Unpin for KTuples
impl UnwindSafe for KTuples
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.