#![no_std]
#[cfg(kani)]
extern crate kani;
pub use oxgraph_topology::{
CanonicalElementIdentity, CanonicalIncidenceIdentity, CanonicalRelationIdentity,
ContainsElement, ContainsIncidence, ContainsRelation, ElementIncidenceCount, ElementIncidences,
ElementIndex, ElementPredecessors, ElementSuccessors, ElementWeight, IncidenceBase,
IncidenceCounts, IncidenceElement, IncidenceIndex, IncidenceRelation, IncidenceRole,
IncidenceWeight, LocalElementIdentity, LocalIncidenceIdentity, LocalRelationIdentity,
RelationIncidenceCount, RelationIncidences, RelationIndex, RelationWeight, TopologyBase,
TopologyCounts, TopologyId,
};
pub type NodeId<G> = <G as TopologyBase>::ElementId;
pub type EdgeId<G> = <G as TopologyBase>::RelationId;
pub type EndpointId<G> = <G as IncidenceBase>::IncidenceId;
pub type EndpointRole<G> = <G as IncidenceBase>::Role;
pub trait GraphBase: TopologyBase {}
impl<T> GraphBase for T where T: TopologyBase {}
pub trait GraphCounts: TopologyCounts {
fn node_count(&self) -> usize {
self.element_count()
}
fn edge_count(&self) -> usize {
self.relation_count()
}
}
pub trait NodeIndex: ElementIndex {
fn node_bound(&self) -> usize {
self.element_bound()
}
fn node_index(&self, node: Self::ElementId) -> usize {
self.element_index(node)
}
}
impl<T> NodeIndex for T where T: ElementIndex {}
pub trait EdgeIndex: RelationIndex {
fn edge_bound(&self) -> usize {
self.relation_bound()
}
fn edge_index(&self, edge: Self::RelationId) -> usize {
self.relation_index(edge)
}
}
impl<T> EdgeIndex for T where T: RelationIndex {}
pub trait EndpointIndex: IncidenceIndex {
fn endpoint_bound(&self) -> usize {
self.incidence_bound()
}
fn endpoint_index(&self, endpoint: Self::IncidenceId) -> usize {
self.incidence_index(endpoint)
}
}
impl<T> EndpointIndex for T where T: IncidenceIndex {}
pub trait ContainsNode: ContainsElement {
fn contains_node(&self, node: Self::ElementId) -> bool {
self.contains_element(node)
}
}
impl<T> ContainsNode for T where T: ContainsElement {}
pub trait ContainsEdge: ContainsRelation {
fn contains_edge(&self, edge: Self::RelationId) -> bool {
self.contains_relation(edge)
}
}
impl<T> ContainsEdge for T where T: ContainsRelation {}
pub trait ContainsEndpoint: ContainsIncidence {
fn contains_endpoint(&self, endpoint: Self::IncidenceId) -> bool {
self.contains_incidence(endpoint)
}
}
impl<T> ContainsEndpoint for T where T: ContainsIncidence {}
pub trait EdgeSourceGraph: TopologyBase {
fn source(&self, edge: Self::RelationId) -> Self::ElementId;
}
pub trait EdgeTargetGraph: TopologyBase {
fn target(&self, edge: Self::RelationId) -> Self::ElementId;
}
pub trait EdgeEndpointGraph: EdgeSourceGraph + EdgeTargetGraph {
fn endpoints(&self, edge: Self::RelationId) -> (Self::ElementId, Self::ElementId) {
(self.source(edge), self.target(edge))
}
}
impl<T> EdgeEndpointGraph for T where T: EdgeSourceGraph + EdgeTargetGraph {}
pub trait OutgoingGraph: TopologyBase {
type OutEdges<'view>: Iterator<Item = Self::RelationId>
where
Self: 'view;
fn outgoing_edges(&self, node: Self::ElementId) -> Self::OutEdges<'_>;
}
pub trait IncomingGraph: TopologyBase {
type InEdges<'view>: Iterator<Item = Self::RelationId>
where
Self: 'view;
fn incoming_edges(&self, node: Self::ElementId) -> Self::InEdges<'_>;
}
pub trait OutgoingNeighborsGraph: ElementSuccessors {
type OutNeighbors<'view>: Iterator<Item = Self::ElementId>
where
Self: 'view;
fn outgoing_neighbors(&self, node: Self::ElementId) -> Self::OutNeighbors<'_>;
}
impl<T> OutgoingNeighborsGraph for T
where
T: ElementSuccessors,
{
type OutNeighbors<'view>
= <T as ElementSuccessors>::Successors<'view>
where
T: 'view;
fn outgoing_neighbors(&self, node: Self::ElementId) -> Self::OutNeighbors<'_> {
<Self as ElementSuccessors>::element_successors(self, node)
}
}
pub trait IncomingNeighborsGraph: ElementPredecessors {
type InNeighbors<'view>: Iterator<Item = Self::ElementId>
where
Self: 'view;
fn incoming_neighbors(&self, node: Self::ElementId) -> Self::InNeighbors<'_>;
}
impl<T> IncomingNeighborsGraph for T
where
T: ElementPredecessors,
{
type InNeighbors<'view>
= <T as ElementPredecessors>::Predecessors<'view>
where
T: 'view;
fn incoming_neighbors(&self, node: Self::ElementId) -> Self::InNeighbors<'_> {
<Self as ElementPredecessors>::element_predecessors(self, node)
}
}
pub trait OutgoingEdgeCount: TopologyBase {
fn out_degree(&self, node: Self::ElementId) -> usize;
}
pub trait IncomingEdgeCount: TopologyBase {
fn in_degree(&self, node: Self::ElementId) -> usize;
}
pub trait DirectedGraph: EdgeEndpointGraph + OutgoingGraph + IncomingGraph {}
impl<T> DirectedGraph for T where T: EdgeEndpointGraph + OutgoingGraph + IncomingGraph {}
pub trait ForwardGraph: EdgeTargetGraph + OutgoingGraph {}
impl<T> ForwardGraph for T where T: EdgeTargetGraph + OutgoingGraph {}
pub trait ReverseGraph: EdgeSourceGraph + IncomingGraph {}
impl<T> ReverseGraph for T where T: EdgeSourceGraph + IncomingGraph {}