Skip to main content

Module selector

Module selector 

Source
Expand description

Vertex and edge selectors.

Many igraph functions operate on a set of vertices or edges, described by an igraph_vs_t / igraph_es_t selector. In Rust these are the enums VertexSelector and EdgeSelector, which convert from convenient values thanks to From:

Rust valueSelected verticesC constructor
.. or VertexSelector::Allall verticesigraph_vs_all
VertexSelector::Noneno vertexigraph_vs_none
3 (an i64)the single vertex 3igraph_vs_1
&[0, 2, 5], vec![..], &VectorIntthe listed vertices, in orderigraph_vss_vector
2..6vertices 2, 3, 4, 5igraph_vs_range
2..=5vertices 2, 3, 4, 5igraph_vs_range
VertexSelector::adjacent(v, mode)the neighbors of vigraph_vs_adj
VertexSelector::non_adjacent(v, mode)the vertices not adjacent to v (including v itself unless it has a loop)igraph_vs_nonadj
Rust valueSelected edgesC constructor
.. or EdgeSelector::All, EdgeSelector::AllOrdered(order)all edges, by id or by endpointigraph_es_all
EdgeSelector::Noneno edgeigraph_es_none
3, &[0, 2], vec![..], 1..4, 1..=3as for verticesigraph_es_1, igraph_ess_vector, igraph_es_range
EdgeSelector::incident(v, mode)the edges incident to vigraph_es_incident
EdgeSelector::pairs(&[(a, b), ..], directed)one edge between each pairigraph_es_pairs
EdgeSelector::path(&[a, b, c, ..], directed)the edges along a pathigraph_es_path
EdgeSelector::all_between(a, b, directed)all the (multi-)edges between two verticesigraph_es_all_between

The immediate constructors (igraph_vss_none, igraph_vss_1, igraph_vss_range, igraph_ess_all, igraph_ess_none, igraph_ess_1, igraph_ess_range), the copying ones (igraph_vs_vector_copy, igraph_es_vector_copy, igraph_vs_copy, igraph_es_copy), the non-immediate vector ones (igraph_vs_vector, igraph_es_vector), the variadic *_small ones (igraph_vs_vector_small, igraph_es_pairs_small, igraph_es_path_small) and the iterators (igraph_vit_create, igraph_vit_destroy, igraph_vit_as_vector, igraph_eit_create, igraph_eit_destroy, igraph_eit_as_vector) are not wrapped: the constructors in the tables above cover the same selections (a Rust selector is rebuilt, not copied, for every call), and Graph::select_vertices / Graph::select_edges resolve a selector to a Vec where C code would iterate.

The C constructors are documented in the Iterators chapter of the igraph manual. Selectors are resolved against a graph with Graph::select_vertices / Graph::select_edges and counted with Graph::vs_size / Graph::es_size (igraph_iterators.h).

Functions accept impl Into<VertexSelector<'_>>, e.g. graph.degree(.., NeighborMode::All, Loops::Twice) or graph.degree(&[0, 1][..], ...).

use igraph::prelude::*;

let g = Graph::from_edges(&[(0, 1), (1, 2), (2, 0), (2, 3)], 4, false).unwrap();
assert_eq!(g.degree(.., NeighborMode::All, Loops::Twice).unwrap(), vec![2, 2, 3, 1]);
assert_eq!(g.degree(vec![2, 3], NeighborMode::All, Loops::Twice).unwrap(), vec![3, 1]);
let adjacent_to_2 = VertexSelector::Adjacent { vertex: 2, mode: NeighborMode::All };
assert_eq!(g.select_vertices(adjacent_to_2).unwrap(), vec![0, 1, 3]);

// Edge selectors: remove the triangle's edges along the path 0 - 1 - 2.
let mut h = g.clone();
h.delete_edges(EdgeSelector::path(&[0, 1, 2], false)).unwrap();
assert_eq!(h.edge_list(), vec![(0, 2), (2, 3)]);

Selectors are accepted all over the crate, e.g. by Graph::induced_subgraph, Graph::closeness or Graph::subgraph_from_edges.

Structs§

RawEs
A raw igraph_es_t together with the storage it points to; it is destroyed (with igraph_es_destroy) on drop.
RawVs
A raw igraph_vs_t together with the storage it points to.

Enums§

EdgeSelector
A set of edges, see the module docs.
VertexSelector
A set of vertices, see the module docs.