<commit_before>// Slightly modified from http://entitycrisis.blogspot.com/2011/07/spatial-hash-in-javascript-for-2d.html
function SpatialHash (cellSize) {
  this.cellSize = cellSize;
  this.idx = [];
}

SpatialHash.prototype = {
  add: function (x, y, object) {
    var cell = [];
    var keys = this.keys(x, y);

    // Add to self and neighbouring cells
    for (var i in keys) {
      var key = keys[i];

      if (key in this.idx) {
        cell = this.idx[key];
      } else {
        this.idx[key] = cell;
      }

      if (cell.indexOf(object) === -1) {
        cell.push(object);
      }
    }
  },

  query: function (x, y) {
    var key = this.key(x, y);
    return (typeof this.idx[key] === 'undefined') ? [] : this.idx[key];
  },

  // Get own and neighbouring cells
  keys: function (x, y) {
    var d = this.cellSize / 2;
    return [
      this.key(x-d, y-d),
      this.key(x,   y-d),
      this.key(x+d, y-d),

      this.key(x-d, y),
      this.key(x,   y),
      this.key(x+d, y),

      this.key(x-d, y+d),
      this.key(x,   y+d),
      this.key(x+d, y+d)
    ];
  },
<commit_msg>Make spatial hash more flexible.<commit_after>// Slightly modified from http://entitycrisis.blogspot.com/2011/07/spatial-hash-in-javascript-for-2d.html
function SpatialHash (cellSize) {
  this.cellSize = cellSize;
  this.idx = [];
}

SpatialHash.prototype = {
  add: function (x, y, object) {
    var cell = [];
    var key = this.key(x, y);

    if (typeof this.idx.key !== 'undefined') {
      cell = this.idx[key];
    } else {
      this.idx[key] = cell;
    }

    if (cell.indexOf(object) === -1) {
      cell.push(object);
    }
  },

  query: function (x, y, pxRadius) {
    pxRadiux = pxRadius || this.cellSize;
    var keys = this.keys(x, y, pxRadius);
    var results = [];

    for (var i = 0; i < keys.length; i++) {
      var key = keys[i];
      if (typeof this.idx[key] !== 'undefined')
        results.push(this.idx[key]);
    }

    return [].concat.apply([], results); // flatten results array
  },

  // Obtain keys for cells in a radius (default 1 cell around)  cell at x, y position
  keys: function (x, y, pxRadius) {
    var d = this.cellSize / 2;
    var results = [];
    var depth = Math.ceil(pxRadiux / this.cellSize);

    for (var i = -depth; i <= depth; i++) {
      for (var j = -depth; j <= depth; j++) {
        results.push(this.key(x + i * this.cellSize, y + j * this.cellSize));
      }
    }

    return results;
  },

{'fraction_non_alphanumeric': 0.17202114680764538, 'fraction_numerical': 0.008133387555917039, 'mean_word_length': 2.203125, 'pattern_counts': {'":': 0, '<': 6, '<?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': '730401', 'n_tokens_mistral': 933, 'n_tokens_neox': 900, 'n_words': 224}