PandA-2024.02
hash.c
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #define SIZE 500
4 #include "hash.h"
5 
6 //#define PRINT_RESULT
7 //#define CHECK_COLLISION
8 //#define CHECK_RESULT
9 
14 
15 #define BINSIZE 500
16 
17 int hash1()
18 {
19  int result[BINSIZE] = {0};
20  int i, a, collision=0;
21  for (i=0; i<SIZE; i++) {
22  a = input[i];
23  a = (a+0x7ed55d16) + (a<<12);
24  a = (a^0xc761c23c) ^ (a>>19);
25  a = (a+0x165667b1) + (a<<5);
26  a = (a+0xd3a2646c) ^ (a<<9);
27  a = (a+0xfd7046c5) + (a<<3);
28  a = (a^0xb55a4f09) ^ (a>>16);
29  a = (a<0) ? -1*a : a;
30  int hash = a%BINSIZE;
31  int temp = result[hash]++;
32  collision = (temp!=0) ? collision+1 : collision;
33  }
34  return collision;
35 }
36 
37 int hash2()
38 {
39  int result[BINSIZE] = {0};
40  int i, a, collision=0;
41  for (i=0; i<SIZE; i++) {
42  a = input[i];
43  a -= (a<<6);
44  a ^= (a>>17);
45  a -= (a<<9);
46  a ^= (a<<4);
47  a -= (a<<3);
48  a ^= (a<<10);
49  a ^= (a>>15);
50  a = (a<0) ? -1*a : a;
51  int hash = a%BINSIZE;
52  int temp = result[hash]++;
53  collision = (temp!=0) ? collision+1 : collision;
54  }
55  return collision;
56 }
57 
58 int hash3() {
59  int result[BINSIZE] = {0};
60  int i, a, collision=0;
61  for (i=0; i<SIZE; i++) {
62  a = input[i];
63  a = (a ^ 61) ^ (a >> 16);
64  a = a + (a << 3);
65  a = a ^ (a >> 4);
66  a = a * 0x27d4eb2d;
67  a = a ^ (a >> 15);
68  a = (a<0) ? -1*a : a;
69  int hash = a%BINSIZE;
70  int temp = result[hash]++;
71  collision = (temp!=0) ? collision+1 : collision;
72  }
73  return collision;
74 }
75 
76 int hash4()
77 {
78  int result[BINSIZE] = {0};
79  int i, a, collision=0;
80  for (i=0; i<SIZE; i++) {
81  a = input[i];
82  a = (a+0x479ab41d) + (a<<8);
83  a = (a^0xe4aa10ce) ^ (a>>5);
84  a = (a+0x9942f0a6) - (a<<14);
85  a = (a^0x5aedd67d) ^ (a>>3);
86  a = (a+0x17bea992) + (a<<7);
87  a = (a<0) ? -1*a : a;
88  int hash = a%BINSIZE;
89  int temp = result[hash]++;
90  collision = (temp!=0) ? collision+1 : collision;
91  }
92  return collision;
93 }
94 
95 #define CHECK_RESULT
96 int main(int argc, char ** argv) {
97  int i;
98  int collisions[4] = {0};
99  int (*hash[4])() = {hash1, hash2, hash3, hash4};
100 #pragma omp parallel for
101  for (i = 0; i < 4; i++)
102  collisions[i] = hash[i]();
103  int count=0;
104  count += (collisions[0] == 178);
105  count += (collisions[1] == 182);
106  count += (collisions[2] == 196);
107  count += (collisions[3] == 179);
108  printf("result = %d\n", count);
109  if (count == 4) {
110  printf("PASS\n");
111  }
112  else {
113  printf("FAIL\n");
114  }
115  return 0;
116 }
int input[SIZE]
Definition: hash.h:1
#define BINSIZE
Definition: hash.c:15
int result4[SIZE]
Definition: hash.c:13
#define SIZE
Definition: hash.c:3
int hash1()
Definition: hash.c:17
int main(int argc, char **argv)
Definition: hash.c:96
int hash4()
Definition: hash.c:76
int result2[SIZE]
Definition: hash.c:11
int result[SIZE]
Definition: adpcm.c:800
int result1[SIZE]
Definition: hash.c:10
int hash3()
Definition: hash.c:58
int result3[SIZE]
Definition: hash.c:12
int hash2()
Definition: hash.c:37

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13