Example #1
0
        public Heap GetWordsHeap()
        {
            Heap heap = new Heap();

            if (IsEnd)
            {
                heap.Add(new HeapNode(ToWord(), SearchCount));
            }
            if (Children.Any())
            {
                for (int i = 0; i < Children.Count; i++)
                {
                    HeapTrieNode currentChild = Children.ElementAt(i);
                    if (currentChild != null)
                    {
                        var childHeap = currentChild.GetWordsHeap();
                        for (int j = 0; j < childHeap.Size; j++)
                        {
                            heap.Add(childHeap.Nodes.ElementAt(j));
                        }
                    }
                }
            }
            return(heap);
        }
        public Heap FindMatchesHeap(string prefix)
        {
            HeapTrieNode lastNode = root;

            for (int i = 0; i < prefix.Length; i++)
            {
                lastNode = lastNode.GetChild(prefix[i]);
                if (lastNode == null)
                {
                    return(new Heap());
                }
            }
            return(lastNode.GetWordsHeap());
        }