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
— TypeQueue{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::Type
Queue element data type.blksize::Integer=1024
Unrolled 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.:==
— Method==(x::Queue, y::Queue)
Verify if queues x
and y
are equivalent in their contents.
Base.eltype
— Methodeltype(::Type{Queue{T}}) where {T}
Return the type of the elements in the queue.
Base.empty!
— Methodempty!(q::Queue)
Removes all elements from queue q
.
Base.first
— Methodfirst(q::Queue)
Get the first item from queue q
.
Base.isempty
— Methodisempty(q::Queue)
Check if queue q
is empty.
Base.last
— Methodlast(q::Queue)
Get the last element in queue q
.
Base.length
— Methodlength(q::Queue)
Return the number of elements in queue q
.
Base.popfirst!
— Methodpopfirst!(q::Queue)
Removes an element from the front of the queue q
and returns it.
Base.push!
— Methodpush!(q::Queue, x)
Inserts the value x
to the end of the queue q
.