/// <summary>
        /// This method performs the BurrowsWheelerTransform algorithm on the input SuffixArray.
        /// </summary>
        /// <returns></returns>
        public BurrowsWheelerTransformBin(SuffixArrayBin suffixArray)
        {
            textLength = suffixArray.InputText.Length;

              List<BitArray> bwtTemp =
            (suffixArray.Suffixes.Select(
              i => new { i, lenSuffix = i.Length }).Select(
            @t => @t.i.Append(suffixArray.InputText.Substring(0, textLength - @t.lenSuffix))
              )
            ).ToList();

              bwtTemp.Sort(
            (BitArray bA, BitArray bB) => {
              int order = 0;
              for (int i = 0; i < Math.Max(bA.Length, bB.Length); i++) {
            if (i >= bA.Length) {
              order = -1;
              break;
            }
            if (i >= bB.Length) {
              order = 1;
              break;
            }
            if (!bA[i] && bB[i]) {
              order = -1;
              break;
            }
            if (bA[i] && !bB[i]) {
              order = 1;
              break;
            }
              }
              return order;
            }
              );

              BitArray F = new BitArray(bwtTemp.Count);
              BitArray L = new BitArray(bwtTemp.Count);
              for (int i = 0; i < bwtTemp.Count; i++) {
            F[i] = bwtTemp[i][0];
            L[i] = bwtTemp[i][bwtTemp[i].Length - 1];
              }

              waveletTree = new WaveletTreeBin(L);

              WaveletTreeBin waveletTreeF = new WaveletTreeBin(F);
              C = new Dictionary<bool, int>(2);
              if (F.HasZeros())
            C[false] = waveletTreeF.Select(false, 1);
              else
            C[false] = -1;
              if (F.HasOnes())
            C[true] = waveletTreeF.Select(true, 1);
              else
            C[true] = -1;
        }
        public WaveletTreeNodeBin(BitArray text, NodeList leaves)
        {
            List<bool> distinctChars = new List<bool>();
              if (text.HasZeros())
            distinctChars.Add(false);
              if (text.HasOnes())
            distinctChars.Add(true);

              // Leaf Node
              if (distinctChars.Count == 1) {
            BitArray bitArray = new BitArray(text.Length);
            bitString = new BitString(bitArray);
            groupMembership = new Dictionary<bool, bool>();
            groupMembership[text[0]] = false;
            left = null;
            right = null;
            leaves.Add(text[0], this);
              }

              // Inner Node
              else {
            groupMembership = new Dictionary<bool, bool>(2);
            groupMembership[false] = false;
            groupMembership[true] = true;

            BitArray group1 = new BitArray(0);
            BitArray group2 = new BitArray(0);
            BitArray bitArray = new BitArray(text.Length);
            for (int i = 0; i < text.Length; i++) {
              if (text[i] == false) {
            group1 = group1.Append(false);
            bitArray[i] = false;
              }
              else {
            group2 = group2.Append(true);
            bitArray[i] = true;
              }
            }
            bitString = new BitString(bitArray);

            left = new WaveletTreeNodeBin(group1, leaves);
            right = new WaveletTreeNodeBin(group2, leaves);
            left.parent = right.parent = this;
              }
        }