Skip to main content

EdgeMapping

Struct EdgeMapping 

Source
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 -> parse

inverted 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

Source

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.

Source

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().

Source

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.

Source

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

Source

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().

Source

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().

Source

pub fn is_partial(&self) -> bool

Returns whether some index is not mapped. Equivalent to mapped_count() < index_count().

Time: O(1).

Source

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).

Source

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

Source§

fn clone(&self) -> EdgeMapping

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EdgeMapping

Source§

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

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

impl Eq for EdgeMapping

Source§

impl Hash for EdgeMapping

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IndexMapping for EdgeMapping

Source§

fn get(&self, id: u32) -> Option<u32>

Returns the index that id maps to, or None if id is not mapped - Java’s -1. Read more
Source§

fn is_mapped(&self, id: u32) -> bool

Returns whether id is mapped. Equivalent to get(id).is_some(). Read more
Source§

fn is_partial(&self) -> bool

Returns whether some index is not mapped. Equivalent to mapped_count() < index_count(). Read more
Source§

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. Read more
Source§

fn index_count(&self) -> u32

Returns the number of indices this mapping maps from, mapped or not. Read more
Source§

impl PartialEq for EdgeMapping

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for EdgeMapping

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.