comparison 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
comparison
equal deleted inserted replaced
26:c0ddc978475a 27:95a10553ff90
1 #include "BitDecoder.hpp"
2
3 BitDecoder::BitDecoder(BitDecoder* low_in, BitDecoder* high_in) : low(low_in), high(high_in)
4 {
5 }
6
7 BitDecoder::BitDecoder(const QString& d) : low(0), high(0), _data(d)
8 {
9 }
10
11 BitDecoder::~BitDecoder()
12 {
13 delete low;
14 delete high;
15 }
16
17 const QString& BitDecoder::data() const
18 {
19 return _data;
20 }
21
22 BitDecoder* BitDecoder::merge(BitDecoder* low, BitDecoder* high)
23 {
24 return new BitDecoder(low, high);
25 }
26
27 /*
28 QBitArray BitDecoder::unite(const QBitArray& first, const QBitArray& second)
29 {
30 QBitArray result(first.size() + second.size());
31 int n = first.size();
32 for (int i = 0; i < n; ++i) {
33 result[i] = first[i];
34 }
35 for (int i = 0; i < second.size(); ++i) {
36 result[n + i] = second[i];
37 }
38 return result;
39 }
40 */
41
42 QMap<QString, QBitArray> BitDecoder::createEncoder() const
43 {
44 QMap<QString, QBitArray> retVal;
45 if (!_data.isNull()) {
46 retVal.insert(_data, QBitArray());
47 }
48 if (low) {
49 QMap<QString, QBitArray> vals = low->createEncoder();
50 for(QMap<QString, QBitArray>::const_iterator it = vals.begin();
51 it != vals.end(); ++it) {
52 retVal.insert(it.key(), unite(QBitArray(1, false), it.value()));
53 }
54 }
55 if (high) {
56 QMap<QString, QBitArray> vals = high->createEncoder();
57 for(QMap<QString, QBitArray>::const_iterator it = vals.begin();
58 it != vals.end(); ++it) {
59 retVal.insert(it.key(), unite(QBitArray(1, true), it.value()));
60 }
61 }
62 return retVal;
63 }