Hashing and the HashTable Class

Michael McMillan · Cambridge University Press eBooks · 2005

Hashing is a very common technique for storing data in such a way that the data can be inserted and retrieved very quickly. Hashing uses a data structure called a hash table . Although hash tables provide fast insertion, deletion, and retrieval, they perform poorly for operations that involve searching, such as finding the minimum or maximum value. For these types of operations, other data structures are preferred (see, for example, Chapter 14 on binary search trees). The.NET Framework library provides a very useful class for working with hash tables, the Hashtable class. We will examine this class in this chapter, but we will also discuss how to implement a custom hash table. Building hash tables is not very difficult and the programming techniques used are well worth knowing. AN OVERVIEW OF HASHING A hash table data structure is designed around an array. The array consists of elements 0 through some predetermined size, though we can increase the size later if necessary. Each data item is stored in the array based on some piece of the data, called the key . To store an element in the hash table, the key is mapped into a number in the range of 0 to the hash table size using a function called a hash function . Ideally, the hash function stores each key in its own cell in the array.

Read the paper · More papers on PaperTik