Mercurial > dedupe
comparison BitDecoder.hpp @ 45:41cc0d8ac77f
Decode directly from bitString.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 10 Sep 2012 21:29:43 +0200 |
| parents | f711ddb56ae7 |
| children | f8d0ea827db3 |
comparison
equal
deleted
inserted
replaced
| 44:7348d4efa4f6 | 45:41cc0d8ac77f |
|---|---|
| 11 QString _data; | 11 QString _data; |
| 12 | 12 |
| 13 private: | 13 private: |
| 14 BitDecoder(BitDecoder* low_in, BitDecoder* high_in); | 14 BitDecoder(BitDecoder* low_in, BitDecoder* high_in); |
| 15 | 15 |
| 16 uint decode(QString& resString, const QBitArray& bits, uint offset) | 16 uint decode(QString& resString, const QBitArray& bits, uint offset) const |
| 17 { | 17 { |
| 18 //Data is always stored in a leaf node. | 18 //Data is always stored in a leaf node. |
| 19 if (high) { | 19 if (high) { |
| 20 return (bits.testBit(offset) ? high : low)->decode(resString, bits, offset + 1) + 1; | 20 return (bits.testBit(offset) ? high : low)->decode(resString, bits, offset + 1) + 1; |
| 21 } | 21 } |
| 28 public: | 28 public: |
| 29 BitDecoder(const QString& d); | 29 BitDecoder(const QString& d); |
| 30 ~BitDecoder(); | 30 ~BitDecoder(); |
| 31 const QString& data() const; | 31 const QString& data() const; |
| 32 | 32 |
| 33 QString decode(const QBitArray& bits) | 33 QString decode(const QBitArray& bits) const |
| 34 { | 34 { |
| 35 QString combined; | 35 QString combined; |
| 36 uint n = bits.size(); | 36 uint n = bits.size(); |
| 37 //Just a qualified overestimate guess on what we will need. | 37 //Just a qualified overestimate guess on what we will need. |
| 38 combined.reserve(n/4); | 38 combined.reserve(n/4); |
| 39 for (uint decodedBits = 0; decodedBits < n; decodedBits += decode(combined, bits, decodedBits) - 1); | 39 for (uint decodedBits = 0; decodedBits < n; decodedBits += decode(combined, bits, decodedBits) - 1); |
| 40 combined.squeeze(); | 40 combined.squeeze(); |
| 41 return combined; | 41 return combined; |
| 42 } | 42 } |
| 43 QString decode(const QString& bits) const; | |
| 43 | 44 |
| 44 static BitDecoder* merge(BitDecoder* low, BitDecoder* high); | 45 static BitDecoder* merge(BitDecoder* low, BitDecoder* high); |
| 46 static QBitArray bitsFromString(const QString& str); | |
| 47 | |
| 45 static QBitArray unite(const QBitArray& first, const QBitArray& second) | 48 static QBitArray unite(const QBitArray& first, const QBitArray& second) |
| 46 { | 49 { |
| 47 int n = first.size(); | 50 int n = first.size(); |
| 48 int n2 = second.size(); | 51 int n2 = second.size(); |
| 49 QBitArray result(n + n2); | 52 QBitArray result(n + n2); |
