Exemple #1
0
 public SuffixTreeNode(string element, SuffixTreeNode parent)
 {
     this.element  = element;
     children      = new Hashtable();
     this.parent   = parent;
     stringsShared = new HashSet <int>();
 }
Exemple #2
0
        public void LocatePrefixNode()
        {
            Queue <SuffixTreeNode> toVisit = new Queue <SuffixTreeNode>();
            Stack <SuffixTreeNode> visited = new Stack <SuffixTreeNode>();
            string result = "";

            toVisit.Enqueue(this.root);
            SuffixTreeNode currentNode = null;

            while (toVisit.Count > 0)
            {
                currentNode = toVisit.Dequeue();
                foreach (SuffixTreeNode node in currentNode.children.Values)
                {
                    toVisit.Enqueue(node);
                }
                visited.Push(currentNode);
            }

            while (visited.Count > 0)
            {
                currentNode = visited.Pop();
                if (currentNode.stringsShared.Count == sequences.Count)
                {
                    break;
                }
            }

            while (currentNode.parent != null)
            {
                result     += currentNode.element;
                currentNode = currentNode.parent;
            }

            char[] answer = result.ToCharArray();
            Array.Reverse(answer);
            Console.WriteLine(new string(answer));
        }
Exemple #3
0
        public void BuildSuffixTree()
        {
            this.root = new SuffixTreeNode("$", null);
            SuffixTreeNode currentNode;

            foreach (string seq in subsequences)
            {
                currentNode = this.root;
                int stringNumber = 99999;
                for (int i = 0; i < seq.Length; i++)
                {
                    string letter = seq[i].ToString();
                    if (int.TryParse(letter, out stringNumber))
                    {
                        stringNumber = int.Parse(seq.Substring(i, seq.Length - i));
                        break;
                    }

                    if (currentNode.HasChild(letter))
                    {
                        currentNode = (SuffixTreeNode)currentNode.children[letter];
                    }
                    else
                    {
                        SuffixTreeNode insert = new SuffixTreeNode(letter, currentNode);
                        currentNode.PutChild(letter, insert);
                        currentNode = insert;
                    }
                }

                while (currentNode.parent != null)
                {
                    currentNode.stringsShared.Add(stringNumber);
                    currentNode = currentNode.parent;
                }
            }
        }
Exemple #4
0
 public void PutChild(string element, SuffixTreeNode node)
 {
     this.children[element] = node;
 }