test nouvelles fonctions

This commit is contained in:
Phuntsok Drak-pa 2018-06-17 04:09:25 +02:00
parent bae6d01bc8
commit 7775fec68e
8 changed files with 976 additions and 150 deletions

View File

@ -7,7 +7,7 @@ set(TGT "projet_lzw")
set(${TGT}_VERSION_MAJOR 0) set(${TGT}_VERSION_MAJOR 0)
set(${TGT}_VERSION_MINOR 1) set(${TGT}_VERSION_MINOR 1)
set(CXX_COVERAGE_COMPILE_FLAGS "-pedantic -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wfloat-equal -Wwrite-strings -Wpointer-arith -Wcast-qual -Wcast-align -Wconversion -Wsign-conversion -Wshadow -Weffc++ -Wredundant-decls -Wdouble-promotion -Winit-self -Wswitch-default -Wswitch-enum -Wundef -Winline -Wunused -Wnon-virtual-dtor -pthread") set(CXX_COVERAGE_COMPILE_FLAGS "-pedantic -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wfloat-equal -Wwrite-strings -Wpointer-arith -Wcast-qual -Wcast-align -Wshadow -Weffc++ -Wredundant-decls -Wdouble-promotion -Winit-self -Wswitch-default -Wswitch-enum -Wundef -Winline -Wunused -Wnon-virtual-dtor -Wno-conversion -pthread")
set(CMAKE_CXX_FLAGS_DEBUG "${CXX_COVERAGE_COMPILE_FLAGS} -DDebug -g -pg") set(CMAKE_CXX_FLAGS_DEBUG "${CXX_COVERAGE_COMPILE_FLAGS} -DDebug -g -pg")
set(CMAKE_CXX_FLAGS_RELEASE "${CXX_COVERAGE_COMPILE_FLAGS} -O3") set(CMAKE_CXX_FLAGS_RELEASE "${CXX_COVERAGE_COMPILE_FLAGS} -O3")

File diff suppressed because it is too large Load Diff

View File

@ -10,27 +10,86 @@
#include <string> #include <string>
#include <vector> #include <vector>
/// \brief Bat-packs the input dynamically ///////////////////////////////////////////////////////////////////////////////
// packing //
///////////////////////////////////////////////////////////////////////////////
std::vector<unsigned char> pack(const std::vector<std::uint16_t> &); std::vector<unsigned char> pack(const std::vector<std::uint16_t> &);
/// \brief Packs std::uint16_t of n bits into unsigned char std::vector<unsigned char> pack_9(std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> std::vector<std::uint16_t>::const_iterator);
pack_n(const std::vector<std::uint16_t>::const_iterator,
const std::vector<std::uint16_t>::const_iterator, const int);
/// \brief Specialization of \ref pack_n for 16bits std::vector<unsigned char> pack_10(std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> std::vector<std::uint16_t>::const_iterator,
pack_16(const std::vector<std::uint16_t>::const_iterator, std::vector<unsigned char> &);
const std::vector<std::uint16_t>::const_iterator);
std::vector<unsigned char> pack_11(std::vector<std::uint16_t>::const_iterator,
std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> &);
std::vector<unsigned char> pack_12(std::vector<std::uint16_t>::const_iterator,
std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> &);
std::vector<unsigned char> pack_13(std::vector<std::uint16_t>::const_iterator,
std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> &);
std::vector<unsigned char> pack_14(std::vector<std::uint16_t>::const_iterator,
std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> &);
std::vector<unsigned char> pack_15(std::vector<std::uint16_t>::const_iterator,
std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> &);
std::vector<unsigned char> pack_16(std::vector<std::uint16_t>::const_iterator,
std::vector<std::uint16_t>::const_iterator,
std::vector<unsigned char> &);
///////////////////////////////////////////////////////////////////////////////
// unpack //
///////////////////////////////////////////////////////////////////////////////
std::vector<std::uint16_t> unpack(std::basic_string<unsigned char> &&); std::vector<std::uint16_t> unpack(std::basic_string<unsigned char> &&);
std::vector<std::uint16_t> std::vector<std::uint16_t>
unpack_n(const std::basic_string<unsigned char>::const_iterator, unpack_9(std::basic_string<unsigned char>::const_iterator,
const std::basic_string<unsigned char>::const_iterator, const int t_n); std::basic_string<unsigned char>::const_iterator);
std::vector<std::uint16_t> std::vector<std::uint16_t>
unpack_16(const std::basic_string<unsigned char>::const_iterator, unpack_10(std::basic_string<unsigned char>::const_iterator,
const std::basic_string<unsigned char>::const_iterator); std::basic_string<unsigned char>::const_iterator,
std::vector<std::uint16_t> &);
std::vector<std::uint16_t>
unpack_11(std::basic_string<unsigned char>::const_iterator,
std::basic_string<unsigned char>::const_iterator,
std::vector<std::uint16_t> &);
std::vector<std::uint16_t>
unpack_12(std::basic_string<unsigned char>::const_iterator,
std::basic_string<unsigned char>::const_iterator,
std::vector<std::uint16_t> &);
std::vector<std::uint16_t>
unpack_13(std::basic_string<unsigned char>::const_iterator,
std::basic_string<unsigned char>::const_iterator,
std::vector<std::uint16_t> &);
std::vector<std::uint16_t>
unpack_14(std::basic_string<unsigned char>::const_iterator,
std::basic_string<unsigned char>::const_iterator,
std::vector<std::uint16_t> &);
std::vector<std::uint16_t>
unpack_15(std::basic_string<unsigned char>::const_iterator,
std::basic_string<unsigned char>::const_iterator,
std::vector<std::uint16_t> &);
std::vector<std::uint16_t>
unpack_16(std::basic_string<unsigned char>::const_iterator,
std::basic_string<unsigned char>::const_iterator,
std::vector<std::uint16_t> &);
#endif /* LZW_SRC_BITPACK_H_ */ #endif /* LZW_SRC_BITPACK_H_ */

