Class: Wongi::Engine::AlphaIndex
- Inherits:
-
Object
- Object
- Wongi::Engine::AlphaIndex
- Defined in:
- lib/wongi-engine/alpha_index.rb
Instance Method Summary collapse
- #add(wme) ⇒ Object
- #collection_for_wme(wme) ⇒ Object
-
#initialize(pattern) ⇒ AlphaIndex
constructor
A new instance of AlphaIndex.
- #remove(wme) ⇒ Object
Constructor Details
#initialize(pattern) ⇒ AlphaIndex
Returns a new instance of AlphaIndex.
7 8 9 10 |
# File 'lib/wongi-engine/alpha_index.rb', line 7 def initialize(pattern) @pattern = pattern @index = Hash.new { |h, k| h[k] = Set.new } end |
Instance Method Details
#add(wme) ⇒ Object
12 13 14 |
# File 'lib/wongi-engine/alpha_index.rb', line 12 def add(wme) collection_for_wme(wme).add(wme) end |
#collection_for_wme(wme) ⇒ Object
24 25 26 |
# File 'lib/wongi-engine/alpha_index.rb', line 24 def collection_for_wme(wme) index[hashed_key(wme)] end |
#remove(wme) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/wongi-engine/alpha_index.rb', line 16 def remove(wme) collection = collection_for_wme(wme) collection.delete(wme) # release some memory index.delete(hashed_key(wme)) if collection.empty? end |