Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@

# Parameters
- `T::Type` Stack element data type.
- `blksize::Integer` Unrolled linked-list block size (in bytes) used in the
underlying representation of the stack. Default = 1024.
- `blksize::Integer` unused

# Examples
```jldoctest
julia> s_int = Stack{Int64}() # create a stack with Int64 elements
Stack{Int64}(Deque [Int64[]])
Stack{Int64}(Int64[])

julia> s_float = Stack{Float64}() # create a stack with Float64 elements
Stack{Float64}(Deque [Float64[]])
Stack{Float64}(Float64[])
```
"""
mutable struct Stack{T}
store::Deque{T}
struct Stack{T}
store::Vector{T}
end

Stack{T}() where {T} = Stack(Deque{T}())
Stack{T}(blksize::Integer) where {T} = Stack(Deque{T}(blksize))
Stack{T}() where {T} = Stack(Vector{T}())
Stack{T}(blksize::Integer) where {T} = Stack{T}()

"""
isempty(s::Stack)
Expand Down Expand Up @@ -58,16 +57,16 @@
the stack).

# Example
```jldoctest

Check failure on line 60 in src/stack.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/stack.jl:60-73 ```jldoctest julia> s = Stack{Float32}() Stack{Float32}(Float32[]) julia> for i in range(1, 0.2, 5) push!(s, i) end julia> s Stack{Float32}[Float32[1.0, 0.8, 0.6, 0.4, 0.2]) julia> first(s) 0.2f0 ``` Subexpression: s Evaluated output: Stack{Float32}(Float32[1.0, 0.8, 0.6, 0.4, 0.2]) Expected output: Stack{Float32}[Float32[1.0, 0.8, 0.6, 0.4, 0.2]) diff = Warning: Diff output requires color. Stack{Float32}[Float32[1.0, Stack{Float32}(Float32[1.0, 0.8, 0.6, 0.4, 0.2])
julia> s = Stack{Float32}()
Stack{Float32}(Deque [Float32[]])
Stack{Float32}(Float32[])

julia> for i in range(1, 0.2, 5)
push!(s, i)
end

julia> s
Stack{Float32}(Deque [Float32[1.0, 0.8, 0.6, 0.4, 0.2]])
Stack{Float32}[Float32[1.0, 0.8, 0.6, 0.4, 0.2])

julia> first(s)
0.2f0
Expand All @@ -84,14 +83,14 @@
# Example
```jldoctest
julia> s = Stack{Float32}()
Stack{Float32}(Deque [Float32[]])
Stack{Float32}(Float32[])

julia> for i in range(1, 0.2, 5)
push!(s, i)
end

julia> s
Stack{Float32}(Deque [Float32[1.0, 0.8, 0.6, 0.4, 0.2]])
Stack{Float32}(Float32[1.0, 0.8, 0.6, 0.4, 0.2])

julia> last(s)
1.0f0
Expand Down Expand Up @@ -128,9 +127,6 @@

Base.iterate(st::Stack, s...) = iterate(Iterators.reverse(st.store), s...)

Iterators.reverse(s::Stack{T}) where {T} = DequeIterator{T}(s.store)


"""
==(x::Stack, y::Stack)

Expand All @@ -141,7 +137,7 @@
# Example
```jldoctest
julia> s1, s2 = Stack{String}(), Stack{String}()
(Stack{String}(Deque [String[]]), Stack{String}(Deque [String[]]))
(Stack{String}(String[]), Stack{String}(String[]))

julia> for string in ["foo", "bar", "42"]
push!(s1, string)
Expand All @@ -159,7 +155,7 @@
```
```jldoctest
julia> a, b = Stack{Int}(), Stack{Int}()
(Stack{Int64}(Deque [Int64[]]), Stack{Int64}(Deque [Int64[]]))
(Stack{Int64}(Int64[]), Stack{Int64}(Int64[]))

julia> for num in [1, 2, 3, 4] push!(a, num) end

Expand Down
Loading