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