mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Move SetCache modules into SetCache.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user