class NRSER::Labs::Index
A very basic index data structure that
Public Class Methods
new(entries = nil, sort: false, &indexer)
click to toggle source
Instantiate a new `NRSER::Index`.
# File lib/nrser/labs/index.rb, line 41 def initialize entries = nil, sort: false, &indexer @indexer = indexer @hash = Hash.new { |hash, key| hash[key] = Set.new } add( *entries ) if entries end
Public Instance Methods
[](key)
click to toggle source
# File lib/nrser/labs/index.rb, line 67 def [] key @hash[key] end
add(*entries)
click to toggle source
# File lib/nrser/labs/index.rb, line 72 def add *entries entries.each do |entry| @hash[key_for( entry )].add entry end self end
key_for(entry)
click to toggle source
keys()
click to toggle source
# File lib/nrser/labs/index.rb, line 57 def keys Set.new @hash.keys end
remove(*entries)
click to toggle source
# File lib/nrser/labs/index.rb, line 81 def remove *entries entries.each do |entry| @hash[key_for( entry )].remove entry end self end
values()
click to toggle source
# File lib/nrser/labs/index.rb, line 62 def values @hash.values.reduce :+ end