ok, after scouring some Java sites and their buglists I have come up with
this implementation of String.hashCode
 
 public static function hashCode(str:String):Number {
  var offset:Number = 0;
  var hash:Number = 0;
  var len:Number = str.length;
  if (len==0) {
   return 0;
  }
  while (offset < len) {
   // (hash<<5)-hash always = 31 (prime#)
   hash = (hash<<5)-hash + str.charCodeAt(offset++);
  }
  return hash;
 }
 
any thoughts or should I just run with it?

  _____  

From: Darren Bowers
Sent: Mon 14/08/2006 5:06 PM
To: 'flashcoders@chattyfig.figleaf.com'
Subject: [Flashcoders] aslib HashTable key



I am trying to get my head around HashTables and how to create the unique 
key reference. 
  
basically, I have an object that has two properties "id" (String) and "href"

(String) and i want to create a HashTable keyed on "id". However the 
HashTable object can only be a Number type. 
  
What is the best way to create a unique key for a hashtable (a number) based

on a string that could effectively be any length? 
  
What does Number(num:Object) actually do with the object passed to it? 
  
cheers, 
  

Darren Bowers 
Learning Media Specialist 
WestOne Services 
Department of Education and Training 
1 Prospect Place, West Perth, WA, 6005 
T: (08) 9229 5284 
F: (08) 9229 5293 
E:  <mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > [EMAIL PROTECTED] 


----------------------------------------------------------------------------
CAUTION & DISCLAIMER: The information contained in this e-mail message
and/or any accompanying data or documents contain information that is 
confidential and subject to legal privilege. The information is intended
only for the recipient named in this message. The sender is excluded from
any liability arising from any further use, dissemination, distribution,
transmission or copying of this information and /or accompanying data by
the recipient. If you are not the intended recipient, you must immediately
erase the information along with all copies of this message and accompanying
data and notify the sender. Views expressed in this message are those of the
original sender, and are not necessarily the views of WestOne Services.
----------------------------------------------------------------------------

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to