[comp.sys.amiga] CATS? ANYONE?

David.Plummer@f70.n140.z1.FIDONET.ORG (David Plummer) (01/03/91)

Below is the function I'm using to calculate the hash value for a
filename:
 
int Hash(unsigned char *filename)                      
{                                                      
   int val;                                            
                                                       
   val=strlen(filename);                               
   while(*filename)                                    
      val=((val*13)+(int)toupper(*filename++)) & 0x7ff;
   return (val % 72);                                  
}
 
My question is, should I use modulus 72?  Or should I use
%(blocksize-56)?  Or should I use %(buffer[3]), which is supposed to
reflect the size of the hash table?  With 512 byte sectors, 72 works
fine, but in order to be upwardly compatible, will the hash function
change to reflect the larger sector size (and therefor, I assume, a
larger hash table)?
 
Any opinions (or correct answers!) would be appreciated.  Thanks...



--  
David Plummer - via FidoNet node 1:140/22
UUCP: ...!herald!weyr!70!David.Plummer
Domain: David.Plummer@f70.n140.z1.FIDONET.ORG
Standard Disclaimers Apply...

csg019@cck.cov.ac.uk (-~=Zaphod=~-) (01/10/91)

In article <2.27842025@weyr.FIDONET.ORG> David.Plummer@f70.n140.z1.FIDONET.ORG (David Plummer) writes:
>Below is the function I'm using to calculate the hash value for a
>filename:
> 
>int Hash(unsigned char *filename)                      
>{                                                      
>   int val;                                            
>                                                       
>   val=strlen(filename);                               
>   while(*filename)                                    
>      val=((val*13)+(int)toupper(*filename++)) & 0x7ff;
>   return (val % 72);                                  
>}
> 

The way i did it (for ZDIR, the worlds fastest dir program. - end of plug)
is:
	hash=length
	repeat
		hash=hash*13
		hash=hash+ascii code of char
		and hash with $7ff
		length=length - 1
	until length = 0
	final_hash=hash MOD 72

length equ 6          <-Just for example
lea filename,a0
move.w #length-1,d0
move.w #length,d1
hashloop:
mulu #13,d1
clr.w d2
move.b (a0)+,d2
add.w d2,d1
and.w #$7ff,d1
dbra d0,hashloop
divu #72,d1
;Could use a few ror.l's instead if divu #72....
swap d1
rts

filename dc.b "file.s"

d1.w contains hash.

-- 
*********///  O O **A member of S.H.I.T. (Super High Intelegence Team)**///***
*       ///    u    Fight, defeat and kill organized laming.           ///   *
*  \\\ ///    ---      Zaphod (TCC)  csg019@uk.ac.cov.cck ok?     \\\ ///    *
****\\X//**********************************************************\\X//******