• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

anyone want to help me with a hashing function?

AznMaverick

Platinum Member
basically, i need a function that will come up with 32 unique hashes for 32 words. these words are: auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.

the program that i am using to try and find values for my hash function looks like this...

#include <stdio.h>
#include <stdlib.h>

void read(void);
void compare(void);
int Hash(int key);
int exp(int base, int exponent);

char string[1023];
int max_entry;
int hash[255];
int bingo;
int step;
int exp_inc;

main() {
int i;

max_entry = 0;
string[0] = 0;
bingo = 0;
step=1;
exp_inc=2;

read();

printf("\nEntered is: ");
for(i=0; i<max_entry; i++)
printf("%c", string);
printf("MAX ENTRY is %d", max_entry);
printf("\n\n\n");

while(!bingo) {
Hash(1);
compare();
}

printf("\nHash values are: ");
for(i=0; i<32; i++)
printf(" %d ", hash);
printf("\nStep is %d\n", step);
printf("exp_inc is %d", exp_inc);
printf("\n\n\n");
}

int Hash(int key) {
int i = 0;
int number = 1;
int count = 0;

step++;
for(i=0; i<max_entry; i++) {
if(string=='\n') {
if(number < 1) number = number * -1;
hash[count] = number % 32;
// printf("\nHASH is %d\n", hash[count]);
number=1;
exp_inc=1;
i++;
count++;
}
// number = number + ((step)* string);
number = number + ((exp(step, exp_inc)) * string);
exp_inc+3;
}
//exp_inc++;
return step;

}

void compare(void) {
int i;
int j;
int increment = 1;
int track;

for(i=0; i<32; i++) {
for(j=increment; j<32; j++)
if(hash==hash[j]) {
// printf("\n%d is the same.", hash);
bingo = 0;
return;
}
increment++;
}

bingo=1;
return;
}
int exp(int base, int exponent) {
int i;
int number = 1;

for(i=0; i< exponent; i++)
number = number * base;

return number;
}
void read(void) {
char entry;
int i;
i=0;
while((entry = getchar()) != EOF) {
string = entry;
printf("%c", string);
i++;
}

max_entry = i;

return;
}


basically, what it will do is keep going in a loop until the hash function comes up with a unique set of hash values for each word. Any other suggestions?
 
Back
Top