vector.tex 2.9 KB

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