-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoubleHashing.java
58 lines (36 loc) · 1.06 KB
/
doubleHashing.java
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
import java.util.Arrays;
public class doubleHashing {
public static void main(String args[]){
int arr[] = { 20,34,45,70,56,41,13};
int N = 7;
int L = 11;
int[] hash_code = new int[11];
for(int i=0; i<L; i++){
hash_code[i] = -1;
}
hashing(hash_code, L, arr, N);
}
static void hashing(int table[], int tsize, int arr[], int N){
for(int i=0; i<N; i++){
int hv = arr[i] % tsize;
if(table[hv] == -1){
table[hv] = arr[i];
}
else
{
for(int j =0; j<tsize; j++ ){
int t = 7 - (arr[i] % 7);
int in = (hv + j*t) % tsize;
if(table[in] == -1){
table[in] = arr[i];
break;
}
}
}
}
printArray(table);
}
static void printArray(int arr[]){
System.out.println(Arrays.toString(arr));
}
}