-
Notifications
You must be signed in to change notification settings - Fork 0
/
rehash_double.cpp
84 lines (72 loc) · 1.19 KB
/
rehash_double.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
#include<iostream>
using namespace std;
int key(int val,int h){
return val%h;
}
int getPrime(int h){
int i,j;int *ar=new int();int count=0;
int k;
for(k=0,i=2;i<=h;i++){
count=0;
for(j=2;j<=i;j++){
if(i%j==0){
++count;
}
}
if(count<=1){
ar[k]=i;
++k;
}
}
for(i=0;i<k;i++)
cout<<"primes are\n"<<ar[i]<<"\n";
return ar[k-1];
}
void double(int hs,int prime,int *A[],){
}
int main(){
int has=0;
cout<<"Enter hash size:";
cin>>has;
int i,j,k;int prime=getPrime(has);
cout<<"\nhere "<<prime<<"\n";
// cout<<"\nenter hash size\n";
// cin>>hs;
int arr[has];int count=0;
for(i=0;i<has;i++)
arr[i]=0;
// int data[]={89,18,49,58,69,55,3,98};
int *data=new int();
int I;int q=prime;int temp=0;int t=0;int choice;
cout<<"\nInput Data\n";i=0;
do{
cin>>data[i];
i++;
temp++;
cout<<"\nwant more:1/0\n";
cin>>choice;
}while(choice);
float LF=temp/has;
if(LF<0.5){
for(i=0;i<temp;i++){
q=prime;
I=key(data[i],has);
if(arr[I]==0)
arr[I]=data[i];
else{
while(arr[I]!=0){
q=q-(data[i]%q);
I=((I+q)%has)%has;
}
arr[I]=data[i];
}
}
}
else{
has*=2;
}
for(i=0;i<has;i++)
cout<<"\n"<<arr[i]<<"\n";
getchar();
return 0;
}