Class: OMF::Rete::Store::Alpha::AlphaLeafElement

Inherits:
AlphaElement
  • Object
show all
Defined in:
lib/omf_rete/store/alpha/alpha_leaf_element.rb

Overview

Module internal class, will only be instantiated by Store

Instance Method Summary collapse

Methods inherited from AlphaElement

create

Constructor Details

#initialize(level, store) ⇒ AlphaLeafElement

Returns a new instance of AlphaLeafElement.



10
11
12
13
14
# File 'lib/omf_rete/store/alpha/alpha_leaf_element.rb', line 10

def initialize(level, store)
  super
  @tsetIndex = {}
  @tsetWildcards = []
end

Instance Method Details

#addTuple(tarray) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/omf_rete/store/alpha/alpha_leaf_element.rb', line 33

def addTuple(tarray)
  # check if we have any matching tsets
  item = tarray[@level]
  if (arr = @tsetIndex[item])
    arr.each do |s|
      s.addTuple(tarray)
    end
  end
  @tsetWildcards.each do |s|
    s.addTuple(tarray)
  end
end

#registerTSet(tset, pattern) ⇒ Object

see Store



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/omf_rete/store/alpha/alpha_leaf_element.rb', line 18

def registerTSet(tset, pattern)
  pitem = pattern[@level]
  leaf = (@level == @length)
  a = pitem ? (@tsetIndex[pitem] ||= []) : @tsetWildcards
  a << tset
  @store.onUnregisterTSet(tset) do
    a.delete(tset)
  end
  # if (pitem)  # not nil
    # (@tsetIndex[pitem] ||= []) << tset
  # else # wildcard
    # @tsetWildcards << tset
  # end
end

#removeTuple(tarray) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/omf_rete/store/alpha/alpha_leaf_element.rb', line 46

def removeTuple(tarray)
  # check if we have any matching tsets
  item = tarray[@level]
  if (arr = @tsetIndex[item])
    arr.each do |s|
      s.removeTuple(tarray)
    end
  end
  @tsetWildcards.each do |s|
    s.removeTuple(tarray)
  end
end