Example #1
0
            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);
            }
Example #2
0
            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);
            }
Example #3
0
            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);
            }