Queue
The Queue data structure, also known as First In, First Out (FIFO) queue, allows addition and deletion of items in opposite ends of the data structure. Insertion is performed in the back of the queue while deletion is performed in the front of the queue. In DataStructures.jl, the Queue type is a light-weight wrapper around the Deque type.
Queues are often used as a base for many different data structures, some of its variations implemented by DataStructures.jl include:
Constructors
DataStructures.Queue — Type
Queue{T}() where {T}
Queue{T}([blksize::Integer=1024])Create a Queue object containing elements of type T for First In, First Out (FIFO) access.
Parameters
T::TypeQueue element data type.blksize::Integer=1024Unrolled linked-list block size (in bytes). Default = 1024.
Examples
julia> q_int = Queue{Int64}() # create a queue with int elements
Queue{Int64}(Deque [Int64[]])
julia> q_float = Queue{Float64}() # create a queue with float elements
Queue{Float64}(Deque [Float64[]])Usage
The Queue type implements the following methods:
eltype(::Type{Queue{T}}) where {T}first(q::Queue)isempty(q::Queue)length(q::Queue)last(q::Queue)push!(q::Queue, x)popfirst!(q::Queue)
Base.eltype — Method
eltype(::Type{Queue{T}}) where {T}Return the type of the elements in the queue.
Base.empty! — Method
empty!(q::Queue)Removes all elements from queue q.
Base.first — Method
first(q::Queue)Get the first item from queue q.
Base.isempty — Method
isempty(q::Queue)Check if queue q is empty.
Base.length — Method
length(q::Queue)Return the number of elements in queue q.
Base.popfirst! — Method
popfirst!(q::Queue)Removes an element from the front of the queue q and returns it.
Base.push! — Method
push!(q::Queue, x)Inserts the value x to the end of the queue q.