Skip to main content

EdgePartition

Struct EdgePartition 

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

A partition of the edges of a graph into groups: the edges behind each edge of a condensed graph, or the blocks of a graph.

get(e) returns the group of edge e, or None if it is in no group, and edges_of the edge indices of a group in ascending order. The groups come from one of two functions:

  • graphs::edge_partition groups the edges of the graph of a NodePartition by the edge of its condensed graph that they condense to: the group IDs are the edge indices of the condensed graph. Edges within a group of nodes, and edges from or to a node in no group, condense to no edge and are in no group.
  • Biconnectivity::blocks groups the edges by block (biconnected component); self-loops are in no block.

Here, by_package groups the methods of a program by package. Its condensed graph package_calls holds the calls between packages (see NodePartition::of). by_package_call tells which calls between methods are behind the call from service to model:

let by_package_call = graphs::edge_partition(&package_calls, &by_package);
let service_to_model = package_calls.edge_index_of(service, model).unwrap();
let behind = by_package_call.edges_of(service_to_model);
// behind: [5, 7] - the calls load -> parse and save -> format

reduce combines data on the edges into one value per group, such as the number of call sites behind each call between packages.

Instances are immutable and safe to share between threads (Send and Sync).

Memory: 4 x (edge_count + mapped_count + group_count) bytes, where mapped_count is the number of edges that belong to a group.

Implementations§

Source§

impl EdgePartition

Source

pub fn edge_count(&self) -> u32

Returns the number of edges of the partitioned graph, in a group or not. Equivalent to index_count.

Time: O(1).

Source

pub fn edges_of(&self, group: u32) -> SortedIntView<'_>

Returns the edge indices in group group, in ascending order. Equivalent to indices_of(group).

The result is a view of this partition’s own array, not a copy.

Time: O(1).

§Panics

With an index out of bounds message if group is not in 0..group_count().

Source§

impl EdgePartition

Source

pub fn group_count(&self) -> u32

Returns the number of groups.

Time: O(1).

Source

pub fn indices_of(&self, group: u32) -> SortedIntView<'_>

Returns the indices in group group, in ascending order.

The result is a view of this partition’s own array, not a copy.

Time: O(1).

§Panics

With an index out of bounds message if group is not in 0..group_count().

Source

pub fn size_of(&self, group: u32) -> u32

Returns the number of indices in group group.

Time: O(1).

§Panics

With an index out of bounds message if group is not in 0..group_count().

Source

pub fn reduce<T: Copy>( &self, values: &[T], identity: T, combine: impl FnMut(T, T) -> T, ) -> Vec<T>

Returns one value per group, combined from the values of its indices.

For each group, starts from identity and combines the result so far with the value of each index in the group, in ascending order of the indices. A group without indices gets identity, and the values of indices in no group are left out. The result is indexed by group ID. combine is called with the result so far and the value of the next index, and returns the two combined. This is one generic function for every Copy type; Java has one per primitive type. reduce_into does the same for other types.

Time: O(index_count + group_count). Memory: size_of::<T>() x group_count bytes for the result.

§Panics

With an invalid argument message if values.len() != index_count().

Source

pub fn reduce_into<T: Clone>( &self, values: &[T], group_values: &mut [T], combine: impl FnMut(T, &T) -> T, )

Writes one value per group into group_values, combined from the values of the indices of that group. This is the form of reduce for values that are not Copy - Java’s overload reduce(T[], T[], BinaryOperator).

For each group, starts from a clone of the value of its first index and combines the result so far with the value of each further index, in ascending order of the indices. That takes one clone per group; Java folds references. combine is called with the result so far and a reference to the value of the next index, and returns the two combined. A group without indices keeps its entry in group_values, and the values of indices in no group are left out. The borrow rules guarantee that the two slices are not the same; Java checks this.

Time: O(index_count + group_count).

§Panics

With an invalid argument message if values.len() != index_count() or group_values.len() != group_count().

Source§

impl EdgePartition

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 EdgePartition

Source§

fn clone(&self) -> EdgePartition

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 EdgePartition

Source§

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

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

impl Eq for EdgePartition

Source§

impl Hash for EdgePartition

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 EdgePartition

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 IndexPartition for EdgePartition

Source§

fn group_count(&self) -> u32

Returns the number of groups. Read more
Source§

fn indices_of(&self, group: u32) -> SortedIntView<'_>

Returns the indices in group group, in ascending order. Read more
Source§

fn size_of(&self, group: u32) -> u32

Returns the number of indices in group group. Read more
Source§

fn reduce<T: Copy>( &self, values: &[T], identity: T, combine: impl FnMut(T, T) -> T, ) -> Vec<T>

Returns one value per group, combined from the values of its indices. Read more
Source§

fn reduce_into<T: Clone>( &self, values: &[T], group_values: &mut [T], combine: impl FnMut(T, &T) -> T, )

Writes one value per group into group_values, combined from the values of the indices of that group. This is the form of reduce for values that are not Copy - Java’s overload reduce(T[], T[], BinaryOperator). Read more
Source§

impl PartialEq for EdgePartition

Source§

fn eq(&self, other: &EdgePartition) -> 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 EdgePartition

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.