Skip to content

Main content

Parent Forest Common Ancestor Chain

Explicit complete acyclic parent forests with exact unique string node IDs and null roots; intersect inclusive ancestor chains for an explicit node set in nearest-first order from its first node; empty query has empty common evidence.

Loading tool…

Description

Intersect inclusive ancestor chains for an explicit node set in nearest-first order from its first node; empty query has empty common evidence.

A parent-record forest represents each node by an exact string ID and a parent ID or null for a root. Depth counts edges toward a root; subtree height counts edges toward the deepest descendant. Node order, identity, cycles and missing references are separate properties that must be checked before structural transformations.

Intersect inclusive ancestor chains for an explicit node set in nearest-first order from its first node; empty query has empty common evidence.

When to use this tool

Use this tool to intersect inclusive ancestor chains for an explicit node set in nearest-first order from its first node; empty query has empty common evidence.

How to use the tool and how it works

  1. Enter parentsJson, ids using the definitions below. Serialize JSON text fields in the decoded shape shown below.
  2. Run the operation. Resolve input-format errors before interpreting an output.
  3. Read result.ancestors, using the stated boundary, ordering, sign and absence conventions.

Require every selected ID to exist. Build self-first ancestor chains and keep members of the first chain occurring in every chain; an empty selection returns [].1

Input fieldMeaning and unitsAccepted input
parentsJsonJSON array of {id,parent} records. id is an exact string; parent is another exact ID or null for a root.Text, at most 8,192 UTF-16 code units; narrower grammar/range rules also apply.
idsExisting node IDs whose common ancestor chains are compared.Dense list of at most 128 literal strings, each at most 8,192 UTF-16 units.

These decoded structures show the examples inside JSON text fields. Supply their serialized JSON strings as input.

json
{
  "parentsJson": [
    {
      "id": "a",
      "parent": null
    },
    {
      "id": "b",
      "parent": "a"
    },
    {
      "id": "c",
      "parent": "a"
    },
    {
      "id": "d",
      "parent": "b"
    }
  ]
}
Output fieldInterpretation
resultObject containing the fields below.
result.ancestorsCommon or proper ancestor IDs in the nearest-first convention stated above.
json
{
  "input": {
    "parentsJson": "[{\"id\": \"a\", \"parent\": null}, {\"id\": \"b\", \"parent\": \"a\"}, {\"id\": \"c\", \"parent\": \"a\"}, {\"id\": \"d\", \"parent\": \"b\"}]",
    "ids": [
      "b",
      "d"
    ]
  },
  "output": {
    "result": {
      "ancestors": [
        "b",
        "a"
      ]
    }
  }
}

Limitations and assumptions

  • Ordering is nearest-to-first-selected then rootward. Nodes in separate components have no common chain.
  • Structural operations require distinct node IDs, existing non-null parent IDs and no parent cycles; audit tools explicitly state when they accept incomplete structure. Multiple roots are allowed. Matching is exact and case-sensitive.
  • Every declared outer field is required and unknown outer fields are rejected. Strings and JSON text have size limits, lists are bounded to 128 entries, and JSON nesting/node counts are bounded. Tighter operation-specific bounds stated above take precedence.
  • Ordinary numeric outputs must be finite and within safe-integer magnitude. Exact large lengths/counts use decimal strings. Original record indexes and code-unit positions are zero-based; span ends are exclusive unless stated otherwise.

Alternative or Complementary methods

Use identity and cycle audits to inspect incomplete records, then structural operations on complete forests. Preserve sibling order explicitly when exchanging traversal results with another tree format.

References

  1. Tool behavior and example: Parent Forest Common Ancestor Chain — tool.io

Similar or alternative tools

  • Parent Forest Ancestor Chain

    Explicit complete acyclic parent forests with exact unique string node IDs and null roots; return strict ancestors nearest-first, excluding the query node; unknown IDs reject.

  • Parent Forest Lowest Common Ancestor

    Explicit complete acyclic parent forests with exact unique string node IDs and null roots; find the lowest common ancestor including self; different components return null, not a fabricated shared root.