Skip to content

Commit 41728ad

Browse files
garrisonc42f
authored andcommitted
Add docstrings for push, pop, pushfirst, popfirst, insert, deleteat
Also tested the new docstrings locally
1 parent be5ae30 commit 41728ad

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

src/deque.jl

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
push(vec::StaticVector, item)
3+
4+
Return a new `StaticVector` with `item` inserted on the end of `vec`.
5+
6+
# Examples
7+
```jldoctest
8+
julia> push(@SVector[1, 2, 3], 4)
9+
4-element SArray{Tuple{4},Int64,1,4} with indices SOneTo(4):
10+
1
11+
2
12+
3
13+
4
14+
```
15+
"""
116
@inline push(vec::StaticVector, x) = _push(Size(vec), vec, x)
217
@generated function _push(::Size{s}, vec::StaticVector, x) where {s}
318
newlen = s[1] + 1
@@ -8,6 +23,22 @@
823
end
924
end
1025

26+
"""
27+
pushfirst(vec::StaticVector, item)
28+
29+
Return a new `StaticVector` with `item` inserted at the beginning of `vec`.
30+
31+
# Examples
32+
```jldoctest
33+
julia> pushfirst(@SVector[1, 2, 3, 4], 5)
34+
5-element SArray{Tuple{5},Int64,1,5} with indices SOneTo(5):
35+
5
36+
1
37+
2
38+
3
39+
4
40+
```
41+
"""
1142
@inline pushfirst(vec::StaticVector, x) = _pushfirst(Size(vec), vec, x)
1243
@generated function _pushfirst(::Size{s}, vec::StaticVector, x) where {s}
1344
newlen = s[1] + 1
@@ -18,6 +49,23 @@ end
1849
end
1950
end
2051

52+
"""
53+
insert(vec::StaticVector, index::Integer, item)
54+
55+
Return a new vector with `item` inserted into `vec` at the given `index`.
56+
57+
# Examples
58+
```jldoctest
59+
julia> insert(@SVector[6, 5, 4, 2, 1], 4, 3)
60+
6-element SArray{Tuple{6},Int64,1,6} with indices SOneTo(6):
61+
6
62+
5
63+
4
64+
3
65+
2
66+
1
67+
```
68+
"""
2169
@propagate_inbounds insert(vec::StaticVector, index, x) = _insert(Size(vec), vec, index, x)
2270
@generated function _insert(::Size{s}, vec::StaticVector, index, x) where {s}
2371
newlen = s[1] + 1
@@ -33,6 +81,19 @@ end
3381
end
3482
end
3583

84+
"""
85+
pop(vec::StaticVector)
86+
87+
Return a new vector with the last item in `vec` removed.
88+
89+
# Examples
90+
```jldoctest
91+
julia> pop(@SVector[1,2,3])
92+
2-element SArray{Tuple{2},Int64,1,2} with indices SOneTo(2):
93+
1
94+
2
95+
```
96+
"""
3697
@inline pop(vec::StaticVector) = _pop(Size(vec), vec)
3798
@generated function _pop(::Size{s}, vec::StaticVector) where {s}
3899
newlen = s[1] - 1
@@ -43,6 +104,19 @@ end
43104
end
44105
end
45106

107+
"""
108+
popfirst(vec::StaticVector)
109+
110+
Return a new vector with the first item in `vec` removed.
111+
112+
# Examples
113+
```jldoctest
114+
julia> popfirst(@SVector[1,2,3])
115+
2-element SArray{Tuple{2},Int64,1,2} with indices SOneTo(2):
116+
2
117+
3
118+
```
119+
"""
46120
@inline popfirst(vec::StaticVector) = _popfirst(Size(vec), vec)
47121
@generated function _popfirst(::Size{s}, vec::StaticVector) where {s}
48122
newlen = s[1] - 1
@@ -53,6 +127,22 @@ end
53127
end
54128
end
55129

130+
"""
131+
deleteat(vec::StaticVector, index::Integer)
132+
133+
Return a new vector with the item at the given `index` removed.
134+
135+
# Examples
136+
```jldoctest
137+
julia> deleteat(@SVector[6, 5, 4, 3, 2, 1], 2)
138+
5-element SArray{Tuple{5},Int64,1,5} with indices SOneTo(5):
139+
6
140+
4
141+
3
142+
2
143+
1
144+
```
145+
"""
56146
@propagate_inbounds deleteat(vec::StaticVector, index) = _deleteat(Size(vec), vec, index)
57147
@generated function _deleteat(::Size{s}, vec::StaticVector, index) where {s}
58148
newlen = s[1] - 1
@@ -73,6 +163,25 @@ end
73163
# Immutable version of setindex!(). Seems similar in nature to the above, but
74164
# could also be justified to live in src/indexing.jl
75165
import Base.setindex
166+
"""
167+
setindex(vec::StaticArray, x, index::Int)
168+
169+
Return a new array with the item at `index` replaced by `x`.
170+
171+
# Examples
172+
```jldoctest
173+
julia> setindex(@SVector[1,2,3], 4, 2)
174+
3-element SArray{Tuple{3},Int64,1,3} with indices SOneTo(3):
175+
1
176+
4
177+
3
178+
179+
julia> setindex(@SMatrix[2 4; 6 8], 1, 2)
180+
2×2 SArray{Tuple{2,2},Int64,2,4} with indices SOneTo(2)×SOneTo(2):
181+
2 4
182+
1 8
183+
```
184+
"""
76185
@propagate_inbounds setindex(a::StaticArray, x, index::Int) = _setindex(Length(a), a, convert(eltype(typeof(a)), x), index)
77186
@generated function _setindex(::Length{L}, a::StaticArray{<:Tuple,T}, x::T, index::Int) where {L, T}
78187
exprs = [:(ifelse($i == index, x, a[$i])) for i = 1:L]

0 commit comments

Comments
 (0)