/
wme.go
53 lines (47 loc) · 1.23 KB
/
wme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package rete
import (
"container/list"
"fmt"
)
type WME struct {
fields [4]string
alpha_mems *list.List
tokens *list.List
negative_join_results *list.List
}
func RemoveWME(w *WME) {
for e := w.alpha_mems.Front(); e != nil; e = e.Next() {
amem := e.Value.(*AlphaMemory)
remove_by_value(amem.items, w)
}
for w.tokens != nil && w.tokens.Len() > 0 {
e := w.tokens.Front()
t := e.Value.(*Token)
t.delete_token_and_descendents()
w.tokens.Remove(e)
}
for e := w.negative_join_results.Front(); e != nil; e = e.Next() {
jr := e.Value.(*NegativeJoinResult)
remove_by_value(jr.owner.join_results, jr)
if jr.owner.join_results.Len() == 0 {
for i := jr.owner.node.GetChildren().Front(); i != nil; i = i.Next() {
child := i.Value.(IReteNode)
child.LeftActivation(jr.owner, nil, nil)
}
}
}
}
func NewWME(class_name, id, attr, value string) *WME {
return &WME{
fields: [4]string{class_name, id, attr, value},
alpha_mems: list.New(),
tokens: list.New(),
negative_join_results: list.New(),
}
}
func (wme *WME) Equal(w *WME) bool {
return wme.fields == w.fields
}
func (wme *WME) String() string {
return fmt.Sprintf("%s", wme.fields)
}