Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algoritmer og datastrukturer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jacob Theisen
Algoritmer og datastrukturer
Commits
0c4e5c85
Commit
0c4e5c85
authored
3 years ago
by
Jacob Theisen
Browse files
Options
Downloads
Patches
Plain Diff
sjo2
parent
34e81f08
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ov8/HM_compression.py
+0
-31
0 additions, 31 deletions
ov8/HM_compression.py
ov8/HM_uncompression.py
+1
-0
1 addition, 0 deletions
ov8/HM_uncompression.py
ov8/hm_uncomp
+0
-0
0 additions, 0 deletions
ov8/hm_uncomp
with
1 addition
and
31 deletions
ov8/HM_compression.py
+
0
−
31
View file @
0c4e5c85
...
@@ -49,22 +49,12 @@ for i in all_strings:
...
@@ -49,22 +49,12 @@ for i in all_strings:
table
=
sorted
(
table
,
key
=
lambda
x
:
x
.
freq
)
table
=
sorted
(
table
,
key
=
lambda
x
:
x
.
freq
)
# A Huffman Tree Node
class
node
:
class
node
:
def
__init__
(
self
,
freq
,
symbol
,
left
=
None
,
right
=
None
):
def
__init__
(
self
,
freq
,
symbol
,
left
=
None
,
right
=
None
):
# frequency of symbol
self
.
freq
=
freq
self
.
freq
=
freq
# symbol name (character)
self
.
symbol
=
symbol
self
.
symbol
=
symbol
# node left of current node
self
.
left
=
left
self
.
left
=
left
# node right of current node
self
.
right
=
right
self
.
right
=
right
# tree direction (0/1)
self
.
huff
=
''
self
.
huff
=
''
...
@@ -76,59 +66,38 @@ class rep_tree():
...
@@ -76,59 +66,38 @@ class rep_tree():
def
printNodes
(
node
,
val
=
''
):
def
printNodes
(
node
,
val
=
''
):
# huffman code for current node
newVal
=
val
+
str
(
node
.
huff
)
newVal
=
val
+
str
(
node
.
huff
)
# if node is not an edge node
# then traverse inside it
if
(
node
.
left
):
if
(
node
.
left
):
printNodes
(
node
.
left
,
newVal
)
printNodes
(
node
.
left
,
newVal
)
if
(
node
.
right
):
if
(
node
.
right
):
printNodes
(
node
.
right
,
newVal
)
printNodes
(
node
.
right
,
newVal
)
# if node is edge node then
# display its huffman code
if
(
not
node
.
left
and
not
node
.
right
):
if
(
not
node
.
left
and
not
node
.
right
):
rep_tree_arr
.
append
(
rep_tree
(
node
.
symbol
,
newVal
))
rep_tree_arr
.
append
(
rep_tree
(
node
.
symbol
,
newVal
))
# list containing unused nodes
nodes
=
[]
nodes
=
[]
for
j
in
table
:
for
j
in
table
:
nodes
.
append
(
node
(
j
.
freq
,
j
.
char
))
nodes
.
append
(
node
(
j
.
freq
,
j
.
char
))
while
len
(
nodes
)
>
1
:
while
len
(
nodes
)
>
1
:
# pick 2 smallest nodes
left
=
nodes
[
0
]
left
=
nodes
[
0
]
right
=
nodes
[
1
]
right
=
nodes
[
1
]
# assign directional value to these nodes
left
.
huff
=
0
left
.
huff
=
0
right
.
huff
=
1
right
.
huff
=
1
# combine the 2 smallest nodes to create
# new node as their parent
newNode
=
node
(
left
.
freq
+
right
.
freq
,
left
.
symbol
+
right
.
symbol
,
left
,
right
)
newNode
=
node
(
left
.
freq
+
right
.
freq
,
left
.
symbol
+
right
.
symbol
,
left
,
right
)
# remove the 2 nodes and add their
# parent as new node among others
nodes
.
remove
(
left
)
nodes
.
remove
(
left
)
nodes
.
remove
(
right
)
nodes
.
remove
(
right
)
nodes
.
append
(
newNode
)
nodes
.
append
(
newNode
)
# Huffman Tree is ready!
printNodes
(
nodes
[
0
])
printNodes
(
nodes
[
0
])
bit_string
=
''
bit_string
=
''
for
i
in
all_strings
:
for
i
in
all_strings
:
a
=
[
a
for
a
in
rep_tree_arr
if
a
.
symb
==
i
]
a
=
[
a
for
a
in
rep_tree_arr
if
a
.
symb
==
i
]
bit_string
+=
a
[
0
].
val
bit_string
+=
a
[
0
].
val
...
...
This diff is collapsed.
Click to expand it.
ov8/HM_uncompression.py
+
1
−
0
View file @
0c4e5c85
...
@@ -101,6 +101,7 @@ for i in range(0,len(lz_code),6):
...
@@ -101,6 +101,7 @@ for i in range(0,len(lz_code),6):
elif
k
not
in
string
.
printable
:
elif
k
not
in
string
.
printable
:
print
(
'
extende
'
)
print
(
'
extende
'
)
counter
+=
1
counter
+=
1
print
(
counter
)
with
open
(
'
./hm_uncomp
'
,
'
a
'
)
as
file
:
with
open
(
'
./hm_uncomp
'
,
'
a
'
)
as
file
:
file
.
write
(
huff_string
[:
value
-
counter
])
file
.
write
(
huff_string
[:
value
-
counter
])
huff_string
=
huff_string
[
value
-
counter
:]
huff_string
=
huff_string
[
value
-
counter
:]
...
...
This diff is collapsed.
Click to expand it.
ov8/hm_uncomp
+
0
−
0
View file @
0c4e5c85
No preview for this file type
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment