pub trait IndexPartition: IndexMapping {
// Required methods
fn group_count(&self) -> u32;
fn indices_of(&self, group: u32) -> SortedIntView<'_>;
fn size_of(&self, group: u32) -> u32;
fn reduce<T: Copy>(
&self,
values: &[T],
identity: T,
combine: impl FnMut(T, T) -> T,
) -> Vec<T>;
fn reduce_into<T: Clone>(
&self,
values: &[T],
group_values: &mut [T],
combine: impl FnMut(T, &T) -> T,
);
}Expand description
A partition of indices into groups: the common base of NodePartition and EdgePartition -
Java’s abstract class IndexPartition.
The indices are node IDs or edge indices. Each index is in at most one group, and the groups are
numbered by group ID 0..group_count(). get(i) returns the group of index
i, or None if it is in no group, and indices_of the indices of a group in
ascending order. reduce combines data on the indices into one value per group.
The data is an array indexed by node ID or edge index.
A partition is a mapping from indices to groups that maps several indices to the same group, so
unlike a NodeMapping or an EdgeMapping, it cannot
be inverted.
NodePartition, EdgePartition and Sccs implement this trait. Each of them
has the same methods as inherent methods too, so the trait is needed only for code that is generic
over them. It is sealed, as Java’s class hierarchy is. Instances are immutable and safe to share
between threads (Send and Sync).
Memory: 4 x (index_count + mapped_count + group_count) bytes, where mapped_count is the number of indices that belong to a group.
Required Methods§
Sourcefn group_count(&self) -> u32
fn group_count(&self) -> u32
Returns the number of groups.
Time: O(1).
Sourcefn indices_of(&self, group: u32) -> SortedIntView<'_>
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().
Sourcefn size_of(&self, group: u32) -> u32
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().
Sourcefn reduce<T: Copy>(
&self,
values: &[T],
identity: T,
combine: impl FnMut(T, T) -> T,
) -> Vec<T>
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. Here, by_package_call groups
the calls between the methods of a program by the call between packages that each belongs to (see
EdgePartition), and the call sites in site_count are summed per call between packages:
let package_site_count =
by_package_call.reduce(&site_count, 0, |sum, count| sum + count);
// 2 for app -> ui, app -> service, service -> model and service -> storage,
// 1 for app -> cli and ui -> modelTime: 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().
Sourcefn reduce_into<T: Clone>(
&self,
values: &[T],
group_values: &mut [T],
combine: impl FnMut(T, &T) -> T,
)
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().
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".