HashMap: Class providing some methods to store data into a hashtable...

HashMapR Documentation

Class providing some methods to store data into a hashtable and access stored items via key

Description

R lists with named elements are not hashed. Hash lookups are O(1), because during insert the key is converted to an integer using a hash function, and then the value put in the space hash(key) (this is a big simplification and avoids the complexity of dealing with collisions). Lookups of the key just require hashing the key to find the value's position (which is O(1), versus a O(n) array lookup). R lists use name lookups which are O(n).

Usage

HashMap

Format

R6Class object.

Value

Object of R6Class with methods for key-value mapping

Fields

field(s)

access all via ()

Construction

“' HashMap$new() “'

Methods

Documentation

For full documentation of each method go to https://github.com/ChrisNice89/ORM

new()

This method creates a HashMap instance.

put(key = "", value = NA)

store key-value pair(s)

get(key,unname=TRUE)

access item(s) with associated key(s)

Examples

hm<-HashMap$new()
keys<- c("tic", "tac", "toe")
values <- c(1, 22, 333)

hm$put("key",1)
hm$put(key = keys,value = values)
hm$get(keys)
hm$get("tic")
hm$size()
hm
hm$remove("tic")
hm$get("tic")
hm$size()
hm$getKeys()[1]
hm$getValues()


ChrisNice89/rdao documentation built on Aug. 26, 2022, 10:14 a.m.