[Assorted-commits] SF.net SVN: assorted: [354] scala-commons/trunk/src/commons/Hash.scala
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-10 18:45:19
|
Revision: 354 http://assorted.svn.sourceforge.net/assorted/?rev=354&view=rev Author: yangzhang Date: 2008-02-10 10:45:24 -0800 (Sun, 10 Feb 2008) Log Message: ----------- added hash functions Added Paths: ----------- scala-commons/trunk/src/commons/Hash.scala Added: scala-commons/trunk/src/commons/Hash.scala =================================================================== --- scala-commons/trunk/src/commons/Hash.scala (rev 0) +++ scala-commons/trunk/src/commons/Hash.scala 2008-02-10 18:45:24 UTC (rev 354) @@ -0,0 +1,33 @@ +package commons + +object Hash { + + /** + * From libstdc++ 4.1 __stl_hash_string. + */ + def hashStl(xs: Seq[Int]) = { + var h = 0 + for (x <- xs) h = 5 * h + x + h + } + + /** + * From Sun JDK6 String.hashCode. + */ + def hashJava(xs: Seq[Int]) = { + var h = 0 + for (x <- xs) h = 31 * h + x + h + } + + /** + * From http://www.cse.yorku.ca/~oz/hash.html. Not sure if this is correct, + * since Int is signed. + */ + def hashDjb2(xs: Seq[Int]) = { + var h = 5381 + for (x <- xs) h = ((h << 5) + h) + x + h + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |