class Matching::HashIndex

Attributes

hashes[R]

Public Class Methods

new() click to toggle source
# File lib/matching/hash_index.rb, line 6
def initialize
  #one hash for each attribute
  @hashes = {}
end

Public Instance Methods

get(attr, val) click to toggle source

Return an array of object ids for a given attribute and value

# File lib/matching/hash_index.rb, line 20
def get(attr, val)
  (@hashes[attr] ? @hashes[attr][val] : nil)
end
put(attr, val, id) click to toggle source

Add a value to the index for a given attribute and object id

# File lib/matching/hash_index.rb, line 12
def put(attr, val, id)
  unless val.nil?
    h = @hashes[attr] || (@hashes[attr] = {})
    (h[val] ? h[val] << id : h[val] = [id])
  end
end