HashMap.d.ts 956 B

12345678910111213141516171819202122
  1. import { initContainer } from "../ContainerBase";
  2. import HashContainer from './Base';
  3. declare class HashMap<K, V> extends HashContainer<K> {
  4. constructor(container?: initContainer<[K, V]>, initBucketNum?: number, hashFunc?: (x: K) => number);
  5. forEach(callback: (element: [K, V], index: number) => void): void;
  6. /**
  7. * @description Insert a new key-value pair to hash map or set value by key.
  8. * @param key The key you want to insert.
  9. * @param value The value you want to insert.
  10. * @example HashMap.setElement(1, 2); // insert a key-value pair [1, 2]
  11. */
  12. setElement(key: K, value: V): void;
  13. /**
  14. * @description Get the value of the element which has the specified key.
  15. * @param key The key you want to get.
  16. */
  17. getElementByKey(key: K): V | undefined;
  18. eraseElementByKey(key: K): void;
  19. find(key: K): boolean;
  20. [Symbol.iterator](): Generator<[K, V], void, unknown>;
  21. }
  22. export default HashMap;