A hashtable in C#. What is it for?

I'm studying theory, tell me what is the practical application of Hashtable.

Author: Андрей NOP, 2018-10-18

2 answers

Hash table (Hashtable) VS dictionary (Dictionary<TKey, TValue>).

What is common:

  1. Both work as key-value storage
  2. Both provide (pseudo) constant access to the value by the key
  3. Both store data in an array of buckets (both have memory costs in a linear relationship with the number of items)

What is the difference:

  1. The table reduces the keys and values to object, which adds memory and speed costs (on boxing/unboxing)
  2. Table, unlike a dictionary, it supports multithreaded reading / single-threaded writing. The dictionary is not designed for several simultaneous readers / one writer (I once screwed up the release on this, be careful)
  3. The table has a wrapper to get a thread-safe table. I didn't see this in the dictionary.
  4. The table and the dictionary calculate collisions in different ways. The table uses double hashing, the dictionary stores something like a pointer to the next element right in the trash (I don't know what this method is called). In theory (in my opinion), because of this, the dictionary should handle read collisions much faster, but I did not check.
 2
Author: tym32167, 2018-10-18 10:07:04

In essence, Hashtable is an untyped version of the dictionary (Dictionary<TKey, TValue>) and can be used in the same situations as you would use a dictionary.

But in modern realities, this is very rarely required and it is better to give preference to a strictly typed data structure.

 3
Author: Андрей NOP, 2018-10-18 08:04:01