From c64a3bd3df63e606e448bb0cccb64393d2508cb9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 10 Jan 2017 10:24:52 -0800 Subject: [PATCH] Move `SetCache` modules into `SetCache`. --- .internal/SetCache.js | 49 +++++++++++++++++++++++++++++----------- .internal/setCacheAdd.js | 19 ---------------- .internal/setCacheHas.js | 14 ------------ 3 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 .internal/setCacheAdd.js delete mode 100644 .internal/setCacheHas.js diff --git a/.internal/SetCache.js b/.internal/SetCache.js index 38124163d..aa0f87762 100644 --- a/.internal/SetCache.js +++ b/.internal/SetCache.js @@ -1,16 +1,17 @@ import MapCache from './.internal/MapCache.js'; -import setCacheAdd from './.internal/setCacheAdd.js'; -import setCacheHas from './.internal/setCacheHas.js'; -/** - * - * Creates an array cache object to store unique values. - * - * @private - * @constructor - * @param {Array} [values] The values to cache. - */ +/** Used to stand-in for `undefined` hash values. */ +const HASH_UNDEFINED = '__lodash_hash_undefined__'; + class SetCache { + + /** + * Creates an array cache object to store unique values. + * + * @private + * @constructor + * @param {Array} [values] The values to cache. + */ constructor(values) { let index = -1; const length = values == null ? 0 : values.length; @@ -20,10 +21,32 @@ class SetCache { this.add(values[index]); } } + + /** + * Adds `value` to the array cache. + * + * @memberOf SetCache + * @alias push + * @param {*} value The value to cache. + * @returns {Object} Returns the cache instance. + */ + add(value) { + this.__data__.set(value, HASH_UNDEFINED); + return this; + } + + /** + * Checks if `value` is in the array cache. + * + * @memberOf SetCache + * @param {*} value The value to search for. + * @returns {number} Returns `true` if `value` is found, else `false`. + */ + has(value) { + return this.__data__.has(value); + } } -// Add methods to `SetCache`. -SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; -SetCache.prototype.has = setCacheHas; +SetCache.prototype.push = SetCache.prototype.add; export default SetCache; diff --git a/.internal/setCacheAdd.js b/.internal/setCacheAdd.js deleted file mode 100644 index 23065e878..000000000 --- a/.internal/setCacheAdd.js +++ /dev/null @@ -1,19 +0,0 @@ -/** Used to stand-in for `undefined` hash values. */ -const HASH_UNDEFINED = '__lodash_hash_undefined__'; - -/** - * Adds `value` to the array cache. - * - * @private - * @name add - * @memberOf SetCache - * @alias push - * @param {*} value The value to cache. - * @returns {Object} Returns the cache instance. - */ -function setCacheAdd(value) { - this.__data__.set(value, HASH_UNDEFINED); - return this; -} - -export default setCacheAdd; diff --git a/.internal/setCacheHas.js b/.internal/setCacheHas.js deleted file mode 100644 index 67f4c8ae2..000000000 --- a/.internal/setCacheHas.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Checks if `value` is in the array cache. - * - * @private - * @name has - * @memberOf SetCache - * @param {*} value The value to search for. - * @returns {number} Returns `true` if `value` is found, else `false`. - */ -function setCacheHas(value) { - return this.__data__.has(value); -} - -export default setCacheHas;