Skip to content

Commit

Permalink
hash function implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
themisvr committed Oct 6, 2020
1 parent b298915 commit 8f6def9
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
Binary file added datasets/t10k-images-idx3-ubyte
Binary file not shown.
Empty file removed datasets/test_input_data
Empty file.
Binary file added datasets/train-images-idx3-ubyte
Binary file not shown.
77 changes: 77 additions & 0 deletions include/hash_function/hash_function.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#pragma once

#include <vector>
#include <algorithm>
#include <random>
#include <cmath>

#include "../math_utils/math_utils.h"


namespace hash {

template <typename T>
class HashFunction {

/*
params:
*/
private:
const uint16_t d;
const uint32_t m;
const uint32_t M;
const double w;
std::vector<double> s_transformations;
std::vector<double> a;

public:

HashFunction( const uint16_t &d, const uint32_t &m, const uint32_t &M,
const uint32_t &w) : d(d), m(m), M(M), w(w), s_transformations(d), a(d) {

std::default_random_engine generator;
std::uniform_real_distribution<double> distribution(0.0, w);

for (size_t i = 0; i != d; ++i) {
s_transformations[i] = distribution(generator);
}
}

~HashFunction() = default;

uint32_t hf_construction(std::vector<double> &pixels) {
uint32_t hash_value = 0;

for (size_t i = 0; i != d; ++i) {
a[i] = floor((pixels[i] - s[i]) / w)
}

std::reverse(a.begin(), a.end());

for (size_t i = 0; i != d; ++i) {
hash_value += (math_utils::modulo(a[i], i) * math_utils::exp_modulo(m, i, M)) % M;
}

return hash_value % M;
}

};


template <typename T>
class AmplifiedFunction {

private:




public:



};


}
26 changes: 26 additions & 0 deletions include/math_utils/math_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once



namespace math_utils {

inline uint32_t exp_modulo(uint32_t base, uint16_t exp, uint32_t mod) {
uint32_t res = 1;

base %= mod;
if (base == 0) return 0;

while (exp > 0) {
if (exp & 1) { res = (res * base) % mod; }
exp >>= 1;
base = (base * base) % mod;
}
return res;
}

inline uint32_t modulo(int i, uint32_t n) {
return ((i % n) + n) % n;
}


}
Empty file removed include/test.h
Empty file.
Empty file removed include/utils/utils.h
Empty file.

0 comments on commit 8f6def9

Please sign in to comment.