OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-CompactHash commits / 3a9bd7c

Merging in changes
3a9bd7c5eae00e5b985fb628bfcbd290b82dea2c
by brobey <brobey@lanl.gov> · 2015-10-21T20:19:52.000Z

Changed files (2) +26 -18

simplehash/simplehash.c +13 -14
……@@ -30,6 +30,8 @@
3030 * This is LANL Copyright Disclosure C14043/LA-CC-14-003
3131 */
3232
33#include <stdio.h>
34#include <stdlib.h>
3335#include "simplehash.h"
3436//#include "timer/timer.h"
3537
……@@ -47,16 +49,13 @@ static uint write_hash_collisions_count = 0;
4749static uint read_hash_collisions_count = 0;
4850static uint hash_report_level = 0;
4951static uint hash_queries;
50static uint hash_method = 1;
52static uint hash_method = QUADRATIC;
5153static uint hash_jump_prime = 41;
5254static double hash_mult = 3.0;
5355static int do_compact_hash = 0;
5456
5557float mem_opt_factor;
5658
57void compact_hash_delete(int *hash){
58 free(hash);
59}
6059
6160int (*read_hash)(ulong, int *);
6261void (*write_hash)(uint, ulong, int *);
……@@ -78,7 +77,6 @@ long long get_hashtablesize(void) {
7877}
7978
8079int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){
81
8280 hash_ncells = 0;
8381 write_hash_collisions = 0;
8482 read_hash_collisions = 0;
……@@ -126,7 +124,7 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){
126124 if (! do_compact_hash) {
127125 read_hash = read_hash_perfect;
128126 write_hash = write_hash_perfect;
129 } else if (hash_method == 0){
127 } else if (hash_method == LINEAR){
130128 if (hash_report_level == 0){
131129 read_hash = read_hash_linear;
132130 write_hash = write_hash_linear;
……@@ -140,7 +138,7 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){
140138 read_hash = read_hash_linear_report_level_3;
141139 write_hash = write_hash_linear_report_level_3;
142140 }
143 } else if (hash_method == 1){
141 } else if (hash_method == QUADRATIC){
144142 if (hash_report_level == 0){
145143 read_hash = read_hash_quadratic;
146144 write_hash = write_hash_quadratic;
……@@ -154,7 +152,7 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){
154152 read_hash = read_hash_quadratic_report_level_3;
155153 write_hash = write_hash_quadratic_report_level_3;
156154 }
157 } else if (hash_method == 2){
155 } else if (hash_method == PRIME_JUMP){
158156 if (hash_report_level == 0){
159157 read_hash = read_hash_primejump;
160158 write_hash = write_hash_primejump;
……@@ -187,7 +185,6 @@ void write_hash_linear(uint ic, ulong hashkey, int *hash){
187185}
188186
189187void write_hash_linear_report_level_1(uint ic, ulong hashkey, int *hash){
190 int icount = 0;
191188 uint hashloc;
192189
193190 hash_ncells++;
……@@ -200,7 +197,6 @@ void write_hash_linear_report_level_1(uint ic, ulong hashkey, int *hash){
200197}
201198
202199void write_hash_linear_report_level_2(uint ic, ulong hashkey, int *hash){
203 int icount = 0;
204200 uint hashloc;
205201
206202 hash_ncells++;
……@@ -1109,16 +1105,19 @@ int read_hash_primejump_report_level_3(ulong hashkey, int *hash){
11091105 return(hashval);
11101106}
11111107
1108void compact_hash_delete(int *hash){
1109 free(hash);
1110}
11121111int read_dev_hash(int hash_method, ulong hashtablesize, ulong AA, ulong BB, ulong hashkey, int *hash){
11131112 //int hash_report_level = 3;
11141113 int max_collisions_allowed = 1000;
11151114 int hashval = -1;
11161115 uint hashloc;
11171116 int icount=0;
1118 if (hash_method == -1) {
1117 if (hash_method == PERFECT_HASH) {
11191118 return(hash[hashkey]);
11201119 }
1121 if (hash_method == 0) {
1120 if (hash_method == LINEAR) {
11221121 if (hash_report_level == 0) {
11231122 for (hashloc = (hashkey*AA+BB)%prime%hashtablesize; hash[2*hashloc] != (int)hashkey && hash[2*hashloc] != -1; hashloc++,hashloc = hashloc%hashtablesize){
11241123 icount++;
……@@ -1155,7 +1154,7 @@ int read_dev_hash(int hash_method, ulong hashtablesize, ulong AA, ulong BB, ulon
11551154 }
11561155 read_hash_collisions += icount;
11571156 }
1158 } else if (hash_method == 1) {
1157 } else if (hash_method == QUADRATIC) {
11591158 if (hash_report_level == 0) {
11601159 for (hashloc = (hashkey*AA+BB)%prime%hashtablesize; hash[2*hashloc] != (int)hashkey && hash[2*hashloc] != -1; hashloc+=(icount*icount),hashloc = hashloc%hashtablesize){
11611160 icount++;
……@@ -1192,7 +1191,7 @@ int read_dev_hash(int hash_method, ulong hashtablesize, ulong AA, ulong BB, ulon
11921191 }
11931192 read_hash_collisions += icount;
11941193 }
1195 } else if (hash_method == 2) {
1194 } else if (hash_method == PRIME_JUMP) {
11961195 uint jump = 1+hashkey%hash_jump_prime;
11971196 if (hash_report_level == 0) {
11981197 for (hashloc = (hashkey*AA+BB)%prime%hashtablesize; hash[2*hashloc] != (int)hashkey && hash[2*hashloc] != -1; hashloc+=(icount*jump),hashloc = hashloc%hashtablesize){
simplehash/simplehash.h +13 -4
……@@ -30,11 +30,20 @@
3030 * This is LANL Copyright Disclosure C14043/LA-CC-14-003
3131 */
3232
33#ifndef _HASH_H
34#define _HASH_H
33#ifndef _SIMPLEHASH_H
34#define _SIMPLEHASH_H
3535
36#include <stdio.h>
37#include <stdlib.h>
36#ifdef _OPENMP
37#include <omp.h>
38#endif
39
40
41enum choose_hash_method
42{ METHOD_UNSET = 0, // use 0 for no method set
43 PERFECT_HASH, // perfect hash 1
44 LINEAR, // linear hash 2
45 QUADRATIC, // quadratic hash 3
46 PRIME_JUMP }; // prime_jump hash 4
3847
3948#ifdef __cplusplus
4049extern "C"