pub struct igraph_adjlist_t { /* private fields */ }Implementations§
Source§impl igraph_adjlist_t
impl igraph_adjlist_t
Sourcepub fn init_empty(n: usize) -> Result<Self>
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.
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn total_len(&self) -> usize
pub fn total_len(&self) -> usize
Total number of entries (neighbor ids) stored in all the lists.
Sourcepub fn clear(&mut self)
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.
Sourcepub fn as_raw_slice(&self) -> &[VectorInt] ⓘ
pub fn as_raw_slice(&self) -> &[VectorInt] ⓘ
The per-vertex lists as a slice of owned igraph vectors.
Sourcepub fn as_raw_mut_slice(&mut self) -> &mut [VectorInt] ⓘ
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.
Sourcepub fn get(&self, v: VertexId) -> Option<&[igraph_int_t]>
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].
Sourcepub fn get_mut(&mut self, v: VertexId) -> Option<&mut VectorInt>
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, …).
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, VectorInt>
pub fn iter_mut(&mut self) -> IterMut<'_, VectorInt>
Iterates mutably over the lists of the vertices 0, 1, ....
Sourcepub fn to_vecs(&self) -> Vec<Vec<igraph_int_t>>
pub fn to_vecs(&self) -> Vec<Vec<igraph_int_t>>
Copies the lists into nested Rust vectors.
Sourcepub fn print(&self) -> Result<()>
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.
Sourcepub fn fprint(&self, out: &mut impl Write) -> Result<()>
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
impl igraph_adjlist_t
Sourcepub fn new(
graph: &Graph,
mode: NeighborMode,
loops: Loops,
multiple: bool,
) -> Result<Self>
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]);Sourcepub fn complementer(
graph: &Graph,
mode: NeighborMode,
loops: Loops,
) -> Result<Self>
pub fn complementer( graph: &Graph, mode: NeighborMode, loops: Loops, ) -> Result<Self>
Adjacency list of the complementer of graph: same as
Graph::adjlist_init_complementer.
Sourcepub fn from_inclist(graph: &Graph, inclist: &IncList) -> Result<Self>
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.
Sourcepub fn sort(&mut self)
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.
Sourcepub fn simplify(&mut self) -> Result<()>
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.
Sourcepub fn has_edge(
&self,
from: VertexId,
to: VertexId,
directed: bool,
) -> Result<bool>
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).
Sourcepub fn replace_edge(
&mut self,
from: VertexId,
oldto: VertexId,
newto: VertexId,
directed: bool,
) -> Result<()>
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
ErrorKind::InvalidVertexIdif a vertex is out of range;ErrorKind::InvalidValueif the edge to replace does not exist or the new edge already exists.
§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 goneBinds igraph_adjlist_replace_edge (declared in igraph_adjlist.h but not part of the
C reference manual).
Sourcepub fn to_graph(&self, mode: NeighborMode, duplicate: bool) -> Result<Graph>
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
impl Clone for igraph_adjlist_t
Source§impl Debug for igraph_adjlist_t
impl Debug for igraph_adjlist_t
Source§impl Default for igraph_adjlist_t
impl Default for igraph_adjlist_t
Source§impl Display for igraph_adjlist_t
impl Display for igraph_adjlist_t
Source§impl Drop for igraph_adjlist_t
impl Drop for igraph_adjlist_t
Source§impl From<&[Vec<i64>]> for igraph_adjlist_t
impl From<&[Vec<i64>]> for igraph_adjlist_t
Source§fn from(lists: &[Vec<igraph_int_t>]) -> Self
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>>
impl From<&igraph_adjlist_t> for Vec<Vec<igraph_int_t>>
Source§fn from(list: &igraph_adjlist_t) -> Self
fn from(list: &igraph_adjlist_t) -> Self
Source§impl From<igraph_adjlist_t> for Vec<Vec<igraph_int_t>>
impl From<igraph_adjlist_t> for Vec<Vec<igraph_int_t>>
Source§fn from(list: igraph_adjlist_t) -> Self
fn from(list: igraph_adjlist_t) -> Self
Source§impl FromIterator<Vec<i64>> for igraph_adjlist_t
impl FromIterator<Vec<i64>> for igraph_adjlist_t
Source§fn from_iter<I: IntoIterator<Item = Vec<igraph_int_t>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Vec<igraph_int_t>>>(iter: I) -> Self
Source§impl Index<usize> for igraph_adjlist_t
impl Index<usize> for igraph_adjlist_t
Source§impl IndexMut<usize> for igraph_adjlist_t
impl IndexMut<usize> for igraph_adjlist_t
Source§fn index_mut(&mut self, v: usize) -> &mut [igraph_int_t] ⓘ
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.