diff options
author | Pixel <> | 2001-03-07 00:41:50 +0000 |
---|---|---|
committer | Pixel <> | 2001-03-07 00:41:50 +0000 |
commit | 3aff7aaa9de61a5f3430bd86960c4f9c4b958786 (patch) | |
tree | e4f83c05031ccd816a2e8e8b3bf8d9a857484fbd /lib/HTree.cc | |
parent | cd61178eb1d3b9182f4fcb64cc8eee61971405a8 (diff) |
Version finale pour les algos.
Diffstat (limited to 'lib/HTree.cc')
-rw-r--r-- | lib/HTree.cc | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/HTree.cc b/lib/HTree.cc index 3910ce3..985d687 100644 --- a/lib/HTree.cc +++ b/lib/HTree.cc @@ -1,12 +1,32 @@ #include <stdio.h> #include <iostream.h> +#include <stdlib.h> +#include <string.h> #include "config.h" #include "HTree.h" +ostream & PrintString(ostream & os, char *str) +{ + char t[2]; + + t[1] = '\0'; + while (*str) { + if (*str >= 33) { + t[0] = *str; + os << t; + } else { + os << "\\" << ((unsigned int) (((unsigned char) *str))); + } + str++; + } + + return os; +} + HTree::HTree(int n_freq, char *n_objet) { freq = n_freq; - objet = n_objet; + objet = strdup(n_objet); left = right = NULL; } @@ -25,6 +45,9 @@ HTree::~HTree() if (right) delete right; + + if (objet) + free(objet); } ostream & HTree::Trace(ostream & os, int d) @@ -39,7 +62,8 @@ ostream & HTree::Trace(ostream & os, int d) if (objet) { cmpr[d] = '\0'; - os << objet << " (" << freq << ") = " << cmpr << endl; + PrintString(os, objet); + os << " (" << freq << ") = " << cmpr << endl; tsize += freq * strlen(cmpr); rsize += freq * strlen(objet); dsize += ((strlen(cmpr) >> 3) + (strlen(cmpr) & 7 ? 1 : 0)) + strlen(objet) + 2; |