Skip to content

Commit cea4331

Browse files
authored
Update tableby.go
table: add QueryBy and DeleteBy for multi-column filtering at Table level Provide user-friendly methods QueryBy and DeleteBy that apply multi-column (col→val) filters across all buckets. These new methods panic if given nil or empty filters, ensuring predictable behavior and avoiding accidental full-table operations. QueryBy returns nil when no matches are found, consistent with the low-level API. DeleteBy performs removals without returning deleted counts, simplifying the interface for typical use cases.
1 parent a41ed3f commit cea4331

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

tableby.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ func (t *Table) QueryBy(filters map[int]string) [][]string {
88
panic("QueryBy: filters must not be nil or empty")
99
}
1010
var result [][]string
11-
// delegate to each bucket
12-
for _, buck := range t.buckets {
11+
for _, buck := range t.b {
1312
rows := buck.getBy(filters)
1413
if rows != nil {
1514
result = append(result, rows...)
@@ -23,23 +22,12 @@ func (t *Table) QueryBy(filters map[int]string) [][]string {
2322

2423
// DeleteBy deletes all rows matching every (col→val).
2524
// Panics if filters is nil or empty.
26-
// Returns the total number of rows deleted.
27-
func (t *Table) DeleteBy(filters map[int]string) int {
25+
func (t *Table) DeleteBy(filters map[int]string) {
2826
if filters == nil || len(filters) == 0 {
2927
panic("DeleteBy: filters must not be nil or empty")
3028
}
31-
deleted := 0
32-
for i := range t.buckets {
33-
// count before
34-
before := len(t.buckets[i].getBy(filters))
35-
t.buckets[i].removeBy(filters)
36-
// count after
37-
afterRows := t.buckets[i].getBy(filters)
38-
if afterRows == nil {
39-
deleted += before
40-
} else {
41-
deleted += before - len(afterRows)
42-
}
29+
30+
for i := range t.b {
31+
t.b[i].removeBy(filters)
4332
}
44-
return deleted
4533
}

0 commit comments

Comments
 (0)