Skip to content

Main content

Prefix Trie Unique Completion Check

Bounded explicit prefix trie with root ID 0, unique sibling UTF-16 code-unit edges and terminal flags; resolve a completion only when exactly one terminal word exists; missing or tied evidence remains null.

Loading tool…

Description

Resolve a completion only when exactly one terminal word exists; missing or tied evidence remains null.

A trie stores literal words as root-to-node character paths, with terminal flags marking complete words. A terminal can also have children, and an existing prefix path need not be a stored word. This family uses one UTF-16 code unit per ordinary edge, so code-unit length differs from a displayed character or Unicode code-point count.

Resolve a completion only when exactly one terminal word exists; missing or tied evidence remains null.

When to use this tool

Use this tool to resolve a completion only when exactly one terminal word exists; missing or tied evidence remains null.

How to use the tool and how it works

  1. Enter nodesJson, prefix 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.unique, result.completion, result.count, using the stated boundary, ordering, sign and absence conventions.

Reconstruct terminal completions beginning with the literal prefix. Return their count, unique=count===1 and the single {id,word} completion only when unique; otherwise completion=null.1

Input fieldMeaning and unitsAccepted input
nodesJsonJSON array of {id,parent,character,terminal} nodes under the complete root-zero trie rules below.Text, at most 8,192 UTF-16 code units; narrower grammar/range rules also apply.
prefixLiteral prefix; an empty prefix refers to the whole stored word set.Text, at most 8,192 UTF-16 code units; narrower grammar/range rules also apply.

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

json
{
  "nodesJson": [
    {
      "id": 0,
      "parent": null,
      "character": "",
      "terminal": false
    },
    {
      "id": 1,
      "parent": 0,
      "character": "a",
      "terminal": true
    },
    {
      "id": 2,
      "parent": 1,
      "character": "b",
      "terminal": true
    },
    {
      "id": 3,
      "parent": 0,
      "character": "b",
      "terminal": true
    }
  ]
}
Output fieldInterpretation
resultObject containing the fields below.
result.uniqueWhether exactly one terminal completion matches the prefix.
result.completionThe sole {id,word} completion, or null when its count differs from one.
result.countNumber of terminal words beginning with the prefix.
json
{
  "input": {
    "nodesJson": "[{\"id\": 0, \"parent\": null, \"character\": \"\", \"terminal\": false}, {\"id\": 1, \"parent\": 0, \"character\": \"a\", \"terminal\": true}, {\"id\": 2, \"parent\": 1, \"character\": \"b\", \"terminal\": true}, {\"id\": 3, \"parent\": 0, \"character\": \"b\", \"terminal\": true}]",
    "prefix": "ab"
  },
  "output": {
    "result": {
      "unique": true,
      "completion": {
        "id": 2,
        "word": "ab"
      },
      "count": 1
    }
  }
}

Limitations and assumptions

  • A missing prefix gives zero completions, and duplicate input word occurrences are not represented as separate terminal nodes.
  • Ordinary node tables have at most 128 nodes with distinct IDs 0–127, one root ID 0 with empty character and null parent, unique parent/character edges, complete acyclic parent links and a boolean terminal flag. Every nonroot character is exactly one UTF-16 code unit.
  • 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

Choose word membership, prefix existence, completion or ranking according to the question. Normalize text separately if needed; these operations preserve exact code units and caller order.

References

  1. Tool behavior and example: Prefix Trie Unique Completion Check — tool.io

Similar or alternative tools

  • Prefix Trie Literal Prefix Completion Count

    Bounded explicit prefix trie with root ID 0, unique sibling UTF-16 code-unit edges and terminal flags; count distinct terminal completions, not duplicate original word observations or inferred dictionary frequencies.

  • Prefix Trie Literal Prefix Completion List

    Bounded explicit prefix trie with root ID 0, unique sibling UTF-16 code-unit edges and terminal flags; select terminal word completions in source-node order, including the prefix itself if terminal.