|
-
October 16th, 2005, 10:06 PM
#1
HashTable question
Hi :
Java's implementation of Hashtable provides the users with the public Object get(Object key)So if the user wants to retrieve the object value in the existing HashTable, they just need to provide the key, and the operation time is O(1).
However, I don't see the similar method in C#, it only has getEnumerator which will go through the entire table. and the timing is O(N)
I would like to know if there is something similar to the get(Object key) method I can use and has a time of O(1).
Many thanks,
------------
I.B.M... I Blame Microsoft
-
October 16th, 2005, 10:43 PM
#2
Re: HashTable question
The following code will print 17 in constant amount of time...I think. I'm pretty sure it's a requirement that retrievals from a Hashtable take O(1) time, else I'm not really sure what distinguishes a HashTable...
Code:
Hashtable ht = new Hashtable();
ht.Add("Jason", 23);
ht.Add("Josh", 23);
ht.Add("Jacob", 7);
ht.Add("Jeremy", 17);
System.Console.WriteLine(ht["Jeremy"]);
Jason Isom
.NET 2.0 / VS2005 Developer
-
October 16th, 2005, 11:24 PM
#3
Re: HashTable question
hashtable has a special enumerator IDictionaryEnumerator for obtaining / iterating through a list of keys or dict entries, and the actual get(key) function uses normal hashing to obtain the value.
Last edited by MadHatter; October 16th, 2005 at 11:31 PM.
-
October 17th, 2005, 08:26 AM
#4
Re: HashTable question
...and the same goes for ArrayList. Java uses list.get(index) whereas C# uses the array syntax, list[index]
Useful? Then click on (Rate This Post) at the top of this post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|