-
Notifications
You must be signed in to change notification settings - Fork 5
/
efd.go
77 lines (63 loc) · 1.45 KB
/
efd.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package efd
//go:generate go run make.go -input data/efd.tar.gz -input data -output zdb.go
var All = Select()
type Predicate func(*Formula) bool
type Formulae []*Formula
func (f Formulae) Filter(predicates ...Predicate) Formulae {
if len(predicates) == 0 {
return f
}
result := make(Formulae, 0)
for _, formula := range f {
keep := true
for _, predicate := range predicates {
keep = predicate(formula) && keep
}
if keep {
result = append(result, formula)
}
}
return result
}
func Select(predicates ...Predicate) Formulae {
return Formulae(formulae).Filter(predicates...)
}
func WithClass(class string) Predicate {
return func(f *Formula) bool { return f.Class == class }
}
func WithShape(shape string) Predicate {
return func(f *Formula) bool { return f.Shape.Tag == shape }
}
func WithRepresentation(repr string) Predicate {
return func(f *Formula) bool { return f.Representation.Tag == repr }
}
func WithOperation(op string) Predicate {
return func(f *Formula) bool { return f.Operation == op }
}
func WithProgram(f *Formula) bool {
return f.Program != nil
}
func LookupShape(id string) *Shape {
for _, s := range shapes {
if s.ID == id {
return s
}
}
return nil
}
func LookupRepresentation(id string) *Representation {
for _, r := range representations {
if r.ID == id {
return r
}
}
return nil
}
func LookupFormula(id string) *Formula {
for _, f := range formulae {
if f.ID == id {
return f
}
}
return nil
}