mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Move SetCache modules into SetCache.
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
import MapCache from './.internal/MapCache.js';
|
import MapCache from './.internal/MapCache.js';
|
||||||
import setCacheAdd from './.internal/setCacheAdd.js';
|
|
||||||
import setCacheHas from './.internal/setCacheHas.js';
|
|
||||||
|
|
||||||
/**
|
/** Used to stand-in for `undefined` hash values. */
|
||||||
*
|
const HASH_UNDEFINED = '__lodash_hash_undefined__';
|
||||||
* Creates an array cache object to store unique values.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @constructor
|
|
||||||
* @param {Array} [values] The values to cache.
|
|
||||||
*/
|
|
||||||
class SetCache {
|
class SetCache {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an array cache object to store unique values.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @constructor
|
||||||
|
* @param {Array} [values] The values to cache.
|
||||||
|
*/
|
||||||
constructor(values) {
|
constructor(values) {
|
||||||
let index = -1;
|
let index = -1;
|
||||||
const length = values == null ? 0 : values.length;
|
const length = values == null ? 0 : values.length;
|
||||||
@@ -20,10 +21,32 @@ class SetCache {
|
|||||||
this.add(values[index]);
|
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.push = SetCache.prototype.add;
|
||||||
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
|
||||||
SetCache.prototype.has = setCacheHas;
|
|
||||||
|
|
||||||
export default SetCache;
|
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