added comments
This commit is contained in:
parent
5a8e1e6cf6
commit
da12fce77a
1 changed files with 13 additions and 1 deletions
14
filter.go
14
filter.go
|
|
@ -12,6 +12,12 @@ import (
|
|||
|
||||
const any = '*'
|
||||
|
||||
// Filter is the filter interface to be implemented for faster non generic filtering
|
||||
// Example implementation:
|
||||
// type f []struct
|
||||
// func (v f) Len() int { return len(v) }
|
||||
// func (v f) Index(i int) interface{} { return v[i] }
|
||||
// func (v *f) Remove(i, j int) { *v = append((*v)[:i], (*v)[j:]...) }
|
||||
type Filter interface {
|
||||
Len() int
|
||||
Index(int) interface{}
|
||||
|
|
@ -23,15 +29,19 @@ type match struct {
|
|||
value string
|
||||
}
|
||||
|
||||
// Logic is the filter logic
|
||||
type Logic int
|
||||
|
||||
const (
|
||||
// AND all of the queries have to match
|
||||
AND Logic = iota
|
||||
// OR only one query has to match
|
||||
OR
|
||||
// NOT none of the queries have to match
|
||||
NOT
|
||||
)
|
||||
|
||||
// Query implements the filter query
|
||||
// Query is the filter query
|
||||
type Query struct {
|
||||
m []match
|
||||
l Logic
|
||||
|
|
@ -260,6 +270,8 @@ func (q *Query) GenericFilter(i interface{}) interface{} {
|
|||
return ret.Interface()
|
||||
}
|
||||
|
||||
// Filter takes a pointer to the Filter interface as an argument.
|
||||
// The original slice is modified is the filtering process.
|
||||
func (q Query) Filter(f Filter) {
|
||||
count := 0
|
||||
i := 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue