Support 1.23 iterator in a backward-compatible way
Resolve #471
Provide two new functions:
Values: An iterator in normal orderBackward: An iterator in reverse order
Unit test:
iter123_test.go: Test the 1.23 iterator by for-rangeiter_test.go: Test the iterator by call function way
Design consideration
- I used a naming method similar to
slices.Valuesandslices.Backwardto make it easier to use. - It is compatible to use
ValuesandBackwardbefore version 1.23 without for-range function syntax, which means we don't need to update the go.mod version. - For version 1.23 or later, we can use the for-range function syntax, and these two functions are also compatible with the iterator type in the
iterpackage.
Hi @lemire,
The unit test I wrote uses a similar approach to the one for testing Bitmap.ReverseIterator and Bitmap.Iterator. However, I am not confident that the test case is robust enough. Could you please review it? If you find the implementation acceptable, I will proceed with writing the Go doc comments and add examples to it.
Can you add benchmarks ? See https://github.com/RoaringBitmap/roaring/blob/fb67118dd4dcf59f0ab7061809a48868a14b382b/benchmark_test.go#L18
Hi @lemire The benchmark is added in df9d672e2620937083a8802a8158255fcbd5deb4
@amikai Can you share your benchmark results ? E.g., on your own machine ?
Hi @lemire, here is the benchmark on my computer:
goos: darwin
goarch: arm64
pkg: github.com/RoaringBitmap/roaring/v2
cpu: Apple M2
BenchmarkIterator123/simple_iteration_with_alloc-8 24210 48902 ns/op 112 B/op 1 allocs/op
BenchmarkIterator123/simple_iteration-8 25024 47947 ns/op 0 B/op 0 allocs/op
BenchmarkIterator123/values_iteration-8 23919 49615 ns/op 112 B/op 1 allocs/op
BenchmarkIterator123/reverse_iteration_with_alloc-8 22402 54250 ns/op 112 B/op 1 allocs/op
BenchmarkIterator123/reverse_iteration-8 25252 47785 ns/op 0 B/op 0 allocs/op
BenchmarkIterator123/backward_iteration-8 22621 52362 ns/op 112 B/op 1 allocs/op
BenchmarkIterator123/many_iteration_with_alloc-8 57945 20636 ns/op 4224 B/op 2 allocs/op
BenchmarkIterator123/many_iteration-8 59941 20383 ns/op 0 B/op 0 allocs/op
BenchmarkIterator123/values_iteration_1.23-8 24662 49834 ns/op 112 B/op 1 allocs/op
BenchmarkIterator123/backward_iteration_1.23-8 23325 51611 ns/op 112 B/op 1 allocs/op
BenchmarkIteratorAlloc/simple_iteration_with_alloc-8 24333 48729 ns/op 112 B/op 1 allocs/op
BenchmarkIteratorAlloc/simple_iteration-8 24201 50280 ns/op 0 B/op 0 allocs/op
BenchmarkIteratorAlloc/values_iteration-8 24680 49221 ns/op 112 B/op 1 allocs/op
BenchmarkIteratorAlloc/reverse_iteration_with_alloc-8 23397 51549 ns/op 112 B/op 1 allocs/op
BenchmarkIteratorAlloc/reverse_iteration-8 26040 45923 ns/op 0 B/op 0 allocs/op
BenchmarkIteratorAlloc/backward_iteration-8 23385 51324 ns/op 112 B/op 1 allocs/op
BenchmarkIteratorAlloc/many_iteration_with_alloc-8 57744 20754 ns/op 4224 B/op 2 allocs/op
BenchmarkIteratorAlloc/many_iteration-8 57397 19987 ns/op 0 B/op 0 allocs/op
@amikai The performance is ok.
Can you just tweak the small things I flagged ? We will be able to merge.
Hi @lemire, I have tweaked the test.
Great. I am running the CI tests, if it passes, we shall merge and release !!!
Hi @lemire, If there any concerns to merge the PR and release?
Merging!