The hash table
In this section, we will learn about the HashTable
class, also known as HashMap
, a hash implementation of the Dictionary
class.
Hashing consists of finding a value in a data structure in the shortest time possible. You learned in previous chapters that if we want to get a value from a data structure (using a get
method), we need to iterate through the structure until we find it. When we use a hash function, we already know which position the value is in, so we can simply retrieve it. A hash function is a function that, given a key
, will return an address in the table where the value is.
In computer science, the hash table has several use cases. It can be used as associative arrays, since it is an implementation of the dictionary. It can also be used to index a database. When we create a new table in a relational database such as MySQL, Microsoft SQL Server, Oracle, and so on, it is always a good practice to create an index
to allow for faster searching of the record key
. In...