Mercurial > dedupe
diff 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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastBitDecoder.hpp Mon Sep 10 21:31:10 2012 +0200 @@ -0,0 +1,40 @@ +#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
