Skip to main content

VecGraph

Struct VecGraph 

Source
pub struct VecGraph(/* private fields */);
Expand description

A mutable RandomAccessGraph implementation based on a vector of vectors.

This implementation is faster and uses less resources than a BTreeGraph, but it is less flexible as arcs can be added only in increasing successor order.

This struct can be serialized with ε-serde. By setting the feature serde, this struct can be serialized using serde, too.

§Implementation Notes

This is just a newtype for a LabeledVecGraph with () labels. All mutation methods are delegated.

Implementations§

Source§

impl VecGraph

Source

pub fn new() -> Self

Creates a new empty graph.

Source

pub fn empty(n: usize) -> Self

Creates a new empty graph with n nodes.

Source

pub fn add_node(&mut self, node: usize) -> bool

Add an isolated node to the graph and return true if it is a new node.

Source

pub fn add_arc(&mut self, u: usize, v: usize)

Add an arc to the graph.

New arcs must be added in increasing successor order, or this method will panic.

§Panics

This method will panic:

  • if one of the given nodes is greater or equal than the number of nodes in the graph;
  • if the successor is lesser than or equal to the current last successor of the source node.
Source

pub fn add_lender<I: IntoLender>(&mut self, iter_nodes: I) -> &mut Self
where I::Lender: for<'next> NodeLabelsLender<'next, Label = usize>,

Add nodes and successors from an IntoLender yielding a NodeLabelsLender.

If the lender is sorted, consider using add_sorted_lender, as it does not need to sort the output of the lender.

Source

pub fn from_lender<I: IntoLender>(iter_nodes: I) -> Self
where I::Lender: for<'next> NodeLabelsLender<'next, Label = usize>,

Creates a new graph from an IntoLender yielding a NodeLabelsLender.

If the lender is sorted, consider using from_sorted_lender, as it does not need to sort the output of the lender.

Source

pub fn add_sorted_lender<I: IntoLender>(&mut self, iter_nodes: I) -> &mut Self
where I::Lender: for<'next> NodeLabelsLender<'next, Label = usize> + SortedLender, for<'succ> LenderIntoIter<'succ, I::Lender>: SortedIterator,

Add nodes and successors from an IntoLender yielding a sorted NodeLabelsLender.

This method is faster than add_lender as it does not need to sort the output of the lender.

Source

pub fn from_sorted_lender<I: IntoLender>(iter_nodes: I) -> Self
where I::Lender: for<'next> NodeLabelsLender<'next, Label = usize> + SortedLender, for<'succ> LenderIntoIter<'succ, I::Lender>: SortedIterator,

Creates a new graph from a sorted IntoLender yielding a NodeLabelsLender.

This method is faster than from_lender as it does not need to sort the output of the lender.

Source

pub fn add_exact_lender<I: IntoLender>(&mut self, iter_nodes: I) -> &mut Self
where I::Lender: for<'next> NodeLabelsLender<'next, Label = usize> + SortedLender, for<'succ> LenderIntoIter<'succ, I::Lender>: SortedIterator + ExactSizeIterator,

Add nodes and successors from an IntoLender yielding a sorted NodeLabelsLender whose successors implement ExactSizeIterator.

This method has a better memory behavior than add_sorted_lender as it can allocate the right amount of memory for each node at once.

Source

pub fn from_exact_lender<I: IntoLender>(iter_nodes: I) -> Self
where I::Lender: for<'next> NodeLabelsLender<'next, Label = usize> + SortedLender, for<'succ> LenderIntoIter<'succ, I::Lender>: SortedIterator + ExactSizeIterator,

Creates a new graph from a sorted IntoLender yielding a NodeLabelsLender whose successors implement ExactSizeIterator.

This method has a better memory behavior than from_sorted_lender as it can allocate the right amount of memory for each node at once.

Source

pub fn add_arcs(&mut self, arcs: impl IntoIterator<Item = (usize, usize)>)

Add arcs from an IntoIterator, adding new nodes as needed.

The items must be pairs of the form (usize, usize) specifying an arc.

Source

pub fn from_arcs(arcs: impl IntoIterator<Item = (usize, usize)>) -> Self

Creates a new graph from an IntoIterator.

The items must be pairs of the form (usize, usize) specifying an arc.

Source

