here i have code for calculate hash value of unsigned char
#include <cstdlib>
#include <iostream>
#include<string.h>
using namespace std;
unsigned oat_hash(unsigned char *key,int len)
{
unsigned char *p=key;
unsigned h=0;
int i;
for(i=0;i<len;++i){
h+=p[i];
h+=(h<<10);
h^=(h>>6);
}
h+=(h<<3);
h^=(h>>11);
h+=(h<<15);
return h;
}
using namespace std;
int main(int argc, char *argv[])
{
unsigned char mystring[]="123456789abcdef";
unsigned char *key=&mystring[0];
int n=sizeof(mystring)/sizeof(mystring[0]);//length of mystring
cout<<oat_hash(key,n)<<endl;
//system("PAUSE");
//return EXIT_SUCCESS;
return 0;
}
name of this hash function is so called One-at-a-Time hash(by Bob Jenkins) i have one question is this little part of code correct?
int n=sizeof(mystring)/sizeof(mystring[0]);//length of mystring
because mysting has not built-in function length,i used this