Home > Archive > C# > March 2004 > Hashtables?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Kevin Parkinson 2004-03-28, 11:32 pm |
| Hello Everyone:
I am new to this newsgroup and to C#, Although I have a little
experience with C++ and Java. Can anyone offer a simple explanation of what
a hashtable is?
Is it simply a table that maps keys to values, or is that only one
implementation? Thank you.
Kevin Parkinson
| |
|
| A Hashtable is a data structure that supports very fast (almost
constant time)
addition, removal and lookup of data. Each stored value has a
corresponding key which uniqely identifies the value. So you can think
of data, stored in a Hashtable, as a <key, value> pairs.
The amount of time that is required for a Hashtable to accomplish
Add(k,v), Remove(k) and Lookup(k) is strongly dependent on the hash
function that is used to hash the keys. There is a lot of theory
behind that issue.
I think hashatbles are well covered in following book,
http://www.amazon.com/exec/obidos/t...179159?v=glance
(but that is only a guess).
In C# System.Collections.Hashtable implements a not synchronized
Hashtable.
Most popular methods for me are Add, Remove and the values indexer
that returns a value upon a key, like in following example:
using System.Collections;
void Main()
{
Hashtable h = new Hashtable();
Data d = new Data();
int key = 1000;
h.Add(key, d);
Data fromhashtable = h[1000]; // will return d
....
....
}
For synchronization purposes see the static Synchronized method of
class
Hashtable. Check out the lines about thread-safe enumeration.
I think that is it.
|
|
|
|
|