Skip to content

Commit 4646dcf

Browse files
committed
docs(stack): removed and refined some of the documentation examples
1 parent 609d419 commit 4646dcf

File tree

2 files changed

+29
-109
lines changed

2 files changed

+29
-109
lines changed

docs/make.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ makedocs(
3535
format = Documenter.HTML()
3636
)
3737

38-
deploydocs(
39-
repo = "github.com/JuliaCollections/DataStructures.jl.git",
40-
)
38+
#deploydocs(
39+
# repo = "github.com/JuliaCollections/DataStructures.jl.git",
40+
#)

src/stack.jl

Lines changed: 26 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
Stack{T}() where {T}
33
Stack{T}(blksize::Integer) where {T}
44
5-
Create a `Stack` object containing elements of type `T` for Last In, First Out (LIFO) access.
5+
Create a `Stack` object containing elements of type `T` for **Last In, First Out**
6+
(LIFO) access.
67
78
# Parameters
89
- `T::Type` Stack element data type.
9-
- `blksize::Integer` Unrolled linked-list bleck size (in bytes). Default = 1024.
10+
- `blksize::Integer` Unrolled linked-list block size (in bytes) used in the
11+
underlying representation of the stack. Default = 1024.
1012
1113
# Examples
1214
```jldoctest
13-
julia> s_int = Stack{Int64}() # create a stack with int elements
15+
julia> s_int = Stack{Int64}() # create a stack with Int64 elements
1416
Stack{Int64}(Deque [Int64[]])
1517
16-
julia> s_float = Stack{Float64}() # create a stack with float elements
18+
julia> s_float = Stack{Float64}() # create a stack with Float64 elements
1719
Stack{Float64}(Deque [Float64[]])
1820
```
1921
"""
@@ -27,23 +29,7 @@ Stack{T}(blksize::Integer) where {T} = Stack(Deque{T}(blksize))
2729
"""
2830
isempty(s::Stack)
2931
30-
Check if stack `s` is empty.
31-
32-
# Example
33-
```jldoctest
34-
julia> s = Stack{Char}()
35-
Stack{Char}(Deque [Char[]])
36-
37-
julia> isempty(s)
38-
true
39-
40-
julia> for char in "racecar"
41-
push!(s, char)
42-
end
43-
44-
julia> isempty(s)
45-
false
46-
```
32+
Returns `true` if stack `s` is empty - i.e. has no elements - or `false` otherwise.
4733
"""
4834
Base.isempty(s::Stack) = isempty(s.store)
4935

@@ -52,19 +38,6 @@ Base.isempty(s::Stack) = isempty(s.store)
5238
length(s::Stack)
5339
5440
Return the number of elements in stack `s`.
55-
56-
# Example
57-
```jldoctest
58-
julia> s = Stack{Char}()
59-
Stack{Char}(Deque [Char[]])
60-
61-
julia> for char in "racecar"
62-
push!(s, char)
63-
end
64-
65-
julia> length(s)
66-
7
67-
```
6841
"""
6942
Base.length(s::Stack) = length(s.store)
7043

