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 value | Selected vertices | C constructor |
|---|---|---|
.. or VertexSelector::All | all vertices | igraph_vs_all |
VertexSelector::None | no vertex | igraph_vs_none |
3 (an i64) | the single vertex 3 | igraph_vs_1 |
&[0, 2, 5], vec![..], &VectorInt | the listed vertices, in order | igraph_vss_vector |
2..6 | vertices 2, 3, 4, 5 | igraph_vs_range |
2..=5 | vertices 2, 3, 4, 5 | igraph_vs_range |
VertexSelector::adjacent(v, mode) | the neighbors of v | igraph_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 value | Selected edges | C constructor |
|---|---|---|
.. or EdgeSelector::All, EdgeSelector::AllOrdered(order) | all edges, by id or by endpoint | igraph_es_all |
EdgeSelector::None | no edge | igraph_es_none |
3, &[0, 2], vec![..], 1..4, 1..=3 | as for vertices | igraph_es_1, igraph_ess_vector, igraph_es_range |
EdgeSelector::incident(v, mode) | the edges incident to v | igraph_es_incident |
EdgeSelector::pairs(&[(a, b), ..], directed) | one edge between each pair | igraph_es_pairs |
EdgeSelector::path(&[a, b, c, ..], directed) | the edges along a path | igraph_es_path |
EdgeSelector::all_between(a, b, directed) | all the (multi-)edges between two vertices | igraph_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_ttogether with the storage it points to; it is destroyed (withigraph_es_destroy) on drop. - RawVs
- A raw
igraph_vs_ttogether with the storage it points to.
Enums§
- Edge
Selector - A set of edges, see the module docs.
- Vertex
Selector - A set of vertices, see the module docs.