Class EdgeMapping
- Namespace
- Graphity
- Assembly
- Graphity.Core.dll
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.
public sealed class EdgeMapping : IndexMapping
- Inheritance
-
EdgeMapping
- Inherited Members
Examples
Here, siteCount 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:
int[] loadingSiteCount =
Graphs.EdgeMapping(loading, calls, newToOld).Gather(siteCount);
// 1 for load -> parse and for load -> read, 2 for parse -> parse
Remarks
Get(e) is the edge index that edge e maps to, or -1 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. EdgeMapping(Graph, Graph, NodeMapping) derives one from the NodeMapping of
a subgraph or a renumbering, and leaves a new edge without a counterpart in the old graph
unmapped. TransposedEdgeMapping(Graph) maps each edge of the transposed graph to
the edge it reverses.
Gather carries data on the old edges over to the new ones. Inverted(int) returns
the mapping from old to new, and Compose(EdgeMapping) chains two mappings.
Instances are immutable and safe to share between threads.
Memory: 4 x IndexCount bytes.
Methods
Compose(EdgeMapping)
Returns the mapping that applies inner first and then this mapping.
public EdgeMapping Compose(EdgeMapping inner)
Parameters
innerEdgeMappingThe mapping to apply first.
Returns
- EdgeMapping
The composed mapping.
Remarks
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.IndexCount).
Memory: 4 x inner.IndexCount bytes for the result.
Exceptions
- ArgumentOutOfRangeException
innermaps an edge to an edge index outside0..IndexCount-1.
Gather<T>(ReadOnlySpan<T>)
Returns values renumbered by this mapping: the value at position i
of the result is values[Get(i)], or default (0 for a number) if edge
i is not mapped.
public T[] Gather<T>(ReadOnlySpan<T> values) where T : unmanaged
Parameters
valuesReadOnlySpan<T>The value of each edge of the graph that this mapping maps to.
Returns
- T[]
The renumbered values, of length IndexCount.
Type Parameters
TThe element type: an unmanaged value type such as
int.
Remarks
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. One generic method serves int,
long, double and any other unmanaged value type.
Gather<T>(ReadOnlySpan<T>, Span<T>) does the same for objects.
Time: O(IndexCount).
Memory: one element per index for the result, 4 x IndexCount bytes for int.
Exceptions
- ArgumentOutOfRangeException
An edge maps to an edge index outside
values.
Gather<T>(ReadOnlySpan<T>, Span<T>)
Writes values renumbered by this mapping into newValues,
for objects.
public void Gather<T>(ReadOnlySpan<T> values, Span<T> newValues)
Parameters
valuesReadOnlySpan<T>The value of each edge of the graph that this mapping maps to.
newValuesSpan<T>Receives the renumbered values; length IndexCount, and not overlapping
values.
Type Parameters
TThe element type, nullable or not.
Remarks
newValues[i] becomes values[Get(i)], and stays as it is if edge i is not
mapped. References are copied, not the objects. If an exception is thrown,
newValues may be partly written.
Time: O(IndexCount).
Exceptions
- ArgumentException
newValues.Length != IndexCount, or the two overlap.- ArgumentOutOfRangeException
An edge maps to an edge index outside
values.
Inverted(int)
Returns the inverse mapping, which maps Get(e) back to e.
public EdgeMapping Inverted(int targetCount)
Parameters
targetCountintThe edge count of the graph that this mapping maps to.
Returns
- EdgeMapping
The inverse mapping, with an index count of
targetCount.
Remarks
The inverse maps the targetCount 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,
targetCount is the edge count of the old graph, and the inverse gives the
new edge index of an old edge: newToOld.Inverted(oldGraph.EdgeCount).Get(oldEdge).
Time: O(IndexCount + targetCount).
Memory: 4 x targetCount bytes for the result.
Exceptions
- ArgumentException
targetCountis negative or larger thanArray.MaxLength, or two edges map to the same edge.- ArgumentOutOfRangeException
An edge maps to
targetCountor more.