some style improvement

This commit is contained in:
Phuntsok Drak-pa 2018-05-23 16:27:54 +02:00
parent 7c2ea0477a
commit 34399b9b93
3 changed files with 10 additions and 8 deletions

View File

@ -30,10 +30,11 @@ using dic_t = std::map<std::pair<uint32_t, uint8_t>, uint32_t>;
const std::pair<bool, uint32_t> const std::pair<bool, uint32_t>
dico(std::map<std::pair<uint32_t, uint8_t>, uint32_t> &t_dictionary, dico(std::map<std::pair<uint32_t, uint8_t>, uint32_t> &t_dictionary,
uint32_t t_nr_chaine, uint8_t t_c) { uint32_t t_nr_chaine, uint8_t t_c) {
if (t_nr_chaine == 0xFFFF) if (t_nr_chaine == 0xFFFF) {
return std::make_pair(true, t_c); return std::make_pair(true, t_c);
}
auto &e = t_dictionary[std::make_pair(t_nr_chaine, t_c)]; auto &e = t_dictionary[std::make_pair(t_nr_chaine, t_c)];
return (e) ? std::make_pair(true, e) return (e != 0) ? std::make_pair(true, e)
: std::make_pair( : std::make_pair(
false, false,
(e = static_cast< (e = static_cast<

View File

@ -92,8 +92,8 @@ void compress(const std::string &t_in_file, const char *t_out_file) {
// Fichier de sortie // Fichier de sortie
FILE *out = FILE *out =
(t_out_file) ? fopen(t_out_file, "wb") : fopen("output.lzw", "wb"); (t_out_file != nullptr) ? fopen(t_out_file, "wb") : fopen("output.lzw", "wb");
if (!out) { if (out == nullptr) {
std::cerr << "Error at " << __FILE__ << ":" << __LINE__ - 4 std::cerr << "Error at " << __FILE__ << ":" << __LINE__ - 4
<< ": could not open output file. Aborting...\n"; << ": could not open output file. Aborting...\n";
input_file.close(); input_file.close();
@ -132,8 +132,9 @@ void compress(const std::string &t_in_file, const char *t_out_file) {
chunk.reserve(static_cast<size_t>(input_file.tellg() - prev_pos)); chunk.reserve(static_cast<size_t>(input_file.tellg() - prev_pos));
input_file.seekg(prev_pos, std::ios::beg); input_file.seekg(prev_pos, std::ios::beg);
std::istreambuf_iterator<char> itr(input_file); std::istreambuf_iterator<char> itr(input_file);
for (std::streamoff i = 0; i < prev_pos; ++i, ++itr) for (std::streamoff i = 0; i < prev_pos; ++i, ++itr){
; ;
}
chunk.assign((itr), std::istreambuf_iterator<char>()); chunk.assign((itr), std::istreambuf_iterator<char>());
} }
uvec ret{}; uvec ret{};

View File

@ -54,7 +54,6 @@ void help() {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if constexpr (debug_mode) { if constexpr (debug_mode) {
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
printf("argv[%d] = %s\n", i, argv[i]); printf("argv[%d] = %s\n", i, argv[i]);
@ -151,7 +150,7 @@ int main(int argc, char *argv[]) {
if constexpr (debug_mode) { if constexpr (debug_mode) {
puts("Beginning compression"); puts("Beginning compression");
} }
if(output_path.empty()) { if (output_path.empty()) {
compress(input_path, nullptr); compress(input_path, nullptr);
} else { } else {
compress(input_path, output_path.c_str()); compress(input_path, output_path.c_str());
@ -160,7 +159,8 @@ int main(int argc, char *argv[]) {
} else { } else {
puts("Not yet implemented :("); puts("Not yet implemented :(");
/* /*
Inversion des types du dictionnaire pour retrouver les chaînes plus aisément Inversion des types du dictionnaire pour retrouver les chaînes plus
aisément
*/ */
} }