visit method Null safety

  1. @optionalTypeArgs
void visit(
  1. RadixTreeNode<T> node,
  2. String prefixAllowed,
  3. String prefix,
  4. RadixTreeKVVisitor<T?> visitor
)

Visits the given node of this tree with the given prefix and visitor. Also, recursively visits the left/right subtrees of this node.

Implementation

@optionalTypeArgs
void visit(RadixTreeNode<T> node, String prefixAllowed, String prefix,
    RadixTreeKVVisitor<T?> visitor) {
  if (node.hasValue && prefix.startsWith(prefixAllowed)) {
    visitor(prefix, node.value);
  }

  for (final child in node) {
    final prefixLength = prefix.length;
    final newPrefix = prefix + child.prefix;

    if (prefixAllowed.length <= prefixLength ||
        newPrefix.length <= prefixLength ||
        newPrefix[prefixLength] == prefixAllowed[prefixLength]) {
      visit(child, prefixAllowed, newPrefix, visitor);
    }
  }
}