File tree 3 files changed +28
-1
lines changed 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
1
name = " DataStructures"
2
2
uuid = " 864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
3
- version = " 0.17.2 "
3
+ version = " 0.17.3 "
4
4
5
5
[deps ]
6
6
InteractiveUtils = " b77e0a4c-d291-57a0-90e8-8db25a27a240"
Original file line number Diff line number Diff line change @@ -193,3 +193,26 @@ capacity(cb::CircularBuffer) = cb.capacity
193
193
Test whether the buffer is full.
194
194
"""
195
195
isfull (cb:: CircularBuffer ) = length (cb) == cb. capacity
196
+
197
+ """
198
+ first(cb)
199
+
200
+ Get the first element of CircularBuffer.
201
+ """
202
+ Base. @propagate_inbounds function Base. first (cb:: CircularBuffer )
203
+ @boundscheck if cb. length == 0
204
+ throw (BoundsError (cb, 1 ))
205
+ end
206
+ cb. buffer[cb. first]
207
+ end
208
+ """
209
+ last(cb)
210
+
211
+ Get the last element of CircularBuffer.
212
+ """
213
+ Base. @propagate_inbounds function Base. last (cb:: CircularBuffer )
214
+ @boundscheck if cb. length == 0
215
+ throw (BoundsError (cb, 1 ))
216
+ end
217
+ cb. buffer[_buffer_index (cb, cb. length)]
218
+ end
Original file line number Diff line number Diff line change 6
6
@test length (cb) == 0
7
7
@test capacity (cb) == 5
8
8
@test_throws BoundsError first (cb)
9
+ @test_throws BoundsError last (cb)
9
10
@test isempty (cb) == true
10
11
@test isfull (cb) == false
11
12
@test eltype (cb) == Int
17
18
@test length (cb) == 1
18
19
@test capacity (cb) == 5
19
20
@test isfull (cb) == false
21
+ @test first (cb) == last (cb)
20
22
end
21
23
22
24
@testset " Appending many elements" begin
38
40
@test_throws BoundsError cb[3 : 6 ]
39
41
@test cb[3 : 4 ] == Int[6 ,7 ]
40
42
@test cb[[1 ,5 ]] == Int[4 ,8 ]
43
+ @test first (cb) == 4
44
+ @test last (cb) == 8
41
45
end
42
46
43
47
@testset " setindex" begin
You can’t perform that action at this time.
0 commit comments