Move SetCache modules into SetCache.

This commit is contained in:
John-David Dalton
2017-01-10 10:24:52 -08:00
parent 0cd28f982d
commit c64a3bd3df
3 changed files with 36 additions and 46 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;