From: remove-this-spam-blocker.bstowers@pobox.com (Bradley D. Stowers) Subject: Re: Hash function Date: 16 Dec 1997 00:00:00 GMT Message-ID: <3496e29d.1985986@forums.borland.com> Content-Transfer-Encoding: 7bit References: <34922A30.4D59@usa.net> Content-Type: text/plain; charset=us-ascii Organization: None Mime-Version: 1.0 Newsgroups: borland.public.delphi.winapi On Fri, 12 Dec 1997 22:24:48 -0800, "Horatiu A. Tanescu" wrote: >I have a list of long file names and I add file names to this list only >if the file doesn't already exists in the list. I can't sort the list to >perform a fast binary search so I decided to use a hash technique to >compare the file name with all the files in the list. For each file in >the list I compute an integer value (e.g. the sum of all characters in >name) and when I search if the file name exists in list I have to >compare only integer values (quite faster). > >The problem is the hash function (that converts the file name into an >integer value). If I compute the sum of all characters in name I could >have a large number of strings with the same associated integer value. >Is there a better choice for the hash function? For simple hashing, you might want to consider the Windows API Atom functions (InitAtomTable, AddAtom, DeleteAtom, GetAtomName, etc.). They are really just simple hash-type functions. The are limited in that the strings must be 255 or less characters, and they are not case sensitive. This may be a problem for you since I *think* long file names can be 255 characters without their path. Regards, Brad Stowers Delphi Free Stuff http://www.pobox.com/~bstowers/delphi/