hashset.tex 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. \chapter{THashSet}
  2. Implements container for storing unordered set of unique elements.
  3. Takes 2 arguments for specialization, first one is type of elements, second one is a hash functor
  4. (class which has class function hash, which takes element and number $n$ and returns hash of the
  5. element in range $0, 1, \dots, n-1$).
  6. Usage example:
  7. \lstinputlisting[language=Pascal]{hashsetexample.pp}
  8. Memory complexity:
  9. Arounds two times of size of stored elements
  10. Members list:
  11. \begin{longtable}{|m{10cm}|m{5cm}|}
  12. \hline
  13. Method & Complexity guarantees \\ \hline
  14. \multicolumn{2}{|m{15cm}|}{Description} \\ \hline\hline
  15. \verb!Create! & O(1) \\ \hline
  16. \multicolumn{2}{|m{15cm}|}{Constructor. Creates empty set.} \\ \hline\hline
  17. \verb!function Size(): SizeUInt! & O(1) \\ \hline
  18. \multicolumn{2}{|m{15cm}|}{Returns number of elements in set.} \\\hline\hline
  19. \verb!procedure Insert(value: T)! &
  20. O(1) on average \\ \hline
  21. \multicolumn{2}{|m{15cm}|}{Inserts element into set, if given element is already there nothing
  22. happens.} \\\hline\hline
  23. \verb!procedure Delete(value: T)! &
  24. O(1) on average \\ \hline
  25. \multicolumn{2}{|m{15cm}|}{Deletes value from set. If element is not in set, nothing happens.} \\\hline\hline
  26. \verb!function Contains(value: T):boolean! & O(1) on average \\\hline
  27. \multicolumn{2}{|m{15cm}|}{Checks whether element is in set.} \\\hline\hline
  28. \verb!function Iterator:TIterator! & O(1) \\\hline
  29. \multicolumn{2}{|m{15cm}|}{Returns iterator allowing traversal through set. If set is empty returns nil.} \\\hline\hline
  30. \verb!function IsEmpty(): boolean! & O(1) \\ \hline
  31. \multicolumn{2}{|m{15cm}|}{Returns true when set is empty.} \\\hline
  32. \end{longtable}
  33. Some methods return type TIterator, which has following methods:
  34. \begin{longtable}{|m{10cm}|m{5cm}|}
  35. \hline
  36. Method & Complexity guarantees \\ \hline
  37. \multicolumn{2}{|m{15cm}|}{Description} \\ \hline\hline
  38. \verb!function Next:boolean! & O(N) worst case, but traversal of whole set takes O(N) time \\\hline
  39. \multicolumn{2}{|m{15cm}|}{Moves iterator to next larger element in set. Returns true on
  40. success. If the iterator is already pointing on last element returns false.} \\\hline\hline
  41. \verb!property Data:T! & $O(1)$ \\\hline
  42. \multicolumn{2}{|m{15cm}|}{Property, which allows reading of the element.} \\\hline
  43. \end{longtable}