func (n *clauseNode) Walk(fact Fact, acc *lookup) { vals, ok := acc.factCache[n.attr] if !ok { vals = intset.Use(fact.GetQualifiable(n.attr)...) acc.factCache[n.attr] = vals } ruleCache, ok := acc.ruleCache[n.attr] if !ok { ruleCache = make(map[uint64]bool, 100) acc.ruleCache[n.attr] = ruleCache } ruleID := n.rule.UID() match, ok := ruleCache[ruleID] if !ok { match = n.rule.Match(vals) ruleCache[ruleID] = match } if !match { return } n.baseNode.Walk(fact, acc) }
func newBaseRule(sign byte, vals []int) *baseRule { vset := intset.Use(vals...) hash := newCRCHash(sign, len(vals)) for _, val := range vals { hash.Add(uint64(val)) } return &baseRule{hash: hash.Sum64(), vals: vset} }
subject = OneOf([]int{3, 2, 1}) }) It("should return a string", func() { Expect(subject.String()).To(Equal(`+[1 2 3]`)) }) It("should have an ID", func() { Expect(subject.UID()).To(Equal(uint64(4016361724135366094))) Expect(OneOf([]int{2, 3, 1}).UID()).To(Equal(uint64(4016361724135366094))) Expect(OneOf([]int{7, 8, 9}).UID()).To(Equal(uint64(11523927376963847877))) }) It("should check inclusion", func() { Expect(subject.Match(nil)).To(BeFalse()) Expect(subject.Match(intset.Use())).To(BeFalse()) Expect(subject.Match(intset.Use(1))).To(BeTrue()) Expect(subject.Match(intset.Use(1, 2))).To(BeTrue()) Expect(subject.Match(intset.Use(7, 2))).To(BeTrue()) Expect(subject.Match(intset.Use(7, 8))).To(BeFalse()) }) }) var _ = Describe("Exclusion", func() { var subject *Exclusion var _ Rule = subject BeforeEach(func() { subject = NoneOf([]int{3, 2, 1}) })