hashmap.tex 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. \chapter{THashMap}
  2. Implements container for unordered associative array with unique keys.
  3. Takes 3 arguments for specialization, first one is type of keys, second one is type of values, third
  4. one is is a hash functor
  5. (class which has class function hash, which takes element and number $n$ and returns hash of the
  6. element in range $0, 1, \dots, n-1$).
  7. Usage example:
  8. \lstinputlisting[language=Pascal]{hashmapexample.pp}
  9. Memory complexity:
  10. Arounds two times of size of stored elements
  11. Members list:
  12. \begin{longtable}{|m{10cm}|m{5cm}|}
  13. \hline
  14. Method & Complexity guarantees \\ \hline
  15. \multicolumn{2}{|m{15cm}|}{Description} \\ \hline\hline
  16. \verb!Create! & O(1) \\ \hline
  17. \multicolumn{2}{|m{15cm}|}{Constructor. Creates empty map.} \\ \hline\hline
  18. \verb!function Size(): SizeUInt! & O(1) \\ \hline
  19. \multicolumn{2}{|m{15cm}|}{Returns number of elements in map.} \\\hline\hline
  20. \verb!procedure Insert(key: TKey; value: TValue)! &
  21. O(1) \\ \hline
  22. \multicolumn{2}{|m{15cm}|}{Inserts key value pair into map. If key was already there, it will have
  23. new value assigned.} \\\hline\hline
  24. \verb!procedure Delete(key: TKey)! &
  25. O(lg N) \\ \hline
  26. \multicolumn{2}{|m{15cm}|}{Deletes key (and associated value) from map. If element is not in map, nothing happens.} \\\hline\hline
  27. \verb!function Contains(key: TKey):boolean! & O(1) on average \\\hline
  28. \multicolumn{2}{|m{15cm}|}{Checks whether element with given key is in map.} \\\hline\hline
  29. \verb!function Iterator:TIterator! & O(1) on average \\\hline
  30. \multicolumn{2}{|m{15cm}|}{Returns iterator allowing traversal through map. If map is empty returns nil.} \\\hline\hline
  31. \verb!function IsEmpty(): boolean! & O(1) \\ \hline
  32. \multicolumn{2}{|m{15cm}|}{Returns true when map is empty.} \\\hline
  33. \verb!property item[i: Key]: TValue; default;! & O(1) on average \\\hline
  34. \multicolumn{2}{|m{15cm}|}{Property for accessing key i in map. Can be used just by square
  35. brackets (its default property).} \\\hline\hline
  36. \end{longtable}
  37. Some methods return type TIterator, which has following methods:
  38. \begin{longtable}{|m{10cm}|m{5cm}|}
  39. \hline
  40. Method & Complexity guarantees \\ \hline
  41. \multicolumn{2}{|m{15cm}|}{Description} \\ \hline\hline
  42. \verb!function Next:boolean! & O(N) worst case, but traversal of whole set takes O(N) time \\\hline
  43. \multicolumn{2}{|m{15cm}|}{Moves iterator to next larger element in set. Returns true on
  44. success. If the iterator is already pointing on last element returns false.} \\\hline\hline
  45. \verb!property Key:TKey! & $O(1)$ \\\hline
  46. \multicolumn{2}{|m{15cm}|}{Property, which allows reading the key.} \\\hline
  47. \verb!property Value:TValue! & $O(1)$ \\\hline
  48. \multicolumn{2}{|m{15cm}|}{Property, which allows reading and writing of the value.} \\\hline
  49. \verb!property MutableValue:PValue! & $O(1)$ \\\hline
  50. \multicolumn{2}{|m{15cm}|}{Returns pointer on stored value. Usefull for accessing records and
  51. objects.} \\\hline
  52. \end{longtable}