/// <summary> /// Append another bit array to the end of this bit array. /// </summary> /// <param name="bitSet">The bit array to append.</param> public void Append(DAABitArray bitSet) { for (int ii = 0; ii < bitSet.NumBits; ii++) { m_bits.Add(bitSet.GetBitAsBool(ii)); } }
/// <summary> /// Append another bit array to the end of this bit array. /// Amended to return the array for simpler recursion. /// </summary> /// <param name="bitSet">The bit array to append.</param> /// <returns>Itself</returns> public DAABitArray Append(DAABitArray bitSet) { for (int ii = 0; ii < bitSet.NumBits; ii++) { m_bits.Add(bitSet.GetBitAsBool(ii)); } return(this); }
//Converts binary stream to uncompressed text. public string decompressStream(DAABitArray decompStream, List <HuffLeafNode> leafNodePtrs) { DAABitArray tempBitArray = new DAABitArray(); string decompString = ""; for (int i = 0; i < decompStream.NumBits; i++) //Iterate through each bit of bit stream. { tempBitArray.Append(decompStream.GetBitAsBool(i)); //Add one bit to temp bit stream. for (int j = 0; j < leafNodePtrs.Count; j++) //Compare temp bit stream to each leaf node of huffman tree. { if (bitArraysEqual(tempBitArray, leafNodePtrs[j].getHashCode()) == true) //If symbol found, add character to output string. { tempBitArray = new DAABitArray(); decompString = decompString + leafNodePtrs[j].getSymbol(); } } } return(decompString); }
/// Parses the Huffman tree to retrieve symbol values of the /// provided bitset. private String ParseTree(Node n, DAABitArray bitArray) { String finalString = ""; Node temp = n; while (bitArray.GetCount() > 0) { while (temp.IsBranch()) { if (bitArray.GetBitAsBool(0)) { temp = temp.GetRight(); bitArray.RemoveFirstBit(); } else { temp = temp.GetLeft(); bitArray.RemoveFirstBit(); } } finalString += temp.GetSymbol(); temp = n; } return finalString; }
/// When the message is encoded, a '1' is added to the bitset, /// followed by a series of '0's to buffer the bitset into sections /// of 6 bits each (% 6). This function removes this buffer to /// provide the original bitset. private DAABitArray RemoveBuffer(DAABitArray bitArray) { while (!bitArray.GetBitAsBool(bitArray.GetCount() -1)) { bitArray.RemoveLastBit(); /// Remove '0's } bitArray.RemoveLastBit(); /// Remove '1' return bitArray; }
/// <summary> /// Append another bit array to the end of this bit array. /// Amended to return the array for simpler recursion. /// </summary> /// <param name="bitSet">The bit array to append.</param> /// <returns>Itself</returns> public DAABitArray Append(DAABitArray bitSet) { for (int ii = 0; ii < bitSet.NumBits; ii++) { m_bits.Add(bitSet.GetBitAsBool(ii)); } return this; }