Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!warwick!covpoly!csg019 From: csg019@cck.cov.ac.uk (-~=Zaphod=~-) Newsgroups: comp.sys.amiga Subject: Re: CATS? ANYONE? Message-ID: <1991Jan9.163927.2808@cck.cov.ac.uk> Date: 9 Jan 91 16:39:27 GMT References: <2.27842025@weyr.FIDONET.ORG> Organization: Coventry Polytechnic, Coventry, UK Lines: 51 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//******