Skip to main content

igraph_adjlist_t

Struct igraph_adjlist_t 

Source
pub struct igraph_adjlist_t { /* private fields */ }

Implementations§

Source§

impl igraph_adjlist_t

Source

pub fn init_empty(n: usize) -> Result<Self>

Creates an adjacency list for n vertices, all with empty lists (igraph_adjlist_init_empty).

Useful to build a structure vertex by vertex, e.g. before turning it into a graph. Time complexity: O(n).

Binds igraph_adjlist_init_empty.

§Errors

ErrorKind::InvalidValue if n does not fit in an igraph_int_t, or an out-of-memory error if it is too large to be allocated.

Source

pub fn len(&self) -> usize

Number of vertices, i.e. of lists, in the an adjacency list (igraph_adjlist_size).

Time complexity: O(1).

Binds igraph_adjlist_size.

Source

pub fn is_empty(&self) -> bool

Whether there are no vertices at all.

Source

pub fn total_len(&self) -> usize

Total number of entries (neighbor ids) stored in all the lists.

Source

pub fn clear(&mut self)

Removes all neighbor ids from every list, keeping the number of vertices (igraph_adjlist_clear).

Time complexity: O(n), n being the number of vertices.

Binds igraph_adjlist_clear.

Source

pub fn as_raw_slice(&self) -> &[VectorInt] ⓘ

The per-vertex lists as a slice of owned igraph vectors.

Source

pub fn as_raw_mut_slice(&mut self) -> &mut [VectorInt] ⓘ

The per-vertex lists as a mutable slice of owned igraph vectors: every list can be resized, pushed to, sorted, or even replaced by another VectorInt.

Source

pub fn get(&self, v: VertexId) -> Option<&[igraph_int_t]>

The list of vertex v, or None if v is out of range (the igraph_adjlist_get macro).

The panicking counterpart is indexing: list[v].

Source

pub fn get_mut(&mut self, v: VertexId) -> Option<&mut VectorInt>

The list of vertex v as a mutable VectorInt, or None if v is out of range.

Unlike IndexMut, this allows changing the length of the list (push, pop, resize, clear, …).

Source

pub fn iter(&self) -> Iter<'_> ⓘ

Iterates over the lists of the vertices 0, 1, ..., as slices.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, VectorInt>

Iterates mutably over the lists of the vertices 0, 1, ....

Source

pub fn to_vecs(&self) -> Vec<Vec<igraph_int_t>>

Copies the lists into nested Rust vectors.

Source

pub fn print(&self) -> Result<()>

Prints the lists to the standard output, one vertex per line, entries separated by spaces (igraph_adjlist_print).

The same text is produced by the Display implementation and by igraph_adjlist_t::fprint.

Note that the text goes to the C stdout stream, bypassing Rust’s output capturing (e.g. in cargo test): prefer println!("{list}") in Rust code.

Source

pub fn fprint(&self, out: &mut impl Write) -> Result<()>

Writes the lists to out in igraph’s textual format, one vertex per line (igraph_adjlist_fprint).

The output is produced by the C library itself (through a memory stream), and it matches the Display implementation.

§Errors

ErrorKind::File if writing fails.

Source§

impl igraph_adjlist_t

Source

pub fn new( graph: &Graph, mode: NeighborMode, loops: Loops, multiple: bool, ) -> Result<Self>

Adjacency list of graph: same as Graph::adjlist_init.

use igraph::prelude::*;
use igraph::adjlist::AdjList;
let g = Graph::from_edges(&[(0, 1), (1, 2)], 3, false).unwrap();
let al = AdjList::new(&g, NeighborMode::All, Loops::Twice, true).unwrap();
assert_eq!(&al[1], &[0, 2]);
Source

pub fn complementer( graph: &Graph, mode: NeighborMode, loops: Loops, ) -> Result<Self>

Adjacency list of the complementer of graph: same as Graph::adjlist_init_complementer.

Source

pub fn from_inclist(graph: &Graph, inclist: &IncList) -> Result<Self>

Adjacency list consistent with an incidence list of graph: same as Graph::adjlist_init_from_inclist.

Source

pub fn sort(&mut self)

Sorts every neighbor list in increasing order (igraph_adjlist_sort).

Lists created by Graph::adjlist_init are already sorted; this is useful after edits, or after simplify, which does not preserve the order. Sorted lists are required by has_edge and replace_edge.

Time complexity: O(m log m), m being the total number of entries.

Binds igraph_adjlist_sort.

Source

pub fn simplify(&mut self) -> Result<()>

Removes self-loops and repeated neighbors from every list (igraph_adjlist_simplify).

After the call, vertex v appears in no list of its own and each neighbor appears at most once per list. The order of the remaining entries is not preserved (removed entries are replaced with the last one): call sort afterwards if needed. When the list comes from a graph, prefer passing Loops::None and multiple = false to Graph::adjlist_init instead; to simplify the graph itself use Graph::simplify.

Time complexity: O(|V|+|E|).

§Errors

ErrorKind::InvalidVertexId if some list contains an id that is not a vertex of the list (checked on the Rust side, as the C code would read out of bounds).

§Examples
use igraph::adjlist::AdjList;
let mut al = AdjList::from(vec![vec![0, 1, 1, 2], vec![0, 0], vec![0, 2]]);
al.simplify().unwrap();
al.sort();
assert_eq!(al.to_vecs(), vec![vec![1, 2], vec![0], vec![0]]);

Binds igraph_adjlist_simplify.

Source

