diff options
-rw-r--r-- | include/BHeap.h | 2 | ||||
-rw-r--r-- | include/BinHeap.h | 5 | ||||
-rw-r--r-- | include/CList.h | 2 | ||||
-rw-r--r-- | include/FHeap.h | 5 | ||||
-rw-r--r-- | include/HTree.h | 8 | ||||
-rw-r--r-- | include/Huffman.h | 6 | ||||
-rw-r--r-- | include/PCommon.h | 2 | ||||
-rw-r--r-- | include/PLList.h | 5 | ||||
-rw-r--r-- | lib/BinHeap.cc | 11 | ||||
-rw-r--r-- | lib/HTree.cc | 24 | ||||
-rw-r--r-- | lib/Huffman.cc | 5 | ||||
-rw-r--r-- | src/test.cc | 4 |
12 files changed, 45 insertions, 34 deletions
diff --git a/include/BHeap.h b/include/BHeap.h index 9c31467..b39804b 100644 --- a/include/BHeap.h +++ b/include/BHeap.h @@ -17,7 +17,7 @@ class BHeap:public PriorityList { public: BHeap(void); // Constructor - virtual ~BHeap(void); // Destructor + virtual ~ BHeap(void); // Destructor virtual int rn(void); virtual Key_t ReadKey(Cell C); virtual Datas_t ReadDatas(Cell C); diff --git a/include/BinHeap.h b/include/BinHeap.h index 41872f7..c67239c 100644 --- a/include/BinHeap.h +++ b/include/BinHeap.h @@ -10,11 +10,12 @@ struct binheap_t { }; #ifdef __cplusplus -typedef class BinHeap:public PriorityList { private: +typedef class BinHeap:public PriorityList { + private: void PackUp(int i); public: BinHeap(void); // Constructor - virtual ~BinHeap(void); // Destructor + virtual ~ BinHeap(void); // Destructor virtual int rn(void); diff --git a/include/CList.h b/include/CList.h index 1bc7fe2..71f2f37 100644 --- a/include/CList.h +++ b/include/CList.h @@ -18,7 +18,7 @@ class CList { public: CList(void); - virtual ~CList(void); + virtual ~ CList(void); virtual Datas_t ReadDatas(Cell C); virtual Key_t ReadKey(Cell C); diff --git a/include/FHeap.h b/include/FHeap.h index 6cbbeb6..292540c 100644 --- a/include/FHeap.h +++ b/include/FHeap.h @@ -4,8 +4,7 @@ #define DFMAX 128 #ifdef __cplusplus -typedef class FHeap:public PriorityList { - private: +typedef class FHeap:public PriorityList { private: FHeap * Father, *Child, *Left, *Right; int Degree; bool Mark; @@ -19,7 +18,7 @@ typedef class FHeap:public PriorityList { public: FHeap(void); // Constructor - virtual ~FHeap(void); // Destructor + virtual ~ FHeap(void); // Destructor virtual int rn(void); diff --git a/include/HTree.h b/include/HTree.h index c153415..d049bb1 100644 --- a/include/HTree.h +++ b/include/HTree.h @@ -11,14 +11,14 @@ class HTree { private: HTree * left, *right; int freq; - char * objet; + char *objet; public: - HTree(int n_freq, char * n_objet); + HTree(int n_freq, char *n_objet); HTree(HTree * n_left, HTree * n_right); ~HTree(); ostream & Trace(ostream & os, int d = 0); - int ReadFreq(void); - char * ReadObj(void); + int ReadFreq(void); + char *ReadObj(void); }; #else diff --git a/include/Huffman.h b/include/Huffman.h index aacbf79..4e6ea22 100644 --- a/include/Huffman.h +++ b/include/Huffman.h @@ -4,7 +4,7 @@ #include "PCommon.h" #include "HTree.h" -HTree * Coder(PriorityList * P); -void HInsert(PriorityList * P, int freq, char * object); +HTree *Coder(PriorityList * P); +void HInsert(PriorityList * P, int freq, char *object); -#endif
\ No newline at end of file +#endif diff --git a/include/PCommon.h b/include/PCommon.h index e1190fb..63d73fa 100644 --- a/include/PCommon.h +++ b/include/PCommon.h @@ -28,7 +28,7 @@ class PriorityList { public: PriorityList(void); - virtual ~PriorityList(void); + virtual ~ PriorityList(void); virtual Key_t ReadKey(Cell C); virtual Datas_t ReadDatas(Cell C); diff --git a/include/PLList.h b/include/PLList.h index c722900..f729ffe 100644 --- a/include/PLList.h +++ b/include/PLList.h @@ -5,12 +5,13 @@ #include <SList.h> #ifdef __cplusplus -class PLList:public PriorityList { private: +class PLList:public PriorityList { + private: SList Head; public: PLList(void); - virtual ~PLList(void); + virtual ~ PLList(void); virtual Key_t ReadKey(Cell C); virtual Datas_t ReadDatas(Cell C); 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); } diff --git a/src/test.cc b/src/test.cc index bc53810..e9a15c1 100644 --- a/src/test.cc +++ b/src/test.cc @@ -75,8 +75,8 @@ void FullTest(void) DoCombTest(0); DoCombTest(10); DoCombTest(70); - DoCombTest(1000); - DoCombTest(10000); + DoCombTest(1000); + DoCombTest(10000); #ifdef BT DoCombTest(100000); #ifdef VBT |