pub struct EdgeMapping { /* private fields */ }Expand description
A mapping from the edge indices of one graph to those of another, to carry data on edges over to a subgraph, a renumbered graph or the transposed graph.
get(e) is the edge index that edge e maps to, or None if edge e is not mapped.
The factories return mappings from a new graph to an old one. These map each new edge to the edge
it comes from. graphs::edge_mapping derives one from the
NodeMapping of a subgraph or a renumbering, and leaves a new edge without a counterpart in the
old graph unmapped. graphs::transposed_edge_mapping
maps each edge of the transposed graph to the edge it reverses.
gather carries data on the old edges over to the new ones. Here, site_count
holds the number of call sites of each call by edge index of calls, and the subgraph loading
from the example at NodeMapping takes these counts along:
let loading_site_count =
graphs::edge_mapping(&loading, &calls, &new_to_old).gather(&site_count);
// 1 for load -> parse and for load -> read, 2 for parse -> parseinverted returns the mapping from old to new, and compose
chains two mappings.
Instances are immutable and safe to share between threads (Send and Sync).
Memory: 4 x index_count bytes.
Implementations§
Source§impl EdgeMapping
impl EdgeMapping
Sourcepub fn inverted(&self, target_count: u32) -> EdgeMapping
pub fn inverted(&self, target_count: u32) -> EdgeMapping
Returns the inverse mapping, which maps get(e) back to e.
The inverse maps the target_count edges of the graph that this mapping maps to; an edge that no
edge maps to is not mapped, and the inverse is then partial. For a mapping from new to old edge
indices, as the factories return it, target_count is the edge count of the old graph, and the
inverse gives the new edge index of an old edge:
new_to_old.inverted(old_graph.edge_count()).get(old_edge).
Time: O(index_count + target_count). Memory: 4 x target_count bytes for the result.
§Panics
With an invalid argument message if target_count is larger than 2^31 - 9, or two edges map
to the same edge; with an index out of bounds message if an edge maps to target_count or more.
Sourcepub fn compose(&self, inner: &EdgeMapping) -> EdgeMapping
pub fn compose(&self, inner: &EdgeMapping) -> EdgeMapping
Returns the mapping that applies inner first and then this mapping.
If inner maps the edges of a graph A to those of B, and this mapping maps B to C, the result
maps A to C. An edge is not mapped in the result if inner does not map it, or if this mapping
does not map the edge that inner maps it to.
Time: O(inner.index_count()). Memory: 4 x inner.index_count() bytes for the result.
§Panics
With an index out of bounds message if inner maps an edge to an edge index outside
0..index_count().
Sourcepub fn gather<T: Copy + Default>(&self, values: &[T]) -> Vec<T>
pub fn gather<T: Copy + Default>(&self, values: &[T]) -> Vec<T>
Returns values renumbered by this mapping: the value at position i of the result is
values[get(i)], or T::default() - Java’s 0 - if edge i is not mapped.
For a mapping from new to old edge indices, as the factories return it, this carries data on the
edges of the old graph over to the new graph. This is one generic function for every Copy type;
Java has one per primitive type. gather_into does the same for other types.
Time: O(index_count).
Memory: size_of::<T>() x index_count bytes for the result.
§Panics
With an index out of bounds message if an edge maps to an edge index outside values.
Sourcepub fn gather_into<T: Clone>(&self, values: &[T], new_values: &mut [T])
pub fn gather_into<T: Clone>(&self, values: &[T], new_values: &mut [T])
Writes values renumbered by this mapping into new_values, for values that are not Copy -
Java’s overload gather(T[], T[]).
new_values[i] becomes a clone of values[get(i)], and stays as it is if edge i is not mapped.
If it panics, new_values may be partly written. The borrow rules guarantee that the two slices
are not the same; Java checks this.
Time: O(index_count).
§Panics
With an invalid argument message if new_values.len() != index_count(); with an
index out of bounds message if an edge maps to an edge index outside values.
Source§impl EdgeMapping
impl EdgeMapping
Sourcepub fn get(&self, id: u32) -> Option<u32>
pub fn get(&self, id: u32) -> Option<u32>
Returns the index that id maps to, or None if id is not mapped - Java’s -1.
In a partition, it is the group of id.
Time: O(1).
§Panics
With an index out of bounds message if id is not in 0..index_count().
Sourcepub fn is_mapped(&self, id: u32) -> bool
pub fn is_mapped(&self, id: u32) -> bool
Returns whether id is mapped. Equivalent to get(id).is_some().
Time: O(1).
§Panics
With an index out of bounds message if id is not in 0..index_count().
Sourcepub fn is_partial(&self) -> bool
pub fn is_partial(&self) -> bool
Returns whether some index is not mapped. Equivalent to mapped_count() < index_count().
Time: O(1).
Sourcepub fn mapped_count(&self) -> u32
pub fn mapped_count(&self) -> u32
Returns the number of indices that are mapped; in a partition, the number of indices that belong to a group.
Time: O(1).
Sourcepub fn index_count(&self) -> u32
pub fn index_count(&self) -> u32
Returns the number of indices this mapping maps from, mapped or not.
It is the length of the arrays that gather returns and that reduce takes.
Time: O(1).
Trait Implementations§
Source§impl Clone for EdgeMapping
impl Clone for EdgeMapping
Source§fn clone(&self) -> EdgeMapping
fn clone(&self) -> EdgeMapping
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EdgeMapping
impl Debug for EdgeMapping
impl Eq for EdgeMapping
Source§impl Hash for EdgeMapping
impl Hash for EdgeMapping
Source§impl IndexMapping for EdgeMapping
impl IndexMapping for EdgeMapping
Source§fn is_partial(&self) -> bool
fn is_partial(&self) -> bool
mapped_count() < index_count(). Read more