pub fn shrink_to_fit(&mut self)

Shrink the capacity of the graph to fit its current size.

Trait Implementations§

Source§

impl AlignHash for VecGraph

Source§

fn align_hash(hasher: &mut impl Hasher, offset_of: &mut usize)

Accumulates alignment information in hasher assuming to be positioned at offset_of.
Source§

fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)

Calls AlignHash::align_hash on a value.
Source§

impl Clone for VecGraph

Source§

fn clone(&self) -> VecGraph

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 CopyType for VecGraph

Source§

impl Debug for VecGraph

Source§

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

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

impl Default for VecGraph

Source§

fn default() -> VecGraph

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

impl DeserInner for VecGraph

Source§

type DeserType<'__epserde_desertype> = VecGraph

The deserialization type associated with this type. It can be retrieved conveniently with the alias DeserType.
Source§

fn __check_covariance<'__long: '__short, '__short>( proof: CovariantProof<Self::DeserType<'__long>>, ) -> CovariantProof<Self::DeserType<'__short>>

Compile-time covariance check for DeserType. Read more
Source§

unsafe fn _deser_full_inner( backend: &mut impl ReadWithPos, ) -> Result<Self, Error>

Safety Read more
Source§

unsafe fn _deser_eps_inner<'deser_eps_inner_lifetime>( backend: &mut SliceWithPos<'deser_eps_inner_lifetime>, ) -> Result<Self::DeserType<'deser_eps_inner_lifetime>, Error>

Safety Read more
Source§

impl From<LabeledVecGraph<()>> for VecGraph

Source§

fn from(g: LabeledVecGraph<()>) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoLender for &'a VecGraph

Convenience implementation that makes it possible to iterate over the graph using the for_ macro (see the crate documentation).

Source§

type Lender = <VecGraph as SequentialLabeling>::Lender<'a>

The lender type that this type converts into.
Source§

fn into_lender(self) -> Self::Lender

Converts this type into a Lender.
Source§

impl PartialEq for VecGraph

Source§