View File

@ -15,10 +15,10 @@ int ipow(int, int);
/// \brief Recherche ou ajout de chaine dans le dictionnaire /// \brief Recherche ou ajout de chaine dans le dictionnaire
std::pair<bool, std::uint16_t> std::pair<bool, std::uint16_t>
dico(std::map<std::pair<std::uint16_t, std::uint8_t>, std::uint16_t> &, dico(std::map<std::pair<std::uint16_t, std::uint8_t>, std::uint16_t> &,
const std::uint16_t, const std::uint8_t); std::uint16_t, std::uint8_t);
std::basic_string<unsigned char> std::basic_string<unsigned char>
dico_uncompress(std::map<std::uint16_t, std::basic_string<unsigned char>> &, dico_uncompress(std::map<std::uint16_t, std::basic_string<unsigned char>> &,
const std::uint16_t, const std::uint16_t); std::uint16_t, std::uint16_t);
#endif /* LZW_SRC_COMMON_H_ */ #endif /* LZW_SRC_COMMON_H_ */

View File

@ -74,12 +74,7 @@ void compress(const std::string &t_in_file, const char *t_out_file) {
assert(input_file); assert(input_file);
FILE *const out = (t_out_file != nullptr) ? fopen(t_out_file, "wb") FILE *const out = (t_out_file != nullptr) ? fopen(t_out_file, "wb")
: fopen("output.lzw", "wb"); : fopen("output.lzw", "wb");
if (out == nullptr) { assert(out);
std::cerr << "Error at " << __FILE__ << ":" << __LINE__ - 4
<< ": could not open output file. Aborting...\n";
std::fclose(input_file);
exit(1);
}
std::fseek(input_file, 0L, SEEK_END); std::fseek(input_file, 0L, SEEK_END);
const auto file_size = static_cast<size_t>(ftell(input_file)); const auto file_size = static_cast<size_t>(ftell(input_file));

View File

@ -7,9 +7,9 @@
#define LZW_SRC_COMPRESS_H_ #define LZW_SRC_COMPRESS_H_
#include "common.hh" #include "common.hh"
#include <vector>
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <vector>
/// \brief Compression d'une chaine de caractères /// \brief Compression d'une chaine de caractères
std::vector<std::vector<std::uint16_t>> std::vector<std::vector<std::uint16_t>>

View File

@ -6,8 +6,8 @@
#ifndef LZW_SRC_IO_H_ #ifndef LZW_SRC_IO_H_
#define LZW_SRC_IO_H_ #define LZW_SRC_IO_H_
#include <cstdio>
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
@ -19,17 +19,17 @@
* *
* Un chunk se compose ainsi : * Un chunk se compose ainsi :
* nb_char_chunk : nombre de caractères du chunk (2B) * nb_char_chunk : nombre de caractères du chunk (2B)
* text* : caractères de taille char_size (ceil((char_size * nb_char_chunk) / 8)) * text* : caractères de taille char_size (ceil((char_size * nb_char_chunk) /
* 8))
* *
* Si le dernier caractère ne termine pas le dernier octet du chunk, les * Si le dernier caractère ne termine pas le dernier octet du chunk, les
* derniers bits sont mit à zéro * derniers bits sont mit à zéro
*/ */
/// \brief Écrit dans le fichier le texte compressé /// \brief Écrit dans le fichier le texte compressé
void write_file(FILE *const, const std::vector<std::vector<std::uint16_t>> &); void write_file(FILE *, const std::vector<std::vector<std::uint16_t>> &);
/// \brief Écrit un chunk dans le fichier de sortie /// \brief Écrit un chunk dans le fichier de sortie
void write_chunk(FILE *const, const std::vector<std::uint16_t> &); void write_chunk(FILE *, const std::vector<std::uint16_t> &);
#endif /* LZW_SRC_IO_H_ */ #endif /* LZW_SRC_IO_H_ */

View File

@ -5,8 +5,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
std::basic_string<unsigned char> std::basic_string<unsigned char> lzw_uncompress(std::vector<std::uint16_t> &&);
lzw_uncompress(std::vector<std::uint16_t> &&);
void uncompress(const std::string &, const char *); void uncompress(const std::string &, const char *);