js-priority-queue
Version:
Priority queue data structures
25 lines (20 loc) • 604 B
text/coffeescript
module.exports = class AbstractPriorityQueue
constructor: (options) ->
throw 'Must pass options.strategy, a strategy' if !options?.strategy?
throw 'Must pass options.comparator, a comparator' if !options?.comparator?
= new options.strategy(options)
= options?.initialValues?.length || 0
queue: (value) ->
++
.queue(value)
undefined
dequeue: (value) ->
throw 'Empty queue' if !
--
.dequeue()
peek: (value) ->
throw 'Empty queue' if !
.peek()
clear: ->
= 0
.clear()