Struct SeqGraph

Source
pub struct SeqGraph<NodeId: U16orU32 = u16> {
    pub nodes: Nodes<NodeId>,
    pub edges: HashMap<(NodeId, NodeId), BitVec>,
}

Fields§

§nodes: Nodes<NodeId>§edges: HashMap<(NodeId, NodeId), BitVec>

Implementations§

Source§

impl<NodeId: U16orU32> SeqGraph<NodeId>

Source

pub fn builder(nodes_len: usize) -> SeqGraphBuilder<NodeId>

Create a new SeqGraphBuilder with the given number of nodes.

Default NodeId is u16, which can hold up to 65536 nodes. If you need more nodes, you can specify u32 as the NodeId type, like SeqGraph::<u32>::builder(100_000)

Source

pub fn into_builder(self) -> SeqGraphBuilder<NodeId>

Converts this graph into a builder.

This is useful if you want to update the graph, like resizing nodes or adding/removing edges.

Then you can build the graph again.

Source

pub fn neighbor_to(&self, curr: NodeId, dest: NodeId) -> Option<NodeId>

Given a current node and a destination node, return the first neighboring node that is the shortest path to the destination node.

This operation is very fast as all paths for all nodes are precomputed.

None is returned when:

  • curr and dest are the same node
  • curr has no path to dest

Note: In case there are multiple neighboring nodes that lead to the destination node, the first one found will be returned. The same node will be returned for the same input. However, the order of the nodes is not guaranteed.

You can use neighbor_to_with to filter matching neighbors, or neighbors_to to get all neighboring nodes.

Source

pub fn neighbor_to_with( &self, curr: NodeId, dest: NodeId, f: impl Fn(NodeId) -> bool, ) -> Option<NodeId>

Given a current node and a destination node, and a filter function, return the neighboring node that is the shortest path to the destination node.

Same as self.neighbors_to(curr, dest).find(f)

This may be useful if you want some custom behavior when choosing the next node.

Ex) In a game, you might want to randomize which path to take when there are multiple shortest paths.

None is returned when:

  • curr and dest are the same node
  • curr has no path to dest
  • The filter function returns false for all neighboring nodes
Source

pub fn neighbors_to( &self, curr: NodeId, dest: NodeId, ) -> NeighborsToIter<'_, NodeId>

Given a current node and a destination node, return all neighboring nodes that are shortest paths to the destination node.

The nodes will be returned in the same order for the same inputs. However, the ordering of the nodes is not guaranteed.

Source

pub fn path_to(&self, curr: NodeId, dest: NodeId) -> PathIter<'_, NodeId>

Given a current node and a destination node, return a path from the current node to the destination node.

The path is a list of node IDs, starting with current node and ending at the destination node.

This is same as calling .neighbor_to repeatedly until the destination node is reached.

If there is no path, the list will be empty.

Source

pub fn path_exists(&self, curr: NodeId, dest: NodeId) -> bool

Check if there is a path from the current node to the destination node.

Source

pub fn neighbors(&self, node: NodeId) -> &[NodeId]

Return a list of all neighboring nodes of the given node.

Source

pub fn nodes_len(&self) -> usize

Return the number of nodes in this graph.

Source

pub fn edges_len(&self) -> usize

Return the number of edges in this graph.

Trait Implementations§

Source§

impl<NodeId: Clone + U16orU32> Clone for SeqGraph<NodeId>

Source§

fn clone(&self) -> SeqGraph<NodeId>

Returns a copy 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<NodeId: Debug + U16orU32> Debug for SeqGraph<NodeId>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<NodeId> Freeze for SeqGraph<NodeId>

§

impl<NodeId> RefUnwindSafe for SeqGraph<NodeId>
where NodeId: RefUnwindSafe,

§

impl<NodeId> Send for SeqGraph<NodeId>

§

impl<NodeId> Sync for SeqGraph<NodeId>

§

impl<NodeId> Unpin for SeqGraph<NodeId>
where NodeId: Unpin,

§

impl<NodeId> UnwindSafe for SeqGraph<NodeId>
where NodeId: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V