This is a discussion on Overview of Hash table. within the Other Web Programming Languages forums, part of the Web Development category; Overview of Hash table. Hashtable are very sophisticated data structures that allows accessing an element based on some key, which ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Overview of Hash table. Hashtable are very sophisticated data structures that allows accessing an element based on some key, which can be of any type. 1. Is member of System.Collections namespace. 2. Hashtable _table = new Hashtable() ; Hashtable _table2 = new Hashtable(10); // capacity or size. Hashtable _table3 = new Hashtable(10 ,06); //capacity , loadfactor Loadfactor this factor helps for performance, The smaller the load size the more efficiently hash table works and the more memory it occupy. 1. Create a Hashtable Hashtable _simpleTable = new Hashtable(); 2. Added some data in it. _simpleTable.Add("Key1", "Value1"); _simpleTable.Add("Key2", "Value2"); 3. Get the size. _simpleTable.Count; // an int value. 4. Fetching data a. create an object of IDictonaryEnumerator , this is an interface that creates an enumerator and customized for Dictonary objects. IDictionaryEnumerator _enumerator = _simpleTable.GetEnumerator(); b. while (_enumerator.MoveNext()) { _string += _enumerator.Key + " "; _string += _enumerator.Value + "\n"; } c. and that all you fetched the Data !!! d. clear hash table.. _simpleTable.Clear(); e. Search for a specific key : remember its value type when used if (_simpleTable.ContainsKey("Key1")) { Console.WriteLine("Key1 is present"); } f. Search for a specific key : remember its value type when used if (_simpleTable.ContainsValue("Value1")) { Console.WriteLine("Value1 is present"); } |
| Sponsored Links |
| |||
| What is a hash table? A hash-table is a data-structure that consists of an array of linked lists. The beauty of this arrangement is that you can have the speed of array-access, along with the convenience of inserting objects into linked lists. What's more, inserting and searching through a hash-table is very, very fast. How does it work? Hashing describes the process of taking some key value, and generating an array index from it. Usually, this array index has seemingly little in common with the key. Values put into a hash-table will be placed all over the array, in no particular order. But the trick is that for any key, there is only one hash value that is always generated. As an example, suppose you have an integer array of 10 locations. You want to insert a certain value, such as 134. 134 is the key. You need to generate a hash value from 0 to 9, One way to do this is: int hash = 134 % 10. This guarantees a value from 0 to 9, which can be our array index. But what if we then wanted to add the number 124 to the same array/hashtable? 134 % 10 = 4 124 % 10 = 4 The hash value is the same. This is where the linked list comes in. Instead of having an array of mere values, the array contains objects with links to other objects, as well as the actual values you want to store. for example: class MyObject extends Object { int value; MyObject next; }; Now, you can have more than one value in a single array position. Because of this, the array positions are sometimes referred to as buckets. PHP Code: Last edited by leoraja8 : 09-14-2007 at 06:37 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ASP.NET Cookies Overview | KiruthikaSambandam | ASP and ASP.NET Programming | 8 | 05-30-2008 01:10 AM |
| How do I sort a hash by the hash value? | S.Vinothkumar | Perl | 2 | 11-26-2007 05:56 AM |
| Overview of Software Testing Certifications | cool7575 | Software Testing | 0 | 09-22-2007 12:16 PM |
| What’s the difference between Hash Map and Hash Table? | mobilegeek | Java Programming | 2 | 09-14-2007 05:37 AM |
| What is a hash? | vadivelanvaidyanathan | Perl | 1 | 07-30-2007 06:29 AM |