<commit_before>FLOOR = Math.floor
CEIL = Math.ceil

class SpatialHash
  lookup: null
  width: 0
  height: 0
  pixelWidth: 0
  pixelHeight: 0
  maxHash: 0
  constructor: (options)->
    if options
      @width = options.width if options.width
      @height = options.height if options.height
      @pixelWidth = options.pixelWidth if options.pixelWidth
      @pixelHeight = options.pixelHeight if options.pixelHeight
      @maxHash = @width * @height / @pixelWidth / @pixelHeight
    @lookup = {}
  add: (object, layer = 'default')->
    position = object.position
    bounds = object.bounds
    if position?
      if bounds?
        @addBounds(object, layer)
      else
        hash = @hash(position.x, position.y)
        @addByHash(object, hash, layer)
  addByHash: (object, hash, layer)->
    if !(buckets = @lookup[hash])
      buckets = @lookup[hash] = {}
    if !(bucket = buckets[layer])
      bucket = buckets[layer] = []
    bucket.push(object)
  addBounds: (object, layer)->
    position = object.position
    bounds = object.bounds
    maxX = position.x+bounds.width
    maxY = position.y+bounds.height
    pixelWidth = @pixelWidth
    pixelHeight = @pixelHeight

    for x in [position.x..FLOOR(maxX/pixelWidth)*pixelWidth] by pixelWidth
      if x >= position.x
        for y in [position.y..FLOOR(maxY/pixelHeight)*pixelHeight] by pixelHeight
          if y >= position.y
            hash = @hash(x, y)
            @addByHash(object, hash, layer)
  get: (hash)->
    return @lookup[hash]
  hashRect: (sX, sY, width, height)->
    hashes = []
    maxX = sX+width
    maxY = sY+height
    pixelWidth = @pixelWidth
    pixelHeight = @pixelHeight
    for x in [sX..CEIL(maxX/pixelWidth)*pixelWidth] by pixelWidth
      if x >= sX
        for y in [sY..CEIL(maxY/pixelHeight)*pixelHeight] by pixelHeight
          if y >= sY
            hashes.push(@hash(x, y))<commit_msg>ceil fix<commit_after>FLOOR = Math.floor
CEIL = Math.ceil

class SpatialHash
  lookup: null
  width: 0
  height: 0
  pixelWidth: 0
  pixelHeight: 0
  maxHash: 0
  constructor: (options)->
    if options
      @width = options.width if options.width
      @height = options.height if options.height
      @pixelWidth = options.pixelWidth if options.pixelWidth
      @pixelHeight = options.pixelHeight if options.pixelHeight
      @maxHash = @width * @height / @pixelWidth / @pixelHeight
    @lookup = {}
  add: (object, layer = 'default')->
    position = object.position
    bounds = object.bounds
    if position?
      if bounds?
        @addBounds(object, layer)
      else
        hash = @hash(position.x, position.y)
        @addByHash(object, hash, layer)
  addByHash: (object, hash, layer)->
    if !(buckets = @lookup[hash])
      buckets = @lookup[hash] = {}
    if !(bucket = buckets[layer])
      bucket = buckets[layer] = []
    bucket.push(object)
  addBounds: (object, layer)->
    position = object.position
    bounds = object.bounds
    maxX = position.x+bounds.width
    maxY = position.y+bounds.height
    pixelWidth = @pixelWidth
    pixelHeight = @pixelHeight

    for x in [position.x..CEIL(maxX/pixelWidth)*pixelWidth] by pixelWidth
      if x >= position.x
        for y in [position.y..CEIL(maxY/pixelHeight)*pixelHeight] by pixelHeight
          if y >= position.y
            hash = @hash(x, y)
            @addByHash(object, hash, layer)
  get: (hash)->
    return @lookup[hash]
  hashRect: (sX, sY, width, height)->
    hashes = []
    maxX = sX+width
    maxY = sY+height
    pixelWidth = @pixelWidth
    pixelHeight = @pixelHeight
    for x in [sX..CEIL(maxX/pixelWidth)*pixelWidth] by pixelWidth
      if x >= sX
        for y in [sY..CEIL(maxY/pixelHeight)*pixelHeight] by pixelHeight
          if y >= sY
            hashes.push(@hash(x, y))
{'fraction_non_alphanumeric': 0.11924407772158638, 'fraction_numerical': 0.002661698163428267, 'mean_word_length': 2.6134615384615385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6165862', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1189, 'n_words': 314}