Graphity for TypeScript 3.0.0
    Preparing search index...

    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 that node maps to, or -1 if node is 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, calls holds the calls between the methods of a program, and the methods that load reaches become a graph of their own, with their names from names:

    const newToOld = NodeMapping.forSubgraph(Graphs.reachableFrom(calls, load));
    const loading = Graphs.remapped(calls, newToOld);
    const loadingNames = new Array<string>(loading.nodeCount);
    newToOld.gather(names, loadingNames);
    // loadingNames: [load, parse, read]
    // loading: load -> parse, load -> read, parse -> parse

    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.

    Hierarchy (View Summary)

    Index
    • get indexCount(): number

      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).

      Returns number

    • get isPartial(): boolean

      Whether some index is not mapped. Equivalent to mappedCount < indexCount.

      Time: O(1).

      Returns boolean

    • get mappedCount(): number

      The number of indices that are mapped; in a partition, the number of indices that belong to a group.

      Time: O(1).

      Returns number

    • 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.

      Parameters

      Returns NodeMapping

      the composed mapping

      RangeError if inner maps a node to a node ID outside 0..indexCount-1

    • 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.

      Type Parameters

      Parameters

      • values: A

        the value of each node of the graph that this mapping maps to

      Returns A

      the renumbered values, of length IndexMapping.indexCount

      RangeError if a node maps to a node ID outside values

    • 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).

      Type Parameters

      • T

      Parameters

      • values: ArrayLike<T>

        the value of each node of the graph that this mapping maps to

      • newValues: T[]

        receives the renumbered values; length IndexMapping.indexCount, and not the same array as values

      Returns void

      Error if newValues.length !== indexCount, or both are the same array

      RangeError if a node maps to a node ID outside values

    • Returns the index that id maps to, or -1 if id is not mapped.

      In a partition, it is the group of id.

      Time: O(1).

      Parameters

      • id: number

        index in 0..indexCount-1

      Returns number

      index that id maps to, or -1

      RangeError if id is out of range

    • 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.

      Parameters

      • targetCount: number

        the node count of the graph that this mapping maps to

      Returns NodeMapping

      the inverse mapping, with an index count of targetCount

      Error if targetCount is not an integer, is negative or larger than 2^31 - 9, or two nodes map to the same node

      RangeError if a node maps to targetCount or more

    • Returns whether id is mapped. Equivalent to get(id) !== -1.

      Time: O(1).

      Parameters

      • id: number

        index in 0..indexCount-1

      Returns boolean

      true if id is mapped

      RangeError if id is out of range

    • Returns 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.

      Parameters

      • order: IntList

        the node IDs in their new order

      Returns NodeMapping

      the mapping from new to old node IDs

      RangeError if a node ID is not in 0..order.length-1

      Error if a node ID occurs more than once

    • Returns 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.

      Parameters

      • selected: BitSet

        the selected node IDs

      Returns NodeMapping

      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.

      Parameters

      • selected: IntList

        the selected node IDs

      Returns NodeMapping

      the mapping from new to old node IDs

      RangeError if a node ID is negative or not an integer

      Error if a node ID occurs more than once

      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.

      Parameters

      • ...selected: number[]

        the selected node IDs

      Returns NodeMapping

      the mapping from new to old node IDs

      RangeError if a node ID is negative or not an integer

      Error if a node ID occurs more than once

    • Returns 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.

      Parameters

      • mapping: ArrayLike<number>

        the node ID that each node maps to, or -1; any array of numbers

      Returns NodeMapping

      the mapping

      RangeError if a value is less than -1 or not an integer

    • Returns 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.

      Parameters

      • graph: Graph

        the graph whose nodes are numbered

      Returns NodeMapping

      the mapping from new to old node IDs

      Error if a depth-first path is longer than 2^30 - 5 nodes