HighDots Forums  

HashTable implementation

Javascript JavaScript language (comp.lang.javascript)


Discuss HashTable implementation in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Eduardo F. Sandino
 
Posts: n/a

Default HashTable implementation - 03-03-2006 , 11:59 AM






I need help in how to implement a HashTable but specific the method
getKeys(); anyone could help.?


Reply With Quote
  #2  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: HashTable implementation - 03-03-2006 , 12:33 PM






"Eduardo F. Sandino" <eduardo.sandino (AT) gmail (DOT) com> writes:

Quote:
I need help in how to implement a HashTable but specific the method
getKeys(); anyone could help.?
Why? Do you have a specific use for it, or is it for a library?

How do you plan to calculate the hash value?

/L
--
Lasse Reichstein Nielsen - lrn (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #3  
Old   
Matt Kruse
 
Posts: n/a

Default Re: HashTable implementation - 03-03-2006 , 12:45 PM



Eduardo F. Sandino wrote:
Quote:
I need help in how to implement a HashTable but specific the method
getKeys(); anyone could help.?
You need to be more specific.
If all you want is a "hashtable" or objects, with the ability to get the
"keys" then a simple Object works fine.

var o = new Object();
o["a"] = 1;
o["b"] = 2;
for (key in o) {
alert(o + " = " + o[key]);
}

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com




Reply With Quote
  #4  
Old   
Eduardo F. Sandino
 
Posts: n/a

Default Re: HashTable implementation - 03-03-2006 , 01:26 PM



Thanks i will try it... I be writing from here until have a nice
HashTable implementation... optimized to solve any needs...


Reply With Quote
  #5  
Old   
John G Harris
 
Posts: n/a

Default Re: HashTable implementation - 03-03-2006 , 02:59 PM



In article <fylza0xc.fsf (AT) hotpop (DOT) com>, Lasse Reichstein Nielsen
<lrn (AT) hotpop (DOT) com> writes
Quote:
"Eduardo F. Sandino" <eduardo.sandino (AT) gmail (DOT) com> writes:

I need help in how to implement a HashTable but specific the method
getKeys(); anyone could help.?

Why? Do you have a specific use for it, or is it for a library?

How do you plan to calculate the hash value?
Just as important, how do you plan to allocate the raw storage that must
be allocated when a Hash Table is created?

John
--
John Harris


Reply With Quote
  #6  
Old   
VK
 
Posts: n/a

Default Re: HashTable implementation - 03-04-2006 , 04:07 AM




Eduardo F. Sandino wrote:
Quote:
Thanks i will try it... I be writing from here until have a nice
HashTable implementation... optimized to solve any needs...
You may want to write it for non-IE UA's then, as JScript has native
Dictionary object (=== Perl hash) and Enumerator wrapper for
HTMLCollection (see MSDN for details). These objects are not
replaceable by custom made equivalents: say no way you can emulate real
hashtable baskets structure w/o Dictionary. And in many situations (say
file collections returned by fso) JScript wants Enumerator and
Enumerator only.

So the task would be then to write an unifiormed interface atop
Dictionary/Enumerator (IE) and custom emulators (others).



Reply With Quote
  #7  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: HashTable implementation - 03-04-2006 , 07:53 AM



"Eduardo F. Sandino" <eduardo.sandino (AT) gmail (DOT) com> writes:

Quote:
Thanks i will try it... I be writing from here until have a nice
HashTable implementation... optimized to solve any needs...
I doubt one thing can solve all needs. That's why it's good to have
several solutions to choose from.

I'm not sure why you need a hash table.

A hash table is a specific implementation of an associative array
(aka. dictionaray, aka. map), an updateable data structure thatm aps
key values keys into other values.

There are many ways to implement an assocative array, each with
different time/memory behavior.

A hash table creates a hash value of the keys, i.e., a number, and
uses that to index into an array - the bucket for that hash
value. Then it goes through the list of key/value pairs in that
bucket, all the ones with a key that hashes to the same value.
This gives, for a reasonable table size, an expected constant time
for insert, lookup and delete operations.

If you are just trying to implement an associative array, then it's
not necessarily a hash table that is the best choice of implementation
in Javascript. You could use the language's own implementation of
properties on objects instead, suitably wrapped. That will not
guarantee the time complexity, as different Javascript implementations
do object properties differently (some might use a hash table
internally, others might not).

/L
--
Lasse Reichstein Nielsen - lrn (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #8  
Old   
Eduardo F. Sandino
 
Posts: n/a

Default Re: HashTable implementation - 03-04-2006 , 11:28 PM



I am planing to make that HashTable to have a good one collection in
where to store the values from some clases, and the posibility to
export them to other formats i am saying imaging you are working in a
JavaScript program and the user want to stop the session... getAll the
info in the hashtable for example in a hidden control compacted to be
stored in da DB server when the user plan to return other day to
continue using the JavaScript program... thats the Way... Order and
Simplicity... i know there are good choices but i need to scale one
level up of common structures.. so i am looking for optimization of the
hash and things like that...


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.