PriorityQueue.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Base, initContainer } from "../ContainerBase";
  2. declare class PriorityQueue<T> extends Base {
  3. /**
  4. * @description PriorityQueue's constructor.
  5. * @param container Initialize container, must have a forEach function.
  6. * @param cmp Compare function.
  7. * @param copy When the container is an array, you can choose to directly operate on the original object of
  8. * the array or perform a shallow copy. The default is shallow copy.
  9. */
  10. constructor(container?: initContainer<T>, cmp?: (x: T, y: T) => number, copy?: boolean);
  11. clear(): void;
  12. /**
  13. * @description Push element into a container in order.
  14. * @param item The element you want to push.
  15. */
  16. push(item: T): void;
  17. /**
  18. * @description Removes the top element.
  19. */
  20. pop(): void;
  21. /**
  22. * @description Accesses the top element.
  23. */
  24. top(): T | undefined;
  25. /**
  26. * @description Check if element is in heap.
  27. * @param item The item want to find.
  28. * @return Boolean about if element is in heap.
  29. */
  30. find(item: T): boolean;
  31. /**
  32. * @description Remove specified item from heap.
  33. * @param item The item want to remove.
  34. * @return Boolean about if remove success.
  35. */
  36. remove(item: T): boolean;
  37. /**
  38. * @description Update item and it's pos in the heap.
  39. * @param item The item want to update.
  40. * @return Boolean about if update success.
  41. */
  42. updateItem(item: T): boolean;
  43. /**
  44. * @return Return a copy array of heap.
  45. */
  46. toArray(): T[];
  47. }
  48. export default PriorityQueue;