Sunday, June 14, 2009

Chapter 4-Lesson 3

  • Dictionary classes in .NET framework are used to map a Key to a Value.
  • Useful when creating Lookup tables.
  • Dictionaries can also use indexers.
  • Objects in Dictionaries are typically of type DictionaryEntry, which hold a key and a value.
  • All Dictionary classes derive from IDictionary which in turn derives from ICollection interface.
  • The ContainsKey( )/ContainsValue( ) methods in HashTable are used to know the existance of specific Keys/Values in a HashTable collection.
  • HashTable uses unique Hash values to store Values. So using the same Key for different values over time would retain just the latest because all others would overwrite each other.
  • Hash values are internally integers.
  • When using strings as Key, the string class overrides the GetHashCode( ) and Equals( ) method of the object class to make sure two similar strings in the Key specification get to the same Hash value in the collection (keep in mind strings are by default immutable)
  • Therefore, if we use our objects' reference as Key, we might want to override these methods to make sure two instances with some property similar between them would be treated as the same Key point in the collection. (See Page 214-215 [Fish class example] in MS Press Book)
  • The IComparer interface allows for sorting of objects of a class.
  • We may supply object from a class that implements IEqualityComparer in the constructor of a HashTable. IEqualityComparer provides the same two methods discussed above to provide results of comparison in HashTable. Details on Page 216.
  • HashTable returns items in the order of their Hash Values while traversal.
  • SortedList collection returns objects in the sorted order. Sorting takes place with respect to Key.
  • The indices of the DictionaryEntry objects may change as items are added or removed.
  • HashTable is not good (in performance) for small collections (fewer than ten elements). Instead, use ListDictionary.
  • HybirdDictionary starts as a ListDictionary and, as the data grows converts itself into a HashTable. Usage is same as HashTable.
  • HashTable does NOT allow access to items by index.
  • OrderedList class is used to attain performance of HashTable in large data scenario and at the same time allow the use of index for data items. Therefore it has extra methods that allow for insertion and removal as well as accessinf of data at specific index.

No comments:

Post a Comment