Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!border2.nntp.ams2.giganews.com!border1.nntp.ams2.giganews.com!backlog3.nntp.ams3.giganews.com!backlog3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 23 Apr 2014 03:57:13 -0500 From: rossum Newsgroups: comp.lang.java.programmer Subject: Re: 64-bit hashing function Date: Wed, 23 Apr 2014 09:57:11 +0100 Message-ID: <5mvel9lrq0upfvobfbssrait15iicoi6ak@4ax.com> References: User-Agent: ForteAgent/7.20.32.1218 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 32 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-eImb808wNCEDtbihBlDkWWXcnHrDWdqi5qkB8LY5BXeE+f1bR6DK9TobbBPMyMUclMJW21xuxQlYZZQ!wkZk9YR/ozj3smTBv7Ldfud8Lbmkkw8kzH5fAQVnXgqJYGTUXZF/7hBjyiL8WjkonnYGy7jZFFP9!Zltu X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2046 Xref: csiph.com comp.lang.java.programmer:28196 On Sun, 20 Apr 2014 15:15:07 -0700, Roedy Green wrote: >What is your favourite 64-bit hashing function/digest? This is not for >cryptography. Ideally there is Java source available and it is fast. > >I will be using it to collapse filenames down. There is no malice or >privacy to worry about. > >I would like similar filenames to generate different results. I usually suggest the FNV hash for this sort of situation: http://isthe.com/chongo/tech/comp/fnv/ It is a non-crypto (and hence fast) hash in sizes from 32 bit to 1024 bit and is simple to program: hash = offset_basis for each octet_of_data to be hashed hash = hash xor octet_of_data hash = hash * FNV_prime endfor return hash For the 64 bit version: offset_basis = 14695981039346656037 FNV_prime = 1099511628211 hash is an unsigned 64 bit integer. HTH rossum