qfy

package
v0.0.0-...-b0418aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentDict

type ConcurrentDict struct {
	// contains filtered or unexported fields
}

ConcurrentDict is just like Dict, but thread-safe and therefore slightly slower.

func NewConcurrentDict

func NewConcurrentDict() *ConcurrentDict

NewConcurrentDict creates a new dict

func (*ConcurrentDict) Add

func (d *ConcurrentDict) Add(v string) int

Add adds a value to the dictionary if not already present and returns the associtated ID

func (*ConcurrentDict) AddSlice

func (d *ConcurrentDict) AddSlice(vv ...string) []int

AddSlice adds a whole slice of values

func (*ConcurrentDict) GetSlice

func (d *ConcurrentDict) GetSlice(vv ...string) []int

GetSlice is a read-only operation, only returns known IDs

type Conjunction

type Conjunction struct {
	// contains filtered or unexported fields
}

Conjunction combines two or more rules into by creating a logical AND

func All

func All(rules ...Rule) *Conjunction

All requires all of the rules to match

func (*Conjunction) Match

func (r *Conjunction) Match(vals *intset.Set) bool

Match tests if the rule is qualified

func (*Conjunction) String

func (r *Conjunction) String() string

String returns a human-readable description

func (*Conjunction) UID

func (r *Conjunction) UID() uint64

UID returns a combined unique ID

type Dict

type Dict map[string]int

Dict is a simple helper to to turn convert strings into integers using dictionary encoding. Dict instances are NOT thread-safe because they are populated sequentially on Qualifier creation and then only read.

If your use case requires rules to call Add operations concurrently please use (the slower but) thread-safe ConcurrentDict

func NewDict

func NewDict() Dict

NewDict creates a new dict

func (Dict) Add

func (d Dict) Add(v string) int

Add adds a value to the dictionary if not already present and returns the associtated ID

func (Dict) AddSlice

func (d Dict) AddSlice(vv ...string) []int

AddSlice adds a whole slice of values

func (Dict) GetSlice

func (d Dict) GetSlice(vv ...string) []int

GetSlice is a read-only operation, only returns known IDs

type Disjunction

type Disjunction struct {
	// contains filtered or unexported fields
}

Disjunction combines two or more rules into by creating a logical OR

func Any

func Any(rules ...Rule) *Disjunction

Any requires any of the rules to match

func (*Disjunction) Match

func (r *Disjunction) Match(vals *intset.Set) bool

Match tests if the rule is qualified

func (*Disjunction) String

func (r *Disjunction) String() string

String returns a human-readable description

func (*Disjunction) UID

func (r *Disjunction) UID() uint64

UID returns a combined unique ID

type Exclusion

type Exclusion struct {
	// contains filtered or unexported fields
}

Exclusion rules require none of the values to be present in the fact

func NoneOf

func NoneOf(vals []int) *Exclusion

NoneOf constructs an Exclusion

func (*Exclusion) Match

func (r *Exclusion) Match(vv *intset.Set) bool

Match tests if the rule is qualified

func (*Exclusion) String

func (r *Exclusion) String() string

String returns a human-readable description

func (*Exclusion) UID

func (r *Exclusion) UID() uint64

UID returns a unique rule identifier

type Fact

type Fact interface {
	GetQualifiable(string) []int
}

Fact is an interface of a fact that may be passed to a qualifier. Each fact must implement a Get(string) method which receives the attribute name and must return either a string or an int slice, depending on the attribute definition.

type Inclusion

type Inclusion struct {
	// contains filtered or unexported fields
}

Inclusion rules require either of values to be present in the fact

func OneOf

func OneOf(vals []int) *Inclusion

OneOf constructs an Inclusion

func (*Inclusion) Match

func (r *Inclusion) Match(vv *intset.Set) bool

Match tests if the rule is qualified

func (*Inclusion) String

func (r *Inclusion) String() string

String returns a human-readable description

func (*Inclusion) UID

func (r *Inclusion) UID() uint64

UID returns a unique rule identifier

type Negation

type Negation struct {
	// contains filtered or unexported fields
}

Negation inverts a Rule

func Not

func Not(rule Rule) *Negation

Not creates a negation

func (*Negation) Match

func (r *Negation) Match(vals *intset.Set) bool

Match tests if the rule is qualified

func (*Negation) String

func (r *Negation) String() string

String returns a human-readable description

func (*Negation) UID

func (r *Negation) UID() uint64

UID returns a combined unique ID

type Qualifier

type Qualifier struct {
	// contains filtered or unexported fields
}

Qualifier represents a rule engine that can match a fact against a list of rule-sets using a fixed set of attributes

Example setup:

q := qfy.New([]string{"country", "months"})

q.Feed(11, map[string]Rule{
  "country": qfy.Include(q, []string{"GB"}),
  "months":  qfy.Include(q, []int{2015, 2014}),
})
q.Feed(12, map[string]Rule{
  "country": qfy.Exclude(q, []string{"US"}),
  "months":  qfy.And(qfy.Between(2010, 2015), qfy.Exclude(q, []int{2012})),
})

func New

func New(attrs []string) *Qualifier

New creates a new qualifier with a list of known/qualifiable attributes

func (*Qualifier) Feed

func (q *Qualifier) Feed(targetID int, rules map[string]Rule)

Feed registers a new targetID with a set of rules by attribute name.

func (*Qualifier) Graph

func (q *Qualifier) Graph(w io.Writer)

Graph prints a graph to writer, pass nil to print to stdout

func (*Qualifier) Select

func (q *Qualifier) Select(fact Fact) []int

Select performs the qualification and matches all known rules against a given fact returning a list of associated identifiers

type Rule

type Rule interface {
	// UID uniquely identifies the rule
	UID() uint64

	// Match tests if the rule is qulified
	Match(*intset.Set) bool

	// String returns a human-readable rule description
	String() string
}

Rule is an abstract logic evaluation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL