-
Notifications
You must be signed in to change notification settings - Fork 261
Allow negative indices <= 0 and indices > 2n in CircularBuffers #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Please ignore this proposition, if you prefer not to allow negative indices and indices > 2n.
|
Thanks for this. But in anycase, Let us know if you have any trouble. |
Codecov Report
@@ Coverage Diff @@
## master #451 +/- ##
=========================================
+ Coverage 98.79% 98.8% +<.01%
=========================================
Files 27 27
Lines 1332 1338 +6
=========================================
+ Hits 1316 1322 +6
Misses 16 16
Continue to review full report at Codecov.
|
timholy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the biggest concern is performance, but that "fast exit" at the beginning should help a lot in performance-sensitive cases.
On balance I think it makes sense to make the indexing truly periodic.
|
Before julia> using DataStructures, BenchmarkTools
julia> c = CircularBuffer{Int64}(100);
julia> for i in 1:100 push!(c, i) end
julia> import DataStructures: _buffer_index
julia> @benchmark _buffer_index($c, 40)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 1.953 ns (0.00% GC)
median time: 1.966 ns (0.00% GC)
mean time: 1.970 ns (0.00% GC)
maximum time: 11.326 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
julia> @benchmark _buffer_index($c, 140)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 1.634 ns (0.00% GC)
median time: 1.642 ns (0.00% GC)
mean time: 1.647 ns (0.00% GC)
maximum time: 10.826 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000After: julia> @benchmark _buffer_index($c, 40)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 1.954 ns (0.00% GC)
median time: 1.969 ns (0.00% GC)
mean time: 2.246 ns (0.00% GC)
maximum time: 15.625 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
julia> @benchmark _buffer_index($c, 140)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 5.520 ns (0.00% GC)
median time: 5.539 ns (0.00% GC)
mean time: 5.602 ns (0.00% GC)
maximum time: 17.713 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
julia> @benchmark _buffer_index($c, -140)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 11.299 ns (0.00% GC)
median time: 11.521 ns (0.00% GC)
mean time: 11.802 ns (0.00% GC)
maximum time: 48.642 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 999 |
test/test_circular_buffer.jl
Outdated
| @test DataStructures._buffer_index(cb, j) == k | ||
| k += 1 | ||
| if k > 5 k = 1 end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little too complex.
Testing the right things,
but a good test set is trivially obvious.
Like
@test cb[1]=1
@test cb[5]=5
@test cb[20]=5
@test cb[0]=5
@test cb[-1]=4
@test cb[-11]=6
Your for j in -19:20 loop does the same thing,
and more comprehensively.
But it is not obvious what it is doing.
Test code that is non-obvious might have bugs.
(and because tests don't have tests ...)
|
@oxinabox Thanks for your feedback. |
Please ignore this proposition, if you prefer not to allow negative indices and indices > 2n.