Mercurial > dedupe
view FastBitDecoder.hpp @ 46:877327e9061a
N-Tree for decoding.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 10 Sep 2012 21:31:10 +0200 |
| parents | |
| children | f8d0ea827db3 |
line wrap: on
line source
#ifndef FASTBITDECODER_HPP #define FASTBITDECODER_HPP #include <QtCore/QString> #include <QtCore/QMap> #include <QtCore/QBitArray> class FastBitDecoder { static const size_t N = 256; FastBitDecoder* decoder[N]; unsigned char numBits[N]; QString* data[N]; static unsigned char getPaddedChar(const QBitArray& bitArray, uint offset = 0); static QBitArray removeFirst(const QBitArray& bits); void fill(); void blank(); FastBitDecoder(); void insert(const QBitArray& key, const QString& value); uint decode(QString& resString, const QBitArray& bits, uint offset) const; public: FastBitDecoder(const QMap<QString, QBitArray>& encoder); QString decode(const QBitArray& 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; } QString decode(const QString& bits) const; }; #endif //BITDECODER_HPP
