Mercurial > dedupe
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 45:41cc0d8ac77f | 46:877327e9061a |
|---|---|
| 1 #ifndef FASTBITDECODER_HPP | |
| 2 #define FASTBITDECODER_HPP | |
| 3 | |
| 4 #include <QtCore/QString> | |
| 5 #include <QtCore/QMap> | |
| 6 #include <QtCore/QBitArray> | |
| 7 | |
| 8 class FastBitDecoder { | |
| 9 static const size_t N = 256; | |
| 10 FastBitDecoder* decoder[N]; | |
| 11 unsigned char numBits[N]; | |
| 12 QString* data[N]; | |
| 13 | |
| 14 static unsigned char getPaddedChar(const QBitArray& bitArray, uint offset = 0); | |
| 15 static QBitArray removeFirst(const QBitArray& bits); | |
| 16 | |
| 17 void fill(); | |
| 18 void blank(); | |
| 19 FastBitDecoder(); | |
| 20 void insert(const QBitArray& key, const QString& value); | |
| 21 uint decode(QString& resString, const QBitArray& bits, uint offset) const; | |
| 22 | |
| 23 public: | |
| 24 FastBitDecoder(const QMap<QString, QBitArray>& encoder); | |
| 25 QString decode(const QBitArray& bits) const | |
| 26 { | |
| 27 QString combined; | |
| 28 uint n = bits.size(); | |
| 29 //Just a qualified overestimate guess on what we will need. | |
| 30 combined.reserve(n/4); | |
| 31 for (uint decodedBits = 0; decodedBits < n; decodedBits += decode(combined, bits, decodedBits)); | |
| 32 combined.squeeze(); | |
| 33 return combined; | |
| 34 } | |
| 35 QString decode(const QString& bits) const; | |
| 36 | |
| 37 | |
| 38 }; | |
| 39 | |
| 40 #endif //BITDECODER_HPP |
