lib/purecdb/reader.rb
# Returns all values for +key+ in an array
Returns all values for +key+ in an array
Returns all values for + key + in an array
def values(key)
      h = hash(key)
      hoff = @hashes[(h % 256)*2]
      hlen = @hashes[(h % 256)*2 + 1]
      return [] if hlen == 0
      off = (h / 256) % hlen
      vals = []
      while
          (slot = read(hoff + off * hashref_size .. hoff + off * hashref_size + hashref_size - 1)) &&
          (dslot = ary_unpack(slot,2)) && dslot[1] != 0
        if dslot[0] == h
          pos = dslot[1]
          rkey, value = read_entry(pos)
          if rkey == key
            vals << value
          end
        end
        off = (off + 1) % hlen
      end
      return vals
    end
def values ( key ) h = hash ( key ) hoff = @hashes [ ( h % 256 ) * 2 ] hlen = @hashes [ ( h % 256 ) * 2 + 1 ] return [ ] if hlen == 0 off = ( h / 256 ) % hlen vals = [ ] while ( slot = read ( hoff + off * hashref_size .. hoff + off * hashref_size + hashref_size - 1 ) ) && ( dslot = ary_unpack ( slot , 2 ) ) && dslot [ 1 ] != 0 if dslot [ 0 ] == h pos = dslot [ 1 ] rkey , value = read_entry ( pos ) if rkey == key vals << value end end off = ( off + 1 ) % hlen end return vals end
Returns all values for +key+ in an array
Returns all values for + key + in an array
# FIXME: Is this potentially an infinite loop (if full)? # Easy to avoid by exiting if off reaches the same value twice.
key
<not_specific>