83d627505c337579e7f197dd84551d639a2ce914e588c74b8688cb019525d186ce811bfb32e5976401ed6e5afd55dee230e65256867dc684ef357d3269d6ba 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type TreeIterator from './TreeIterator';
  2. import { Container } from "../../ContainerBase";
  3. declare abstract class TreeContainer<K, V> extends Container<K | [K, V]> {
  4. clear(): void;
  5. /**
  6. * @description Update node's key by iterator.
  7. * @param iter - The iterator you want to change.
  8. * @param key - The key you want to update.
  9. * @returns Whether the modification is successful.
  10. * @example
  11. * const st = new orderedSet([1, 2, 5]);
  12. * const iter = st.find(2);
  13. * st.updateKeyByIterator(iter, 3); // then st will become [1, 3, 5]
  14. */
  15. updateKeyByIterator(iter: TreeIterator<K, V>, key: K): boolean;
  16. eraseElementByPos(pos: number): number;
  17. /**
  18. * @description Remove the element of the specified key.
  19. * @param key - The key you want to remove.
  20. * @returns Whether erase successfully.
  21. */
  22. eraseElementByKey(key: K): boolean;
  23. eraseElementByIterator(iter: TreeIterator<K, V>): TreeIterator<K, V>;
  24. forEach(callback: (element: K | [K, V], index: number, tree: TreeContainer<K, V>) => void): void;
  25. getElementByPos(pos: number): K | [K, V];
  26. /**
  27. * @description Get the height of the tree.
  28. * @returns Number about the height of the RB-tree.
  29. */
  30. getHeight(): number;
  31. /**
  32. * @param key - The given key you want to compare.
  33. * @returns An iterator to the first element less than the given key.
  34. */
  35. abstract reverseUpperBound(key: K): TreeIterator<K, V>;
  36. /**
  37. * @description Union the other tree to self.
  38. * @param other - The other tree container you want to merge.
  39. * @returns The size of the tree after union.
  40. */
  41. abstract union(other: TreeContainer<K, V>): number;
  42. /**
  43. * @param key - The given key you want to compare.
  44. * @returns An iterator to the first element not greater than the given key.
  45. */
  46. abstract reverseLowerBound(key: K): TreeIterator<K, V>;
  47. /**
  48. * @param key - The given key you want to compare.
  49. * @returns An iterator to the first element not less than the given key.
  50. */
  51. abstract lowerBound(key: K): TreeIterator<K, V>;
  52. /**
  53. * @param key - The given key you want to compare.
  54. * @returns An iterator to the first element greater than the given key.
  55. */
  56. abstract upperBound(key: K): TreeIterator<K, V>;
  57. }
  58. export default TreeContainer;