From da12fce77a29f744dfb9669149f8610a176d353d Mon Sep 17 00:00:00 2001 From: ston1th Date: Sun, 9 Jul 2017 15:17:59 +0200 Subject: [PATCH] added comments --- filter.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/filter.go b/filter.go index 71235f0..6c9f8d0 100644 --- a/filter.go +++ b/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