Moved ipow function
This commit is contained in:
parent
f8b493de2b
commit
9f70b01886
@ -1,4 +1,5 @@
|
||||
#include "bitpack.hh"
|
||||
#include "common.hh"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
@ -8,28 +9,13 @@ using uchar = unsigned char;
|
||||
using vuint16 = vector<uint16_t>;
|
||||
using vuchar = vector<uchar>;
|
||||
|
||||
constexpr int ipow(int base, int exp) {
|
||||
int result = 1;
|
||||
for (;;) {
|
||||
if (exp & 1) {
|
||||
result *= base;
|
||||
}
|
||||
exp >>= 1;
|
||||
if (exp == 0) {
|
||||
break;
|
||||
}
|
||||
base *= base;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// packing //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
[[nodiscard]] vuchar pack(const vuint16 &t_input) {
|
||||
vuchar ret{};
|
||||
constexpr int max_value = ipow(2, 8);
|
||||
const int max_value = ipow(2, 8);
|
||||
for (auto it = t_input.begin(); it != t_input.end(); ++it) {
|
||||
if (*it >= max_value) {
|
||||
const auto next_vec =
|
||||
@ -125,7 +111,7 @@ constexpr int ipow(int base, int exp) {
|
||||
[[nodiscard]] vuint16 unpack(const vuchar &t_input) {
|
||||
vuint16 ret{};
|
||||
|
||||
constexpr int max_value = ipow(2, 8) - 1;
|
||||
const int max_value = ipow(2, 8) - 1;
|
||||
|
||||
// begin with 8bits
|
||||
for (auto it = t_input.begin(); it != t_input.end(); ++it) {
|
||||
|
@ -11,6 +11,21 @@ using dic_comp_t = std::map<std::pair<uint16_t, uint8_t>, uint16_t>;
|
||||
using dic_un_t = std::map<std::uint16_t, std::unique_ptr<std::pair<uint16_t, uint8_t>>>;
|
||||
using ustring = std::basic_string<unsigned char>;
|
||||
|
||||
int ipow(int base, int exp) {
|
||||
int result = 1;
|
||||
for (;;) {
|
||||
if (exp & 1) {
|
||||
result *= base;
|
||||
}
|
||||
exp >>= 1;
|
||||
if (exp == 0) {
|
||||
break;
|
||||
}
|
||||
base *= base;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction a pour double usage la recherche d’une chaine de caractères
|
||||
* dans le dictionnaire, ou bien l’ajout d’une nouvelle chaîne si celle-ci n’est
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
int ipow(int, int);
|
||||
|
||||
/// \brief Recherche ou ajout de chaine dans le dictionnaire
|
||||
std::pair<bool, std::uint16_t>
|
||||
dico(std::map<std::pair<std::uint16_t, std::uint8_t>, std::uint16_t> &,
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "compress.hh"
|
||||
#include "io.hh"
|
||||
#include "common.hh"
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
@ -19,22 +20,7 @@ using std::string;
|
||||
using dict_t = std::map<std::pair<uint16_t, uint8_t>, uint16_t>;
|
||||
using std::printf;
|
||||
|
||||
constexpr int ipow(int base, int exp) {
|
||||
int result = 1;
|
||||
for (;;) {
|
||||
if (exp & 1) {
|
||||
result *= base;
|
||||
}
|
||||
exp >>= 1;
|
||||
if (exp == 0) {
|
||||
break;
|
||||
}
|
||||
base *= base;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
constexpr size_t DICT_MAX = ipow(2, 13) - 256; /* 12 bits */
|
||||
const size_t DICT_MAX = static_cast<size_t>(ipow(2, 17) - 256); /* 16 bits */
|
||||
|
||||
/**
|
||||
* La chaîne de caractères \p t_text est lue caractère par caractère, et est
|
||||
|
Loading…
Reference in New Issue
Block a user