_MapCache.js 869 B

123456789101112131415161718192021222324252627282930313233
  1. var mapCacheClear = require('./_mapCacheClear'),
  2. mapCacheDelete = require('./_mapCacheDelete'),
  3. mapCacheGet = require('./_mapCacheGet'),
  4. mapCacheHas = require('./_mapCacheHas'),
  5. mapCacheSet = require('./_mapCacheSet');
  6. /**
  7. * Creates a map cache object to store key-value pairs.
  8. *
  9. * @private
  10. * @constructor
  11. * @param {Array} [entries] The key-value pairs to cache.
  12. */
  13. function MapCache(entries) {
  14. var index = -1,
  15. length = entries == null ? 0 : entries.length;
  16. this.clear();
  17. while (++index < length) {
  18. var entry = entries[index];
  19. this.set(entry[0], entry[1]);
  20. }
  21. }
  22. // Add methods to `MapCache`.
  23. MapCache.prototype.clear = mapCacheClear;
  24. MapCache.prototype['delete'] = mapCacheDelete;
  25. MapCache.prototype.get = mapCacheGet;
  26. MapCache.prototype.has = mapCacheHas;
  27. MapCache.prototype.set = mapCacheSet;
  28. module.exports = MapCache;