Esempio n. 1
0
        private static FindingAnyChildResult FindAnyChild(Node currentNode, byte character)
        {
            var comparisonsCount = 0;
              foreach (var currentCharacter in currentNode.Children.Keys)
              {
            comparisonsCount++;
            if (currentCharacter == character)
            {
              return new FindingAnyChildResult(true, comparisonsCount);
            }
              }

              return new FindingAnyChildResult(false, comparisonsCount);
        }
Esempio n. 2
0
 private int InsertSuffix(byte[] text, int from)
 {
     var currentComparisonsCount = 0;
       var currentNode = _root;
       for (var i = from; i < text.Length; ++i)
       {
     var character = text[i];
     var findingResult = FindAnyChild(currentNode, character);
     currentComparisonsCount += findingResult.ComparisonsCount;
     if (!findingResult.CharacterExists)
     {
       var n = new Node() { Index = from };
       currentNode.Children.Add(character, n);
     }
     currentNode = currentNode.Children[character];
       }
       currentNode.Children.Add(0, new Node());
       return currentComparisonsCount;
 }