Skip to content

Commit

Permalink
faster filter (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar authored Jun 24, 2021
1 parent b1680b8 commit 15fc3b7
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 163 deletions.
21 changes: 11 additions & 10 deletions collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ import (
)

/*
BenchmarkCollection/insert-8 5545016 216.8 ns/op 18 B/op 0 allocs/op
BenchmarkCollection/fetch-8 27272726 43.61 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/scan-8 648 1844623 ns/op 147 B/op 0 allocs/op
BenchmarkCollection/count-8 1000000 1107 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/range-8 10000 102549 ns/op 9 B/op 0 allocs/op
BenchmarkCollection/update-at-8 4316584 280.7 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/update-all-8 826 1379693 ns/op 53068 B/op 0 allocs/op
BenchmarkCollection/delete-at-8 7059126 169.1 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/delete-all-8 196734 6294 ns/op 0 B/op 0 allocs/op
cpu: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
BenchmarkCollection/insert-8 5531546 215.9 ns/op 18 B/op 0 allocs/op
BenchmarkCollection/fetch-8 23749724 44.97 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/scan-8 784 1527506 ns/op 160 B/op 0 allocs/op
BenchmarkCollection/count-8 1000000 1081 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/range-8 10000 100833 ns/op 14 B/op 0 allocs/op
BenchmarkCollection/update-at-8 4225484 281.7 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/update-all-8 830 1388480 ns/op 105714 B/op 0 allocs/op
BenchmarkCollection/delete-at-8 6928646 171.9 ns/op 0 B/op 0 allocs/op
BenchmarkCollection/delete-all-8 180884 6373 ns/op 1 B/op 0 allocs/op
*/
func BenchmarkCollection(b *testing.B) {
amount := 100000
Expand Down Expand Up @@ -156,7 +157,7 @@ func BenchmarkCollection(b *testing.B) {
// Test replication many times
func TestReplicate(t *testing.T) {
for x := 0; x < 20; x++ {
runReplication(t, 5000, 500)
runReplication(t, 5000, 50)
}
}

Expand Down
20 changes: 7 additions & 13 deletions column_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,24 @@ func (c *columnnumber) LoadUint64(idx uint32) (v uint64, ok bool) {

// FilterFloat64 filters down the values based on the specified predicate.
func (c *columnnumber) FilterFloat64(index *bitmap.Bitmap, predicate func(v float64) bool) {
index.Filter(func(idx uint32) (match bool) {
if idx < uint32(len(c.data)) && c.fill.Contains(idx) {
match = predicate(float64(c.data[idx]))
}
return
index.And(c.fill)
index.Filter(func(idx uint32) bool {
return idx < uint32(len(c.data)) && predicate(float64(c.data[idx]))
})
}

// FilterInt64 filters down the values based on the specified predicate.
func (c *columnnumber) FilterInt64(index *bitmap.Bitmap, predicate func(v int64) bool) {
index.And(c.fill)
index.Filter(func(idx uint32) (match bool) {
if idx < uint32(len(c.data)) && c.fill.Contains(idx) {
match = predicate(int64(c.data[idx]))
}
return
return idx < uint32(len(c.data)) && predicate(int64(c.data[idx]))
})
}

// FilterUint64 filters down the values based on the specified predicate.
func (c *columnnumber) FilterUint64(index *bitmap.Bitmap, predicate func(v uint64) bool) {
index.And(c.fill)
index.Filter(func(idx uint32) (match bool) {
if idx < uint32(len(c.data)) && c.fill.Contains(idx) {
match = predicate(uint64(c.data[idx]))
}
return
return idx < uint32(len(c.data)) && predicate(uint64(c.data[idx]))
})
}
Loading

0 comments on commit 15fc3b7

Please sign in to comment.