-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtableby.go
More file actions
53 lines (49 loc) · 1.26 KB
/
tableby.go
File metadata and controls
53 lines (49 loc) · 1.26 KB
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
package table
// QueryByHoles finds all rows matching every (col→val), including any holes.
// Panics if filters is nil or empty.
// Returns nil for no matches.
func (t *Table) QueryByHoles(filters map[int]string) [][]string {
if filters == nil || len(filters) == 0 {
panic("QueryByHoles: filters must not be nil or empty")
}
var result [][]string
for _, buck := range t.b {
rows := buck.getBy(filters)
if rows != nil {
result = append(result, rows...)
}
}
if len(result) == 0 {
return nil
}
return result
}
// QueryBy finds all rows matching every (col→val), skipping any holes.
// Panics if filters is nil or empty.
// Returns nil for no matches.
func (t *Table) QueryBy(filters map[int]string) [][]string {
raw := t.QueryByHoles(filters)
if raw == nil {
return nil
}
var filtered [][]string
for _, row := range raw {
if row != nil && len(row) > 0 {
filtered = append(filtered, row)
}
}
if len(filtered) == 0 {
return nil
}
return filtered
}
// DeleteBy deletes all rows matching every (col→val).
// Panics if filters is nil or empty.
func (t *Table) DeleteBy(filters map[int]string) {
if filters == nil || len(filters) == 0 {
panic("DeleteBy: filters must not be nil or empty")
}
for i := range t.b {
t.b[i].removeBy(filters)
}
}