@dogmalang/queue
v0.2.0
Published
A queue implementation.
Downloads
1
Readme
@dogmalang/queue
A queue implementation.
Developed in Dogma, compiled to JavaScript.
Engineered in Valencia, Spain, EU by Justo Labs.
Use
The package must be imported as follows:
////////////////
// JavaScript //
////////////////
import Queue from "@dogmalang/queue";
#########
# Dogma #
#########
use "@dogmalang/queue" as Queue
Constructor
////////////////
// JavaScript //
////////////////
constructor()
constructor(items:array, opts?:{max:number})
constructor(opts:{max:number})
#########
# Dogma #
#########
type Queue()
type Queue(items:list, opts?:{max:num})
type Queue(opts:{max:num})
items
, initial items.opts
, the options:max
, maximum number of items.
Examples:
////////////////
// JavaScript //
////////////////
q = new Queue()
q = new Queue([1, 2, 3, 4])
q = new Queue({max: 123})
#########
# Dogma #
#########
q = Queue()
q = Queue([1, 2, 3, 4])
q = Queue({max=123})
enqueue() and append()
Add a new item at the end of the queue:
////////////////
// JavaScript //
////////////////
append(item) : Queue
enqueue(item) : Queue
#########
# Dogma #
#########
@alias("append")
fn Queue.enqueue(item) -> self
The method returns the queue for chaining other appends.
If the queue has max
and this reached, an error is raised.
Example:
q.enqueue("one").enqueue("two").enqueue("three")
unshift()
Add an item at the beginning of the queue:
////////////////
// JavaScript //
////////////////
unshift(item) : Queue
#########
# Dogma #
#########
fn Queue.unshift(item) -> self
shift() and dequeue()
Remove the first/front item and returning it:
////////////////
// JavaScript //
////////////////
shift() : any
dequeue() : any
#########
# Dogma #
#########
@alias("shift")
fn Queue.dequeue() : any
If the queue is empty, an error is raised.
Example:
i = q.shift()
len
Return the current length:
////////////////
// JavaScript //
////////////////
len : number
#########
# Dogma #
#########
fn Queue.len : num
Example:
size = q.len
max
Return the maximum size if set:
////////////////
// JavaScript //
////////////////
max : number
#########
# Dogma #
#########
@prop
fn Queue.max() : num
Example:
max = q.max
isEmpty()
Check whether the queue is empty:
////////////////
// JavaScript //
////////////////
isEmpty() : boolean
#########
# Dogma #
#########
fn Queue.isEmpty() : bool
Example:
q.isEmpty()
isFull()
Check whether the queue is full:
////////////////
// JavaScript //
////////////////
isFull() : boolean
#########
# Dogma #
#########
fn Queue.isFull() : bool
first
Return the first/front item without removing it:
////////////////
// JavaScript //
////////////////
first : any
#########
# Dogma #
#########
@prop
fn Queue.first() : any
Example:
q.append("one").append("two").first
last
Return the last/back item without removing it:
////////////////
// JavaScript //
////////////////
last : any
#########
# Dogma #
#########
@prop
fn Queue.last() : any
Example:
q.append("one").append("two").last
get()
Return the item in a given position:
////////////////
// JavaScript //
////////////////
get(pos:number) : any
#########
# Dogma #
#########
fn Queue.get(pos:num) : any
list()
Return a list with the items:
////////////////
// JavaScript //
////////////////
list() : any[]
#########
# Dogma #
#########
fn Queue.list() : list
Example:
q.list()