Mercurial > dedupe
comparison FastBitDecoder.hpp @ 49:f8d0ea827db3
Use BitArray.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 10 Sep 2012 23:59:46 +0200 |
| parents | 877327e9061a |
| children | c8111de2e0bb |
comparison
equal
deleted
inserted
replaced
| 48:ef429402e03b | 49:f8d0ea827db3 |
|---|---|
| 1 #ifndef FASTBITDECODER_HPP | 1 #ifndef FASTBITDECODER_HPP |
| 2 #define FASTBITDECODER_HPP | 2 #define FASTBITDECODER_HPP |
| 3 | 3 |
| 4 #include "BitArray.hpp" | |
| 5 | |
| 4 #include <QtCore/QString> | 6 #include <QtCore/QString> |
| 5 #include <QtCore/QMap> | 7 #include <QtCore/QMap> |
| 6 #include <QtCore/QBitArray> | |
| 7 | 8 |
| 8 class FastBitDecoder { | 9 class FastBitDecoder { |
| 9 static const size_t N = 256; | 10 static const size_t N = 256; |
| 10 FastBitDecoder* decoder[N]; | 11 FastBitDecoder* decoder[N]; |
| 11 unsigned char numBits[N]; | 12 unsigned char numBits[N]; |
| 12 QString* data[N]; | 13 QString* data[N]; |
| 13 | 14 |
| 14 static unsigned char getPaddedChar(const QBitArray& bitArray, uint offset = 0); | 15 static unsigned char getPaddedChar(const BitArray& bitArray, uint offset = 0); |
| 15 static QBitArray removeFirst(const QBitArray& bits); | 16 static BitArray removeFirst(const BitArray& bits); |
| 16 | 17 |
| 17 void fill(); | 18 void fill(); |
| 18 void blank(); | 19 void blank(); |
| 19 FastBitDecoder(); | 20 FastBitDecoder(); |
| 20 void insert(const QBitArray& key, const QString& value); | 21 void insert(const BitArray& key, const QString& value); |
| 21 uint decode(QString& resString, const QBitArray& bits, uint offset) const; | 22 uint decode(QString& resString, const BitArray& bits, uint offset) const; |
| 22 | 23 |
| 23 public: | 24 public: |
| 24 FastBitDecoder(const QMap<QString, QBitArray>& encoder); | 25 FastBitDecoder(const QMap<QString, BitArray>& encoder); |
| 25 QString decode(const QBitArray& bits) const | 26 QString decode(const BitArray& bits) const |
| 26 { | 27 { |
| 27 QString combined; | 28 QString combined; |
| 28 uint n = bits.size(); | 29 uint n = bits.size(); |
| 29 //Just a qualified overestimate guess on what we will need. | 30 //Just a qualified overestimate guess on what we will need. |
| 30 combined.reserve(n/4); | 31 combined.reserve(n/4); |
