public bool MoveDown(bool toFirstChild) { CursorPathComponent currentLocation = path.Peek(); if (currentLocation.ChildIndex >= 0) { TrieNode currentChild = currentLocation.Children[currentLocation.ChildIndex]; if (currentChild.Children != null) { CursorPathComponent newLocation = new CursorPathComponent(); newLocation.Children = currentChild.Children; if (toFirstChild) { newLocation.ChildIndex = -1; path.Push(newLocation); MoveRight(); } else { newLocation.ChildIndex = currentChild.Children.Length; path.Push(newLocation); MoveLeft(); } return(true); } } return(false); }
public TrieNodeCursor(ITrieDomain <TAtom> domain, TrieNode[] currentChildren, int childIndex) { this.domain = domain; CursorPathComponent currentPath = new CursorPathComponent(); currentPath.Children = currentChildren; currentPath.ChildIndex = childIndex; path.Push(currentPath); }
public bool MoveRight() { CursorPathComponent currentLocation = path.Peek(); int newIndex = currentLocation.ChildIndex; TrieNode[] children = currentLocation.Children; if (children != null) { while (++newIndex < children.Length) { if (children[newIndex] != null) { currentLocation.ChildIndex = newIndex; return(true); } } currentLocation.ChildIndex = newIndex; } return(false); }