Skip to main content

OrderMap

Struct OrderMap 

Source
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>

Source

pub(super) fn try_from_graph<G>(graph: G) -> Result<Self, Cycle<G::NodeId>>

Source

pub(super) fn with_capacity(nodes: usize) -> Self

Source

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.

Source

pub(super) fn at_position(&self, pos: TopologicalPosition) -> Option<N>

Map a position in the topological order to a node, if it exists.

Source

pub(super) fn nodes_iter(&self) -> impl Iterator<Item = N> + '_

Get an iterator over the nodes, ordered by their position.

Source

pub(super) fn range( &self, range: impl RangeBounds<TopologicalPosition>, ) -> impl Iterator<Item = N> + '_

Get an iterator over the nodes within the range of positions.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<N: Clone> Clone for OrderMap<N>

Source§

fn clone(&self) -> OrderMap<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Debug> Debug for OrderMap<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N> Default for OrderMap<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<N> Freeze for OrderMap<N>

§

impl<N> RefUnwindSafe for OrderMap<N>
where N: RefUnwindSafe,

§

impl<N> Send for OrderMap<N>
where N: Send,

§

impl<N> Sync for OrderMap<N>
where N: Sync,

§

impl<N> Unpin for OrderMap<N>

§

impl<N> UnsafeUnpin for OrderMap<N>

§

impl<N> UnwindSafe for OrderMap<N>
where N: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.