-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhashFunctionMatrix.cpp
49 lines (40 loc) · 1.17 KB
/
hashFunctionMatrix.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
#include "hashFunctionMatrix.h"
#include "psedoRandomNumbers.h"
#include "generalFunctions.h"
#include <cmath>
HashFunctionMatrix::HashFunctionMatrix(int X1, int X2, double DistX1X2):x1(X1), x2(X2), distX1X2(DistX1X2)
{
}
HashFunctionMatrix::~HashFunctionMatrix()
{
}
bool HashFunctionMatrix::value(MatrixPoint* key)
{
return (dCalculation(key) >= median);
}
double HashFunctionMatrix::dCalculation(MatrixPoint* key)
{
return (pow(key->get_distance(x1), 2)+pow(key->get_distance(x2), 2) - pow(distX1X2, 2))/(2*distX1X2); //ypologizei thn timh ths h
}
void HashFunctionMatrix::setMedian(double medianValue)
{
median = medianValue;
}
double median(double* anArray, int no)
{
NodeDistance<char>* sortedArray = new NodeDistance<char>[no]; //create array for qicksort
for(int i =0; i < no; i++)
{
sortedArray[i].dist = anArray[i];
}
quickSort(sortedArray, 0, no-1);
if(no%2==0) //artios
{
return (sortedArray[no/2].dist+sortedArray[no/2-1].dist)/2; //pairnoume ta dyo mesaia kai vriskoume mesw oro
}
else //perittos
{
return sortedArray[(no/2)].dist; //pairnoume to mesaio
}
delete[]sortedArray;
}