9470c4ef9b0557e666decc806aa19ee376ab3d4fc9522d484c8c90a627e48551bf942442b1da7980585482fe5652956d5d76ce20a420fadd1c22d1c208609c 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. declare type Key = string | number | symbol;
  2. /**
  3. * SetArray acts like a `Set` (allowing only one occurrence of a string `key`), but provides the
  4. * index of the `key` in the backing array.
  5. *
  6. * This is designed to allow synchronizing a second array with the contents of the backing array,
  7. * like how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`,
  8. * and there are never duplicates.
  9. */
  10. export declare class SetArray<T extends Key = Key> {
  11. private _indexes;
  12. array: readonly T[];
  13. constructor();
  14. }
  15. /**
  16. * Gets the index associated with `key` in the backing array, if it is already present.
  17. */
  18. export declare function get<T extends Key>(setarr: SetArray<T>, key: T): number | undefined;
  19. /**
  20. * Puts `key` into the backing array, if it is not already present. Returns
  21. * the index of the `key` in the backing array.
  22. */
  23. export declare function put<T extends Key>(setarr: SetArray<T>, key: T): number;
  24. /**
  25. * Pops the last added item out of the SetArray.
  26. */
  27. export declare function pop<T extends Key>(setarr: SetArray<T>): void;
  28. /**
  29. * Removes the key, if it exists in the set.
  30. */
  31. export declare function remove<T extends Key>(setarr: SetArray<T>, key: T): void;
  32. export {};