An edge is a labeled connection from one node to another. In a trie, each outgoing edge carries a character label and points to the node reached by that character. section 5.2.1
A trie node exposes edges through operations that preserve their meaning:
- EdgeLabels lists the labels on outgoing edges. section 5.2.1
- FollowEdge returns the node reached by a label; TryFollowEdge avoids failure when the edge is absent. section 5.2.1
- HasEdge tests existence, while AddNewNode and TryAddNewNode create or reuse an outgoing edge. section 5.2.1
Listing 5.2 A trie node
sealed class Node
{
private readonly Dictionary<char, Node> edges = [];
public bool IsEnd { get; set; }
public IEnumerable<char> EdgeLabels => edges.Keys;
public Node FollowEdge(char c) => edges [c]; #1
public Node? TryFollowEdge(char c) => #2
HasEdge(c) ? FollowEdge(c) : null;
public bool HasEdge(char c) => edges.ContainsKey(c);
public Node AddNewNode(char c) => edges [c] = new();
public Node TryAddNewNode(char c) =>
HasEdge(c) ? FollowEdge(c) : AddNewNode(c);
}
A compact C# trie-node implementation represents labeled edges with Dictionary<char, Node> while hiding that storage behind node operations. section 5.2.1

















