R: Priority Queue

priority_queue {collections} | R Documentation

## Priority Queue

### Description

`priority_queue` creates a priority queue (a.k.a heap).

### Usage

    priority_queue(items = NULL, priorities = rep(0, length(items)))

### Arguments

`items` | a list of items
`priorities` | a vector of interger valued priorities

### Details

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

### Examples

    q <- priority_queue()
    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

    q <- priority_queue(list("not_urgent", "urgent"), c(0, 2))
    q$push("not_as_urgent", 1)$push("not_urgent2")

[Package collections version 0.3.3 Index]