Graphity for TypeScript 3.0.0
    Preparing search index...

    An Ancestry that also holds the preorder of its forest, for an ancestor test in O(1) and the nodes of every subtree.

    PreorderAncestry.of builds it from an index and shares the arrays of that index. In preorder, every subtree is a contiguous range: the subtree of node takes the positions preorderIndexOf(node)..preorderIndexOf(node) + subtreeSizeOf(node) - 1 of PreorderAncestry.preorder. So PreorderAncestry.isAncestorOf is a range test, and PreorderAncestry.subtreeOf returns a view of that range. Here, the basic blocks of the method load that body dominates, from the dominators of load:

    const dominance = PreorderAncestry.of(Ancestry.of(dominators));
    // [2, 3, 4] - body, then and next
    const dominatedByBody = dominance.subtreeOf(body);

    The preorder visits the roots in ascending order, and the children of each node in ascending order. If the node IDs were assigned in this order, as is usual for a syntax tree numbered in source order, the preorder is 0..nodeCount-1, and the subtree of node is node..node + subtreeSizeOf(node) - 1.

    Instances are immutable.

    Memory: 12 x nodeCount bytes on top of the Ancestry it extends.

    Hierarchy (View Summary)

    Index
    • get preorder(): Int32Array

      All nodes in preorder: the roots in ascending order, and the children of each node in ascending order; each node once (Java: preorder()).

      It is this index's own array, not a copy, and must not be modified (Java: an unmodifiable view).

      Time: O(1).

      Returns Int32Array

    • Returns the depth of node: the number of edges from the root of its tree to it. A root has depth 0.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      depth

      RangeError if node is out of range

    • Returns whether node is an ancestor of descendant: whether it lies on the path from the root of its tree to descendant. A node is its own ancestor.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      • descendant: number

        node ID in 0..nodeCount-1

      Returns boolean

      true if node is an ancestor of descendant

      RangeError if node or descendant is out of range

    • Returns the lowest common ancestor of a and b, or -1 if they are in different trees.

      The lowest common ancestor is the deepest node that is an ancestor of both. As a node is its own ancestor, the result is a if a is an ancestor of b.

      Time: O(log nodeCount).

      Parameters

      • a: number

        node ID in 0..nodeCount-1

      • b: number

        node ID in 0..nodeCount-1

      Returns number

      lowest common ancestor, or -1

      RangeError if a or b is out of range

    • Returns the parent of node, or -1 if it is the root of its tree.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      parent, or -1

      RangeError if node is out of range

    • Returns the position of node in PreorderAncestry.preorder.

      Data in an array indexed by preorder position has every subtree in a contiguous range. Prefix sums over such an array, for example, give the sum over any subtree in O(1).

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      position in 0..nodeCount-1

      RangeError if node is out of range

    • Returns the nodes of the subtree of node, in preorder, starting with node.

      The result is a view of this index's own array, not a copy, and must not be modified (Java: an unmodifiable view).

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns Int32Array

      nodes of the subtree

      RangeError if node is out of range

    • Returns the number of nodes in the subtree of node, node included.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      subtree size, at least 1

      RangeError if node is out of range

    • Returns a PreorderAncestry for the forest of ancestry.

      The result shares the arrays of ancestry instead of copying them. The preorder is computed anew on every call, not cached: keep the result to use it more than once. If ancestry already is a PreorderAncestry, returns it.

      Time: O(nodeCount), or O(1) if already a PreorderAncestry. Memory: +12 x nodeCount bytes for the result; while it runs, 8 x nodeCount bytes more; none if already a PreorderAncestry.

      Parameters

      • ancestry: Ancestry

        the index to add the preorder to

      Returns PreorderAncestry

      the index with the preorder

    • Returns the plain index of a forest or of a dominator tree, without the preorder. This is Ancestry.of, inherited as Java's static methods are.

      Parameters

      Returns Ancestry