Learn R Programming

hashmap (version 0.2.2)

hashmap: Atomic vector hash map

Description

Create a new Hashmap instance

Usage

hashmap(keys, values, ...)

Arguments

keys

an atomic vector representing lookup keys

values

an atomic vector of values associated with keys in a pair-wise manner

...

other arguments passed to new when constructing the Hashmap instance

Value

a Hashmap object

Details

The following atomic vector types are currently supported for keys:

  • integer

  • numeric

  • character

  • Date

  • POSIXct

The following atomic vector types are currently supported for values:

  • logical

  • integer

  • numeric

  • character

  • complex

  • Date

  • POSIXct

See Also

Hashmap-class for a more detailed discussion of available methods

Examples

Run this code
# NOT RUN {
x <- replicate(10e3,
    paste0(sample(letters, 12, TRUE),
           collapse = "")
)
y <- rnorm(length(x))
z <- sample(x, 100)

H <- hashmap(x, y)

all.equal(y[match(z, x)], H[[z]])

# }
# NOT RUN {
microbenchmark::microbenchmark(
    "R" = y[match(z, x)],
    "H" = H[[z]],
    times = 500L
)
# }

Run the code above in your browser using DataLab