hash-class: Class "hash"

Description Details Slots Author(s) See Also Examples

Description

Implements a S4 hash class in R similar to hashes / associatesd arrays / dictionaries in other programming languages. Where possible, the hash class uses the standard R accessors: \$, [ and [[ as well as other common hash methods. Hash construction is flexible and takes several syntaxes. See the constructor method hash() for detaiols

Details

For shorter key-value pairs, lists yield higher performance. Hashes outperform list once the have an appreciable length typically greater than 100 elements. Hash objects have defined methods that (should) make them flexible, intuitive and easy to use especially for developers familar with other languages.

The haah class inherits from environment and has no defined slots. It is essentially a wrapper around base::environment() and is very similar to reference classes in that most of the semantic are pass-by-reference rather than pass-by-value. For this reason, some of the behaviour is not as expected.

Slots

.xData

an base::environment()

Author(s)

Christopher Brown

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  h <- new( "hash" )   # new empty hash
  h <- hash()          # same
  class(h)             # "hash"
  is.hash(h)           # TRUE
  
  h[ letters ] <- 1:26 # populate the hash
  
  as.list( h )         # convert to a list

  hash( list(a=1,b=1) )
  showClass("hash")

decisionpatterns/r-hash documentation built on Feb. 6, 2019, 10:27 p.m.