From ec68b01357f608f7800da530fc14f41d32cb2b45 Mon Sep 17 00:00:00 2001 From: Pixel <> Date: Mon, 5 Mar 2001 14:24:03 +0000 Subject: Plein de modifs --- include/Makefile.am | 2 +- include/numbers.h | 12 ++++ lib/BHeap.cc | 3 +- lib/Makefile.am | 8 +-- po/POTFILES.in | 1 + po/PriorityLists.pot | 124 +++++++++++++++++++++++++++++++++++++---- po/cat-id-tbl.c | 61 ++++++++++++++------ po/de.po | 88 +++++++++++++++++++++++++---- po/fr.po | 88 +++++++++++++++++++++++++---- src/Makefile.am | 2 +- src/main.cc | 154 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/test.cc | 21 ++++--- 12 files changed, 489 insertions(+), 75 deletions(-) create mode 100644 include/numbers.h diff --git a/include/Makefile.am b/include/Makefile.am index eeda5cf..99bae25 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -include_HEADERS = PCommon.h PLList.h FHeap.h BHeap.h BinHeap.h CList.h SList.h PTypes.h Huffman.h +include_HEADERS = PCommon.h PLList.h FHeap.h BHeap.h BinHeap.h CList.h SList.h PTypes.h Huffman.h numbers.h diff --git a/include/numbers.h b/include/numbers.h new file mode 100644 index 0000000..6eba30d --- /dev/null +++ b/include/numbers.h @@ -0,0 +1,12 @@ +#ifndef __NUMBERS_H__ +#define __NUMBERS_H__ + +#ifdef __cplusplus +extern "C" { +#endif +int char_to_number(char * st, int * valid); +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/BHeap.cc b/lib/BHeap.cc index ef4bd04..89d6f0f 100644 --- a/lib/BHeap.cc +++ b/lib/BHeap.cc @@ -312,7 +312,8 @@ Key_t BHeap::Extract_Min(Datas_t & Datas) /* - * Implémentation directe de l'algorithme UNION-TAS-BINOMIAUX(T1, T2) avec T1 = this. + * Implémentation de l'algorithme UNION-TAS-BINOMIAUX(T1, T2) avec T1 = this. + * Il y a quelques changements par rapport a l'algorithme du cormen (voir rapport) */ PriorityList *BHeap::Union(PriorityList * P) diff --git a/lib/Makefile.am b/lib/Makefile.am index 10ae1fd..c195459 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -3,10 +3,10 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ AM_CFLAGS = -O3 -Wall -Wstrict-prototypes $(CFLAGS) AM_CXXFLAGS = -O3 -Wall -Wstrict-prototypes $(CXXFLAGS) INCLUDES = -I. -I.. -I$(includedir) -I../include -lib_LTLIBRARIES = libPriorityLists.la +lib_LTLIBRARIES = libPriorityLists.la libHuffman.la -libPriorityLists_la_SOURCES = PCommon.cc BHeap.cc FHeap.cc BinHeap.cc PLList.cc CList.cc SList.cc HTree.cc Huffman.cc +libPriorityLists_la_SOURCES = PCommon.cc BHeap.cc FHeap.cc BinHeap.cc PLList.cc CList.cc SList.cc +libHuffman_la_SOURCES = HTree.cc Huffman.cc numbers.c libPriorityLists_la_LDFLAGS = -version-info $(PriorityLists_VERSION_INFO) - -EXTRA_DIST = FHeap.cc \ No newline at end of file +libHuffman_la_LDFLAGS = -version-info $(PriorityLists_VERSION_INFO) diff --git a/po/POTFILES.in b/po/POTFILES.in index 196d40a..09b12f8 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,5 @@ src/test.cc +src/main.cc lib/FHeap.cc lib/BHeap.cc lib/BinHeap.cc diff --git a/po/PriorityLists.pot b/po/PriorityLists.pot index 81d06a9..32402f6 100644 --- a/po/PriorityLists.pot +++ b/po/PriorityLists.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2001-03-05 02:26+0100\n" +"POT-Creation-Date: 2001-03-05 14:56+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -125,6 +125,106 @@ msgid "" "All the tests were successfull\n" msgstr "" +#: src/main.cc:34 src/main.cc:166 +msgid "Unknow priority list type: " +msgstr "" + +#: src/main.cc:45 src/main.cc:71 +msgid "Error opening file (" +msgstr "" + +#: src/main.cc:77 +msgid "Bad dictionnary structure. See doc/README.en (missing : separator)" +msgstr "" + +#: src/main.cc:90 +msgid "Bad dictionnary structure. See doc/README.en (missing word)" +msgstr "" + +#: src/main.cc:101 +msgid "Bad dictionnary structure. See doc/README.en (missing frequency)" +msgstr "" + +#: src/main.cc:109 +msgid "Huffman [{-f|-i} file] {type}" +msgstr "" + +#: src/main.cc:110 +msgid "Huffman -h" +msgstr "" + +#: src/main.cc:111 +msgid "By Nicolas Noble (nicolas@nobis-crew.org)." +msgstr "" + +#: src/main.cc:112 +msgid "This will encode the input file with the Huffman code" +msgstr "" + +#: src/main.cc:113 +msgid "using the priority list defined by type." +msgstr "" + +#: src/main.cc:114 +msgid "Type is a number taken from this list:" +msgstr "" + +#: src/main.cc:115 +msgid " 0 : Binary Heap (default)" +msgstr "" + +#: src/main.cc:116 +msgid " 1 : Binomial Heap" +msgstr "" + +#: src/main.cc:117 +msgid " 2 : Fibbonacci Heap (bugged)" +msgstr "" + +#: src/main.cc:118 +msgid " 3 : Sorted chained list" +msgstr "" + +#: src/main.cc:119 +msgid "-f file means that you specify a dictionnary file which is" +msgstr "" + +#: src/main.cc:120 +msgid " structured as described into the README file." +msgstr "" + +#: src/main.cc:121 +msgid "-i file means that you specify a file to encode. It will" +msgstr "" + +#: src/main.cc:122 +msgid " built a quiet dumb dictionnary." +msgstr "" + +#: src/main.cc:123 +msgid "By default, a dictionnary will be built from stdin." +msgstr "" + +#: src/main.cc:124 +msgid "-h prints this help and exit." +msgstr "" + +#: src/main.cc:140 +msgid "Unknow option: " +msgstr "" + +#: src/main.cc:149 src/main.cc:157 +msgid "-i and -f options are exclusive" +msgstr "" + +#: src/main.cc:170 +msgid "Extra command: " +msgstr "" + +#: src/main.cc:189 +msgid "Internal error." +msgstr "" + #: lib/FHeap.cc:80 msgid " * Head cell. (" msgstr "" @@ -147,11 +247,11 @@ msgid "" " |\n" msgstr "" -#: lib/BinHeap.cc:121 +#: lib/BinHeap.cc:122 msgid "Not enough memory" msgstr "" -#: lib/BinHeap.cc:148 +#: lib/BinHeap.cc:149 msgid "negative overflow" msgstr "" @@ -161,38 +261,38 @@ msgid "" " |\n" msgstr "" -#: lib/HTree.cc:57 +#: lib/HTree.cc:58 msgid "Bitstream length : " msgstr "" -#: lib/HTree.cc:57 lib/HTree.cc:58 lib/HTree.cc:60 lib/HTree.cc:61 +#: lib/HTree.cc:58 lib/HTree.cc:61 lib/HTree.cc:63 lib/HTree.cc:64 msgid " bits (= " msgstr "" -#: lib/HTree.cc:57 lib/HTree.cc:58 lib/HTree.cc:60 lib/HTree.cc:61 +#: lib/HTree.cc:60 lib/HTree.cc:61 lib/HTree.cc:63 lib/HTree.cc:68 msgid " bytes)\n" msgstr "" -#: lib/HTree.cc:58 +#: lib/HTree.cc:61 msgid "Real size input : " msgstr "" -#: lib/HTree.cc:59 +#: lib/HTree.cc:62 msgid "Size squeezed by : " msgstr "" -#: lib/HTree.cc:59 lib/HTree.cc:62 +#: lib/HTree.cc:62 lib/HTree.cc:70 msgid " percents\n" msgstr "" -#: lib/HTree.cc:60 +#: lib/HTree.cc:63 msgid "Dictionnary size : " msgstr "" -#: lib/HTree.cc:61 +#: lib/HTree.cc:64 msgid "Total bitstream length : " msgstr "" -#: lib/HTree.cc:62 +#: lib/HTree.cc:69 msgid "Real gain (4 bytes header) : " msgstr "" diff --git a/po/cat-id-tbl.c b/po/cat-id-tbl.c index 831b93c..98417ba 100644 --- a/po/cat-id-tbl.c +++ b/po/cat-id-tbl.c @@ -47,27 +47,52 @@ Extracting datas...\n", 23}, Ok.\n\ \n\ All the tests were successfull\n", 25}, - {" * Head cell. (", 26}, - {"Insert: not over Head.", 27}, - {"Insert: No more memory.", 28}, - {"Extract_Min: Priority List is empty.", 29}, + {"Unknow priority list type: ", 26}, + {"Error opening file (", 27}, + {"Bad dictionnary structure. See doc/README.en (missing : separator)", 28}, + {"Bad dictionnary structure. See doc/README.en (missing word)", 29}, + {"Bad dictionnary structure. See doc/README.en (missing frequency)", 30}, + {"Huffman [{-f|-i} file] {type}", 31}, + {"Huffman -h", 32}, + {"By Nicolas Noble (nicolas@nobis-crew.org).", 33}, + {"This will encode the input file with the Huffman code", 34}, + {"using the priority list defined by type.", 35}, + {"Type is a number taken from this list:", 36}, + {" 0 : Binary Heap (default)", 37}, + {" 1 : Binomial Heap", 38}, + {" 2 : Fibbonacci Heap (bugged)", 39}, + {" 3 : Sorted chained list", 40}, + {"-f file means that you specify a dictionnary file which is", 41}, + {" structured as described into the README file.", 42}, + {"-i file means that you specify a file to encode. It will", 43}, + {" built a quiet dumb dictionnary.", 44}, + {"By default, a dictionnary will be built from stdin.", 45}, + {"-h prints this help and exit.", 46}, + {"Unknow option: ", 47}, + {"-i and -f options are exclusive", 48}, + {"Extra command: ", 49}, + {"Internal error.", 50}, + {" * Head cell. (", 51}, + {"Insert: not over Head.", 52}, + {"Insert: No more memory.", 53}, + {"Extract_Min: Priority List is empty.", 54}, {"\ * Head cell.\n\ - |\n", 30}, - {"Not enough memory", 31}, - {"negative overflow", 32}, + |\n", 55}, + {"Not enough memory", 56}, + {"negative overflow", 57}, {"\ * Head cell\n\ - |\n", 33}, - {"Bitstream length : ", 34}, - {" bits (= ", 35}, - {" bytes)\n", 36}, - {"Real size input : ", 37}, - {"Size squeezed by : ", 38}, - {" percents\n", 39}, - {"Dictionnary size : ", 40}, - {"Total bitstream length : ", 41}, - {"Real gain (4 bytes header) : ", 42}, + |\n", 58}, + {"Bitstream length : ", 59}, + {" bits (= ", 60}, + {" bytes)\n", 61}, + {"Real size input : ", 62}, + {"Size squeezed by : ", 63}, + {" percents\n", 64}, + {"Dictionnary size : ", 65}, + {"Total bitstream length : ", 66}, + {"Real gain (4 bytes header) : ", 67}, }; -int _msg_tbl_length = 42; +int _msg_tbl_length = 67; diff --git a/po/de.po b/po/de.po index 81d06a9..c67b75a 100644 --- a/po/de.po +++ b/po/de.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2001-03-05 02:26+0100\n" +"POT-Creation-Date: 2001-03-05 02:52+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -125,6 +125,70 @@ msgid "" "All the tests were successfull\n" msgstr "" +#: src/main.cc:29 +msgid "Error opening file (" +msgstr "" + +#: src/main.cc:44 +msgid "Huffman [{-f|-i} file] {type}" +msgstr "" + +#: src/main.cc:45 +msgid "By Nicolas Noble (nicolas@nobis-crew.org)." +msgstr "" + +#: src/main.cc:46 +msgid "This will encode the input file with the Huffman code" +msgstr "" + +#: src/main.cc:47 +msgid "using the priority list defined by type." +msgstr "" + +#: src/main.cc:48 +msgid "Type is a number taken from this list:" +msgstr "" + +#: src/main.cc:49 +msgid " 0 : Binary Heap (default)" +msgstr "" + +#: src/main.cc:50 +msgid " 1 : Binomial Heap" +msgstr "" + +#: src/main.cc:51 +msgid " 2 : Fibbonacci Heap (bugged)" +msgstr "" + +#: src/main.cc:52 +msgid " 3 : Sorted chained list" +msgstr "" + +#: src/main.cc:53 +msgid "-f file means that you specify a dictionnary file which is" +msgstr "" + +#: src/main.cc:54 +msgid " structured as described into the README file." +msgstr "" + +#: src/main.cc:55 +msgid "-i file means that you specify a file to encode. It will" +msgstr "" + +#: src/main.cc:56 +msgid " built a quiet dumb dictionnary." +msgstr "" + +#: src/main.cc:57 +msgid "By default, a dictionnary will be built from stdin." +msgstr "" + +#: src/main.cc:63 +msgid "Unknow option: " +msgstr "" + #: lib/FHeap.cc:80 msgid " * Head cell. (" msgstr "" @@ -147,11 +211,11 @@ msgid "" " |\n" msgstr "" -#: lib/BinHeap.cc:121 +#: lib/BinHeap.cc:122 msgid "Not enough memory" msgstr "" -#: lib/BinHeap.cc:148 +#: lib/BinHeap.cc:149 msgid "negative overflow" msgstr "" @@ -161,38 +225,38 @@ msgid "" " |\n" msgstr "" -#: lib/HTree.cc:57 +#: lib/HTree.cc:58 msgid "Bitstream length : " msgstr "" -#: lib/HTree.cc:57 lib/HTree.cc:58 lib/HTree.cc:60 lib/HTree.cc:61 +#: lib/HTree.cc:58 lib/HTree.cc:61 lib/HTree.cc:63 lib/HTree.cc:64 msgid " bits (= " msgstr "" -#: lib/HTree.cc:57 lib/HTree.cc:58 lib/HTree.cc:60 lib/HTree.cc:61 +#: lib/HTree.cc:60 lib/HTree.cc:61 lib/HTree.cc:63 lib/HTree.cc:68 msgid " bytes)\n" msgstr "" -#: lib/HTree.cc:58 +#: lib/HTree.cc:61 msgid "Real size input : " msgstr "" -#: lib/HTree.cc:59 +#: lib/HTree.cc:62 msgid "Size squeezed by : " msgstr "" -#: lib/HTree.cc:59 lib/HTree.cc:62 +#: lib/HTree.cc:62 lib/HTree.cc:70 msgid " percents\n" msgstr "" -#: lib/HTree.cc:60 +#: lib/HTree.cc:63 msgid "Dictionnary size : " msgstr "" -#: lib/HTree.cc:61 +#: lib/HTree.cc:64 msgid "Total bitstream length : " msgstr "" -#: lib/HTree.cc:62 +#: lib/HTree.cc:69 msgid "Real gain (4 bytes header) : " msgstr "" diff --git a/po/fr.po b/po/fr.po index 43ffaaf..e34f6a4 100644 --- a/po/fr.po +++ b/po/fr.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PriorityList-1.0.0\n" -"POT-Creation-Date: 2001-03-05 02:26+0100\n" +"POT-Creation-Date: 2001-03-05 02:52+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Nicolas Noble \n" "Language-Team: French \n" @@ -140,6 +140,70 @@ msgstr "" "\n" "Tous les tests se sont déroulés correctement\n" +#: src/main.cc:29 +msgid "Error opening file (" +msgstr "Erreur à l'ouverture du fichier (" + +#: src/main.cc:44 +msgid "Huffman [{-f|-i} file] {type}" +msgstr "Huffman [{-f|-i} file] {type}" + +#: src/main.cc:45 +msgid "By Nicolas Noble (nicolas@nobis-crew.org)." +msgstr "Par Nicolas Noble {nicolas@nobis-crew.org)." + +#: src/main.cc:46 +msgid "This will encode the input file with the Huffman code" +msgstr "" + +#: src/main.cc:47 +msgid "using the priority list defined by type." +msgstr "" + +#: src/main.cc:48 +msgid "Type is a number taken from this list:" +msgstr "" + +#: src/main.cc:49 +msgid " 0 : Binary Heap (default)" +msgstr "" + +#: src/main.cc:50 +msgid " 1 : Binomial Heap" +msgstr "" + +#: src/main.cc:51 +msgid " 2 : Fibbonacci Heap (bugged)" +msgstr "" + +#: src/main.cc:52 +msgid " 3 : Sorted chained list" +msgstr "" + +#: src/main.cc:53 +msgid "-f file means that you specify a dictionnary file which is" +msgstr "" + +#: src/main.cc:54 +msgid " structured as described into the README file." +msgstr "" + +#: src/main.cc:55 +msgid "-i file means that you specify a file to encode. It will" +msgstr "" + +#: src/main.cc:56 +msgid " built a quiet dumb dictionnary." +msgstr "" + +#: src/main.cc:57 +msgid "By default, a dictionnary will be built from stdin." +msgstr "" + +#: src/main.cc:63 +msgid "Unknow option: " +msgstr "" + #: lib/FHeap.cc:80 msgid " * Head cell. (" msgstr " * Cellule d'entête. (" @@ -164,11 +228,11 @@ msgstr "" " * Cellule d'entête.\n" " |\n" -#: lib/BinHeap.cc:121 +#: lib/BinHeap.cc:122 msgid "Not enough memory" msgstr "Pas assez de mémoire" -#: lib/BinHeap.cc:148 +#: lib/BinHeap.cc:149 msgid "negative overflow" msgstr "Débordement négatif" @@ -180,38 +244,38 @@ msgstr "" " * Cellule d'entête.\n" " |\n" -#: lib/HTree.cc:57 +#: lib/HTree.cc:58 msgid "Bitstream length : " msgstr "Taille du flux de bits : " -#: lib/HTree.cc:57 lib/HTree.cc:58 lib/HTree.cc:60 lib/HTree.cc:61 +#: lib/HTree.cc:58 lib/HTree.cc:61 lib/HTree.cc:63 lib/HTree.cc:64 msgid " bits (= " msgstr " bits (= " -#: lib/HTree.cc:57 lib/HTree.cc:58 lib/HTree.cc:60 lib/HTree.cc:61 +#: lib/HTree.cc:60 lib/HTree.cc:61 lib/HTree.cc:63 lib/HTree.cc:68 msgid " bytes)\n" msgstr " octets)\n" -#: lib/HTree.cc:58 +#: lib/HTree.cc:61 msgid "Real size input : " msgstr "Taille réelle de l'entrée : " -#: lib/HTree.cc:59 +#: lib/HTree.cc:62 msgid "Size squeezed by : " msgstr "Taille réduite de : " -#: lib/HTree.cc:59 lib/HTree.cc:62 +#: lib/HTree.cc:62 lib/HTree.cc:70 msgid " percents\n" msgstr " pourcents\n" -#: lib/HTree.cc:60 +#: lib/HTree.cc:63 msgid "Dictionnary size : " msgstr "Taille du dictionnaire : " -#: lib/HTree.cc:61 +#: lib/HTree.cc:64 msgid "Total bitstream length : " msgstr "Taille totale du flux de bits : " -#: lib/HTree.cc:62 +#: lib/HTree.cc:69 msgid "Real gain (4 bytes header) : " msgstr "Gain réel (entête de 4 octets) : " diff --git a/src/Makefile.am b/src/Makefile.am index 173e832..c8a43f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,4 +12,4 @@ Huffman_SOURCES = main.cc LDADD = ../lib/libPriorityLists.la testTas_LDADD = $(LDADD) -Huffman_LDADD = $(LDADD) +Huffman_LDADD = $(LDADD) ../lib/libHuffman.la diff --git a/src/main.cc b/src/main.cc index 520f6ec..9cc96d5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,7 @@ #include #include +#include +#include #include "config.h" #include "BHeap.h" #include "FHeap.h" @@ -9,20 +11,41 @@ void exception(int e, char *msg) { - fprintf(stderr, "%s\n", msg); + cerr << msg << endl; exit(-1); } -PriorityList *newlist(void) +PriorityList *newlist(int method) { - return new BinHeap; + switch (method) { + case 0: + return new BinHeap; + break; + case 1: + return new BHeap; + break; + case 2: + return new FHeap; + break; + case 3: + return new PLList; + break; + default: + cerr << _("Unknow priority list type: ") << method << endl; + exit(-1); + } } void Count(FILE * strm, PriorityList * P) { - int tab[256], i; + int tab[256], i, valid; char *t; + if (!strm) { + cerr << _("Error opening file (") << strerror(errno) << ")\n"; + exit(-1); + } + for (i = 0; i < 256; i++) { tab[i] = 0; } @@ -41,12 +64,131 @@ void Count(FILE * strm, PriorityList * P) } } +void ReadDic(FILE * strm, PriorityList * P) { + char t[1024], *f, *word, *p; + + if (!strm) { + cerr << _("Error opening file (") << strerror(errno) << ")\n"; + exit(-1); + } + + while(gets(t)) { + if (!(f = strchr(t, ':'))) { + cerr << _("Bad dictionnary structure. See doc/README.en (missing : separator)") << endl; + exit (-1); + } + *(f++) = '\0'; + word = t; + while (*word == ' ') { + word++; + } + p = word + strlen(word) - 1; + while (*p == ' ') { + *(p--) = '\0'; + } + if (!strlen(word)) { + cerr << _("Bad dictionnary structure. See doc/README.en (missing word)") << endl; + exit (-1); + } + while (*f == ' ') { + f++; + } + p = f + strlen(f) - 1; + while (*p == ' ') { + *(p--) = '\0'; + } + if (!strlen(f)) { + cerr << _("Bad dictionnary structure. See doc/README.en (missing frequency)") << endl; + exit (-1); + } + } +} + +void Usage(void) +{ + cerr << _("Huffman [{-f|-i} file] {type}") << endl; + cerr << _("Huffman -h") << endl; + cerr << _("By Nicolas Noble (nicolas@nobis-crew.org).") << endl; + cerr << _("This will encode the input file with the Huffman code") << endl; + cerr << _("using the priority list defined by type.") << endl; + cerr << _("Type is a number taken from this list:") << endl; + cerr << _(" 0 : Binary Heap (default)") << endl; + cerr << _(" 1 : Binomial Heap") << endl; + cerr << _(" 2 : Fibbonacci Heap (bugged)") << endl; + cerr << _(" 3 : Sorted chained list") << endl; + cerr << _("-f file means that you specify a dictionnary file which is") << endl; + cerr << _(" structured as described into the README file.") << endl; + cerr << _("-i file means that you specify a file to encode. It will") << endl; + cerr << _(" built a quiet dumb dictionnary.") << endl; + cerr << _("By default, a dictionnary will be built from stdin.") << endl; + cerr << _("-h prints this help and exit.") << endl; + exit(0); +} + int main(int argc, char **argv) { - PriorityList *P = newlist(); + PriorityList *P; HTree *H; + FILE * f; + int method = -1, readm = -1; + char *filename = NULL; - Count(stdin, P); + while (--argc) { + argv++; + if (*argv[0] == '-') { + if (strlen(*argv) != 2) { + cerr << _("Unknow option: ") << *argv << endl; + Usage(); + } + switch (*argv[1]) { + case 'h': + Usage(); + break; + case 'i': + if (readm != -1) { + cerr << _("-i and -f options are exclusive") << endl; + Usage(); + } + readm = 1; + filename = *(++argv); + break; + case 'f': + if (readm != -1) { + cerr << _("-i and -f options are exclusive") << endl; + Usage(); + } + readm = 2; + filename = *(++argv); + break; + } + } else { + if ((strlen(*argv) != 1) || ((*argv[0] < '0' || *argv[0] > '3'))) { + cerr << _("Unknow priority list type: ") << *argv << endl; + Usage(); + } + if (method != -1) { + cerr << _("Extra command: ") << *argv << endl; + } + method = *argv[0] - '0'; + } + } + + P = newlist(method); + + switch (readm) { + case -1: + Count(stdin, P); + break; + case 1: + Count(fopen(filename, "r"), P); + break; + case 2: + ReadDic(fopen(filename, "r"), P); + break; + default: + cerr << _("Internal error.") << endl; + exit(-1); + } H = Coder(P); H->Trace(cout); diff --git a/src/test.cc b/src/test.cc index e9a15c1..48d7762 100644 --- a/src/test.cc +++ b/src/test.cc @@ -20,7 +20,7 @@ void exception(int e, char *msg) PriorityList *newlist(void) { - return new FHeap; + return new BHeap; } void DoCombTest(int number) @@ -59,7 +59,7 @@ void FullTest(void) { PriorityList *T; Datas_t Datas; - Cell C1, C2; + Cell C1, C2, C3; Key_t K; int i; @@ -76,7 +76,7 @@ void FullTest(void) DoCombTest(10); DoCombTest(70); DoCombTest(1000); - DoCombTest(10000); +// DoCombTest(10000); #ifdef BT DoCombTest(100000); #ifdef VBT @@ -88,7 +88,8 @@ void FullTest(void) T = newlist(); for (i = 0; i < 30; i++) { fprintf(stderr, "%i ", N[i]); - T->Insert(N[i], NULL); + C1 = T->Insert(N[i], NULL); + if (N[i] == 30) C3 = C1; } fprintf(stderr, "59 54 -10\n"); @@ -101,18 +102,22 @@ void FullTest(void) cerr << _("Ok.\nExtract_Min + List browsing...\n"); cerr << T->Extract_Min(Datas) << endl; T->Dump(cerr); - cerr << _("Ok.\nLower_Key(-12) over 59...\n"); - T->Lower_Key(C1, -12); + cerr << _("Ok.\nLower_Key(0) over 59...\n"); + T->Lower_Key(C1, 0); cerr << _("Ok.\nList browsing...\n"); T->Dump(cerr); cerr << _("Ok.\nDelete over 54...\n"); T->Delete(Datas, C2); cerr << _("Ok.\nList browsing...\n"); T->Dump(cerr); - cerr << "Ok.\nExtract_Min...\n"; + cerr << _("Ok.\nLower_Key(-12) over 30...\n"); + T->Lower_Key(C3, -12); + cerr << _("Ok.\nList browsing...\n"); + T->Dump(cerr); + cerr << _("Ok.\nExtract_Min...\n"); cerr << T->Extract_Min(Datas) << endl; cerr << _("Ok.\nExtracting datas...\n"); - for (i = 1; i <= 30; i++) { + for (i = 0; i <= 29; i++) { cerr << _("Minimum #") << i << " = " << (K = (T->Extract_Min(Datas))) << endl; if (K != i) -- cgit v1.2.3