Deque.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import SequentialContainer from './Base';
  2. import { initContainer } from "../ContainerBase";
  3. import { RandomIterator } from "./Base/RandomIterator";
  4. export declare class DequeIterator<T> extends RandomIterator<T> {
  5. copy(): DequeIterator<T>;
  6. }
  7. declare class Deque<T> extends SequentialContainer<T> {
  8. constructor(container?: initContainer<T>, _bucketSize?: number);
  9. clear(): void;
  10. front(): T | undefined;
  11. back(): T | undefined;
  12. begin(): DequeIterator<T>;
  13. end(): DequeIterator<T>;
  14. rBegin(): DequeIterator<T>;
  15. rEnd(): DequeIterator<T>;
  16. pushBack(element: T): void;
  17. popBack(): void;
  18. /**
  19. * @description Push the element to the front.
  20. * @param element The element you want to push.
  21. */
  22. pushFront(element: T): void;
  23. /**
  24. * @description Remove the _first element.
  25. */
  26. popFront(): void;
  27. forEach(callback: (element: T, index: number) => void): void;
  28. getElementByPos(pos: number): T;
  29. setElementByPos(pos: number, element: T): void;
  30. insert(pos: number, element: T, num?: number): void;
  31. /**
  32. * @description Remove all elements after the specified position (excluding the specified position).
  33. * @param pos The previous position of the _first removed element.
  34. * @example deque.cut(1); // Then deque's size will be 2. deque -> [0, 1]
  35. */
  36. cut(pos: number): void;
  37. eraseElementByPos(pos: number): void;
  38. eraseElementByValue(value: T): void;
  39. eraseElementByIterator(iter: DequeIterator<T>): DequeIterator<T>;
  40. find(element: T): DequeIterator<T>;
  41. reverse(): void;
  42. unique(): void;
  43. sort(cmp?: (x: T, y: T) => number): void;
  44. /**
  45. * @description Remove as much useless space as possible.
  46. */
  47. shrinkToFit(): void;
  48. [Symbol.iterator](): Generator<T, void, unknown>;
  49. }
  50. export default Deque;