Exemplo n.º 1
0
        public WaveletTreeNodeAsc(string text, NodeList leaves)
        {
            List<char> distinctCharList = text.Distinct<char>().ToList<char>();
              distinctCharList.Sort();
              string distinctChars = new string(distinctCharList.ToArray<char>());

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

              // Inner Node
              else {
            string charsGroup1 = distinctChars.Substring(0, distinctChars.Length / 2);
            string charsGroup2 = distinctChars.Substring(distinctChars.Length / 2);

            groupMembership = new Dictionary<char, bool>(charsGroup1.Length + charsGroup2.Length);
            foreach (char c in charsGroup1)
              groupMembership[c] = false;
            foreach (char c in charsGroup2)
              groupMembership[c] = true;

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

            left = new WaveletTreeNodeAsc(group1, leaves);
            right = new WaveletTreeNodeAsc(group2, leaves);
            left.parent = right.parent = this;
              }
        }
Exemplo n.º 2
0
        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;
              }
        }