fn eq(&self, other: &VecGraph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RandomAccessGraph for VecGraph

Source§

fn successors( &self, node_id: usize, ) -> <Self as RandomAccessLabeling>::Labels<'_>

Returns the successors of a node. Read more
Source§

fn has_arc(&self, src_node_id: usize, dst_node_id: usize) -> bool

Returns whether there is an arc going from src_node_id to dst_node_id. Read more
Source§

impl RandomAccessLabeling for VecGraph

Source§

type Labels<'succ> = AssumeSortedIterator<Map<Copied<Iter<'succ, LabeledArc<()>>>, fn(LabeledArc<()>) -> usize>>

The type of the iterator over the labels of a node returned by labels.
Source§

fn num_arcs(&self) -> u64

Returns the number of arcs in the graph.
Source§

fn outdegree(&self, node: usize) -> usize

Returns the number of labels associated with a node.
Source§

fn labels(&self, node: usize) -> <Self as RandomAccessLabeling>::Labels<'_>

Returns the labels associated with a node.
Source§

impl SequentialLabeling for VecGraph

Source§

type Label = usize

Source§

type Lender<'a> = LenderImpl<'a, VecGraph> where Self: 'a

The type of Lender over the successors of a node returned by iter.
Source§

fn num_nodes(&self) -> usize

Returns the number of nodes in the graph.
Source§

fn num_arcs_hint(&self) -> Option<u64>

Returns the number of arcs in the graph, if available.
Source§

fn iter_from(&self, from: usize) -> Self::Lender<'_>

Returns an iterator over the labeling starting at from (included). Read more
Source§

fn iter(&self) -> Self::Lender<'_>

Returns an iterator over the labeling. Read more
Source§

fn build_dcf(&self) -> DCF

Builds the degree cumulative function for this labeling. Read more
Source§

fn par_node_apply<A: Default + Send, F: Fn(Range<usize>) -> A + Sync, R: Fn(A, A) -> A + Sync>( &self, func: F, fold: R, granularity: Granularity, pl: &mut impl ConcurrentProgressLog, ) -> A

Applies func to each chunk of nodes of size node_granularity in parallel, and folds the results using fold. Read more
Source§

fn par_apply<F: Fn(Range<usize>) -> A + Sync, A: Default + Send, R: Fn(A, A) -> A + Sync, D: for<'a> Succ<Input = usize, Output<'a> = usize>>( &self, func: F, fold: R, granularity: Granularity, deg_cumul: &D, pl: &mut impl ConcurrentProgressLog, ) -> A

Applies func to each chunk of nodes containing approximately arc_granularity arcs in parallel and folds the results using fold. Read more
Source§

impl SerInner for VecGraph

Source§

const IS_ZERO_COPY: bool

Inner constant used by the derive macros to keep track recursively of whether the type satisfies the conditions for being zero-copy. It is checked at runtime against the trait implemented by the type, and if a ZeroCopy type has this constant set to false serialization will panic.
Source§

type SerType = VecGraph

This is the type that will be written in the header of the file, and thus the type that will be deserialized. In most cases it is Self, but in some cases, as for references to slices, it is customized.
Source§

unsafe fn _ser_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>

Serializes this structure using the given backend. Read more
Source§

impl SplitLabeling for VecGraph

Source§

type SplitLender<'a> = Take<<VecGraph as SequentialLabeling>::Lender<'a>> where Self: 'a

Source§

type IntoIterator<'a> = Iter<'a, VecGraph> where Self: 'a

Source§

fn split_iter(&self, how_many: usize) -> Self::IntoIterator<'_>

Source§

impl TypeHash for VecGraph
where LabeledVecGraph<()>: SerInner<SerType: TypeHash>,

Source§

fn type_hash(hasher: &mut impl Hasher)

Accumulates type information in hasher.
Source§

fn type_hash_val(&self, hasher: &mut impl Hasher)

Calls TypeHash::type_hash on a value.
Source§

impl Eq for VecGraph

Source§

impl SequentialGraph for VecGraph

Source§

impl StructuralPartialEq for VecGraph

Auto Trait Implementations§

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

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
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> Deserialize for T

Source§

unsafe fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<T, Error>

§Safety

See the documentation of Deserialize.

Source§

unsafe fn deserialize_eps( backend: &[u8], ) -> Result<<T as DeserInner>::DeserType<'_>, Error>

§Safety

See the documentation of Deserialize.

Source§

unsafe fn load_full(path: impl AsRef<Path>) -> Result<Self, Error>

Convenience method to fully deserialize from a file. Read more
Source§

unsafe fn read_mem( read: impl ReadNoStd, size: usize, ) -> Result<MemCase<Self>, Error>

Reads data from a reader into heap-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out. Read more
Source§

unsafe fn load_mem(path: impl AsRef<Path>) -> Result<MemCase<Self>, Error>

Loads a file into heap-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out. Read more
Source§

unsafe fn read_mmap( read: impl ReadNoStd, size: usize, flags: Flags, ) -> Result<MemCase<Self>, Error>

Reads data from a reader into mmap()-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out. Read more
Source§

unsafe fn load_mmap( path: impl AsRef<Path>, flags: Flags, ) -> Result<MemCase<Self>, Error>

Loads a file into mmap()-allocated memory and ε-deserialize a data structure from it, returning a MemCase containing the data structure and the memory. Excess bytes are zeroed out. Read more
Source§

unsafe fn mmap( path: impl AsRef<Path>, flags: Flags, ) -> Result<MemCase<Self>, Error>

Memory maps a file and ε-deserializes a data structure from it, returning a MemCase containing the data structure and the memory mapping. Read more
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Serialize for T

Source§

unsafe fn ser_on_field_write( &self, backend: &mut impl WriteWithNames, ) -> Result<(), Error>

Serializes the type using the given WriteWithNames. Read more
Source§

unsafe fn serialize( &self, backend: &mut impl WriteNoStd, ) -> Result<usize, Error>

Serializes the type using the given backend. Read more
Source§

unsafe fn serialize_with_schema( &self, backend: &mut impl WriteNoStd, ) -> Result<Schema, Error>

Serializes the type using the given backend and return a schema describing the data that has been written. Read more
Source§

unsafe fn store(&self, path: impl AsRef<Path>) -> Result<(), Error>

Convenience method to serialize to a file. Read more
Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

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

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> DeepCopy for T
where T: CopyType<Copy = Deep> + SerInner, <T as SerInner>::SerType: TypeHash + AlignHash,