6 namespace tdc {
namespace lz78 {
14 inline uint64_t
hash(uint64_t key)
const {
19 return (hash * _aInv) %
_prime;
25 uint64_t getModInverse(uint64_t a, uint64_t prime);
27 uint64_t nextPrimeNumber(uint64_t inputNumber);
29 bool isPrime(uint64_t input);
31 void euclAlgorithm(uint64_t prime);
33 uint64_t _universeSize;
40 :
_prime(nextPrimeNumber(universeSize - 1)) {
41 _universeSize = universeSize;
55 uint64_t Randomizer::nextPrimeNumber(uint64_t inputNumber) {
56 uint64_t nextPrimeNumber;
57 if (inputNumber <= 0) {
58 std::cout <<
"The number you have entered is zero or negative.\n";
60 while (inputNumber != 0) {
61 nextPrimeNumber = inputNumber + 1;
62 if (nextPrimeNumber % 2 == 0 && nextPrimeNumber != 2) {
65 while (!isPrime(nextPrimeNumber)) {
68 if (isPrime(nextPrimeNumber))
69 return nextPrimeNumber;
72 return nextPrimeNumber;
78 bool Randomizer::isPrime(uint64_t input) {
86 if (input % 2 == 0 || input <= 1) {
89 for (i = 3; i <= sqrt(input); i += 2) {
100 uint64_t Randomizer::getModInverse(uint64_t a, uint64_t prime) {
102 for (uint64_t x = 1; x < prime; x++)
103 if ((a * x) % prime == 1)
108 void Randomizer::euclAlgorithm(uint64_t prime) {
109 long long aTemp = (
long long) (0.66 * (
double) prime);
110 long long aInvTemp = prime;
112 aInvTemp = getModInverse(aTemp, prime);
113 if (aInvTemp == prime)
Contains the text compression and encoding framework.
Randomizer(uint64_t universeSize)
uint64_t hash(uint64_t key) const
uint64_t invertHash(uint64_t hash) const