Dictionaries, HashSets, HashTables, and HashBrowns
Yesterday I was asked a question about what the differences were between a dictionary, a hashset, and a hashtable. While I was able to reason through part of the question, I wanted to follow up with a blog post describing how each of the data structures relate.
Hashtables and Dictionary is a collection key-value data pairs that allows you to store a key and relate it back to a value.
Hashsets implement the Set interface which maintains that the collection contains only unique elements.
Dictionaries are: Generic, Not thread-safe, Output KeyValuePair for enumeration, potentially faster for value types (No unboxing-needed)
Hashtables - Non-generic, thread-safe, Output DictionaryEntry for enumeration, potentially slower for value types. Hashtable can only store object types, therefore when working with value types boxing/unboxing must occur.
Both are: Internally manged by a hash table data structure, need immutable and unique keys.
Hashtables and Dictionary is a collection key-value data pairs that allows you to store a key and relate it back to a value.
Hashsets implement the Set interface which maintains that the collection contains only unique elements.
Differences between Hashtables and Dictionaries
The differences between Hashtables and Dictionaries in C#:Dictionaries are: Generic, Not thread-safe, Output KeyValuePair for enumeration, potentially faster for value types (No unboxing-needed)
Hashtables - Non-generic, thread-safe, Output DictionaryEntry for enumeration, potentially slower for value types. Hashtable can only store object types, therefore when working with value types boxing/unboxing must occur.
Both are: Internally manged by a hash table data structure, need immutable and unique keys.
Comments
Post a Comment