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
a2a89b46
Commit
a2a89b46
authored
9 years ago
by
Eduardo Machado
Browse files
Options
Downloads
Patches
Plain Diff
quase lá
parent
dd009b50
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
Makefile
+7
-11
7 additions, 11 deletions
Makefile
include/lzw.h
+11
-5
11 additions, 5 deletions
include/lzw.h
src/lzw.cpp
+15
-10
15 additions, 10 deletions
src/lzw.cpp
src/main.cpp
+70
-0
70 additions, 0 deletions
src/main.cpp
teste.txt
+3
-0
3 additions, 0 deletions
teste.txt
with
106 additions
and
26 deletions
Makefile
+
7
−
11
View file @
a2a89b46
...
...
@@ -6,18 +6,14 @@ LIB=./lib
INCLUDE
=
./include
SRC
=
./src
OBJ
=
./obj
FLAGS
=
-Wall
FLAGS
=
-Wall
-lm
main
:
connectionRawSocket messages
$(
CC
)
$(
SRC
)
/main.cpp
$(
OBJ
)
/
connectionRawSocket.o
$(
OBJ
)
/messages
.o
$(
FLAGS
)
-I
$(
INCLUDE
)
-L
$(
LIB
)
-o
connection
main
:
lzw
$(
CC
)
$(
SRC
)
/main.cpp
$(
OBJ
)
/
lzw
.o
$(
FLAGS
)
-I
$(
INCLUDE
)
-L
$(
LIB
)
-o
lzw
connectionRawSocket
:
$(
CC
)
-c
$(
SRC
)
/connectionRawSocket.cpp
$(
FLAGS
)
-I
$(
INCLUDE
)
-o
$(
OBJ
)
/connectionRawSocket.o
ar
-cru
$(
LIB
)
/connectionRawSocket.a
$(
OBJ
)
/connectionRawSocket.o
messages
:
$(
CC
)
-c
$(
SRC
)
/messages.cpp
$(
FLAGS
)
-I
$(
INCLUDE
)
-o
$(
OBJ
)
/messages.o
ar
-cru
$(
LIB
)
/messages.a
$(
OBJ
)
/messages.o
lzw
:
$(
CC
)
-c
$(
SRC
)
/lzw.cpp
$(
FLAGS
)
-I
$(
INCLUDE
)
-o
$(
OBJ
)
/lzw.o
ar
-cru
$(
LIB
)
/lzw.a
$(
OBJ
)
/lzw.o
clean
:
rm
connection
$(
SRC
)
/
*
~
$(
OBJ
)
/
*
o
$(
LIB
)
/
*
a
rm
lzw
$(
SRC
)
/
*
~
$(
OBJ
)
/
*
o
$(
LIB
)
/
*
a
This diff is collapsed.
Click to expand it.
include/lzw.h
+
11
−
5
View file @
a2a89b46
// Implementado por Eduardo Machado e Victor Perszel
// 2015
#include
<iostream>
#include
<string>
#include
<fstream>
#include
<map>
#include
<cstdlib>
#include
<cmath>
using
namespace
std
;
class
LZW
{
public:
int
*
pack
(
string
&
input
);
string
unpack
(
int
input
[]);
};
\ No newline at end of file
void
pack
(
string
input
,
int
*
intOutput
);
string
unpack
(
int
*
input
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/lzw.cpp
+
15
−
10
View file @
a2a89b46
// Implementado por Eduardo Machado e Victor Perszel
// 2015
#include
"lzw.h"
using
namespace
std
;
int
*
LZW
::
pack
(
string
&
input
){
void
pack
(
string
input
,
int
*
intOutput
){
map
<
string
,
int
>
dictionary
;
string
output
=
""
;
string
nextChar
,
currentChar
=
""
;
int
i
,
temp
,
n
,
lastI
,
cont
=
0
,
dictionarySize
=
256
;
int
*
intOutput
;
intOutput
=
new
int
[
dictionarySize
-
1
];
int
i
,
j
,
temp
,
n
=
0
,
size
,
lastI
,
cont
=
0
,
dictionarySize
=
256
;
//inicializa o dicionário
for
(
i
=
0
;
i
<
256
;
i
++
){
dictionary
[
string
(
1
,
i
)]
=
i
;
}
for
(
i
=
0
;
i
<
input
.
size
();
i
++
){
size
=
input
.
size
();
for
(
i
=
0
;
i
<
size
;
i
++
){
nextChar
=
input
[
i
];
if
(
dictionary
[
currentChar
+
nextChar
]
!=
0
){
currentChar
=
currentChar
+
nextChar
;
}
else
{
output
+=
dictionary
[
currentChar
]
+
" "
;
cout
<<
dictionary
[
currentChar
]
<<
endl
;
cout
<<
output
<<
endl
;
dictionary
[
currentChar
+
nextChar
]
=
dictionarySize
;
currentChar
=
nextChar
;
dictionarySize
++
;
cont
++
;
}
//cout << output << endl;
}
output
+=
dictionary
[
currentChar
]
+
" "
;
cont
++
;
// --------------------- CONVERSAO --------------------------
intOutput
=
new
int
[
dictionarySize
-
1
];
do
{
if
(
output
[
i
]
!=
' '
&&
output
[
i
]
!=
'\0'
){
temp
++
;
...
...
@@ -49,15 +53,15 @@ int* LZW::pack(string &input){
i
++
;
}
while
(
output
[
i
-
1
]
!=
'\0'
);
//-----------------------------------------------------------
cout
<<
intOutput
<<
endl
;
return
&
intOutput
;
//-----------------------------------------------------------
}
string
LZW
::
unpack
(
int
input
[]
){
string
unpack
(
int
*
input
){
map
<
int
,
string
>
dictionary
;
string
currentChar
,
nextChar
,
output
=
""
;
int
i
,
dictionarySize
=
256
;
int
i
,
size
,
dictionarySize
=
256
;
int
currentWord
,
nextWord
;
//inicializa o dicionário
...
...
@@ -67,7 +71,8 @@ string LZW::unpack(int input[]){
nextWord
=
input
[
0
];
output
+=
dictionary
[
nextWord
];
for
(
i
=
0
;
i
<
sizeof
(
input
)
/
sizeof
(
int
);
i
++
){
size
=
sizeof
(
input
)
/
sizeof
(
int
);
for
(
i
=
0
;
i
<
size
;
i
++
){
currentWord
=
nextWord
;
nextWord
=
input
[
i
+
1
];
if
(
dictionary
[
nextWord
]
!=
""
){
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
0 → 100644
+
70
−
0
View file @
a2a89b46
// Implementado por Eduardo Machado e Victor Perszel
// 2015
#include
"lzw.h"
using
namespace
std
;
int
main
(
int
argc
,
char
*
argv
[])
{
ifstream
fileIn
;
ofstream
fileOut
;
string
parameter
,
temp
,
nameFileIn
,
nameFileOut
,
inputPack
=
""
,
outputUnpack
;
int
*
outputPack
=
NULL
,
*
inputUnpack
,
length
;
// Leitura de parâmetros.
if
(
argc
!=
4
){
cout
<<
"Arquivo não encontrado!"
<<
endl
;
return
0
;
}
nameFileIn
=
argv
[
1
];
parameter
=
argv
[
2
];
nameFileOut
=
argv
[
3
];
if
(
parameter
==
"pack"
){
// Abertura do arquivo de entrada.
fileIn
.
open
(
nameFileIn
.
c_str
(),
ios
::
in
);
fileIn
.
seekg
(
0
);
// Leitura do arquivo.
while
(
getline
(
fileIn
,
temp
))
{
inputPack
+=
temp
+
"
\n
"
;
}
// Compactação.
pack
(
inputPack
,
outputPack
);
// Escrita no arquivo de saída.
fileOut
.
open
(
nameFileOut
.
c_str
(),
ios
::
binary
);
fileOut
<<
outputPack
;
}
else
if
(
parameter
==
"unpack"
){
// Abertura do arquivo de entrada.
fileIn
.
open
(
nameFileIn
.
c_str
(),
ios
::
binary
);
// Contagem do tamanho do arquivo.
fileIn
.
seekg
(
0
,
ios
::
end
);
length
=
fileIn
.
tellg
();
fileIn
.
seekg
(
0
,
ios
::
beg
);
// Alocação do vetor para a leitura do arquivo.
inputUnpack
=
new
int
[
length
/
4
];
// Leitura.
fileIn
.
read
((
char
*
)
inputUnpack
,
sizeof
(
inputUnpack
));
// Descompactação.
outputUnpack
=
unpack
(
inputUnpack
);
// Escrita no arquivo de saída.
fileOut
.
open
(
nameFileOut
.
c_str
(),
ios
::
out
);
fileOut
<<
outputUnpack
;
}
else
{
cout
<<
"Parâmetro inválido!"
<<
endl
;
}
// Fecha os arquivos
fileIn
.
close
();
fileOut
.
close
();
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
teste.txt
0 → 100644
+
3
−
0
View file @
a2a89b46
apenas uma frase
ou duas
apenas para testar.
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