Expand description
Owned igraph vectors that behave like Rust slices.
igraph stores sequences in its own vector types (igraph_vector_t for
reals, igraph_vector_int_t for integers, …). The types below are
those very C structs, enriched with Rusty behaviour:
- they own their buffer and destroy it on
Drop; - they
Derefto a Rust slice, so every slice method (len,iter,sort, indexing,contains, …) works with zero copies; - they convert from and to
Vec, slices and iterators; - they implement
Clone,Debug,PartialEqandDefault.
| Rust alias | C type | element |
|---|---|---|
Vector | igraph_vector_t | f64 |
VectorInt | igraph_vector_int_t | i64 |
VectorBool | igraph_vector_bool_t | bool |
VectorChar | igraph_vector_char_t | c_char |
VectorComplex | igraph_vector_complex_t | igraph_complex_t |
Borrowed, read-only views over Rust slices (no copy at all) are created
with view, e.g. Vector::view; they are what the safe wrappers use to
hand weights and other inputs to igraph.
Most wrappers in this crate return plain Vecs, so these types matter
mostly when calling raw FFI functions, or to use igraph’s vector
algorithms (below) on any slice. Lists of vectors are in
list, matrices in matrix, sparse
matrices in linalg (SparseMat),
and misc has more numeric helpers, e.g.
misc::running_mean and
misc::power_law_fit.
This module covers igraph_vector_pmt.h (and the non-templated parts of
igraph_vector.h and igraph_complex.h). Besides everything slices
offer, the vectors provide igraph’s own algorithms:
| Group | Methods | Types |
|---|---|---|
| editing | insert, remove, swap_remove, remove_section, extend_from_slice, push, pop, truncate, resize, clear | all |
| reordering | shuffle (igraph RNG), permute, select, move_interval, get_interval, search | all |
| memory | reserve, capacity, shrink_to_fit | all |
| order | sort, reverse_sort, sort_ind, min, max, which_min, which_max, minmax, which_minmax, binsearch, contains_sorted | real, int, char |
| comparison | lex_cmp, colex_cmp, all_l, all_g, all_le, all_ge, maxdifference, is_in_interval, any_smaller | real, int, char |
| sorted sets | intersect_sorted, difference_sorted, intersection_size_sorted, difference_and_intersection_sorted, filter_smaller | real, int, char |
| arithmetic | sum, prod, cumsum, add_constant, scale, add, sub, mul, div, abs | real, int, complex |
| floating point | all_almost_e, zapsmall, floor, round, is_nan, is_any_nan, is_all_finite | real (complex) |
| complex | from_parts, from_polar, real, imag, realimag; igraph_complex_t has + - * /, abs, arg, exp, ln, sqrt, pow, trigonometry, … | complex |
Integer arithmetic is done in Rust with wrapping semantics (signed overflow in the C implementation would be undefined behaviour); real and complex arithmetic uses igraph’s functions. All index arguments are validated before reaching igraph, which does not check them.
use igraph::prelude::*;
let scores = Vector::from([0.3, 0.9, 0.1, 0.5]);
let ranking = scores.sort_ind(Order::Descending);
assert_eq!(ranking, vec![1, 3, 0, 2]);
assert_eq!(scores.which_max(), Some(1));
assert_eq!(scores.select(&[1, 3]).unwrap(), vec![0.9, 0.5]);
let a = VectorInt::from([1, 3, 5, 7]);
assert_eq!(a.intersect_sorted(&[3, 4, 5]), vec![3, 5]);
assert_eq!(a.binsearch(4), Err(2));use igraph::prelude::*;
let mut v: VectorInt = (0..5).collect();
v.push(10);
v[0] = -1;
assert_eq!(v.len(), 6);
assert_eq!(v.iter().sum::<i64>(), 19);
assert_eq!(Vec::from(v), vec![-1, 1, 2, 3, 4, 10]);
let weights = [0.5, 1.5];
let view = Vector::view(&weights);
assert_eq!(&view[..], &weights[..]);Structs§
- View
- A read-only view of a Rust slice as an igraph vector, without copying.
Functions§
- format_
real - Formats a real number the way igraph does in its text output
(
igraph_real_snprintf):%g-like, withNaN,Infand-Inffor the special values. - format_
real_ precise - Formats a real number with 15 significant digits
(
igraph_real_snprintf_precise), as used by igraph’s writers.
Type Aliases§
- Vector
- Owned vector of reals (
igraph_vector_t), see the module docs. - Vector
Bool - Owned vector of booleans (
igraph_vector_bool_t), see the module docs. - Vector
Char - Owned vector of chars (
igraph_vector_char_t), see the module docs. - Vector
Complex - Owned vector of complex numbers (
igraph_vector_complex_t), see the module docs. - Vector
Int - Owned vector of integers (
igraph_vector_int_t), see the module docs.