diff --git a/.internal/Hash.js b/.internal/Hash.js index f90554060..d51f371f4 100644 --- a/.internal/Hash.js +++ b/.internal/Hash.js @@ -1,17 +1,15 @@ -import hashClear from './.internal/hashClear.js'; -import hashDelete from './.internal/hashDelete.js'; -import hashGet from './.internal/hashGet.js'; -import hashHas from './.internal/hashHas.js'; -import hashSet from './.internal/hashSet.js'; +/** Used to stand-in for `undefined` hash values. */ +const HASH_UNDEFINED = '__lodash_hash_undefined__'; -/** - * Creates a hash object. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ class Hash { + + /** + * Creates a hash object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ constructor(entries) { let index = -1; const length = entries == null ? 0 : entries.length; @@ -22,13 +20,70 @@ class Hash { this.set(entry[0], entry[1]); } } + + /** + * Removes all key-value entries from the hash. + * + * @memberOf Hash + */ + clear() { + this.__data__ = Object.create(null); + this.size = 0; + } + + /** + * Removes `key` and its value from the hash. + * + * @memberOf Hash + * @param {Object} hash The hash to modify. + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + delete(key) { + const result = this.has(key) && delete this.__data__[key]; + this.size -= result ? 1 : 0; + return result; + } + + /** + * Gets the hash value for `key`. + * + * @memberOf Hash + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + get(key) { + const data = this.__data__; + const result = data[key]; + return result === HASH_UNDEFINED ? undefined : result; + } + + /** + * Checks if a hash value for `key` exists. + * + * @memberOf Hash + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + has(key) { + const data = this.__data__; + return data[key] !== undefined; + } + + /** + * Sets the hash `key` to `value`. + * + * @memberOf Hash + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the hash instance. + */ + set(key, value) { + const data = this.__data__; + this.size += this.has(key) ? 0 : 1; + data[key] = value === undefined ? HASH_UNDEFINED : value; + return this; + } } -// Add methods to `Hash`. -Hash.prototype.clear = hashClear; -Hash.prototype['delete'] = hashDelete; -Hash.prototype.get = hashGet; -Hash.prototype.has = hashHas; -Hash.prototype.set = hashSet; - export default Hash; diff --git a/.internal/hashClear.js b/.internal/hashClear.js deleted file mode 100644 index efb5962af..000000000 --- a/.internal/hashClear.js +++ /dev/null @@ -1,15 +0,0 @@ -import nativeCreate from './.internal/nativeCreate.js'; - -/** - * Removes all key-value entries from the hash. - * - * @private - * @name clear - * @memberOf Hash - */ -function hashClear() { - this.__data__ = nativeCreate ? nativeCreate(null) : {}; - this.size = 0; -} - -export default hashClear; diff --git a/.internal/hashDelete.js b/.internal/hashDelete.js deleted file mode 100644 index 863dc6d69..000000000 --- a/.internal/hashDelete.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Removes `key` and its value from the hash. - * - * @private - * @name delete - * @memberOf Hash - * @param {Object} hash The hash to modify. - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ -function hashDelete(key) { - const result = this.has(key) && delete this.__data__[key]; - this.size -= result ? 1 : 0; - return result; -} - -export default hashDelete; diff --git a/.internal/hashGet.js b/.internal/hashGet.js deleted file mode 100644 index 4be6993e5..000000000 --- a/.internal/hashGet.js +++ /dev/null @@ -1,27 +0,0 @@ -import nativeCreate from './.internal/nativeCreate.js'; - -/** Used to stand-in for `undefined` hash values. */ -const HASH_UNDEFINED = '__lodash_hash_undefined__'; - -/** Used to check objects for own properties. */ -const hasOwnProperty = Object.prototype.hasOwnProperty; - -/** - * Gets the hash value for `key`. - * - * @private - * @name get - * @memberOf Hash - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ -function hashGet(key) { - const data = this.__data__; - if (nativeCreate) { - const result = data[key]; - return result === HASH_UNDEFINED ? undefined : result; - } - return hasOwnProperty.call(data, key) ? data[key] : undefined; -} - -export default hashGet; diff --git a/.internal/hashHas.js b/.internal/hashHas.js deleted file mode 100644 index 462df3ef6..000000000 --- a/.internal/hashHas.js +++ /dev/null @@ -1,20 +0,0 @@ -import nativeCreate from './.internal/nativeCreate.js'; - -/** Used to check objects for own properties. */ -const hasOwnProperty = Object.prototype.hasOwnProperty; - -/** - * Checks if a hash value for `key` exists. - * - * @private - * @name has - * @memberOf Hash - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ -function hashHas(key) { - const data = this.__data__; - return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key); -} - -export default hashHas; diff --git a/.internal/hashSet.js b/.internal/hashSet.js deleted file mode 100644 index 5062bc25c..000000000 --- a/.internal/hashSet.js +++ /dev/null @@ -1,23 +0,0 @@ -import nativeCreate from './.internal/nativeCreate.js'; - -/** Used to stand-in for `undefined` hash values. */ -const HASH_UNDEFINED = '__lodash_hash_undefined__'; - -/** - * Sets the hash `key` to `value`. - * - * @private - * @name set - * @memberOf Hash - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the hash instance. - */ -function hashSet(key, value) { - const data = this.__data__; - this.size += this.has(key) ? 0 : 1; - data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; - return this; -} - -export default hashSet;