Struct EditGraph

Source
pub struct EditGraph { /* private fields */ }
Expand description

An implementation of the MutableGraph trait with additional convenient editing and generating functions.

Implementations§

Source§

impl EditGraph

Source

pub fn path(n: u32) -> EditGraph

Generates a path on n vertices.

Source

pub fn cycle(n: u32) -> EditGraph

Generates a cycle on n vertices.

Source

pub fn matching(n: u32) -> EditGraph

Generates a matching on 2n vertices.

Source

pub fn star(n: u32) -> EditGraph

Generates a star with n leaves, so n+1 vertices total.

Source

pub fn clique(n: u32) -> EditGraph

Generates a complete graph (clique) on n vertices.

Source

pub fn independent(n: u32) -> EditGraph

Generates an empty graph (independent set) on n vertices.

Source

pub fn biclique(s: u32, t: u32) -> EditGraph

Generates a complete bipartite graph (biclique) on s+t vertices.

Source

pub fn complete_kpartite<'a, I>(sizes: I) -> EditGraph
where I: IntoIterator<Item = &'a u32>,

Generates a complete k-partite graph.

§Arguments
  • sizes - The sizes of each partite set as a sequence of integers.
Source

pub fn disj_union(&self, graph: &impl Graph) -> EditGraph

Creates a new graph that is the disjoint union of self and graph. The vertices of the second graph are relabelled to avoid index clashes.

Source

pub fn disj_unions<'a, I, G>(it: I) -> EditGraph
where I: Iterator<Item = &'a G>, G: Graph + 'a,

Computes the disjoint unions of all graphs in the iterator it.

Source

pub fn normalize(&self) -> (EditGraph, FxHashMap<Vertex, Vertex>)

Creates a copy of the graph in which vertices are labelled from $0$ to $n-1$, where $n$ is the number of vertices in the graph. The relative order of the indices is preserved, e.g. the smallest vertex from the original graph will be labelled $0$ and the largest one $n-1$.

Returns a tuple (graph, map) where graph is the relabelled graph and map stores the mapping from new vertices to old vertices.

Source

pub fn contract<'a, I>(&mut self, vertices: I) -> Vertex
where I: Iterator<Item = &'a Vertex>,

Contracts all vertices into the first vertex of the sequence. The contracted vertex has as its neighbours all vertices that were adjacent to at least one vertex in vertices.

This function panics if the sequence is empty.

Returns the contracted vertex.

Source

pub fn contract_pair(&mut self, u: &Vertex, v: &Vertex)

Contracts the pair ${u,v}$ be identifying $v$ with $u$. The operation removes $v$ from the graph and adds $v$’s neighbours to $u$.

Panics if either of the two vertices does not exist.

Source

pub fn contract_into<'a, I>(&mut self, center: &Vertex, vertices: I)
where I: Iterator<Item = &'a Vertex>,

Contracts all vertices into the center vertex. The contracted vertex has as its neighbours all vertices that were adjacent to at least one vertex in vertices.

Source§

impl EditGraph

I/O operations for EditGraph defined in crate::io

Source

pub fn from_txt(filename: &str) -> Result<EditGraph>

Loads the graph from a text file which contains edges separated by line breaks. Edges must be pairs of integers separated by a space.

For example, assume the file edges.txt contains the following:

0 1
0 2
0 3

We can then load the file as follows:

use graphbench::graph::*;
use graphbench::editgraph::EditGraph;
use graphbench::iterators::EdgeIterable;
 
fn main() {
    let graph = EditGraph::from_txt("edges.txt").expect("Could not open edges.txt");
    println!("Vertices: {:?}", graph.vertices().collect::<Vec<&Vertex>>());
    println!("Edges: {:?}", graph.edges().collect::<Vec<Edge>>());
}
Source

pub fn from_gzipped(filename: &str) -> Result<EditGraph>

Loads the graph from a gzipped text file which otherwise follows the format described in EditGraph::from_txt.

Trait Implementations§

Source§

impl Clone for EditGraph

Source§

fn clone(&self) -> EditGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EditGraph

Source§

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

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

impl FromIterator<(u32, u32)> for EditGraph

Source§

fn from_iter<T: IntoIterator<Item = Edge>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Graph for EditGraph

Source§

fn num_vertices(&self) -> usize

Returns the number of vertices in the graph.
Source§

fn num_edges(&self) -> usize

Returns the number of edges in the graph.
Source§

fn adjacent(&self, u: &Vertex, v: &Vertex) -> bool

Returns whether vertices u and v are connected by an edge.
Source§

fn degree(&self, u: &Vertex) -> u32

Returns the number of edges incident to u in the graph.
Source§

fn contains(&self, u: &Vertex) -> bool

