/// <summary> /// Creates the suffix array in O(n) time from the given text. /// The last character in argument 'text' must be the unique $ char. see remarks.. /// </summary> /// <param name="text">The text.</param> /// <returns> /// $ happens to sort nicely in front of other normal chars.. so reversing the children collection when parsing the tree to build up the suffix array just works /// small change if you need to terminate your text with other unique char.. /// </returns> public static int[] Create(string text) { var suffixTree = SuffixTree.Create <SortedList>(text); if (suffixTree != null) { return(Create(suffixTree)); } else { return(null); } }
/// <summary> /// Computes the BurrowsWheelerTransform in O(n) time.. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public static string Build(string text) { if (string.IsNullOrEmpty(text)) { return(string.Empty); } var suffixTree = SuffixTree.Create <SortedList>(text); var suffixArray = SuffixArray.Create(suffixTree); var bwt = new StringBuilder(); for (int k = 0; k < suffixArray.Length; ++k) { bwt.Append(suffixArray[k] != 0 ? text[suffixArray[k] - 1] : text[text.Length - 1]); } return(bwt.ToString()); }
private static void CreateSuffixTree(string text) { Console.Write("."); Debug.WriteLine(""); Debug.WriteLine(""); Debug.WriteLine(""); Debug.WriteLine("================================================================================================= "); Debug.WriteLine(text); Debug.WriteLine(""); Debug.WriteLine("text length: {0}", text.Length); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var t = SuffixTree.Create <SortedList>(text); stopWatch.Stop(); Debug.WriteLine("total milliseconds: {0}", stopWatch.ElapsedMilliseconds); Diagnose(t); }
/// <summary> /// Creates a suffix tree for the given text. /// Make sure the last character in 'text' is unique; im using $.. /// </summary> /// <param name="text">The text.</param> /// <returns>if the argument 'text' is empty or null string, function returns null !!</returns> public static ISuffixTree Create(string text) { return(SuffixTree.Create <Dictionary>(text)); }