void encodeNode(HuffmanNode* node, obitstream& output) {
    if (node->isLeaf()) {
        output.writeBit(1);
        output.put(node->character);
    } else {
        output.writeBit(0);
        encodeNode(node->zero, output);
        encodeNode(node->one, output);
    }
}
Beispiel #2
0
void encodeData(istream& input, const Map<int, string>& encodingMap, obitstream& output) {
    rewindStream(input);
    char c;
    while ((c = input.get()) != -1) {
        string s = encodingMap.get(c);
        for (int i = 0; i < s.length(); i++)
            output.writeBit(s[i] - '0');
    }
}
Beispiel #3
0
void encodeData(istream& input, const map<int, string> &encodingMap, obitstream& output) {
    while(input){
        //Ta ut första byten
        int tempByte = input.get();
        string tempCode;
        //Hämta ut bitsekvensen som hör till bokstaven
        if(tempByte == -1){
            tempCode = encodingMap.at(PSEUDO_EOF);
        }else{
            tempCode = encodingMap.at(tempByte);
        }

        while(tempCode.size() > 0){
            //Ta ut första biten från sekvensen
            int tempBit = stringToInteger(string(1,tempCode.front()));
            //Skriv ut den till output
            output.writeBit(tempBit);
            //Ta bort den från sekvensen
            tempCode.erase(tempCode.begin());
        }
    }
}
void writeCode(string& code, obitstream& output) {
    for (size_t i = 0; i < code.size(); ++i) {
        (code[i] == '1') ? output.writeBit(1) : output.writeBit(0);
	}
}