From 3aff7aaa9de61a5f3430bd86960c4f9c4b958786 Mon Sep 17 00:00:00 2001 From: Pixel <> Date: Wed, 7 Mar 2001 00:41:50 +0000 Subject: Version finale pour les algos. --- lib/HTree.cc | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'lib/HTree.cc') 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 #include +#include +#include #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; -- cgit v1.2.3