@@ -73,27 +46,16 @@ Base.length(s::Stack) = length(s.store)
7346
eltype(::Type{Stack{T}}) where {T}
7447
7548
Return the type of the elements in the stack.
76-
77-
# Example
78-
```jldoctest
79-
julia> s = Stack{Float32}()
80-
Stack{Float32}(Deque [Float32[]])
81-
82-
julia> eltype(s)
83-
Float32
84-
85-
julia> eltype(s) <: Number
86-
true
87-
```
8849
"""
8950
Base.eltype(::Type{Stack{T}}) where {T} = T
9051

9152

9253
"""
9354
first(s::Stack)
9455
95-
Get the first element of `s`. Since `s` is a stack, the first element will be the
96-
element at the top of `s` (also known as "peek" of the stack).
56+
Get the first element of `s` in *Last In, First Out* order. Since `s` is a stack,
57+
the first element will be the element at the top of `s` (also known as "peek" of
58+
the stack).
9759
9860
# Example
9961
```jldoctest
@@ -116,8 +78,8 @@ Base.first(s::Stack) = last(s.store)
11678
"""
11779
last(s::Stack)
11880
119-
Get the last element of `s`. Since `s` is a stack, the last element will be the at
120-
bottom of the stack.
81+
Get the last element of `s` in *Last In, First Out*. Since `s` is a stack, the last
82+
element will be the at bottom of the stack.
12183
12284
# Example
12385
```jldoctest
@@ -142,18 +104,6 @@ Base.last(s::Stack) = first(s.store)
142104
push!(s::Stack, x)
143105
144106
Insert new element `x` in top of stack `s`.
145-
146-
# Example
147-
```jldoctest
148-
julia> s = Stack{Int}()
149-
Stack{Int64}(Deque [Int64[]])
150-
151-
julia> push!(s, 42)
152-
Stack{Int64}(Deque [[42]])
153-
154-
julia> push!(s, 314)
155-
Stack{Int64}(Deque [[42, 314]])
156-
```
157107
"""
158108
function Base.push!(s::Stack, x)
159109
push!(s.store, x)
@@ -165,28 +115,6 @@ end
165115
pop!(s::Stack)
166116
167117
Remove and return the top element from stack `s`.
168-
169-
# Example
170-
```jldoctest
171-
julia> s = Stack{Int}()
172-
Stack{Int64}(Deque [Int64[]])
173-
174-
julia> for i in 1:10
175-
push!(s, i)
176-
end
177-
178-
julia> s
179-
Stack{Int64}(Deque [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])
180-
181-
julia> popped = pop!(s)
182-
10
183-
184-
julia> s
185-
Stack{Int64}(Deque [[1, 2, 3, 4, 5, 6, 7, 8, 9]])
186-
187-
julia> popped
188-
10
189-
```
190118
"""
191119
Base.pop!(s::Stack) = pop!(s.store)
192120

@@ -195,25 +123,6 @@ Base.pop!(s::Stack) = pop!(s.store)
195123
empty!(s::Stack)
196124
197125
Make `s` empty by inplace-removing all its elements.
198-
199-
# Example
200-
```jldoctest
201-
julia> s = Stack{Int}()
202-
Stack{Int64}(Deque [Int64[]])
203-
204-
julia> for i in 1:4
205-
push!(s, i)
206-
end
207-
208-
julia> isempty(s)
209-
false
210-
211-
julia> empty!(s)
212-
Stack{Int64}(Deque [Int64[]])
213-
214-
julia> isempty(s)
215-
true
216-
```
217126
"""
218127
Base.empty!(s::Stack) = (empty!(s.store); s)
219128

@@ -225,9 +134,9 @@ Iterators.reverse(s::Stack{T}) where {T} = DequeIterator{T}(s.store)
225134
"""
226135
==(x::Stack, y::Stack)
227136
228-
Check if stacks `x` and `y` are equal in term of their contents. Internally calls `==()`
229-
for each of the pairs formed by the elements of `x` and `y` in the order they appear
230-
in the stack.
137+
Check if stacks `x` and `y` are equal in terms of their contents and the order in
138+
which they are present in the stack. Internally calls `==()` for each of the pairs
139+
formed by the elements of `x` and `y` in the order they appear in the stack.
231140
232141
# Example
233142
```jldoctest
@@ -248,5 +157,16 @@ julia> pop!(s1)
248157
julia> s1 == s2
249158
false
250159
```
160+
```jldoctest
161+
julia> a, b = Stack{Int}(), Stack{Int}()
162+
(Stack{Int64}(Deque [Int64[]]), Stack{Int64}(Deque [Int64[]]))
163+
164+
julia> for num in [1, 2, 3, 4] push!(a, num) end
165+
166+
julia> for num in [1, 2, 4, 3] push!(b, num) end
167+
168+
julia> a == b # same elements but in different order
169+
false
170+
```
251171
"""
252172
Base.:(==)(x::Stack, y::Stack) = x.store == y.store

0 commit comments

Comments
 (0)