86496df601cafde451e7a5da021fe7e7c0a77d11d2b253d5e405f8c819acba2797ea12f2900594c10d6b7b2cdc515c32534272fabba23ec196c4842ba2acd5 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Container } from "../../ContainerBase";
  2. declare abstract class SequentialContainer<T> extends Container<T> {
  3. /**
  4. * @description Push the element to the back.
  5. * @param element - The element you want to push.
  6. * @returns The size of container after pushing.
  7. */
  8. abstract pushBack(element: T): number;
  9. /**
  10. * @description Removes the last element.
  11. * @returns The element you popped.
  12. */
  13. abstract popBack(): T | undefined;
  14. /**
  15. * @description Sets element by position.
  16. * @param pos - The position you want to change.
  17. * @param element - The element's value you want to update.
  18. * @example
  19. * container.setElementByPos(-1, 1); // throw a RangeError
  20. */
  21. abstract setElementByPos(pos: number, element: T): void;
  22. /**
  23. * @description Removes the elements of the specified value.
  24. * @param value - The value you want to remove.
  25. * @returns The size of container after erasing.
  26. * @example
  27. * container.eraseElementByValue(-1);
  28. */
  29. abstract eraseElementByValue(value: T): number;
  30. /**
  31. * @description Insert several elements after the specified position.
  32. * @param pos - The position you want to insert.
  33. * @param element - The element you want to insert.
  34. * @param num - The number of elements you want to insert (default 1).
  35. * @returns The size of container after inserting.
  36. * @example
  37. * const container = new Vector([1, 2, 3]);
  38. * container.insert(1, 4); // [1, 4, 2, 3]
  39. * container.insert(1, 5, 3); // [1, 5, 5, 5, 4, 2, 3]
  40. */
  41. abstract insert(pos: number, element: T, num?: number): number;
  42. /**
  43. * @description Reverses the container.
  44. * @example
  45. * const container = new Vector([1, 2, 3]);
  46. * container.reverse(); // [3, 2, 1]
  47. */
  48. abstract reverse(): void;
  49. /**
  50. * @description Removes the duplication of elements in the container.
  51. * @returns The size of container after inserting.
  52. * @example
  53. * const container = new Vector([1, 1, 3, 2, 2, 5, 5, 2]);
  54. * container.unique(); // [1, 3, 2, 5, 2]
  55. */
  56. abstract unique(): number;
  57. /**
  58. * @description Sort the container.
  59. * @param cmp - Comparison function to sort.
  60. * @example
  61. * const container = new Vector([3, 1, 10]);
  62. * container.sort(); // [1, 10, 3]
  63. * container.sort((x, y) => x - y); // [1, 3, 10]
  64. */
  65. abstract sort(cmp?: (x: T, y: T) => number): void;
  66. }
  67. export default SequentialContainer;