f1aa73a72dba2d15a0f1205a575da4dd4db67e180cbf36ddd7b339850d6fe3cfa1d3680b78585bd9c0914d6349b19ffabc107b7ee259860244c8f05cf2b56a 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { initContainer, IteratorType } from "../ContainerBase";
  2. import { HashContainer, HashContainerIterator, HashLinkNode } from "./Base";
  3. declare class HashMapIterator<K, V> extends HashContainerIterator<K, V> {
  4. readonly container: HashMap<K, V>;
  5. constructor(node: HashLinkNode<K, V>, header: HashLinkNode<K, V>, container: HashMap<K, V>, iteratorType?: IteratorType);
  6. get pointer(): [K, V];
  7. copy(): HashMapIterator<K, V>;
  8. equals(iter: HashMapIterator<K, V>): boolean;
  9. }
  10. export type { HashMapIterator };
  11. declare class HashMap<K, V> extends HashContainer<K, V> {
  12. constructor(container?: initContainer<[K, V]>);
  13. begin(): HashMapIterator<K, V>;
  14. end(): HashMapIterator<K, V>;
  15. rBegin(): HashMapIterator<K, V>;
  16. rEnd(): HashMapIterator<K, V>;
  17. front(): [K, V] | undefined;
  18. back(): [K, V] | undefined;
  19. /**
  20. * @description Insert a key-value pair or set value by the given key.
  21. * @param key - The key want to insert.
  22. * @param value - The value want to set.
  23. * @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/>
  24. * If a `undefined` value is passed in, the type will be automatically judged.
  25. * @returns The size of container after setting.
  26. */
  27. setElement(key: K, value: V, isObject?: boolean): number;
  28. /**
  29. * @description Get the value of the element of the specified key.
  30. * @param key - The key want to search.
  31. * @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/>
  32. * If a `undefined` value is passed in, the type will be automatically judged.
  33. * @example
  34. * const val = container.getElementByKey(1);
  35. */
  36. getElementByKey(key: K, isObject?: boolean): V | undefined;
  37. getElementByPos(pos: number): [K, V];
  38. /**
  39. * @description Check key if exist in container.
  40. * @param key - The element you want to search.
  41. * @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/>
  42. * If a `undefined` value is passed in, the type will be automatically judged.
  43. * @returns An iterator pointing to the element if found, or super end if not found.
  44. */
  45. find(key: K, isObject?: boolean): HashMapIterator<K, V>;
  46. forEach(callback: (element: [K, V], index: number, hashMap: HashMap<K, V>) => void): void;
  47. [Symbol.iterator](): Generator<[K, V], void, unknown>;
  48. }
  49. export default HashMap;