Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/randy3k/collections
High-performance container datatypes for R
https://github.com/randy3k/collections
Last synced: 2 days ago
JSON representation
High-performance container datatypes for R
- Host: GitHub
- URL: https://github.com/randy3k/collections
- Owner: randy3k
- License: other
- Created: 2018-04-16T04:42:04.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-23T03:39:03.000Z (over 1 year ago)
- Last Synced: 2025-01-10T03:09:05.063Z (9 days ago)
- Language: R
- Homepage: https://randy3k.github.io/collections
- Size: 12.4 MB
- Stars: 103
- Watchers: 7
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - randy3k/collections - High-performance container datatypes for R (R)
README
---
output:
github_document:
html_preview: false
---```{r results='asis', echo = FALSE, eval = TRUE}
d <- read.dcf("DESCRIPTION")
``````{r results="asis", echo = FALSE, eval = TRUE}
title <- d[colnames(d) == "Title"]
cat(c("# ", paste(trimws(strsplit(title, "\n")[[1]]), collapse = " ")))
```[![check](https://github.com/randy3k/collections/actions/workflows/check.yaml/badge.svg)](https://github.com/randy3k/collections/actions/workflows/check.yaml)
[![codecov](https://codecov.io/gh/randy3k/collections/branch/master/graph/badge.svg?token=ummdWzk2eR)](https://codecov.io/gh/randy3k/collections)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/collections)](https://cran.r-project.org/package=collections)
[![](https://cranlogs.r-pkg.org/badges/grand-total/collections)](https://cran.r-project.org/package=collections)Github: [https://github.com/randy3k/collections](https://github.com/randy3k/collections)
Documentation: [https://randy3k.github.io/collections/](https://randy3k.github.io/collections/)
```{r results="asis", echo = FALSE, eval = TRUE}
cat(d[colnames(d) == "Description"])
```## Installation
You can install the released version of collections from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("collections")
```Install the latest development version using
```r
devtools::install_github("randy3k/collections")
```## Example
```{r}
library(collections, warn.conflicts = FALSE)
```Queue
```{r}
q <- queue()
q$push(1)$push(2)
q$pop()
```Stack
```{r}
s <- stack()
s$push(1)$push(2)
s$pop()
```Deque
```{r}
dq <- deque()
dq$push(1)$pushleft(2)
dq$pop()
```Priority Queue
```{r}
pq <- priority_queue()
pq$push("not_urgent")
pq$push("urgent", priority = 2)
pq$push("not_as_urgent", priority = 1)
pq$pop()
pq$pop()
pq$pop()
```Dictionary. Comparing to R envrionments, `dict()` does not [leak memory](https://r-lib.github.io/fastmap/#memory-leak-examples) and supports various other types of keys.
```{r}
d <- dict()
e <- new.env()
d$set(e, 1)$set(sum, 2)$set(c(1L, 2L), 3)
d$get(c(1L, 2L))
```Ordered Dictionary
```{r}
d <- ordered_dict()
d$set("b", 1)$set("a", 2)
d$as_list()
```