-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: diniya99
Message 6 in Discussion
Hi
i am sending detailed about Hash Table
The <MSHelp:link tabIndex=0
keywords="frlrfSystemCollectionsHashtableClassTopic">Hashtable</MSHelp:link>
class is based on the <MSHelp:link tabIndex=0
keywords="frlrfSystemCollectionsIDictionaryClassTopic">IDictionary</MSHelp:link>
interface, and therefore each element in the collection is a key-and-value
pair.
A Hashtable consists of buckets that contain
the elements of the collection. A bucket is a virtual subgroup of elements
within the Hashtable, which makes searching and retrieving easier and
faster than in most collections. Each bucket is associated with a hash code,
generated using a hash function and based on the key of the element.
A hash function is an algorithm that returns a
numeric hash code based on a key. The key is the value of some property of the
object being stored. A hash function must always return the same hash code for
the same key. It is possible for a hash function to generate the same hash code
for two different keys, but a hash function that generates a unique hash code
for each unique key results in better performance when retrieving elements from
the hash table.
Each object that is used as an element in a
Hashtable must be able to generate a hash code for itself using an
implementation of the <MSHelp:link tabIndex=0
keywords="frlrfSystemObjectClassGetHashCodeTopic">Object.GetHashCode</MSHelp:link>
method. However, you can also specify a hash function for all elements in a
Hashtable by using a Hashtable constructor that accepts an
<MSHelp:link tabIndex=0
keywords="frlrfSystemCollectionsIHashCodeProviderClassTopic">IHashCodeProvider</MSHelp:link>
implementation as one of its parameters.
When an object is added to a Hashtable, it is
stored in the bucket that is associated with the hash code that matches the
object's hash code. When a value is being searched for within the
Hashtable, the hash code is generated for that value and the bucket
associated with that hash code is searched.
For example, a hash function for a string might take
the ASCII codes of each character in the string and add them together to
generate a hash code. The string "picnic" would have a hash code that is
different from the hash code for the string "basket"; therefore, the strings
"picnic" and "basket" would be in different buckets. In contrast, "stressed" and
"desserts" would have the same hash code and would be in the same
bucket.
IDictionaryEnumerator
:
Enumerators only allow reading the data in the
collection. Enumerators cannot be used to modify the underlying
collection.
Initially, the enumerator is positioned before the
first element in the collection. Reset also brings the
enumerator back to this position. At this position, calling Current throws an
exception. Therefore, you must call MoveNext to advance the
enumerator to the first element of the collection before reading the value of
Current.
Current returns the same object until
either MoveNext or Reset is called. MoveNext sets
Current to the next element.
After the end of the collection is passed, the
enumerator is positioned after the last element in the collection, and calling
MoveNext returns false. If the last call to MoveNext
returned false, calling Current throws an exception. To set
Current to the first element of the collection again, you can call
Reset followed by MoveNext.
An enumerator remains valid as long as the collection
remains unchanged. If changes are made to the collection, such as adding,
modifying or deleting elements, the enumerator is irrecoverably invalidated and
the next call to MoveNext or Reset throws an InvalidOperationException.
If the collection is modified between MoveNext and Current,
Current will return the element that it is set to, even if the enumerator
is already invalidated.
The enumerator does not have exclusive access to the
collection; therefore, enumerating through a collection is intrinsically not a
thread-safe procedure. Even when a collection is synchronized, other threads
could still modify the collection, which causes the enumerator to throw an
exception. To guarantee thread safety during enumeration, you can either lock
the collection during the entire enumeration or catch the exceptions resulting
from changes made by other threads.
----- Original Message -----
From:
BalajiKrishnan
To: BDOTNET
Sent: Wednesday, October 08, 2003 4:17
PM
Subject: Hashtable
New Message on BDOTNET
Hashtable
Reply
Reply to Sender Recommend
Message 1 in
Discussion
From: BalajiKrishnan
hi all,
I want to know what is HashTable
How to Create it.
And what is IDictionaryEnumerator how is it related
to Hashtable.
thanks
balaji
View other groups in this
category.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]