Coda File System

Re: Dir entry XX, should be in hash bucket X

From: Troy Benjegerdes <hozer_at_hozed.org>
Date: Wed, 1 Sep 2004 19:09:30 -0500
> 
>     $ ./hash "Various Artists-?????.m3u"
>     87
>     $ ./hash "Various Artists-A:F:S.m3u"
>     41
> 
> So it does in fact look like it is in the right bucket for the funny name.
> Maybe the name isn't corrupt, but for some reason the hash function doesn't
> get it right on your machine (char is a 7-bit datatype?).

PPC defaults to unsigned char, not signed char.. and .. surprise, I can
see the file on x86. (the filename is legit.. I think they are chinese
characters)

Is this a client and server side hash? Can we just put a decent hash
function in?

Maybe we should turn on -werror.. I'll actually go verify this later
tonight (I hope)

> 
> Jan
> 
> /* Coda directory hash function */
> /* compile with gcc -o hash hash.c */
> #include <stdio.h>
> #define NHASH 128
> int DIR_Hash (const char *string)
> {
>     char tc;
>     int hval, tval;
> 
>     hval = 0;
>     while( (tc=(*string++)) )
>         {hval *= 173;
>         hval  += tc;
>         }
>     tval = hval & (NHASH-1);
>     if (tval == 0) return tval;
>     else if (hval < 0) tval = NHASH-tval;
>     return tval;
> }
> 
> int main(int argc, char **argv)
> {
>     int n = DIR_Hash(argv[1]);
>     printf("%d\n", n);
> }
> 

-- 
--------------------------------------------------------------------------
Troy Benjegerdes                'da hozer'                hozer_at_hozed.org  

Somone asked my why I work on this free (http://www.fsf.org/philosophy/)
software stuff and not get a real job. Charles Shultz had the best answer:

"Why do musicians compose symphonies and poets write poems? They do it
because life wouldn't have any meaning for them if they didn't. That's why
I draw cartoons. It's my life." -- Charles Shultz
Received on 2004-09-01 20:11:34