index.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. export declare const enum IteratorType {
  2. NORMAL = 0,
  3. REVERSE = 1
  4. }
  5. export declare abstract class ContainerIterator<T> {
  6. /**
  7. * @description Iterator's type.
  8. */
  9. readonly iteratorType: IteratorType;
  10. protected constructor(iteratorType?: IteratorType);
  11. /**
  12. * @description Pointers to element.
  13. * @return The value of the pointer's element.
  14. */
  15. abstract get pointer(): T;
  16. /**
  17. * @description Set pointer's value (some containers are unavailable).
  18. * @param newValue The new value you want to set.
  19. */
  20. abstract set pointer(newValue: T);
  21. /**
  22. * @description Move `this` iterator to pre.
  23. */
  24. abstract pre(): this;
  25. /**
  26. * @description Move `this` iterator to next.
  27. */
  28. abstract next(): this;
  29. /**
  30. * @param obj The other iterator you want to compare.
  31. * @return Boolean about if this equals to obj.
  32. * @example container.find(1).equals(container.end());
  33. */
  34. abstract equals(obj: ContainerIterator<T>): boolean;
  35. /**
  36. * @description Get a copy of itself.<br/>
  37. * We do not guarantee the safety of this function.<br/>
  38. * Please ensure that the iterator will not fail.
  39. * @return The copy of self.
  40. */
  41. abstract copy(): ContainerIterator<T>;
  42. }
  43. export declare abstract class Base {
  44. /**
  45. * @return The size of the container.
  46. */
  47. size(): number;
  48. /**
  49. * @return Boolean about if the container is empty.
  50. */
  51. empty(): boolean;
  52. /**
  53. * @description Clear the container.
  54. */
  55. abstract clear(): void;
  56. }
  57. export declare abstract class Container<T> extends Base {
  58. /**
  59. * @return Iterator pointing to the beginning element.
  60. */
  61. abstract begin(): ContainerIterator<T>;
  62. /**
  63. * @return Iterator pointing to the super end like c++.
  64. */
  65. abstract end(): ContainerIterator<T>;
  66. /**
  67. * @return Iterator pointing to the end element.
  68. */
  69. abstract rBegin(): ContainerIterator<T>;
  70. /**
  71. * @return Iterator pointing to the super begin like c++.
  72. */
  73. abstract rEnd(): ContainerIterator<T>;
  74. /**
  75. * @return The first element of the container.
  76. */
  77. abstract front(): T | undefined;
  78. /**
  79. * @return The last element of the container.
  80. */
  81. abstract back(): T | undefined;
  82. /**
  83. * @description Iterate over all elements in the container.
  84. * @param callback Callback function like Array.forEach.
  85. */
  86. abstract forEach(callback: (element: T, index: number) => void): void;
  87. /**
  88. * @param element The element you want to find.
  89. * @return An iterator pointing to the element if found, or super end if not found.
  90. */
  91. abstract find(element: T): ContainerIterator<T>;
  92. /**
  93. * @description Gets the value of the element at the specified position.
  94. */
  95. abstract getElementByPos(pos: number): T;
  96. /**
  97. * @description Removes the element at the specified position.
  98. * @param pos The element's position you want to remove.
  99. */
  100. abstract eraseElementByPos(pos: number): void;
  101. /**
  102. * @description Removes element by iterator and move `iter` to next.
  103. * @param iter The iterator you want to erase.
  104. * @example container.eraseElementByIterator(container.begin());
  105. */
  106. abstract eraseElementByIterator(iter: ContainerIterator<T>): ContainerIterator<T>;
  107. /**
  108. * @description Using for `for...of` syntax like Array.
  109. */
  110. abstract [Symbol.iterator](): Generator<T, void, undefined>;
  111. }
  112. export declare type initContainer<T> = ({
  113. size: number;
  114. } | {
  115. length: number;
  116. } | {
  117. size(): number;
  118. }) & {
  119. forEach(callback: (element: T) => void): void;
  120. };