Mercurial > dedupe
diff FastBitDecoder.cpp @ 57:c8111de2e0bb
Add functionality to decode directly from bitstring.
Use BitArrays getPaddedChar directly.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 13 Sep 2012 23:53:35 +0200 |
| parents | f8d0ea827db3 |
| children | 247adcbbaf8b |
line wrap: on
line diff
--- a/FastBitDecoder.cpp Thu Sep 13 23:49:18 2012 +0200 +++ b/FastBitDecoder.cpp Thu Sep 13 23:53:35 2012 +0200 @@ -2,8 +2,6 @@ #include "BitDecoder.hpp" -#include <QtCore/QDebug> - #include <cassert> unsigned char FastBitDecoder::getPaddedChar(const BitArray& bits, uint offset) @@ -29,6 +27,15 @@ } +FastBitDecoder::~FastBitDecoder() +{ + for (size_t i = 0; i < N; ++i) { + delete decoder[i]; + if (i == 0 || (data[i] != data[i - 1])) + delete data[i]; + } +} + void FastBitDecoder::fill() { for (size_t i = 0; i < N; ++i) { @@ -71,7 +78,7 @@ void FastBitDecoder::insert(const BitArray& key, const QString& value) { - unsigned char l = getPaddedChar(key); + unsigned char l = key.getPaddedChar(); if (key.size() <= 8) { data[l] = new QString(value); numBits[l] = key.size(); @@ -81,13 +88,15 @@ decoder[l] = new FastBitDecoder(); decoder[l]->insert(removeFirst(key), value); numBits[l] = 8; - } + } } -uint FastBitDecoder::decode(QString& resString, const BitArray& bits, uint offset) const +uint FastBitDecoder::decode(QString& resString, + const BitArray& bits, + uint offset) const { - unsigned char l = getPaddedChar(bits, offset); + unsigned char l = bits.getPaddedChar(offset); if (data[l]) { resString.append(*data[l]); return numBits[l];
