pub(super) struct OrderMap<N> {
pos_to_node: BTreeMap<TopologicalPosition, N>,
node_to_pos: Vec<TopologicalPosition>,
}Expand description
A bijective map between node indices and their position in a topological order.
Note that this map does not check for injectivity or surjectivity, this must be enforced by the user. Map mutations that invalidate these properties are allowed to make it easy to perform batch modifications that temporarily break the invariants.
Fields§
§pos_to_node: BTreeMap<TopologicalPosition, N>Map topological position to node index.
node_to_pos: Vec<TopologicalPosition>The inverse of pos_to_node, i.e. map node indices to their position.
This is a Vec, relying on N: NodeIndexable for indexing.
Implementations§
Source§impl<N: Copy> OrderMap<N>
impl<N: Copy> OrderMap<N>
pub(super) fn try_from_graph<G>(graph: G) -> Result<Self, Cycle<G::NodeId>>
pub(super) fn with_capacity(nodes: usize) -> Self
Sourcepub(super) fn get_position(
&self,
id: N,
graph: impl NodeIndexable<NodeId = N>,
) -> TopologicalPosition
pub(super) fn get_position( &self, id: N, graph: impl NodeIndexable<NodeId = N>, ) -> TopologicalPosition
Map a node to its position in the topological order.
Panics if the node index is out of bounds.
Sourcepub(super) fn at_position(&self, pos: TopologicalPosition) -> Option<N>
pub(super) fn at_position(&self, pos: TopologicalPosition) -> Option<N>
Map a position in the topological order to a node, if it exists.
Sourcepub(super) fn nodes_iter(&self) -> impl Iterator<Item = N> + '_
pub(super) fn nodes_iter(&self) -> impl Iterator<Item = N> + '_
Get an iterator over the nodes, ordered by their position.
Sourcepub(super) fn range(
&self,
range: impl RangeBounds<TopologicalPosition>,
) -> impl Iterator<Item = N> + '_
pub(super) fn range( &self, range: impl RangeBounds<TopologicalPosition>, ) -> impl Iterator<Item = N> + '_
Get an iterator over the nodes within the range of positions.
Sourcepub(super) fn add_node(
&mut self,
id: N,
graph: impl NodeIndexable<NodeId = N>,
) -> TopologicalPosition
pub(super) fn add_node( &mut self, id: N, graph: impl NodeIndexable<NodeId = N>, ) -> TopologicalPosition
Add a node to the order map and assign it an arbitrary position.
Return the position of the new node.
Sourcepub(super) fn remove_node(
&mut self,
id: N,
graph: impl NodeIndexable<NodeId = N>,
)
pub(super) fn remove_node( &mut self, id: N, graph: impl NodeIndexable<NodeId = N>, )
Remove a node from the order map.
Panics if the node index is out of bounds.
Sourcepub(super) fn set_position(
&mut self,
id: N,
pos: TopologicalPosition,
graph: impl NodeIndexable<NodeId = N>,
)
pub(super) fn set_position( &mut self, id: N, pos: TopologicalPosition, graph: impl NodeIndexable<NodeId = N>, )
Set the position of a node.
Panics if the node index is out of bounds.