Move blocklenght lookup table to Bases.h

This commit is contained in:
Leonetienne 2022-05-27 03:27:43 +02:00
parent 407c0ad5bc
commit 6834ea4ad8
No known key found for this signature in database
GPG Key ID: C33879CD92E9708C
2 changed files with 20 additions and 23 deletions

View File

@ -1,6 +1,26 @@
#pragma once
#include <vector>
#include <string>
#include <map>
// This lookup table holds how many digits a block is long
// in any iobase.
// This cannot be calculated on the fly, as it involves
// arithmetic with involving REALLY big numbers (like, 2^512).
// Here's how to calculate these numbers:
// Print an all 1's block in this format, and check the string size.
// That's it.
auto blockLengthByBase =
std::map<Configuration::IOBASE_FORMAT, std::size_t>({
std::make_pair(Configuration::IOBASE_FORMAT::BASE_BYTES, 64),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_2, 512),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_8, 171),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_10, 155),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_16, 128),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_64, 86),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_UWU, 125),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_UGH, 125)
});
// Actually useful bases
static const std::vector<std::string> BASE_2 = { "0","1" };

View File

@ -3,34 +3,11 @@
#include <GeneralUtility/BaseConversion.h>
#include <StringTools/StringTools.h>
#include <GCrypt/Util.h>
#include <map>
#include <iostream>
using namespace Leonetienne::GCrypt;
using namespace Leonetienne::StringTools;
using namespace Leonetienne::GeneralUtility;
namespace {
// This lookup table holds how many digits a block is long
// in any iobase.
// This cannot be calculated on the fly, as it involves
// arithmetic with involving REALLY big numbers (like, 2^512).
// Here's how to calculate these numbers:
// Print an all 1's block in this format, and check the string size.
// That's it.
auto blockLengthByBase =
std::map<Configuration::IOBASE_FORMAT, std::size_t>({
std::make_pair(Configuration::IOBASE_FORMAT::BASE_BYTES, 64),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_2, 512),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_8, 171),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_10, 155),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_16, 128),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_64, 86),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_UWU, 125),
std::make_pair(Configuration::IOBASE_FORMAT::BASE_UGH, 125)
});
}
std::string ModuleDataFormatter::FormatBlock(
const Block& block,
const Configuration::IOBASE_FORMAT base