<commit_before>'use strict';

// http://stackoverflow.com/a/10090443/3055415
function getBits(k, m, n) {
  return ((k >> m) & ((1 << (n - m)) - 1));
}

function getBit(k, n) {
  return ((k) & (1 << n)) > 0 ? 1 : 0;
}


function encodeUnsignedInteger(data, offset, value, size) {
  switch (size) {
    case 1:
      return data.writeUInt8(value, offset);
    case 2:
      return data.writeUInt16LE(value, offset);
    case 4:
      return data.writeUInt32LE(value, offset);
    case 8:
      return data.writeBigUInt64LE(value, offset);
    default:
      throw new Error(`Invalid size: ${size}`);
  }
}

function decodeUnsignedInteger(data, offset, size) {
  switch (size) {
    case 1:
      return data.readUInt8(offset);
    case 2:
      return data.readUInt16LE(offset);
    case 4:
      return data.readUInt32LE(offset);
    case 8:
      return data.readBigUInt64LE(offset);
    default:
      throw new Error(`Invalid size: ${size}`);
  }
}


/**
 * @param {Object|Map} obj 
 */
function InvertKeyValues(obj) {
  let inverted;
  const type = Object.prototype.toString.call(obj);
  if (type === '[object Object]') {
    inverted = {};
    for (let [key, value] of Object.entries(obj)) {
      inverted[value] = key;
    }
  } else if (type === '[object Map]') {
    inverted = new Map();
    for (let [key, value] of obj.entries()) {
      inverted.set(value, key);
    }
  }
  return inverted;
}

/**
 * https://stackoverflow.com/a/12713611/3055415
 * @param {Function} fn 
 * @param {*} context 
 */
function once(fn, context) {
  let result;
  return function() {
    if (fn) {
      result = fn.apply(context || this, arguments);
      fn = null;
    }
    return result;
  };
}

<commit_msg>InvertKeyValues use switch<commit_after>'use strict';

// http://stackoverflow.com/a/10090443/3055415
function getBits(k, m, n) {
  return ((k >> m) & ((1 << (n - m)) - 1));
}

function getBit(k, n) {
  return ((k) & (1 << n)) > 0 ? 1 : 0;
}


function encodeUnsignedInteger(data, offset, value, size) {
  switch (size) {
    case 1:
      return data.writeUInt8(value, offset);
    case 2:
      return data.writeUInt16LE(value, offset);
    case 4:
      return data.writeUInt32LE(value, offset);
    case 8:
      return data.writeBigUInt64LE(value, offset);
    default:
      throw new Error(`Invalid size: ${size}`);
  }
}

function decodeUnsignedInteger(data, offset, size) {
  switch (size) {
    case 1:
      return data.readUInt8(offset);
    case 2:
      return data.readUInt16LE(offset);
    case 4:
      return data.readUInt32LE(offset);
    case 8:
      return data.readBigUInt64LE(offset);
    default:
      throw new Error(`Invalid size: ${size}`);
  }
}


/**
 * @param {Object|Map} obj 
 */
function InvertKeyValues(obj) {
  let inverted;
  switch (Object.prototype.toString.call(obj)) {
    case '[object Object]':
      inverted = {};
      for (let [key, value] of Object.entries(obj)) {
        inverted[value] = key;
      }
      break;
    case '[object Map]':
      inverted = new Map();
      for (let [key, value] of obj.entries()) {
        inverted.set(value, key);
      }
      break;
    default:
      break;
  }
  return inverted;
}
// function InvertKeyValues(obj) {
//   let inverted;
//   const type = Object.prototype.toString.call(obj);
//   if (type === '[object Object]') {
//     inverted = {};
//     for (let [key, value] of Object.entries(obj)) {
//       inverted[value] = key;
//     }
//   } else if (type === '[object Map]') {
//     inverted = new Map();
//     for (let [key, value] of obj.entries()) {
//       inverted.set(value, key);
//     }
//   }
//   return inverted;
// }

/**
 * https://stackoverflow.com/a/12713611/3055415
 * @param {Function} fn 
 * @param {*} context 
 */
function once(fn, context) {
  let result;
  return function() {
    if (fn) {
      result = fn.apply(context || this, arguments);
      fn = null;
    }
    return result;
  };
}


{'fraction_non_alphanumeric': 0.1633587786259542, 'fraction_numerical': 0.029516539440203562, 'mean_word_length': 2.583409298085688, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2167642', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1343, 'n_words': 338}