changeset 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 76846cb92b5c
children 7b7e84356b39
files FastBitDecoder.cpp FastBitDecoder.hpp
diffstat 2 files changed, 19 insertions(+), 7 deletions(-) [+]
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];
--- a/FastBitDecoder.hpp	Thu Sep 13 23:49:18 2012 +0200
+++ b/FastBitDecoder.hpp	Thu Sep 13 23:53:35 2012 +0200
@@ -23,6 +23,10 @@
 
 public:
   FastBitDecoder(const QMap<QString, BitArray>& encoder);
+  ~FastBitDecoder();
+
+  QString decode(const QString& bits) const;
+
   QString decode(const BitArray& bits) const
   {
     QString combined;
@@ -33,7 +37,6 @@
     combined.squeeze();
     return combined;
   }
-  QString decode(const QString& bits) const;
 
 
 };