Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rudolf
/
huffman
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
55b4562c
authored
Nov 22, 2016
by
Rudolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove noisy logging
And show useful logs only when DEBUG := 1
parent
ae4ef0c8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
23 deletions
header.c
tree.c
header.c
View file @
55b4562c
...
...
@@ -13,7 +13,6 @@ static int write_entries(struct BIT_BUFFER *bitbuf, struct tree *parent)
if
(
left
&&
right
)
{
bit
=
1
;
bb_write
(
bitbuf
,
&
bit
,
1
);
printf
(
" 1"
);
}
if
(
left
)
...
...
@@ -26,8 +25,6 @@ static int write_entries(struct BIT_BUFFER *bitbuf, struct tree *parent)
bit
=
0
;
bb_write
(
bitbuf
,
&
bit
,
1
);
bb_writebyte
(
bitbuf
,
parent
->
ch
);
printf
(
" 0"
);
printf
(
"%c"
,
parent
->
ch
);
}
return
0
;
...
...
@@ -53,7 +50,8 @@ static int read_entry(struct BIT_BUFFER *bitbuf, struct tree *parent)
}
else
{
int
*
c
=
bb_readbyte
(
bitbuf
);
parent
->
ch
=
*
c
;
printf
(
"Found from header %c
\n
"
,
*
c
);
if
(
DEBUG
)
printf
(
"Found from encoded header %c
\n
"
,
*
c
);
free
(
c
);
}
...
...
tree.c
View file @
55b4562c
...
...
@@ -33,7 +33,6 @@ struct tree *merge_smallest(struct tree **forest, int length)
struct
tree
*
smallest1
=
NULL
;
struct
tree
*
smallest2
=
NULL
;
printf
(
"--
\n
"
);
int
i1
=
0
,
i2
=
0
;
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
...
...
@@ -43,16 +42,13 @@ struct tree *merge_smallest(struct tree **forest, int length)
if
(
smallest1
==
NULL
)
{
smallest1
=
forest
[
i
];
i1
=
i
;
printf
(
"init Smallest1 %c:%d
\n
"
,
smallest1
->
ch
,
smallest1
->
freq
);
continue
;
}
else
if
(
smallest2
==
NULL
)
{
smallest2
=
forest
[
i
];
i2
=
i
;
printf
(
"init Smallest2 %c:%d
\n
"
,
smallest2
->
ch
,
smallest2
->
freq
);
continue
;
}
printf
(
"comp %c:%d
\n
"
,
forest
[
i
]
->
ch
,
forest
[
i
]
->
freq
);
if
(
forest
[
i
]
->
freq
<
smallest1
->
freq
)
{
smallest1
=
forest
[
i
];
i1
=
i
;
...
...
@@ -64,9 +60,10 @@ struct tree *merge_smallest(struct tree **forest, int length)
forest
[
i1
]
=
NULL
;
forest
[
i2
]
=
insert_proper_tree
(
smallest1
,
smallest2
);
printf
(
"Smallest1 %c:%d
\n
"
,
smallest1
->
ch
,
smallest1
->
freq
);
printf
(
"Smallest2 %c:%d
\n
"
,
smallest2
->
ch
,
smallest2
->
freq
);
printf
(
"Merged %c:%d
\n
"
,
forest
[
i2
]
->
ch
,
forest
[
i2
]
->
freq
);
if
(
DEBUG
)
printf
(
"Merged %c:%d and %c:%d
\n
"
,
smallest1
->
ch
,
smallest1
->
freq
,
smallest2
->
ch
,
smallest2
->
freq
);
return
forest
[
i2
];
}
...
...
@@ -102,6 +99,7 @@ struct tree *create_tree(FILE *file)
}
}
if
(
DEBUG
)
printf
(
"Created initial tree with %d trees
\n
"
,
ntrees
);
/* Sort ascending */
...
...
@@ -115,10 +113,6 @@ struct tree *create_tree(FILE *file)
}
}
for
(
int
i
=
0
;
i
<
ntrees
;
i
++
)
{
printf
(
"ch %c freq %d
\n
"
,
forest
[
i
]
->
ch
,
forest
[
i
]
->
freq
);
}
struct
tree
*
parent
=
forest
[
0
];
for
(
int
i
=
0
;
i
<
ntrees
-
1
;
i
++
)
{
parent
=
merge_smallest
(
forest
,
ntrees
);
...
...
@@ -131,7 +125,7 @@ struct tree *create_tree(FILE *file)
/* This is not needed anymore */
free
(
forest
);
if
(
DEBUG
)
printf
(
"Returning tree
\n
"
);
return
parent
;
}
...
...
@@ -180,20 +174,16 @@ static int write_entry(struct BIT_BUFFER *bitbuf, struct tree *parent,
unsigned
char
c
,
int
*
pathbuf
)
{
int
length
=
get_rev_path
(
parent
,
c
,
pathbuf
,
0
);
printf
(
"Length %d
\n
"
,
length
);
/* The path is in reverse. Now write it out in correct order. */
for
(
int
i
=
length
-
1
;
i
>=
0
;
i
--
)
{
bb_write
(
bitbuf
,
&
pathbuf
[
i
],
1
);
printf
(
"i %d Bit %d
\n
"
,
i
,
pathbuf
[
i
]);
}
}
int
encode_tree
(
struct
BIT_BUFFER
*
bitbuf
,
struct
tree
*
parent
,
char
*
buf
,
size_t
length
)
{
printf
(
"Bit pos at %d %d
\n
"
,
ftell
(
bitbuf
->
fp
),
bitbuf
->
pos
);
/* It makes much more sense to write the count when there is only one
* char. */
if
(
!
parent
->
left
&&
!
parent
->
right
)
{
...
...
@@ -237,15 +227,14 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
}
while
((
bit
=
bb_read
(
bitbuf
,
1
))
!=
NULL
)
{
printf
(
"Reading bit %d
\n
"
,
*
bit
);
if
(
*
bit
==
0
)
leaf
=
leaf
->
left
;
else
leaf
=
leaf
->
right
;
if
(
!
leaf
->
left
&&
!
leaf
->
right
)
{
printf
(
"Found from encoded %c
\n
"
,
leaf
->
ch
);
if
(
DEBUG
)
printf
(
"Found from encoded tree %c
\n
"
,
leaf
->
ch
);
fwrite
(
&
leaf
->
ch
,
1
,
1
,
out
);
leaf
=
parent
;
}
...
...
@@ -253,6 +242,7 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
free
(
bit
);
if
(
ftell
(
bitbuf
->
fp
)
==
lastbyte
&&
bitbuf
->
pos
+
throwaways
>=
8
)
{
if
(
DEBUG
)
printf
(
"Stopping
\n
"
);
break
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment