priority_queue
creates a priority queue (a.k.a heap).
a list of items
a vector of interger valued priorities
Following methods are exposed:
.$push(item, priority = 0)
.$pop()
.$clear()
.$size()
.$as_list()
.$print()
item
: any R object
priority
: a real number, item with larger priority pops first
q <- priority_queue()
q$push("not_urgent")
q$push("urgent", priority = 2)
q$push("not_as_urgent", priority = 1)
q$pop() # urgent
#> [1] "urgent"
q$pop() # not_as_urgent
#> [1] "not_as_urgent"
q$pop() # not_urgent
#> [1] "not_urgent"
q <- priority_queue(list("not_urgent", "urgent"), c(0, 2))
q$push("not_as_urgent", 1)$push("not_urgent2")