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
a169c230
authored
Nov 16, 2016
by
Rudolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not redefine bit
parent
9c75370d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
27 deletions
header.c
huffman.c
print_helper.c
print_helper.h
tree.c
header.c
View file @
a169c230
...
@@ -7,25 +7,24 @@
...
@@ -7,25 +7,24 @@
static
int
write_entries
(
struct
BIT_BUFFER
*
bitbuf
,
struct
tree
*
parent
)
static
int
write_entries
(
struct
BIT_BUFFER
*
bitbuf
,
struct
tree
*
parent
)
{
{
int
bit
;
if
(
parent
->
left
)
{
if
(
parent
->
left
)
{
int
bit
=
1
;
bit
=
1
;
bb_write
(
bitbuf
,
&
bit
,
1
);
bb_write
(
bitbuf
,
&
bit
,
1
);
write_entries
(
bitbuf
,
parent
->
left
);
write_entries
(
bitbuf
,
parent
->
left
);
}
}
if
(
!
parent
->
left
)
{
if
(
!
parent
->
left
)
{
int
bit
=
0
;
bit
=
0
;
bb_write
(
bitbuf
,
&
bit
,
1
);
/* This means now we have 8 bits of char. */
bb_write
(
bitbuf
,
&
bit
,
1
);
/* This means now we have 8 bits of char. */
bb_writebyte
(
bitbuf
,
parent
->
ch
);
bb_writebyte
(
bitbuf
,
parent
->
ch
);
fprintf
(
stderr
,
"%x
\n
"
,
parent
->
ch
);
}
}
if
(
parent
->
right
)
{
if
(
parent
->
right
)
{
/* Why should we write this
-
we can save more bits. */
/* Why should we write this
if
we can save more bits. */
//
int
bit = 0;
//bit = 0;
//bb_write(bitbuf, &bit, 1);
//bb_write(bitbuf, &bit, 1);
bb_writebyte
(
bitbuf
,
parent
->
right
->
ch
);
bb_writebyte
(
bitbuf
,
parent
->
right
->
ch
);
fprintf
(
stderr
,
"%x
\n
"
,
parent
->
right
->
ch
);
}
}
}
}
...
...
huffman.c
View file @
a169c230
...
@@ -7,24 +7,6 @@
...
@@ -7,24 +7,6 @@
#include "header.h"
#include "header.h"
#include "tree.h"
#include "tree.h"
void
print_char
(
char
c
)
{
switch
(
c
)
{
case
'\n'
:
printf
(
"
\\
n
\n
"
);
break
;
case
'\r'
:
printf
(
"
\\
r
\n
"
);
break
;
case
'\t'
:
printf
(
"
\\
t
\n
"
);
break
;
default:
printf
(
"%c
\n
"
,
c
);
break
;
}
}
void
free_tree
(
struct
tree
*
parent
)
void
free_tree
(
struct
tree
*
parent
)
{
{
while
(
parent
!=
NULL
)
{
while
(
parent
!=
NULL
)
{
...
...
print_helper.c
View file @
a169c230
...
@@ -26,3 +26,21 @@ void __printb(void *value, size_t size)
...
@@ -26,3 +26,21 @@ void __printb(void *value, size_t size)
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
void
print_char
(
char
c
)
{
switch
(
c
)
{
case
'\n'
:
printf
(
"
\\
n
\n
"
);
break
;
case
'\r'
:
printf
(
"
\\
r
\n
"
);
break
;
case
'\t'
:
printf
(
"
\\
t
\n
"
);
break
;
default:
printf
(
"%c
\n
"
,
c
);
break
;
}
}
print_helper.h
View file @
a169c230
...
@@ -16,3 +16,5 @@ void __printb(void *value, size_t size);
...
@@ -16,3 +16,5 @@ void __printb(void *value, size_t size);
typeof(value) _v = value; \
typeof(value) _v = value; \
__printb((typeof(_v) *) &_v, sizeof(_v)); \
__printb((typeof(_v) *) &_v, sizeof(_v)); \
})
})
void
print_char
(
char
c
);
tree.c
View file @
a169c230
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
struct
tree
*
insert_simple_tree
(
int
character
,
int
frequency
)
struct
tree
*
insert_simple_tree
(
int
character
,
int
frequency
)
{
{
struct
tree
*
new
=
malloc
(
sizeof
(
struct
tree
));
struct
tree
*
new
=
malloc
(
sizeof
(
struct
tree
));
//printf("Created %p\n", new);
new
->
left
=
NULL
;
new
->
left
=
NULL
;
new
->
right
=
NULL
;
new
->
right
=
NULL
;
new
->
ch
=
character
;
new
->
ch
=
character
;
...
@@ -22,7 +21,6 @@ struct tree *insert_simple_tree(int character, int frequency)
...
@@ -22,7 +21,6 @@ struct tree *insert_simple_tree(int character, int frequency)
struct
tree
*
insert_proper_tree
(
struct
tree
*
left
,
struct
tree
*
right
)
struct
tree
*
insert_proper_tree
(
struct
tree
*
left
,
struct
tree
*
right
)
{
{
struct
tree
*
new
=
malloc
(
sizeof
(
*
new
));
struct
tree
*
new
=
malloc
(
sizeof
(
*
new
));
//printf("Created %p\n", new);
new
->
left
=
left
;
new
->
left
=
left
;
new
->
right
=
right
;
new
->
right
=
right
;
new
->
ch
=
0
;
new
->
ch
=
0
;
...
@@ -142,7 +140,7 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
...
@@ -142,7 +140,7 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
}
}
free
(
bit
);
free
(
bit
);
}
}
fprintf
(
stdout
,
"
\n
"
);
return
0
;
return
0
;
}
}
...
...
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