HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/LC/node_modules/mnemonist/default-map.js
/**
 * Mnemonist DefaultMap
 * =====================
 *
 * JavaScript implementation of a default map that will return a constructed
 * value any time one tries to access an inexisting key. It's quite similar
 * to python's defaultdict.
 */

/**
 * DefaultMap.
 *
 * @constructor
 */
function DefaultMap(factory) {
  if (typeof factory !== 'function')
    throw new Error('mnemonist/DefaultMap.constructor: expecting a function.');

  this.items = new Map();
  this.factory = factory;
  this.size = 0;
}

/**
 * Method used to clear the structure.
 *
 * @return {undefined}
 */
DefaultMap.prototype.clear = function() {

  // Properties
  this.items.clear();
  this.size = 0;
};

/**
 * Method used to get the value set for given key. If the key does not exist,
 * the value will be created using the provided factory.
 *
 * @param  {any} key - Target key.
 * @return {any}
 */
DefaultMap.prototype.get = function(key) {
  var value = this.items.get(key);

  if (typeof value === 'undefined') {
    value = this.factory(key, this.size);
    this.items.set(key, value);
    this.size++;
  }

  return value;
};

/**
 * Method used to get the value set for given key. If the key does not exist,
 * a value won't be created.
 *
 * @param  {any} key - Target key.
 * @return {any}
 */
DefaultMap.prototype.peek = function(key) {
  return this.items.get(key);
};

/**
 * Method used to set a value for given key.
 *
 * @param  {any} key   - Target key.
 * @param  {any} value - Value.
 * @return {DefaultMap}
 */
DefaultMap.prototype.set = function(key, value) {
  this.items.set(key, value);
  this.size = this.items.size;

  return this;
};

/**
 * Method used to test the existence of a key in the map.
 *
 * @param  {any} key   - Target key.
 * @return {boolean}
 */
DefaultMap.prototype.has = function(key) {
  return this.items.has(key);
};

/**
 * Method used to delete target key.
 *
 * @param  {any} key   - Target key.
 * @return {boolean}
 */
DefaultMap.prototype.delete = function(key) {
  var deleted = this.items.delete(key);

  this.size = this.items.size;

  return deleted;
};

/**
 * Method used to iterate over each of the key/value pairs.
 *
 * @param  {function}  callback - Function to call for each item.
 * @param  {object}    scope    - Optional scope.
 * @return {undefined}
 */
DefaultMap.prototype.forEach = function(callback, scope) {
  scope = arguments.length > 1 ? scope : this;

  this.items.forEach(callback, scope);
};

/**
 * Iterators.
 */
DefaultMap.prototype.entries = function() {
  return this.items.entries();
};

DefaultMap.prototype.keys = function() {
  return this.items.keys();
};

DefaultMap.prototype.values = function() {
  return this.items.values();
};

/**
 * Attaching the #.entries method to Symbol.iterator if possible.
 */
if (typeof Symbol !== 'undefined')
  DefaultMap.prototype[Symbol.iterator] = DefaultMap.prototype.entries;

/**
 * Convenience known methods.
 */
DefaultMap.prototype.inspect = function() {
  return this.items;
};

if (typeof Symbol !== 'undefined')
  DefaultMap.prototype[Symbol.for('nodejs.util.inspect.custom')] = DefaultMap.prototype.inspect;

/**
 * Typical factories.
 */
DefaultMap.autoIncrement = function() {
  var i = 0;

  return function() {
    return i++;
  };
};

/**
 * Exporting.
 */
module.exports = DefaultMap;