summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/BinHeap.cc11
-rw-r--r--lib/HTree.cc24
-rw-r--r--lib/Huffman.cc5
3 files changed, 25 insertions, 15 deletions
diff --git a/lib/BinHeap.cc b/lib/BinHeap.cc
index 89dd0be..45f77e6 100644
--- a/lib/BinHeap.cc
+++ b/lib/BinHeap.cc
@@ -23,7 +23,7 @@ void BinHeap::PackUp(int i)
{
int l = LEFT(i), r = RIGHT(i), min;
binheap_t *binheap = (binheap_t *) Datas;
-
+
min = ((l <= Key) && (binheap[l - 1].Key < binheap[i - 1].Key)) ? l : i;
if ((r <= Key) && (binheap[r - 1].Key < binheap[min - 1].Key))
min = r;
@@ -51,10 +51,11 @@ PriorityList *BinHeap::Union(PriorityList * P)
bool BinHeap::Lower_Key(Cell x, Key_t NKey)
{
- int i = ((binheap_t *)x) - ((binheap_t*)Datas) + 1;
- binheap_t * binheap = (binheap_t*) Datas;
+ int i = ((binheap_t *) x) - ((binheap_t *) Datas) + 1;
+ binheap_t *binheap = (binheap_t *) Datas;
- if (((binheap_t*)x)->Key < NKey) return false;
+ if (((binheap_t *) x)->Key < NKey)
+ return false;
while ((i > 1) && (binheap[FATHER(i) - 1].Key > NKey)) {
SWAP(binheap[i - 1], binheap[FATHER(i) - 1]);
i = FATHER(i);
@@ -124,7 +125,7 @@ Cell BinHeap::Insert(Key_t IKey, Datas_t const &IDatas)
i = Key;
binheap = (binheap_t *) Datas;
-
+
while ((i > 1) && (binheap[FATHER(i) - 1].Key > IKey)) {
binheap[i - 1] = binheap[FATHER(i) - 1];
i = FATHER(i);
diff --git a/lib/HTree.cc b/lib/HTree.cc
index 682ac14..3910ce3 100644
--- a/lib/HTree.cc
+++ b/lib/HTree.cc
@@ -34,7 +34,8 @@ ostream & HTree::Trace(ostream & os, int d)
static int rsize;
static int dsize;
- if (!d) tsize = rsize = dsize = 0;
+ if (!d)
+ tsize = rsize = dsize = 0;
if (objet) {
cmpr[d] = '\0';
@@ -52,14 +53,21 @@ ostream & HTree::Trace(ostream & os, int d)
right->Trace(os, d + 1);
}
}
-
+
if (!d) {
- os << _("Bitstream length : ") << tsize << _(" bits (= ") << ((tsize >> 3) + (tsize & 7 ? 1 : 0)) << _(" bytes)\n");
- os << _("Real size input : ") << (rsize << 3) << _(" bits (= ") << rsize << _(" bytes)\n");
- os << _("Size squeezed by : ") << 100.0 - 100.0 * tsize / (rsize << 3) << _(" percents\n");
- os << _("Dictionnary size : ") << (dsize << 3) << _(" bits (= ") << dsize << _(" bytes)\n");
- os << _("Total bitstream length : ") << tsize + (dsize << 3) << _(" bits (= ") << ((tsize >> 3) + (tsize & 7 ? 1 : 0) + dsize) << _(" bytes)\n");
- os << _("Real gain (4 bytes header) : ") << 100.0 - 100.0 * ((tsize >> 3) + (tsize & 7 ? 1 : 0) + dsize + 4) / rsize << _(" percents\n");
+ os << _("Bitstream length : ") << tsize << _(" bits (= ") << ((tsize >> 3) +
+ (tsize & 7 ? 1 : 0)) <<
+ _(" bytes)\n");
+ os << _("Real size input : ") << (rsize << 3) << _(" bits (= ") << rsize << _(" bytes)\n");
+ os << _("Size squeezed by : ") << 100.0 - 100.0 * tsize / (rsize << 3) << _(" percents\n");
+ os << _("Dictionnary size : ") << (dsize << 3) << _(" bits (= ") << dsize << _(" bytes)\n");
+ os << _("Total bitstream length : ") << tsize + (dsize << 3) << _(" bits (= ") << ((tsize >> 3) +
+ (tsize & 7 ? 1 :
+ 0) +
+ dsize) <<
+ _(" bytes)\n");
+ os << _("Real gain (4 bytes header) : ") << 100.0 - 100.0 * ((tsize >> 3) + (tsize & 7 ? 1 : 0) +
+ dsize + 4) / rsize << _(" percents\n");
}
return os;
}
diff --git a/lib/Huffman.cc b/lib/Huffman.cc
index aadf927..4f68852 100644
--- a/lib/Huffman.cc
+++ b/lib/Huffman.cc
@@ -10,7 +10,7 @@ HTree *Coder(PriorityList * P)
Datas_t tx, ty;
x = y = z = NULL;
-
+
for (i = 0; i < n - 1; i++) {
f1 = P->Extract_Min(tx);
f2 = P->Extract_Min(ty);
@@ -26,6 +26,7 @@ HTree *Coder(PriorityList * P)
void HInsert(PriorityList * P, int freq, char *object)
{
- HTree * leaf = new HTree(freq, object);
+ HTree *leaf = new HTree(freq, object);
+
P->Insert(freq, (Datas_t) leaf);
}