473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Hashtable lookup - speed ?

I have build an application which uses Hashtables for storing information in
collections.

My question is simple - I wonder how big a (performance) difference it is,
to lookup a value in a hashtable with 500.000 items, and a hashtable with 500
items ?

Is there any difference or anything else I should be aware of ?
Regards,
Tony
Jul 21 '05 #1
2 1492
Hi,

It mostly depends on the distribution of your hashcodes. In the ideal
case, the hashtable lookup should be always an O(1) operation regardless
of the item count. In the worst case, however, with all items having the
same hashcode, you would get an O(n) operation.

HTH,
Stefan

Tony Godt wrote:
I have build an application which uses Hashtables for storing information in
collections.

My question is simple - I wonder how big a (performance) difference it is,
to lookup a value in a hashtable with 500.000 items, and a hashtable with 500
items ?

Is there any difference or anything else I should be aware of ?
Regards,
Tony

Jul 21 '05 #2
Tony,

Like Stefan said if the hashcodes are well distributed then the
hashtable will have an average case runtime complexity of O(1). That
means that the operations will run in the same amount of time
regardless of the size of the table. If you're using the primitive
types as the keys for the table then this won't be a problem. If you
have created your own class to be used as keys then pay special
attention to the implementation of the GetHashCode method.

Brian

Tony Godt wrote:
I have build an application which uses Hashtables for storing
information in collections.

My question is simple - I wonder how big a (performance)
difference it is, to lookup a value in a hashtable with
500.000 items, and a hashtable with 500 items ?

Is there any difference or anything else I should be aware
of ?
Regards,
Tony


Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alfonso Morra | last post by:
I am implementing an application which requires the storage of a large number of items in a cache. I have 3-tuple key reprented by a struct, as well as an n-tuple (n is fixed) dataset, also...
3
by: _eee_ | last post by:
I have been using a HashTable to store name/value pairs, but now I need to add a third element (name/value/flag). I still need to be able to index by , and I'd like to keep lookup speed as high...
4
by: Anders Borum | last post by:
Hello! I have a list of singleton classes (model managers) that store objects internally using hashtables. Each of these classes use a single hashtable to store e.g. users, pages, elements and...
6
by: Steven Wolf | last post by:
Hi guys, can a hashtable be faster than a sql server?? i made my own O/R mapping with an "entity cache" (caching all mapped objects). So, when i get some data from my sql server, i map that data...
2
by: John Grandy | last post by:
What are good rules of thumb to use when deciding between a NameValueCollection, an ArrayList, or a Hashtable ?
3
by: Bob | last post by:
I have a name-value pair type of data that I need to search against. It's to determine what menu item to highlight given the asp.net page name. So the list has all my page names (unique) and the...
2
by: Tony Godt | last post by:
I have build an application which uses Hashtables for storing information in collections. My question is simple - I wonder how big a (performance) difference it is, to lookup a value in a...
8
by: Martin Pöpping | last post by:
Hello, I´ve implemented a Hashtable with Int-Keys and Double Values. Now I want to get the i-th Int-Key of my hashtable. How do I do that? I tried it like that: ICollection intKeys =...
2
by: Bruce | last post by:
Hi I am having a problem understanding the exact advantages of using an ArrayList over a Hashtable in any situation. In most areas of an application I am working on, lookup needs to be fast. If I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.