All files / src/core Node.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 0/0
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                          727x                         727x    
/**
 * Node — building block for the fixed-depth prefix tree.
 *
 * Maps 1:1 to Python `Node` class (drain.py L28-L35).
 *
 * Python `__slots__` equivalent: keyToChildNode, clusterIds
 *
 * Each Node in the parse tree represents a position within the token sequence.
 * Nodes at the maximum depth (maxNodeDepth) hold cluster_ids — references
 * to clusters that share the same token prefix path.
 */
 
export class Node {
  /**
   * Child nodes keyed by token value.
   * Uses Map for O(1) lookup — mirrors Python dict (MutableMapping[str, Node]).
   * The special key `paramStr` (e.g. "<*>") is used as a wildcard for
   * parameterized tokens.
   *
   * Python: self.key_to_child_node: MutableMapping[str, Node] = {}
   */
  readonly keyToChildNode: Map<string, Node> = new Map();
 
  /**
   * IDs of clusters rooted at this node (leaf nodes only).
   * For non-leaf nodes, this is empty.
   *
   * This is a mutable array for performance — cluster IDs are frequently
   * pushed during `addSeqToPrefixTree`. The array is replaced (not mutated
   * in place) when filtering evicted IDs. Python Drain3 uses the same
   * mutable list design.
   *
   * Python: self.cluster_ids: Sequence[int] = []
   */
  clusterIds: number[] = [];
}