Skip to content

iskolbin/tspersistentpriorityqueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status license MIT Licence

Persistent priority queue

Persistent priority queue implemented with pairing heap. Implementation allows fast peek, enqueue, dequeue.

constructor(comparator = DEFAULT_COMPARATOR, arraylike?: [T,P][])

Creates new queue. By default uses comparator for minimal heap, i.e. item with the smallest priority will dequeue first. If arraylike is passed populate queue

length

Property returning size of the queue

isEmpty

Yields true if length is zero and false otherwise

enqueue(element: T, priority: P): PriorityQueue<T,P>

Enqueues element into the queue with specified priority. Returns new queue

dequeue(): PriorityQueue<T,P>

Dequeue element from queue and returns new queue. If queue is empty returns itself

first(): T | undefined

Returns element with the highest priority or undefined if the queue is empty

firstPriority(): P | undefined

Returns highest priority of the queue or undefined if the queue is empty

has(element: T): boolean

Returns true if the element is in the queue and false otherwise. This is slow O(n) method

clear(): boolean

If queue has items returns new empty queue otherwise returns itself

forEach( callback(element: T, priority: P, queue: PriorityQueue<T,P>), thisArg?: any )

Calls callback for each element and priority in the queue.

About

Persistent priority queue implemented with paring heaps

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published