MapCache.js 740 B

12345678910111213141516171819202122232425262728293031
  1. import mapClear from './mapClear';
  2. import mapDelete from './mapDelete';
  3. import mapGet from './mapGet';
  4. import mapHas from './mapHas';
  5. import mapSet from './mapSet';
  6. /**
  7. * Creates a map cache object to store key-value pairs.
  8. *
  9. * @private
  10. * @param {Array} [values] The values to cache.
  11. */
  12. function MapCache(values) {
  13. var index = -1,
  14. length = values ? values.length : 0;
  15. this.clear();
  16. while (++index < length) {
  17. var entry = values[index];
  18. this.set(entry[0], entry[1]);
  19. }
  20. }
  21. // Add functions to the `MapCache`.
  22. MapCache.prototype.clear = mapClear;
  23. MapCache.prototype['delete'] = mapDelete;
  24. MapCache.prototype.get = mapGet;
  25. MapCache.prototype.has = mapHas;
  26. MapCache.prototype.set = mapSet;
  27. export default MapCache;