<commit_before>require 'narray'
class OccupancyGrid
  def initialize(width,height)
#    @mutex = Mutex.new
    @grid = NArray.object(width, height)
  end

  def occupy(x, y, entity)
#    @mutex.synchronize do
      if free? x, y
        @grid[x,y] = entity
      else
        raise "Occupancy Overlap"
      end
#    end
  end

  def leave(x, y)
#    @mutex.synchronize do
      @grid[x,y] = nil
#    end
  end

  def free?(x,y)
#    @mutex.synchronize do
      @grid[x,y].nil?
#    end
  end

  def occupied?(x,y)
    not free? x, y
  end

  def get_occupants(x,y,w,h)
    occupants = {}
    w.times do |r|
      h.times do |c|
        ent = @grid[x+r,y+c]
        occupants[ent.server_id] = ent unless ent.nil?
      end
    end
    occupants.values
  end

end
<commit_msg>occupancy grid get_occupants now uses ranges<commit_after>require 'narray'
class OccupancyGrid
  def initialize(width,height)
#    @mutex = Mutex.new
    @grid = NArray.object(width, height)
  end

  def occupy(x, y, entity)
#    @mutex.synchronize do
      if free? x, y
        @grid[x,y] = entity
      else
        raise "Occupancy Overlap"
      end
#    end
  end

  def leave(x, y)
#    @mutex.synchronize do
      @grid[x,y] = nil
#    end
  end

  def free?(x,y)
#    @mutex.synchronize do
      @grid[x,y].nil?
#    end
  end

  def occupied?(x,y)
    not free? x, y
  end

  def get_occupants(x,y,w,h)
    # TODO may be excluding units half on/off?
    occupants = {}
    rows = (x..x+w-1)
    cols = (y..y+h-1)
#    w.times do |r|
    for r in rows
      for c in cols
#      h.times do |c|
        ent = @grid[r,c]
        occupants[ent.server_id] = ent unless ent.nil?
      end
    end
    occupants.values
  end

end

{'fraction_non_alphanumeric': 0.1211943793911007, 'fraction_numerical': 0.00117096018735363, 'mean_word_length': 2.0792792792792794, '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': '4641871', 'n_tokens_mistral': 682, 'n_tokens_neox': 669, 'n_words': 172}