Huffman to trash

git-svn-id: svn://db.shs.com.ru/pip@107 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-04-17 14:54:50 +00:00
parent 9ec0261d8c
commit 0043f215a0
2 changed files with 0 additions and 53 deletions

View File

@@ -106,39 +106,6 @@ const char PIByteArray::base64InvTable[256] = {
#pragma pack(pop) #pragma pack(pop)
int PIHuffman::nodeCompare(const void * f, const void * s) {
return (reinterpret_cast<node * >(const_cast<void * >(s))->freq -
reinterpret_cast<node * >(const_cast<void * >(f))->freq);
}
PIDeque<uchar> PIHuffman::compress(const PIDeque<uchar> & src) {
calcFrequencies(src);
return src;
}
void PIHuffman::calcFrequencies(const PIDeque<uchar> & src) {
nodes.resize(256);
for (int i = 0; i < 256; ++i) {
nodes[i].parent = nodes[i].right = nodes[i].left = 0;
nodes[i].freq = 0;
nodes[i].word.resize(1);
nodes[i].word[0] = static_cast<uchar>(i);
}
for (int i = 0; i < src.size_s(); ++i)
nodes[src[i]].freq++;
std::qsort(nodes.data(), 256, sizeof(node), nodeCompare);
for (int i = 255; i >= 0; --i)
if (nodes[i].freq > 0 && i < 255)
{nodes.remove(i + 1, 255 - i); break;}
for (int i = 0; i < nodes.size_s(); ++i)
std::cout << std::string((char*)nodes[i].word.data(), 1) << ": " << nodes[i].freq << std::endl;
}
PIHuffman PIByteArray::huffman;
PIByteArray & PIByteArray::convertToBase64() { PIByteArray & PIByteArray::convertToBase64() {
base64HelpStruct hs; base64HelpStruct hs;
PIByteArray t; PIByteArray t;

View File

@@ -33,23 +33,6 @@
class PIString; class PIString;
class PIByteArray; class PIByteArray;
class PIHuffman {
public:
PIDeque<uchar> compress(const PIDeque<uchar> & src);
private:
struct node {
int freq;
PIDeque<uchar> word;
PIBitArray path;
node * parent;
node * right;
node * left;
};
static int nodeCompare(const void * f, const void * s);
void calcFrequencies(const PIDeque<uchar> & src);
PIVector<node> nodes;
};
class PIP_EXPORT PIByteArray: public PIDeque<uchar> class PIP_EXPORT PIByteArray: public PIDeque<uchar>
{ {
@@ -100,8 +83,6 @@ public:
PIByteArray compressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.compressRLE(threshold); return ba;} PIByteArray compressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.compressRLE(threshold); return ba;}
PIByteArray decompressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.decompressRLE(threshold); return ba;} PIByteArray decompressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.decompressRLE(threshold); return ba;}
PIByteArray & compressHuffman() {*this = huffman.compress(*this); return *this;}
PIString toString(int base = 16) const; PIString toString(int base = 16) const;
//! Add to the end data "data" with size "size" //! Add to the end data "data" with size "size"
@@ -145,7 +126,6 @@ private:
static const char base64Table[64]; static const char base64Table[64];
static const char base64InvTable[256]; static const char base64InvTable[256];
static PIHuffman huffman;
}; };