Returns whether the vertex u is contained in the graph.
Source§

fn vertices<'a>(&'a self) -> Box<dyn Iterator<Item = &Vertex> + 'a>

Returns an iterator to this graph’s vertices.
Source§

fn neighbours<'a>( &'a self, u: &Vertex, ) -> Box<dyn Iterator<Item = &Vertex> + 'a>

Returns an iterator over the neighbours of u.
Source§

fn degrees(&self) -> VertexMap<u32>

Returns the degrees of all vertices in the graph as a map.
Source§

fn len(&self) -> usize

Alias for Graph::num_vertices()
Source§

fn is_empty(&self) -> bool

Returns true if the graph contains no vertices
Source§

fn neighbourhood<'a, I>(&self, vertices: I) -> FxHashSet<Vertex>
where I: Iterator<Item = &'a Vertex>, Vertex: 'a,

Given an iterator vertices over vertices, returns all vertices of the graph which are neighbours of those vertices but not part of vertices themselves.
Source§

fn closed_neighbourhood<'a, I>(&self, vertices: I) -> FxHashSet<Vertex>
where I: Iterator<Item = &'a Vertex>, Vertex: 'a,

Given an iterator vertices over vertices, returns all vertices of the graph which are neighbours of those vertices as well as all vertices contained in vertices.
Source§

fn r_neighbours(&self, u: &Vertex, r: usize) -> FxHashSet<Vertex>

Returns all vertices which lie within distance at most r to u.
Source§

fn r_neighbourhood<'a, I>(&self, vertices: I, r: usize) -> FxHashSet<Vertex>
where I: Iterator<Item = &'a Vertex>, Vertex: 'a,

Given an iterator vertices over vertices and a distance r, returns all vertices of the graph which are within distance at most r to vertices contained in vertices.
Source§

fn subgraph<'a, M, I>(&self, vertices: I) -> M
where M: MutableGraph, I: Iterator<Item = &'a Vertex>,

Returns the subgraph induced by the vertices contained in vertices.
Source§

impl MutableGraph for EditGraph

Source§

fn new() -> EditGraph

Creates an emtpy mutable graph.
Source§

fn with_capacity(n_guess: usize) -> Self

Creates a mutable graph with a hint on how many vertices it will probably contain.
Source§

fn add_vertex(&mut self, u: &Vertex) -> bool

Adds the vertex u to the graph. Read more
Source§

fn add_edge(&mut self, u: &Vertex, v: &Vertex) -> bool

Adds the edge uv to the graph. Read more
Source§

fn remove_edge(&mut self, u: &Vertex, v: &Vertex) -> bool

Removes the edge uv from the graph. Read more
Source§

fn remove_vertex(&mut self, u: &Vertex) -> bool

Removes the vertex u from the graph. Read more
Source§

fn add_vertices(&mut self, vertices: impl Iterator<Item = Vertex>) -> u32

Adds a collection of vertices to the graph. Read more
Source§

fn add_edges(&mut self, edges: impl Iterator<Item = Edge>) -> u32

Adds a collection of edges to the graph. Read more
Source§

fn remove_loops(&mut self) -> usize

Removes all loops from the graph. Read more
Source§

fn remove_isolates(&mut self) -> usize

Removes all isolate vertices, that is, vertices without any neighbours. Read more
Source§

impl PartialEq for EditGraph

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for EditGraph

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<G> EdgeIterable<G> for G
where G: Graph,

Source§

fn edges(&self) -> EdgeIterator<'_, G>

Returns an EdgeIterator over the edges of this graph.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<G> GraphAlgorithms for G
where G: Graph,

Source§

fn components(&self) -> Vec<HashSet<u32, BuildHasherDefault<FxHasher>>>

Returns the connected components of this graph.
Source§

fn degeneracy( &self, ) -> (u32, u32, Vec<u32>, HashMap<u32, u32, BuildHasherDefault<FxHasher>>)

Computes the degeneracy (approximate), core-numbers and a degeneracy-ordering of this graph. The return value contains four values: Read more
Source§

fn is_bipartite(&self) -> BipartiteWitness

Tests whether the graph is bipartite and returns a witness.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<G> MixedIterable<G> for G
where G: Graph,

Source§

fn vertices_and_edges(&self) -> MixedIterator<'_, G>

Returns an EdgeIterator over the edges of this graph.
Source§

impl<G> NeighIterable<G> for G
where G: Graph,

Source§

fn neighbourhoods(&self) -> NeighIterator<'_, G>

Returns a NeighIterator for the graph.
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, 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.
Source§

impl<G> WriteGraph for G
where G: Graph,

Source§

fn write_txt(&self, filename: &str) -> Result<(), Error>

Source§

fn write_gzipped(&self, filename: &str) -> Result<(), Error>