summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/main.cc54
-rw-r--r--src/test.cc3
3 files changed, 59 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 03bcc4f..173e832 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,12 +1,15 @@
localedir = $(datadir)/locale
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
-bin_PROGRAMS = testTas
+bin_PROGRAMS = testTas Huffman
testTas_SOURCES = test.cc
+Huffman_SOURCES = main.cc
LDADD = ../lib/libPriorityLists.la
testTas_LDADD = $(LDADD)
+Huffman_LDADD = $(LDADD)
diff --git a/src/main.cc b/src/main.cc
new file mode 100644
index 0000000..520f6ec
--- /dev/null
+++ b/src/main.cc
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+#include "BHeap.h"
+#include "FHeap.h"
+#include "BinHeap.h"
+#include "PLList.h"
+#include "Huffman.h"
+
+void exception(int e, char *msg)
+{
+ fprintf(stderr, "%s\n", msg);
+ exit(-1);
+}
+
+PriorityList *newlist(void)
+{
+ return new BinHeap;
+}
+
+void Count(FILE * strm, PriorityList * P)
+{
+ int tab[256], i;
+ char *t;
+
+ for (i = 0; i < 256; i++) {
+ tab[i] = 0;
+ }
+
+ while ((i = getc(strm)) != EOF) {
+ tab[i]++;
+ }
+
+ for (i = 0; i < 256; i++) {
+ if (tab[i]) {
+ t = (char *) malloc(2);
+ t[0] = i;
+ t[1] = 0;
+ HInsert(P, tab[i], t);
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ PriorityList *P = newlist();
+ HTree *H;
+
+ Count(stdin, P);
+
+ H = Coder(P);
+ H->Trace(cout);
+ return 0;
+}
diff --git a/src/test.cc b/src/test.cc
index 5a1bce5..bc53810 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -20,7 +20,7 @@ void exception(int e, char *msg)
PriorityList *newlist(void)
{
- return new BinHeap;
+ return new FHeap;
}
void DoCombTest(int number)
@@ -59,7 +59,6 @@ void FullTest(void)
{
PriorityList *T;
Datas_t Datas;
- char msg[10240];
Cell C1, C2;
Key_t K;
int i;