Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
redes1-trabalho3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Eduardo Machado
redes1-trabalho3
Commits
30e9a436
Commit
30e9a436
authored
9 years ago
by
Victor Perszel
Browse files
Options
Downloads
Patches
Plain Diff
Pack and unpacking
parent
113a70e9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/lzw.h
+8
-0
8 additions, 0 deletions
include/lzw.h
src/lzw.cpp
+72
-16
72 additions, 16 deletions
src/lzw.cpp
with
80 additions
and
16 deletions
include/lzw.h
0 → 100644
+
8
−
0
View file @
30e9a436
#include
<iostream>
#include
<string>
class
LZW
{
public:
string
pack
(
string
&
input
);
string
unpack
(
int
input
[]);
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/lzw.cpp
+
72
−
16
View file @
30e9a436
// Implementado por Eduardo Machado e Victor Perszel
// Implementado por Eduardo Machado e Victor Perszel
#include
<iostram>
#include
"lzw.h"
#include
<string>
using
namespace
std
;
using
namespace
std
;
class
LZW
{
private:
int
dictionarySize
=
256
;
string
LZW
::
pack
(
string
&
input
){
public:
map
<
string
,
int
>
dictionary
;
compact
(
const
string
&
input
){
string
output
=
""
;
DICT
dictionary
[];
string
nextChar
,
currentChar
=
""
;
int
i
,
cont
=
0
,
dictionarySize
=
256
;
//inicializa o dicionário
//inicializa o dicionário
for
(
i
=
0
;
i
<
dictionarySize
;
i
++
){
for
(
i
=
0
;
i
<
256
;
i
++
){
dictionary
.
str
[
0
]
=
i
;
dictionary
[
str
ing
(
1
,
i
)]
=
i
;
}
}
string
nextChar
,
currentChar
=
""
;
int
i
;
for
(
i
=
0
;
i
<
input
.
size
();
i
++
){
for
(
i
=
0
;
i
<
input
.
size
();
i
++
){
nextChar
=
input
[
i
];
nextChar
=
input
[
i
];
if
(
dictionary
[
currentChar
+
nextChar
]
!=
0
){
currentChar
=
currentChar
+
nextChar
;
}
else
{
output
+=
dictionary
[
currentChar
]
+
" "
;
dictionary
[
currentChar
+
nextChar
]
=
dictionarySize
;
currentChar
=
nextChar
;
dictionarySize
++
;
cont
++
;
}
}
output
+=
dictionary
[
currentChar
]
+
" "
;
cont
++
;
/* CONVERSAO
int *intOutput;
int temp = n = 0;
intOutput = new int[dictionarySize-1];
for(i = 0; i < cont; i++){
if(output[i] != " "){
temp++;
} else {
for (j = temp-1; j >= 0; j--){
intOutput[n] += output[j] * pow(10,j);
}
n++;
temp = 0;
}
}
*/
return
intOutput
;
}
string
LZW
::
unpack
(
int
input
[]){
map
<
int
,
string
>
dictionary
;
string
currentChar
,
nextChar
,
output
=
""
;
int
i
,
dictionarySize
=
256
;
int
currentWord
,
nextWord
;
//inicializa o dicionário
for
(
i
=
0
;
i
<
256
;
i
++
){
dictionary
[
i
]
=
string
(
1
,
i
);
}
nextWord
=
input
[
0
];
output
+=
dictionary
[
nextWord
];
for
(
i
=
0
;
i
<
sizeof
(
input
)
/
sizeof
(
int
);
i
++
){
currentWord
=
nextWord
;
nextWord
=
input
[
i
+
1
];
if
(
dictionary
[
nextWord
]
!=
""
){
output
+=
dictionary
[
nextWord
];
currentChar
=
dictionary
[
currentWord
];
nextChar
=
dictionary
[
nextWord
][
1
];
dictionary
[
dictionarySize
]
=
currentChar
+
nextChar
;
dictionarySize
++
;
}
else
{
currentChar
=
dictionary
[
currentWord
];
nextChar
=
dictionary
[
currentWord
][
1
];
output
+=
currentChar
+
nextChar
;
dictionary
[
dictionarySize
]
=
currentChar
+
nextChar
;
dictionarySize
++
;
}
}
}
}
return
output
;
}
}
\ No newline at end of file
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