deque.tex 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. \chapter{TDeque}
  2. Implements selfresizing array. Indexing is 0-based.
  3. Also implement constant time insertion from front.
  4. Usage example:
  5. \lstinputlisting[language=Pascal]{dequeexample.pp}
  6. Memory complexity:
  7. Uses at most 3times bigger memory than maximal array size (this is only case during reallocation).
  8. Normal consumption is at most twice as maximal array size.
  9. Members list:
  10. \begin{longtable}{|m{10cm}|m{5cm}|}
  11. \hline
  12. Method & Complexity guarantees \\ \hline
  13. \multicolumn{2}{|m{15cm}|}{Description} \\ \hline\hline
  14. \verb!Create! & O(1) \\ \hline
  15. \multicolumn{2}{|m{15cm}|}{Constructor. Creates empty array.} \\ \hline\hline
  16. \verb!function Size(): SizeUInt! & O(1) \\ \hline
  17. \multicolumn{2}{|m{15cm}|}{Returns size of array.} \\\hline\hline
  18. \verb!procedure PushBack(value: T)! & Amortized
  19. O(1), some operations might take O(N) time, when array needs to be reallocated, but sequence of N
  20. operations takes O(N) time. \\ \hline
  21. \multicolumn{2}{|m{15cm}|}{Inserts at the end of array (increases size by 1)} \\\hline\hline
  22. \verb!procedure PopBack()! & O(1) \\\hline
  23. \multicolumn{2}{|m{15cm}|}{Removes element from the end of array (decreases size by 1). When array
  24. is empty, does nothing.} \\\hline\hline
  25. \verb!procedure PushFront(value: T)! & Same as PushBack. \\ \hline
  26. \multicolumn{2}{|m{15cm}|}{Inserts at the beginning of array (increases size by 1)} \\\hline\hline
  27. \verb!procedure PopFront()! & O(1) \\\hline
  28. \multicolumn{2}{|m{15cm}|}{Removes element from the beginning of array (decreases size by 1). When array
  29. is empty, does nothing.} \\\hline\hline
  30. \verb!function IsEmpty(): boolean! & O(1) \\ \hline
  31. \multicolumn{2}{|m{15cm}|}{Returns true when array is empty} \\\hline\hline
  32. \verb!procedure Insert(position: SizeUInt; value: T)! & O(N) \\\hline
  33. \multicolumn{2}{|m{15cm}|}{Inserts value at position. When position is greater than size, puts value
  34. at the end of array.} \\\hline\hline
  35. \verb!procedure Erase(positine: SizeUInt; value: T)! & O(N) \\\hline
  36. \multicolumn{2}{|m{15cm}|}{Erases element from position. When position is outside of array does
  37. nothing.} \\\hline\hline
  38. \verb!procedure Clear! & O(1) \\\hline
  39. \multicolumn{2}{|m{15cm}|}{Clears array (set size to zero). But doesn't free memory used by array.}
  40. \\\hline\hline
  41. \verb!function Front: T! & O(1) \\\hline
  42. \multicolumn{2}{|m{15cm}|}{Returns first element from array.} \\\hline\hline
  43. \verb!function Back: T! & O(1) \\\hline
  44. \multicolumn{2}{|m{15cm}|}{Returns last element from array.} \\\hline\hline
  45. \verb!procedure Resize(num: SizeUInt)! & O(N) \\\hline
  46. \multicolumn{2}{|m{15cm}|}{Changes size of array to num. Doesn't guarantte anything about value of
  47. newly alocated elements.} \\\hline\hline
  48. \verb!procedure Reserve(num: SizeUInt)! & O(N) \\\hline
  49. \multicolumn{2}{|m{15cm}|}{Alocates at least num elements for array. Usefull when you want to
  50. pushback big number of elements and want to avoid frequent reallocation.} \\\hline\hline
  51. \verb!property item[i: SizeUInt]: T; default;! & O(1) \\\hline
  52. \multicolumn{2}{|m{15cm}|}{Property for accessing i-th element in array. Can be used just by square
  53. brackets (its default property).} \\\hline\hline
  54. \verb!property mutable[i: SizeUInt]: T;! & O(1) \\\hline
  55. \multicolumn{2}{|m{15cm}|}{Returns pointer to i-th element in array. Usefull when you store records.} \\\hline
  56. \end{longtable}