From 9a8df29c8ee694734298c57929d1d8695ee7ff45 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Sat, 24 Nov 2007 21:41:53 +0000 Subject: [PATCH] I'm afraid we really do need a hashcode method... git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4880 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/Util.as | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/as/com/threerings/util/Util.as b/src/as/com/threerings/util/Util.as index e11cf9f99..18c06924f 100644 --- a/src/as/com/threerings/util/Util.as +++ b/src/as/com/threerings/util/Util.as @@ -83,6 +83,19 @@ public class Util return false; } + /** + * Compute a hash code for a string. This is pretty expensive, so only compute + * it once if that's at all an option. This is the JDK algorithm... + */ + public static function hashCode (str :String) :int + { + var h :int = 0; + for (var i :int = str.length-1; i >= 0; i--) { + h = int(int(31*h) + str.charCodeAt(i)); + } + return h; + } + /** * If you call a varargs method by passing it an array, the array * will end up being arg 1.