pub fn has_edge( &self, from: VertexId, to: VertexId, directed: bool, ) -> Result<bool>

Whether the adjacency list contains the edge from -> to (igraph_adjlist_has_edge), by binary search.

The lists must be sorted (see sort), otherwise the answer is unspecified. When directed is true, to is searched in the list of from. When it is false, the edge is looked up in the list of the larger endpoint only, i.e. min(from, to) is searched in the list of max(from, to): this matches both a full undirected adjacency list and a “half” one where each vertex only stores its neighbors with smaller or equal ids (the representation that replace_edge keeps consistent).

Time complexity: O(log d), d being the length of the searched list.

See also Graph::get_eid, which answers the same question on the graph itself.

§Errors

ErrorKind::InvalidVertexId if from or to is out of range.

§Examples
use igraph::prelude::*;
let g = Graph::from_edges(&[(0, 1), (1, 2)], 3, true).unwrap();
let al = g.adjlist_init(NeighborMode::Out, Loops::Once, true).unwrap();
assert!(al.has_edge(0, 1, true).unwrap());
assert!(!al.has_edge(1, 0, true).unwrap());
assert_eq!(al.has_edge(0, 9, true).unwrap_err().kind(), ErrorKind::InvalidVertexId);

Binds igraph_adjlist_has_edge (declared in igraph_adjlist.h but not part of the C reference manual).

Source

pub fn replace_edge( &mut self, from: VertexId, oldto: VertexId, newto: VertexId, directed: bool, ) -> Result<()>

Replaces the edge from -> oldto with from -> newto, keeping the lists sorted (igraph_adjlist_replace_edge).

The lists must be sorted. With directed = true the change is made in the list of from. With directed = false the edges are canonicalized as in has_edge: {from, oldto} is removed from the list of max(from, oldto) and {from, newto} is inserted in the list of max(from, newto); the lists of the smaller endpoints are not touched, so this is meant for “half” undirected adjacency lists where each vertex only stores its neighbors with smaller or equal ids. This is the primitive of igraph’s fast degree-preserving rewiring, available ready-made as Graph::rewire.

Time complexity: O(d), d being the length of the lists involved.

§Errors
§Examples
use igraph::adjlist::AdjList;
// Directed: 0 -> 1, 0 -> 2.
let mut al = AdjList::from(vec![vec![1, 2], vec![], vec![], vec![]]);
al.replace_edge(0, 1, 3, true).unwrap();
assert_eq!(&al[0], &[2, 3]);
assert!(al.replace_edge(0, 1, 3, true).is_err()); // 0 -> 1 is gone

Binds igraph_adjlist_replace_edge (declared in igraph_adjlist.h but not part of the C reference manual).

Source

pub fn to_graph(&self, mode: NeighborMode, duplicate: bool) -> Result<Graph>

Builds a graph from this adjacency list: same as Graph::adjlist.

use igraph::prelude::*;
use igraph::adjlist::AdjList;
let al = AdjList::from(vec![vec![1, 2], vec![2], vec![]]);
let g = al.to_graph(NeighborMode::Out, false).unwrap();
assert!(g.is_directed());
assert_eq!(g.edge_list(), vec![(0, 1), (0, 2), (1, 2)]);

Trait Implementations§

Source§

impl Clone for igraph_adjlist_t

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for igraph_adjlist_t

Source§

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

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

impl Default for igraph_adjlist_t

Source§

fn default() -> Self

An empty structure with no vertices.

Source§

impl Display for igraph_adjlist_t

Source§

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

One line per vertex with the entries separated by spaces, exactly like igraph_adjlist_print.

Source§

impl Drop for igraph_adjlist_t

Source§

fn drop(&mut self)

Frees the lists with igraph_adjlist_destroy.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<&[Vec<i64>]> for igraph_adjlist_t

Source§

fn from(lists: &[Vec<igraph_int_t>]) -> Self

Builds the structure from nested vectors, one per vertex.

Source§

impl From<&igraph_adjlist_t> for Vec<Vec<igraph_int_t>>

Source§

fn from(list: &igraph_adjlist_t) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Vec<i64>>> for igraph_adjlist_t

Source§

fn from(lists: Vec<Vec<igraph_int_t>>) -> Self

Builds the structure from nested vectors, one per vertex.

Source§

impl From<igraph_adjlist_t> for Vec<Vec<igraph_int_t>>

Source§

fn from(list: igraph_adjlist_t) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Vec<i64>> for igraph_adjlist_t

Source§

fn from_iter<I: IntoIterator<Item = Vec<igraph_int_t>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<usize> for igraph_adjlist_t

Source§

fn index(&self, v: usize) -> &[igraph_int_t] ⓘ

The list of the given vertex as a slice.

§Panics

If the vertex is out of range.

Source§

type Output = [i64]

The returned type after indexing.
Source§

impl IndexMut<usize> for igraph_adjlist_t

Source§

fn index_mut(&mut self, v: usize) -> &mut [igraph_int_t] ⓘ

The list of the given vertex as a mutable slice (its length cannot change: use igraph_adjlist_t::get_mut for that).

§Panics

If the vertex is out of range.

Source§

impl<'a> IntoIterator for &'a igraph_adjlist_t

Source§

type Item = &'a [i64]

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<'a> ⓘ

Creates an iterator from a value. Read more
Source§

impl PartialEq for igraph_adjlist_t

Source§

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

Equal when both have the same number of vertices and the same lists, in the same order.

1.0.0 (const: unstable) · 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 Send for igraph_adjlist_t

Source§

impl Sync for igraph_adjlist_t

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.