J
jacob navia
Moi a écrit :
The hash table container will be designed as a general hash table with a key
of arbitrary binary data. The dictionary container is a "light" version of it
that associates text keys with arbitrary data. The hash table container will have
automatic resizing and all the needed features of a general hash table. I am
still working on it.
Can you elaborate? Why is "awkward"?
It should make the hash code independent of the character frequency.
But you access the characters as "unsigned char". How can there be ajacob navia said:Ben Pfaff a écrit :
Errors: None. Note that this function will NOT work for
signed characters. The input MUST be unsigned
------------------------------------------------------------------------*/
static unsigned hash(unsigned char *str) {
unsigned int h = scatter[*str];
str++;
while(*str) {
h = (h >> 1) ^ scatter[*str++];
}
return h;
}
Why will this function not work for signed characters?
because if the character is negative, the indexing of the array will
not work OK.
problem, then?
The (unsigned char *) argument is strange.
It will force you to cast the arguments to this function *on every call*
An easier way would be to use a (void*) argument and cast it to
(unsigned char*) *inside the function*
For hashfunctions I normally use the form
****/
unsigned hash_da_thing(void * ptr, size_t siz)
{
unsigned hash;
unsigned char * cp= ptr;
if (!siz) siz = strlen(cp);
for(hash=0 ; siz>0; )
{ ... }
...
return hash;
}
****/
The hash table container will be designed as a general hash table with a key
of arbitrary binary data. The dictionary container is a "light" version of it
that associates text keys with arbitrary data. The hash table container will have
automatic resizing and all the needed features of a general hash table. I am
still working on it.
; this will allow non-string to be hashed, by providing a non-null size;
(plus: add some "const" ;-)
I think the Zobrist hashing is awkward, too.
Can you elaborate? Why is "awkward"?
It should make the hash code independent of the character frequency.