SetCache.js 706 B

1234567891011121314151617181920212223242526272829
  1. var cachePush = require('./cachePush'),
  2. getNative = require('./getNative');
  3. /** Native method references. */
  4. var Set = getNative(global, 'Set');
  5. /* Native method references for those with the same name as other `lodash` methods. */
  6. var nativeCreate = getNative(Object, 'create');
  7. /**
  8. *
  9. * Creates a cache object to store unique values.
  10. *
  11. * @private
  12. * @param {Array} [values] The values to cache.
  13. */
  14. function SetCache(values) {
  15. var length = values ? values.length : 0;
  16. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  17. while (length--) {
  18. this.push(values[length]);
  19. }
  20. }
  21. // Add functions to the `Set` cache.
  22. SetCache.prototype.push = cachePush;
  23. module.exports = SetCache;