Does R have a priority queue like Java's PriorityQueue?

Viewed 2744

I am looking for a general purpose priority queue in R. Does R has any general purpose priority queue implementation (package) like Java PriorityQueue class or Python heapq?

4 Answers

I went ahead and implemented a basic queue as an R Reference Class. The details can be found here. It's been extended to handle a priority queue, as documented here.

The basic and priority queue implementations are now available as the liqueueR package on CRAN, with a development version on GitHub.

Checkout the package collections: https://cran.r-project.org/web/packages/collections/index.html

q <- PriorityQueue()
q$push("not_urgent")
q$push("urgent", priority = 2)
q$push("not_as_urgent", priority = 1)
q$pop() # urgent
q$pop() # not_as_urgent
q$pop() # not_urgent

EDIT: update syntax for collection v0.2.0

Related