Mercurial > dedupe
view FastBitDecoder.hpp @ 57:c8111de2e0bb
Add functionality to decode directly from bitstring.
Use BitArrays getPaddedChar directly.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 13 Sep 2012 23:53:35 +0200 |
| parents | f8d0ea827db3 |
| children | b9515dc35fe4 |
line wrap: on
line source
#ifndef FASTBITDECODER_HPP #define FASTBITDECODER_HPP #include "BitArray.hpp" #include <QtCore/QString> #include <QtCore/QMap> class FastBitDecoder { static const size_t N = 256; FastBitDecoder* decoder[N]; unsigned char numBits[N]; QString* data[N]; static unsigned char getPaddedChar(const BitArray& bitArray, uint offset = 0); static BitArray removeFirst(const BitArray& bits); void fill(); void blank(); FastBitDecoder(); void insert(const BitArray& key, const QString& value); uint decode(QString& resString, const BitArray& bits, uint offset) const; public: FastBitDecoder(const QMap<QString, BitArray>& encoder); ~FastBitDecoder(); QString decode(const QString& bits) const; QString decode(const BitArray& bits) const { QString combined; uint n = bits.size(); //Just a qualified overestimate guess on what we will need. combined.reserve(n/4); for (uint decodedBits = 0; decodedBits < n; decodedBits += decode(combined, bits, decodedBits)); combined.squeeze(); return combined; } }; #endif //BITDECODER_HPP
