roaring icon indicating copy to clipboard operation
roaring copied to clipboard

Support 1.23 iterator in a backward-compatible way

Open amikai opened this issue 7 months ago • 7 comments

Resolve #471

Provide two new functions:

  • Values: An iterator in normal order
  • Backward: An iterator in reverse order

Unit test:

  • iter123_test.go: Test the 1.23 iterator by for-range
  • iter_test.go: Test the iterator by call function way

Design consideration

  • I used a naming method similar to slices.Values and slices.Backward to make it easier to use.
  • It is compatible to use Values and Backward before 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 iter package.

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.

amikai avatar Jun 01 '25 15:06 amikai

Can you add benchmarks ? See https://github.com/RoaringBitmap/roaring/blob/fb67118dd4dcf59f0ab7061809a48868a14b382b/benchmark_test.go#L18

lemire avatar Jun 02 '25 00:06 lemire

Hi @lemire The benchmark is added in df9d672e2620937083a8802a8158255fcbd5deb4

amikai avatar Jun 02 '25 14:06 amikai

@amikai Can you share your benchmark results ? E.g., on your own machine ?

lemire avatar Jun 05 '25 13:06 lemire

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 avatar Jun 05 '25 17:06 amikai

@amikai The performance is ok.

Can you just tweak the small things I flagged ? We will be able to merge.

lemire avatar Jun 05 '25 18:06 lemire

Hi @lemire, I have tweaked the test.

amikai avatar Jun 06 '25 01:06 amikai

Great. I am running the CI tests, if it passes, we shall merge and release !!!

lemire avatar Jun 06 '25 13:06 lemire

Hi @lemire, If there any concerns to merge the PR and release?

amikai avatar Jul 10 '25 11:07 amikai

Merging!

lemire avatar Jul 10 '25 12:07 lemire