-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGhash.cpp
114 lines (83 loc) · 2.36 KB
/
Ghash.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <time.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include "Ghash.hpp"
#define HAMMING 1
#define EUCLIDIAN 2
#define COSINE 3
using namespace std;
bool valueExists(int valueToSearch, int** arrayToSearch, int k, int L) {
int i, j;
for (i = 0; i < L; i++) {
for (j = 0; j < (2 ^ k); j++) {
if (arrayToSearch[i][j] == valueToSearch) {
return true;
}
}
}
return false;
}
int H(int metricSpaceId, int fileLines) {
if (metricSpaceId == HAMMING) {
const unsigned int h = (rand() % fileLines) + 1;
return h;
}
return -1;
}
int H(int metricSpaceId) {
if (metricSpaceId == EUCLIDIAN) {
double x = ((rand() % 99999) + 1) / 100000;
double y = ((rand() % 99999) + 1) / 100000;
// -------------------------------------
x = ((rand() % 99999) + 1) / 100000;
y = ((rand() % 99999) + 1) / 100000;
// -------------------------------------
const double z = ((rand() % 99999) + 1) / 100000;
const double p = x / z;
const int w = 4;
const int t = ((rand() % (w * 10000))) / 10000; // 0 - 3.999
const double n = sqrt((x * x) + (y * y));
// -------------------------------------
const int h = ((p * n) + t) / w;
return h;
}
else if (metricSpaceId == COSINE) {
}
return 0;
}
int** G(int k, int L, int fileLines, int metricSpaceId) {
int i, j;
int** array = new int*[L];
for (i = 0; i < (2 ^ k); i++)
array[i] = new int[(2 ^ k)];
// ---------------------------
for (i = 0; i < L; i++) {
for (j = 0; j < (2 ^ k); j++) {
int value = H(metricSpaceId, fileLines);
while (valueExists(value, array, k, L)) {
value = H(metricSpaceId, fileLines);
}
array[i][j] = value;
}
}
return array;
}
int** G(int k, int L, int metricSpaceId) {
int i, j;
int** array = new int*[L];
for (i = 0; i < (2 ^ k); i++)
array[i] = new int[(2 ^ k)];
// ---------------------------
for (i = 0; i < L; i++) {
for (j = 0; j < (2 ^ k); j++) {
int value = H(metricSpaceId);
while (valueExists(value, array, k, L)) {
value = H(metricSpaceId);
}
array[i][j] = value;
}
}
return array;
}