diff BitDecoder.cpp @ 27:95a10553ff90

Optimize BitDecoder, and refactor functions that are not timecritical out of header.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Thu, 06 Sep 2012 18:20:11 +0200
parents
children 41cc0d8ac77f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BitDecoder.cpp	Thu Sep 06 18:20:11 2012 +0200
@@ -0,0 +1,63 @@
+#include "BitDecoder.hpp"
+
+BitDecoder::BitDecoder(BitDecoder* low_in, BitDecoder* high_in) : low(low_in), high(high_in)
+{
+}
+
+BitDecoder::BitDecoder(const QString& d) : low(0), high(0), _data(d)
+{
+}
+
+BitDecoder::~BitDecoder()
+{
+  delete low;
+  delete high;
+}
+
+const QString& BitDecoder::data() const
+{
+  return _data;
+}
+
+BitDecoder* BitDecoder::merge(BitDecoder* low, BitDecoder* high)
+{
+  return new BitDecoder(low, high);
+}
+
+/*
+QBitArray BitDecoder::unite(const QBitArray& first, const QBitArray& second)
+{
+  QBitArray result(first.size() + second.size());
+  int n = first.size();
+  for (int i = 0; i < n; ++i) {
+    result[i] = first[i];
+  }
+  for (int i = 0; i < second.size(); ++i) {
+    result[n + i] = second[i];
+  }
+  return result;
+}
+*/
+
+QMap<QString, QBitArray> BitDecoder::createEncoder() const
+{
+  QMap<QString, QBitArray> retVal;
+  if (!_data.isNull()) {
+    retVal.insert(_data, QBitArray());
+  }
+  if (low) {
+    QMap<QString, QBitArray> vals = low->createEncoder();
+    for(QMap<QString, QBitArray>::const_iterator it = vals.begin();
+	it != vals.end(); ++it) {
+      retVal.insert(it.key(), unite(QBitArray(1, false), it.value()));
+    }
+  }
+  if (high) {
+    QMap<QString, QBitArray> vals = high->createEncoder();
+    for(QMap<QString, QBitArray>::const_iterator it = vals.begin();
+	it != vals.end(); ++it) {
+      retVal.insert(it.key(), unite(QBitArray(1, true), it.value()));
+    }
+  }
+  return retVal;
+}