<commit_before>/**
 * A utility class to help make it easier to access the data stores
 * @extends {Map}
 */
class Collection extends Map {
  set(key, value) {
    super.set(key, value);
    this.changed = true;
  }

  delete(key) {
    super.delete(key);
    this.changed = true;
  }

  /**
   * Returns an ordered array of the values of this collection.
   * @returns {Array}
   * @example
   * // identical to:
   * Array.from(collection.values());
   */
  array() {
    return Array.from(this.values());
  }

  /**
   * Returns an ordered array of the keys of this collection.
   * @returns {Array}
   * @example
   * // identical to:
   * Array.from(collection.keys());
   */
  keyArray() {
    return Array.from(this.keys());
  }

  /**
   * Returns the first item in this collection.
   * @returns {*}
   */
  first() {
    return this.values().next().value;
  }

  /**
   * Returns the first key in this collection.
   * @returns {*}
   */
  firstKey() {
    return this.keys().next().value;
  }

  /**
   * Returns the last item in this collection. This is a relatively slow operation,
   * since an array copy of the values must be made to find the last element.
   * @returns {*}
   */
  last() {
    const arr = this.array();
    return arr[arr.length - 1];
  }

  /**
   * Returns the last key in this collection. This is a relatively slow operation,
   * since an array copy of the keys must be made to find the last element.
   * @returns {*}
   */
  lastKey() {
    const arr = this.keyArray();
    return arr[arr.length - 1];
  }

  /**
   * Returns a random item from this collection. This is a relatively slow operation,
   * since an array copy of the values must be made to find a random element.
   * @returns {*}
   */
  random() {
    if (!this.cachedArray || this.cachedArray.length !== this.size || this.changed) {
      this.cachedArray = this.array();
      this.changed = false;
    }
    return this.cachedArray[Math.floor(Math.random() * this.cachedArray.length)];
  }

  /**
   * Returns a random key from this collection. This is a relatively slow operation,
   * since an array copy of the keys must be made to find a random element.
   * @returns {*}
   */
  randomKey() {
    if (!this.cachedKeyArray || this.cachedKeyArray.length !== this.size || this.changed) {
      this.cachedKeyArray = this.keyArray();
      this.changed = false;
    }
    return this.cachedKeyArray[Math.floor(Math.random() * this.cachedKeyArray.length)];
  }
<commit_msg>Revert "Cache array and keyArray in Collection (#771)"<commit_after>/**
 * A utility class to help make it easier to access the data stores
 * @extends {Map}
 */
class Collection extends Map {
  /**
   * Returns an ordered array of the values of this collection.
   * @returns {Array}
   * @example
   * // identical to:
   * Array.from(collection.values());
   */
  array() {
    return Array.from(this.values());
  }

  /**
   * Returns an ordered array of the keys of this collection.
   * @returns {Array}
   * @example
   * // identical to:
   * Array.from(collection.keys());
   */
  keyArray() {
    return Array.from(this.keys());
  }

  /**
   * Returns the first item in this collection.
   * @returns {*}
   */
  first() {
    return this.values().next().value;
  }

  /**
   * Returns the first key in this collection.
   * @returns {*}
   */
  firstKey() {
    return this.keys().next().value;
  }

  /**
   * Returns the last item in this collection. This is a relatively slow operation,
   * since an array copy of the values must be made to find the last element.
   * @returns {*}
   */
  last() {
    const arr = this.array();
    return arr[arr.length - 1];
  }

  /**
   * Returns the last key in this collection. This is a relatively slow operation,
   * since an array copy of the keys must be made to find the last element.
   * @returns {*}
   */
  lastKey() {
    const arr = this.keyArray();
    return arr[arr.length - 1];
  }

  /**
   * Returns a random item from this collection. This is a relatively slow operation,
   * since an array copy of the values must be made to find a random element.
   * @returns {*}
   */
  random() {
    const arr = this.array();
    return arr[Math.floor(Math.random() * arr.length)];
  }

  /**
   * Returns a random key from this collection. This is a relatively slow operation,
   * since an array copy of the keys must be made to find a random element.
   * @returns {*}
   */
  randomKey() {
    const arr = this.keyArray();
    return arr[Math.floor(Math.random() * arr.length)];
  }

{'fraction_non_alphanumeric': 0.1320546737213404, 'fraction_numerical': 0.0015432098765432098, 'mean_word_length': 2.566823899371069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '477393', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1360, 'n_words': 477}