Class IndexPartition
- Namespace
- Graphity
- Assembly
- Graphity.Core.dll
A partition of indices into groups: the common base of NodePartition and EdgePartition.
public abstract class IndexPartition : IndexMapping
- Inheritance
-
IndexPartition
- Derived
- Inherited Members
Remarks
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..GroupCount-1. Get(i) returns the group of index i,
or -1 if it is in no group, and IndicesOf(int) 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.
Instances are immutable and safe to share between threads. No other assembly can derive from this class.
Memory: 4 x (IndexCount + MappedCount + GroupCount) bytes, where MappedCount is the number of indices that belong to a group.
Properties
GroupCount
Gets the number of groups.
public int GroupCount { get; }
Property Value
Remarks
Time: O(1).
Methods
IndicesOf(int)
Returns the indices in group groupId, in ascending order.
public SortedIntView IndicesOf(int groupId)
Parameters
groupIdintGroup ID in
0..GroupCount-1.
Returns
- SortedIntView
The indices in the group.
Remarks
The result is a view of this partition's own array, not a copy.
Time: O(1).
Exceptions
- ArgumentOutOfRangeException
groupIdis out of range.
Reduce<T>(ReadOnlySpan<T>, Span<T>, Func<T, T, T>)
Writes one value per group into groupValues, combined from the values of
the indices of that group.
public void Reduce<T>(ReadOnlySpan<T> values, Span<T> groupValues, Func<T, T, T> combine)
Parameters
valuesReadOnlySpan<T>The value of each index; length IndexCount.
groupValuesSpan<T>Receives one value per group, by group ID; length GroupCount, and not overlapping
values.combineFunc<T, T, T>Called with the result so far and the value of the next index, returns the two combined.
Type Parameters
TThe element type, nullable or not.
Remarks
For each group, starts from 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. A group without indices
keeps its entry in groupValues, and the values of indices in no group are
left out.
Time: O(IndexCount + GroupCount).
Exceptions
- ArgumentException
values.Length != IndexCount,groupValues.Length != GroupCount, or the two overlap.
Reduce<T>(ReadOnlySpan<T>, T, Func<T, T, T>)
Returns one value per group, combined from the values of its indices.
public T[] Reduce<T>(ReadOnlySpan<T> values, T identity, Func<T, T, T> combine)
Parameters
valuesReadOnlySpan<T>The value of each index; length IndexCount.
identityTThe start value of each group.
combineFunc<T, T, T>Called with the result so far and the value of the next index, returns the two combined.
Returns
- T[]
One value per group, by group ID.
Type Parameters
TThe element type.
Examples
Here, byPackageCall 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
siteCount are summed per call between packages:
int[] packageSiteCount = byPackageCall.Reduce(siteCount, 0, (a, b) => a + b);
// 2 for app -> ui, app -> service, service -> model and service -> storage,
// 1 for app -> cli and ui -> model
Remarks
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.
One generic method serves int, long, double and any other element type.
Time: O(IndexCount + GroupCount).
Memory: one element per group for the result, 4 x GroupCount bytes for int.
Exceptions
- ArgumentException
values.Length != IndexCount.
SizeOf(int)
Returns the number of indices in group groupId.
public int SizeOf(int groupId)
Parameters
groupIdintGroup ID in
0..GroupCount-1.
Returns
- int
The size of the group.
Remarks
Time: O(1).
Exceptions
- ArgumentOutOfRangeException
groupIdis out of range.