473,387 Members | 2,436 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,387 software developers and data experts.

Hashtables

Hi

I'm using a hashtable where the key is always an integer. The value stored
with the key holds another key that gives me a collection. My question is
will the hashcode generated for the key (an integer) always be unique i.e.
is there any chance given two different integers that I may get the same
hashcode?

If it is possible to get the same hashcode, does the .Net hashtable deal
with this e.g. when I pass in my unique key will it return me the correct
value associated with that key.

Regards
Jul 21 '05 #1
2 1591
In case of Int32, the hash code generated will be the value itself.
So, as long as you know the values are unique, you are fine.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Trevor Hardwick" <tr****@leavemealone.com> wrote in message
news:OK**************@TK2MSFTNGP14.phx.gbl...
Hi

I'm using a hashtable where the key is always an integer. The value
stored with the key holds another key that gives me a collection. My
question is will the hashcode generated for the key (an integer) always be
unique i.e. is there any chance given two different integers that I may
get the same hashcode?

If it is possible to get the same hashcode, does the .Net hashtable deal
with this e.g. when I pass in my unique key will it return me the correct
value associated with that key.

Regards

Jul 21 '05 #2
Trevor Hardwick <tr****@leavemealone.com> wrote:
I'm using a hashtable where the key is always an integer. The value stored
with the key holds another key that gives me a collection. My question is
will the hashcode generated for the key (an integer) always be unique i.e.
is there any chance given two different integers that I may get the same
hashcode?

If it is possible to get the same hashcode, does the .Net hashtable deal
with this e.g. when I pass in my unique key will it return me the correct
value associated with that key.


Dennis gave the answer in terms of the uniqueness of Int32 hashcodes,
but yes, Hashtable does (and *must*) cope with two different keys
returning the same hashcode - otherwise you couldn't use them for
things like strings, for a start.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3

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

Similar topics

7
by: Steve D. Perkins | last post by:
Hello all - I'm a Java and C++ developer, looking to pick up some Python and wxPython skills for prototyping and quick projects. I've been developing for about 15 years, and am very familiar...
6
by: Michael Schollmeyer | last post by:
Hello, The following code writes the text string: Uri uri1 = new Uri("http://www.here.net/aplace?param=one"); Uri uri2 = new Uri("http://www.here.net/aplace?param=two"); int h1 =...
13
by: Anders Borum | last post by:
Hello! Now that generics are introduces with the next version of C#, I was wondering what kind of performance gains we're going to see, when switching from e.g. the general hashtable to a...
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...
1
by: Curtis | last post by:
Does anyone know the proper method to save information to embedded hashtables. I am trying to save parent/child information to hashtables but I am not getting the correct results I have made a...
2
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
7
by: Kamran Shafi | last post by:
Hi, I am creating an arraylist (say masterArrayList) of hashtables, where each hashtable (say table) is of the format key=string, value = arraylist of strings (say existing_strings). In a...
7
by: Mike P | last post by:
I have 2 hashtables each of which I am using to store a set of IDs and Descriptions. Hashtable 1 will have the full set of data (e.g. IDs 1,2,3,4,5) whereas Hashtable 2 will only have a subset of...
0
by: John Smith | last post by:
Hello people, I have a performance query regarding LINQ that I would like some opinions. Currently we have a business logic framework that is used in n-tier applications. We read data from a...
0
by: Jake McCool | last post by:
Hello people, I have a performance query regarding LINQ that I would like some opinions. Currently we have a business logic framework that is used in n-tier applications. We read data from a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.