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).
Whether some index is not mapped. Equivalent to mappedCount < indexCount.
Time: O(1).
The number of indices that are mapped; in a partition, the number of indices that belong to a group.
Time: O(1).
Returns the mapping that applies inner first and then this mapping.
If inner maps the nodes of a graph A to those of B, and this mapping maps B to C, the result
maps A to C. A node is not mapped in the result if inner does not map it, or if this mapping
does not map the node that inner maps it to. For mappings from new to old node IDs,
firstToOriginal.compose(secondToFirst) maps the nodes of a graph remapped twice back to those
of the original one.
Time: O(inner.indexCount). Memory: 4 x inner.indexCount bytes for the result.
the mapping to apply first
the composed mapping
Returns values renumbered by this mapping: the value at position i of the result is
values[get(i)], or 0 if i is not mapped. The result is a typed array of the type of
values (Java: the int[], long[] and double[] forms; here any typed array).
For a mapping from new to old node IDs, as the factories return it, this carries data on the
nodes of the old graph over to the new graph. The form with newValues does the same for
values of any kind, such as names.
Time: O(indexCount).
Memory: one element per index for the result: 4 x indexCount bytes for an Int32Array,
8 x indexCount bytes for a Float64Array or a BigInt64Array.
the value of each node of the graph that this mapping maps to
the renumbered values, of length IndexMapping.indexCount
Writes values renumbered by this mapping into newValues, for values of any kind, such as
names (Java: the T[] form). The second argument selects this form, as in Java's overload
resolution: the values may be in any array-like, also in a typed array.
newValues[i] becomes values[get(i)], and stays as it is if i is not mapped. References
are copied, not the objects. If an error is thrown, newValues may be partly written.
Time: O(indexCount).
the value of each node of the graph that this mapping maps to
receives the renumbered values; length IndexMapping.indexCount, and
not the same array as values
Returns the inverse mapping, which maps get(node) back to node.
The inverse maps the targetCount nodes of the graph that this mapping maps to; a node that no
node maps to is not mapped, and the inverse is then partial. For a mapping from new to old node
IDs, as the factories return it, targetCount is the node count of the old graph, and the
inverse gives the new node ID of an old node:
newToOld.inverted(oldGraph.nodeCount).get(oldNode).
Time: O(indexCount + targetCount). Memory: 4 x targetCount bytes for the result.
the node count of the graph that this mapping maps to
the inverse mapping, with an index count of targetCount
StaticforReturns a mapping that numbers the nodes in the given order, from new to old node IDs.
order[newNode] is the node that gets the new node ID newNode. order holds every node ID
in 0..order.length-1 once, so the mapping maps every node. For example,
NodeMapping.forPermutation(TopOrder.of(dag)) numbers the nodes of a DAG (directed acyclic
graph) in topological order, so that every edge of the remapped graph goes from a lower to a
higher node ID.
Time: O(order.length). Memory: 4 x order.length bytes for the result; while it runs, 1 bit per node.
the node IDs in their new order
the mapping from new to old node IDs
StaticforReturns a mapping from the nodes of a subgraph to the selected nodes, given as the set bits of
selected (Java: java.util.BitSet).
The selected nodes get the new node IDs 0..selected.cardinality()-1, in ascending order of
their node IDs. The selected node IDs are checked against a graph only when the mapping is
used: Graphs.remapped rejects one that is not a node of its graph.
Time: O(selected.length()). Memory: 4 x selected.cardinality() bytes for the result.
the selected node IDs
the mapping from new to old node IDs
Returns a mapping from the nodes of a subgraph to the selected nodes, given as a list.
The selected nodes get the new node IDs 0..selected.length-1, in ascending order of their
node IDs, whatever the order of the list. A SortedIntView, as
Graphs.reachableFrom and NodePartition.nodesOf return it, is taken as it is;
any other list is sorted first, in a copy. As with the BitSet form, the node IDs are checked
against a graph only when the mapping is used.
Time: O(k) for a SortedIntView, O(k log k) for any other list, where k is
selected.length.
Memory: 4 x selected.length bytes for the result.
the selected node IDs
the mapping from new to old node IDs
TypeError if selected is not a list, as IntLists.asArrayLike rejects it
Returns a mapping from the nodes of a subgraph to the selected nodes, given as node IDs.
The selected nodes get the new node IDs 0..selected.length-1, in ascending order of their
node IDs, whatever the order of the arguments; the array is sorted in a copy. As with the
BitSet form, the node IDs are checked against a graph only when the mapping is used.
Time: O(k log k), where k is selected.length.
Memory: 4 x selected.length bytes for the result.
the selected node IDs
the mapping from new to old node IDs
StaticofReturns the mapping that maps each node i to mapping[i], and leaves it unmapped where that
is -1.
Use it for mappings that the other factories do not cover, from new to old or from old to new.
The array is copied. Each value must be -1 or a node ID, and no two nodes may map to the same
node; without a graph, this method can only reject a value below -1. Graphs.remapped
rejects a value that is not a node of its graph, and both it and NodeMapping.inverted
reject two nodes that map to the same node.
Time: O(mapping.length). Memory: 4 x mapping.length bytes for the copy, which the result keeps.
the node ID that each node maps to, or -1; any array of numbers
the mapping
StaticreindexReturns a mapping that numbers the nodes of graph in depth-first preorder, from new to old
node IDs.
The search starts at node 0, follows the out-nodes of each node in ascending order, and
starts again at the smallest node not yet visited until it has visited every node; each node
gets the next new node ID when the search reaches it. Nodes that the search visits one after
another thus get adjacent node IDs. Traversals of the remapped graph then read its arrays more
in order, which can make them faster on large graphs.
Time: O(nodeCount + edgeCount). Memory: 4 x nodeCount bytes for the result; while it runs, 1 bit per node and up to 8 x nodeCount bytes for the stack, which grows with the deepest path.
the graph whose nodes are numbered
the mapping from new to old node IDs
A mapping from the node IDs of one graph to those of another, to extract a subgraph or to renumber the nodes of a graph.
get(node)is the node ID thatnodemaps to, or-1ifnodeis not mapped. The factories return mappings from a new graph to an old one. These map each new node to the node it comes from:Graphs.remapped builds the new graph from the old one, and NodeMapping.gather carries data on the old nodes, such as their names, over to the new ones. Here,
callsholds the calls between the methods of a program, and the methods thatloadreaches become a graph of their own, with their names fromnames:Graphs.edgeMapping derives the EdgeMapping that carries data on edges. NodeMapping.inverted returns the mapping from old to new, and NodeMapping.compose chains two mappings.
Instances are immutable.
Memory: 4 x indexCount bytes.