DelphiBasics
  Home  |  Delphi .net Home  |  System.Collections NameSpace
 .NET Framework
 Namespace References

 System
 System.Collections
 
  ArrayList  Class 
  BitArray  Class 
  CaseInsensitiveComparer  Class 
  Comparer  Class 
  DictionaryEntry  Structure 
  HashTable  Class 
  ICollection  Interface 
  IComparer  Interface 
  IDictionary  Interface 
  IDictionaryEnumerator  Interface 
  IEnumerator  Interface 
  IList  Interface 
  Queue  Class 
  SortedList  Class 
  Stack  Class 
 System.Globalization
 System.IO

 Articles and Tutorials

 Overview of .NET
 Delphi and .NET
 Winform Applications
 ASP .Net Applications
 php Web Services
 Framework Collections
 Framework String Handling
 Framework Files and Folders


 
 
  System.Collections.HashTable Class
 
 Description
Use a HashTable when you have a large amount of key-value data pairs to store, where the key has a good variance. Otherwise, use a Dictionary for key-value pair storage.
 
Hashing refers to a long standing programming storage mechanism. A mathematical algorithm is applied to a key to generate a position in a block of storage. This algorithm ensures that only that key value equates with its block position and vice versa.
 
The benefit of this hashing concept is speed : access to the value for a key is direct via the algorithm, with no searching or indexing required. The down side is that a potentially large amount of storage may be required for small amounts of data. It is therefore best suited to large amounts of data.
 
This is the theory. In .Net, the HashTable class uses a hybrid approach, with the key-value pairs actually stored in a Dictionary. A hash table is used to speed up access to this dictionary.
 
Objects added to the HashTable must provide the GetHash method, unless an IHashCodeProvider is provided in the HashTable constructor.
 
Note that some of the constructors are quite complicated to use - you will only see basic usage of HashTable in Delphi Basics.
 Syntax
Constructor Create ( );
Constructor Create ( InitialCapacity : Integer ; );
Constructor Create ( InitialCapacity : Integer; LoadFactor : Single );
Constructor Create ( InitialCapacity : Integer; HashCodeProvider : IHashCodeProvider; Comparer : IComparer );
Constructor Create ( InitialCapacity : Integer; LoadFactor : Single; HashCodeProvider : IHashCodeProvider; Comparer : IComparer );
Constructor Create ( Dictionary : IDictionary ; );
Constructor Create ( Dictionary : IDictionary; LoadFactor : Single );
Constructor Create ( Dictionary : IDictionary; HashCodeProvider : IHashCodeProvider; Comparer : IComparer );
Constructor Create ( Dictionary : IDictionary; LoadFactor : Single; HashCodeProvider : IHashCodeProvider; Comparer : IComparer );
Constructor Create ( HashCodeProvider : IHashCodeProvider; Comparer : IComparer );
Constructor Create ( Serialization : SerializationInfo; Streaming : StreamingContext );
 Methods
Add  Add an entry to the current HashTable
Clear  Clear (remove) all key-value data pairs from the current HashTable
Clone  Make a new HashTable that is a clone of the current HashTable
Contains  Returns true if the current HashTable contains the given Key
ContainsKey  Returns true if the current HashTable contains the given Key
ContainsValue  Returns true if the current HashTable contains the given Value
CopyTo  Copies elements from the HashTable to a single dimension array
GetEnumerator  Gets an enumerator to allow reading the elements of the current HashTable
Remove  Remove a key-value entry from the current HashTable

 Properties
Count  Integer  Gets the number of key-and-value pairs contained in the Hashtable.
IsFixedSize  Boolean  Gets a value indicating whether the Hashtable has a fixed size.
IsReadOnly  Boolean  Gets a value indicating whether the Hashtable is read-only.
IsSynchronized  Boolean  Gets a value indicating whether access to the Hashtable is synchronized (thread-safe).
Item  Object  Gets or sets the value associated with the specified key. This is the default property, specifiable using [] brackets.
Keys  ICollection  Gets an ICollection containing the keys in the Hashtable.
SyncRoot  Object  Gets an object that can be used to synchronize access to the Hashtable.
Values  ICollection  Gets an ICollection containing the values in the Hashtable.

 Delphi Basics links
 
System.Collections.IComparer
System.Collections.IDictionary

 Microsoft MSDN links
 
System.Collections
System.Collections.hashtable
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page