Parallel version, 3 seconds
This commit is contained in:
parent
971acfe372
commit
296f78b404
60
main.cpp
60
main.cpp
@ -10,9 +10,9 @@
|
||||
* \param my_string
|
||||
* \return
|
||||
*/
|
||||
boost::crc_32_type::value_type getCrc32(const std::string_view my_string) {
|
||||
boost::crc_32_type::value_type getCrc32(const char *__restrict__ const my_string, const std::size_t size) {
|
||||
boost::crc_32_type result;
|
||||
result.process_bytes(my_string.data(), my_string.length());
|
||||
result.process_bytes(my_string, size);
|
||||
return result.checksum();
|
||||
}
|
||||
|
||||
@ -77,30 +77,13 @@ struct NumberBase26 final {
|
||||
|
||||
~NumberBase26() noexcept = default;
|
||||
|
||||
/**
|
||||
* \brief Cela permet d'incrémenter le nombre.
|
||||
* \return
|
||||
*/
|
||||
NumberBase26 &operator++() {
|
||||
std::uint32_t number{ lut.at(data.back()) + 1 }; // C'est là où se trouve l'incrémentation
|
||||
/*
|
||||
* Tant que la retenue se propage à travers les digit, il faut les mettre à 'A' et
|
||||
* poursuivre jusqu'à rencontrer un caractère != 'Z'
|
||||
*/
|
||||
for (std::size_t i = data.size() - 1; 0 <= i; --i) {
|
||||
if (retenue) {
|
||||
number = lut.at(data[i]) + 1;
|
||||
void operator()(std::size_t n) noexcept {
|
||||
for (size_t i = data.size() - 1; 0 <= i; --i) {
|
||||
if (n == 0)
|
||||
return;
|
||||
data[i] = alphabet[n % valMax];
|
||||
n /= valMax;
|
||||
}
|
||||
if (number == valMax) {
|
||||
data[i] = 'A';
|
||||
retenue = true;
|
||||
} else {
|
||||
data[i] = alphabet[number];
|
||||
retenue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const NumberBase26 &number_base_26) {
|
||||
@ -108,9 +91,6 @@ struct NumberBase26 final {
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
//! Signifie la présence d'une retenue.
|
||||
bool retenue{ false };
|
||||
};
|
||||
|
||||
int main() {
|
||||
@ -234,30 +214,20 @@ int main() {
|
||||
constexpr std::size_t maxDig = maxDigits(maxCompute);
|
||||
|
||||
NumberBase26<maxDig> number_base_26{ alphabet };
|
||||
std::vector<std::size_t> crcs;
|
||||
std::vector<char> results;
|
||||
results.reserve(maxDig * maxCompute);
|
||||
crcs.reserve(maxCompute);
|
||||
|
||||
const double start = omp_get_wtime();
|
||||
for (size_t i = 0; i < maxCompute; ++i, ++number_base_26) {
|
||||
const auto crc = ~(getCrc32(std::string_view{ number_base_26.data.data(), maxDig }));
|
||||
#pragma omp parallel for firstprivate(number_base_26)
|
||||
for (size_t i = 0; i < maxCompute; ++i) {
|
||||
number_base_26(i);
|
||||
const auto crc = ~(getCrc32(number_base_26.data.data(), number_base_26.data.size()));
|
||||
if (std::find(cheat_list.cbegin(), cheat_list.cend(), crc) != cheat_list.cend()) {
|
||||
crcs.emplace_back(crc);
|
||||
for (const char &j : number_base_26.data) {
|
||||
results.emplace_back(j);
|
||||
#pragma omp critical
|
||||
{
|
||||
std::cout << number_base_26 << " : 0x" << std::hex << crc << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
const double stop = omp_get_wtime();
|
||||
crcs.shrink_to_fit();
|
||||
results.shrink_to_fit();
|
||||
for (size_t i = 0; i < crcs.size(); ++i) {
|
||||
for (size_t j = 0; j < maxDig; ++j) {
|
||||
std::cout << results[i * maxDig + j];
|
||||
}
|
||||
std::cout << " : 0x" << std::hex << crcs[i] << '\n';
|
||||
}
|
||||
std::cout << "Temps : " << stop - start << 's' << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user