[Flashcoders] aslib HashTable key

2006-08-14 Thread Darren Bowers
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] [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

RE: [Flashcoders] aslib HashTable key

2006-08-14 Thread Darren Bowers
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) {
   // (hash5)-hash always = 31 (prime#)
   hash = (hash5)-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

Re: [Flashcoders] aslib HashTable key

2006-08-14 Thread Ian Thomas

Hi Darren,
 What are you creating a Hashtable _for_..?

For many applications you can just use a native AS object - e.g.:

var myTable:Object=new Object();
myTable[someIDOrOther]=someValue;
trace(myTable[someIDOrOther]); // gives someValue

For example, in your case:
var myTable:Object=new Object();
var myObject:Object={id:SomeID,href:http://somesite.com};

myTable[myObject.id]=myObject;

trace(myTable[SomeID].href); // gives http://somesite.com;

HTH,
 Ian

On 8/14/06, Darren Bowers [EMAIL PROTECTED] wrote:

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) {
   // (hash5)-hash always = 31 (prime#)
   hash = (hash5)-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]




___
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




___
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


RE: [Flashcoders] aslib HashTable key

2006-08-14 Thread Darren Bowers
 
yeah, I see what you are saying. I will have a play and see how it goes.
 
thanks,
Darren 
 

  _  

From: Ian Thomas [mailto:[EMAIL PROTECTED]
Sent: Mon 14/08/2006 11:48 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] aslib HashTable key



Hi Darren, 
  What are you creating a Hashtable _for_..? 

For many applications you can just use a native AS object - e.g.: 

var myTable:Object=new Object(); 
myTable[someIDOrOther]=someValue; 
trace(myTable[someIDOrOther]); // gives someValue 

For example, in your case: 
var myTable:Object=new Object(); 
var myObject:Object={id:SomeID,href:http://somesite.com
http://somesite.com }; 

myTable[myObject.id]=myObject; 

trace(myTable[SomeID].href); // gives http://somesite.com
http://somesite.com  

HTH, 
  Ian 

On 8/14/06, Darren Bowers [EMAIL PROTECTED] wrote: 
 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) { 
// (hash5)-hash always = 31 (prime#) 
hash = (hash5)-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]
mailto:[EMAIL PROTECTED]   [EMAIL PROTECTED]

 
 
 
 
 ___ 
 Flashcoders@chattyfig.figleaf.com 
 To change your subscription options or search the archive: 
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
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://www.figleaf.com  
 http://training.figleaf.com http://training.figleaf.com  
 
 
 
___ 
Flashcoders@chattyfig.figleaf.com 
To change your subscription options or search the archive: 
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
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://www.figleaf.com  
http://training.figleaf.com http://training.figleaf.com  


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