pub enum Path<V, E> {
Id(V),
Seq(NonEmpty<E>),
}Expand description
A path in a graph or category.
This definition by cases can be compared with the perhaps more obvious definition:
struct Path<V, E> {
start: V,
end: V, // Optional: more symmetric but also more redundant.
seq: Vec<E>,
}Not only does the single struct store redundant (hence possibly inconsistent)
information when the sequence of edges is nonempty, one will often need to do a
case analysis on the edge sequence anyway to determine whether, say,
reduce returns a non-null value. Thus, it seems
better to reify the two cases in the data structure itself.
Variants§
Id(V)
The identity, or empty, path at a vertex.
Seq(NonEmpty<E>)
A nontrivial path, comprising a non-empty vector of consecutive edges.
Implementations§
Source§impl Path<ModeApp<QualifiedName>, ModeApp<ModalOp>>
impl Path<ModeApp<QualifiedName>, ModeApp<ModalOp>>
Sourcepub fn generator(id: QualifiedName) -> Self
pub fn generator(id: QualifiedName) -> Self
Constructs the object operation for a generator.
Sourcepub fn concat(list: List, arity: usize, ob_type: ModalObType) -> Self
pub fn concat(list: List, arity: usize, ob_type: ModalObType) -> Self
Constructs a concatenation operation for a list modality.
Sourcepub fn apply_all(self, iter: impl IntoIterator<Item = Modality> + Clone) -> Self
pub fn apply_all(self, iter: impl IntoIterator<Item = Modality> + Clone) -> Self
Applies a sequence of modalities.
Source§impl<V, E> Path<V, E>
impl<V, E> Path<V, E>
Sourcepub fn collect<I>(iter: I) -> Option<Self>where
I: IntoIterator<Item = E>,
pub fn collect<I>(iter: I) -> Option<Self>where
I: IntoIterator<Item = E>,
Constructs a path from an iterator over edges.
Returns None if the iterator is empty.
Sourcepub fn from_vec(vec: Vec<E>) -> Option<Self>
pub fn from_vec(vec: Vec<E>) -> Option<Self>
Constructs a path from a vector of edges.
Returns None if the vector is empty.
Sourcepub fn repeat_n(v: V, e: E, n: usize) -> Selfwhere
E: Clone,
pub fn repeat_n(v: V, e: E, n: usize) -> Selfwhere
E: Clone,
Constructs a path by repeating an edge n times.
The edge should have the same source and target, namely the first argument.
Sourcepub fn iter(&self) -> impl Iterator<Item = &E>
pub fn iter(&self) -> impl Iterator<Item = &E>
Iterates over edges in the path, if any.
This method is a one-sided inverse to Path::collect.
Sourcepub fn only(self) -> Option<E>
pub fn only(self) -> Option<E>
Extracts the unique edge in a path of length 1.
This method is a one-sided inverse to Path::single.
Sourcepub fn insert(&mut self, index: usize, edge: E)
pub fn insert(&mut self, index: usize, edge: E)
Inserts an edge into the path at the given index.
Sourcepub fn splice(self, range: Range<usize>, replace_with: Self) -> Self
pub fn splice(self, range: Range<usize>, replace_with: Self) -> Self
Splices a path into another path at the given range of indices.
Sourcepub fn src(&self, graph: &impl Graph<V = V, E = E>) -> Vwhere
V: Clone,
pub fn src(&self, graph: &impl Graph<V = V, E = E>) -> Vwhere
V: Clone,
Source of the path in the given graph.
Assumes that the path is contained in the graph.
Sourcepub fn tgt(&self, graph: &impl Graph<V = V, E = E>) -> Vwhere
V: Clone,
pub fn tgt(&self, graph: &impl Graph<V = V, E = E>) -> Vwhere
V: Clone,
Target of the path in the given graph.
Assumes that the path is contained in the graph.
Sourcepub fn subpath(
&self,
graph: &impl Graph<V = V, E = E>,
range: Range<usize>,
) -> Self
pub fn subpath( &self, graph: &impl Graph<V = V, E = E>, range: Range<usize>, ) -> Self
Extracts a subpath of a path in a graph.
Panics if the range is invalid or an empty subpath would be inconsistent.
Sourcepub fn replace_subpath(
self,
graph: &impl Graph<V = V, E = E>,
range: Range<usize>,
f: impl FnOnce(Self) -> Self,
) -> Self
pub fn replace_subpath( self, graph: &impl Graph<V = V, E = E>, range: Range<usize>, f: impl FnOnce(Self) -> Self, ) -> Self
Replaces the subpath at the given range with a function of that subpath.
Panics under the same conditions as subpath.
Sourcepub fn concat_in(
self,
graph: &impl Graph<V = V, E = E>,
other: Self,
) -> Option<Self>
pub fn concat_in( self, graph: &impl Graph<V = V, E = E>, other: Self, ) -> Option<Self>
Concatenates this path with another path in the graph.
This methods checks that the two paths are compatible (the target of this
path equals the source of the other path) and it assumes that both paths
are contained in the graph, which should be checked with
contained_in if in doubt. Thus, when returned, the
concatenated path is also a valid path.
Sourcepub fn contained_in(&self, graph: &impl Graph<V = V, E = E>) -> boolwhere
V: Eq,
pub fn contained_in(&self, graph: &impl Graph<V = V, E = E>) -> boolwhere
V: Eq,
Is the path contained in the given graph?
Sourcepub fn is_simple(&self) -> bool
pub fn is_simple(&self) -> bool
Returns whether the path is simple.
On our definition, a path is simple if it has no repeated edges.
Sourcepub fn reduce(self, fv: impl FnOnce(V) -> E, fe: impl FnMut(E, E) -> E) -> E
pub fn reduce(self, fv: impl FnOnce(V) -> E, fe: impl FnMut(E, E) -> E) -> E
Reduces a path using functions on vertices and edges.
Sourcepub fn map<CodV, CodE>(
self,
fv: impl FnOnce(V) -> CodV,
fe: impl FnMut(E) -> CodE,
) -> Path<CodV, CodE>
pub fn map<CodV, CodE>( self, fv: impl FnOnce(V) -> CodV, fe: impl FnMut(E) -> CodE, ) -> Path<CodV, CodE>
Maps a path over functions on vertices and edges.
Sourcepub fn map_reduce<T>(
self,
fv: impl FnOnce(V) -> T,
fe: impl FnMut(E) -> T,
f: impl FnMut(T, T) -> T,
) -> T
pub fn map_reduce<T>( self, fv: impl FnOnce(V) -> T, fe: impl FnMut(E) -> T, f: impl FnMut(T, T) -> T, ) -> T
Trait Implementations§
Source§impl From<Path<QualifiedName, QualifiedName>> for MorType
impl From<Path<QualifiedName, QualifiedName>> for MorType
Source§fn from(value: QualifiedPath) -> Self
fn from(value: QualifiedPath) -> Self
Source§impl<V, E> IntoIterator for Path<V, E>
Converts the path into an iterater over its edges.
impl<V, E> IntoIterator for Path<V, E>
Converts the path into an iterater over its edges.
Source§impl<V: PartialEq, E: PartialEq> PartialEq for Path<V, E>
impl<V: PartialEq, E: PartialEq> PartialEq for Path<V, E>
impl<V: Eq, E: Eq> Eq for Path<V, E>
impl<V, E> StructuralPartialEq for Path<V, E>
Auto Trait Implementations§
impl<V, E> Freeze for Path<V, E>
impl<V, E> RefUnwindSafe for Path<V, E>where
V: RefUnwindSafe,
E: RefUnwindSafe,
impl<V, E> Send for Path<V, E>
impl<V, E> Sync for Path<V, E>
impl<V, E> Unpin for Path<V, E>
impl<V, E> UnsafeUnpin for Path<V, E>where
V: UnsafeUnpin,
E: UnsafeUnpin,
impl<V, E> UnwindSafe for Path<V, E>where
V: UnwindSafe,
E: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.