R topics documented: 2 clone

Similar documents
Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package lvec. May 24, 2018

Package kdtools. April 26, 2018

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package rtext. January 23, 2019

Package messaging. May 27, 2018

Package triebeard. August 29, 2016

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package ECctmc. May 1, 2018

Package geogrid. August 19, 2018

Package githubinstall

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package fastdummies. January 8, 2018

Package validara. October 19, 2017

Package repec. August 31, 2018

Package nngeo. September 29, 2018

Package spark. July 21, 2017

Package mdftracks. February 6, 2017

Package robotstxt. November 12, 2017

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package tidyimpute. March 5, 2018

Package datasets.load

Package ompr. November 18, 2017

Package combiter. December 4, 2017

Package available. November 17, 2017

Package dotcall64. January 11, 2018

Package strat. November 23, 2016

Package purrrlyr. R topics documented: May 13, Title Tools at the Intersection of 'purrr' and 'dplyr' Version 0.0.2

Package semver. January 6, 2017

Package readobj. November 2, 2017

Package dbx. July 5, 2018

Package io. January 15, 2018

Package modules. July 22, 2017

Package RPresto. July 13, 2017

Package fst. December 18, 2017

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package crochet. January 8, 2018

Package profvis. R topics documented:

Package fst. June 7, 2018

Package gtrendsr. October 19, 2017

Package zip. R topics documented: March 11, Title Cross-Platform 'zip' Compression Version 2.0.1

Package clipr. June 23, 2018

Package tibble. August 22, 2017

Package gameofthrones

Package assertive.code

Package sankey. R topics documented: October 22, 2017

Package reconstructr

Package raker. October 10, 2017

Package SimilaR. June 21, 2018

Package darksky. September 20, 2017

Package httpcache. October 17, 2017

Package docxtools. July 6, 2018

Package farver. November 20, 2018

Package wrswor. R topics documented: February 2, Type Package

Package rollply. R topics documented: August 29, Title Moving-Window Add-on for 'plyr' Version 0.5.0

Package IATScore. January 10, 2018

Package desc. May 1, 2018

Package gtrendsr. August 4, 2018

Package opencage. January 16, 2018

Package internetarchive

Package queuecomputer

Package labelvector. July 28, 2018

Package oec. R topics documented: May 11, Type Package

Package virustotal. May 1, 2017

Package fitbitscraper

Package QCAtools. January 3, 2017

Package benchmarkme. R topics documented: February 26, Type Package Title Crowd Sourced System Benchmarks Version 0.2.

Package gifti. February 1, 2018

Package sylcount. April 7, 2017

Package projector. February 27, 2018

Package readxl. April 18, 2017

Package pkgbuild. October 16, 2018

Package keyholder. May 19, 2018

Package packcircles. April 28, 2018

Package autocogs. September 22, Title Automatic Cognostic Summaries Version 0.1.1

Package rbraries. April 18, 2018

Package fbroc. August 29, 2016

Package fasttextr. May 12, 2017

Package BiocManager. November 13, 2018

Package postgistools

Package Matrix.utils

Package RODBCext. July 31, 2017

Package edfreader. R topics documented: May 21, 2017

Package goodpractice

Package CorporaCoCo. R topics documented: November 23, 2017

Package librarian. R topics documented:

Package crossword.r. January 19, 2018

Package rxylib. December 20, 2017

Package OsteoBioR. November 15, 2018

Package harrypotter. September 3, 2018

Package fastrtext. December 10, 2017

Package tidyselect. October 11, 2018

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package memoise. April 21, 2017

Package redux. May 31, 2018

Package shinyhelper. June 21, 2018

Package optimus. March 24, 2017

Package lumberjack. R topics documented: July 20, 2018

Package loggit. April 9, 2018

Package UNF. June 13, 2017

Transcription:

Package hashmap Type Package Title The Faster Hash Map Version 0.2.2 Date 2017-11-16 November 16, 2017 URL https://github.com/nathan-russell/hashmap BugReports https://github.com/nathan-russell/hashmap/issues Provides a hash table class for fast key-value storage of atomic vector types. License MIT + file LICENSE LazyData Yes ByteCompile TRUE Imports Rcpp (>= 0.12.4 LinkingTo Rcpp, BH Suggests devtools, microbenchmark, testthat Depends methods RcppModules Hashmap Collate 'hashmap.r' 'classes.r' 'Hashmap-class.R' 'RcppExports.R' 'clone.r' 'load_hashmap.r' 'merge.r' 'plugin.r' 'save_hashmap.r' 'zzz.r' RoxygenNote 6.0.1 NeedsCompilation yes Author Nathan Russell [aut, cre] Maintainer Nathan Russell <russell.nr2012@gmail.com> Repository CRAN Date/Publication 2017-11-16 15:19:42 UTC 1

2 clone R topics documented: clone............................................. 2 hashmap........................................... 3 Hashmap-class....................................... 4 internal-functions...................................... 7 load_hashmap........................................ 8 merge............................................ 9 plot............................................. 10 Rcpp_Hashmap-class.................................... 11 save_hashmap........................................ 11 Index 13 clone Clone a Hashmap clone creates a deep copy of a Hashmap so that modifications made to the cloned object do not affect the original object. clone(x x an object created by a call to hashmap. Since the actual cloning is done in C++, y <- clone(x should be much more efficient than y <- hashmap(x$keys(, x$values(. Value a Hashmap identical to the input object. See Also hashmap

hashmap 3 x <- hashmap(letters[1:5], 1:5 ## shallow copy y <- x y[["a"]] <- 999 ## original is affected x[["a"]] == 999 z <- clone(x z[["c"]] <- 888 ## original not affected x[["c"]] == 888 hashmap Atomic vector hash map Create a new Hashmap instance hashmap(keys, values,... 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 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

4 Hashmap-class integer numeric character complex Date POSIXct Value a Hashmap object See Also Hashmap-class for a more detailed discussion of available methods 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 ## End(Not run Hashmap-class Internal hash map class A C++ class providing hash map functionality for atomic vectors

Hashmap-class 5 A Hashmap object (H resulting from a call to hashmap(keys, values provides the following methods accessible via $method_name: keys(: returns the keys of H. values(: returns the values of H. cache_keys(: caches an internal vector with the hash table s current keys resulting in very low overhead calls to keys(. For larger hash tables this has a significant effect. However, any calls to modifying functions (clear, insert, etc. will invalidate the cached state. cache_values(: caches an internal vector with the hash table s current values resulting in very low overhead calls to values(. For larger hash tables this has a significant effect. However, any calls to modifying functions (clear, insert, etc. will invalidate the cached state. keys_cached(: returns TRUE if the hash table s keys are currently cached, and FALSE otherwise. values_cached(: returns TRUE if the hash table s values are currently cached, and FALSE otherwise. erase(remove_keys: deletes entries for elements that exist in the hash table, and ignores elements that do not. clear(: deletes all keys and values from H. data(: returns a named vector of values using the keys of H as names. empty(: returns TRUE if H is empty (e.g. immediately following a call to clear, else returns FALSE. find(lookup_keys: returns the values associated with lookup_keys for existing key elements, and NA otherwise. has_key(lookup_key: returns TRUE if lookup_key exists as a key in H and FALSE if it does not. has_keys(lookup_keys: vectorized equivalent of has_key. rehash(n_buckets: for the internal hash table, sets the number of buckets to at least n and the load factor to less than the max load factor. bucket_count(: returns the current number of buckets in the internal hash table. hash_value(keys: compute hash values for the vector keys using the hash table s internal hash function. Note that keys need not exist in the hash table, but it must have the same type as the hash table s keys. This can be useful for investigating the efficacy of the object s hash function. renew(new_keys, new_values: deletes current keys and values, and reinitialize H with new_keys and new_values, where new_keys and new_values are allowed to be different SEXP types than the original keys and values. insert(more_keys, more_values: adds more key-value pairs to H, where existing key elements (intersect(h$keys(, more_keys will be updated with the corresponding elements in more_values, and non-existing key elements setdiff(h$keys(, more_keys will be inserted with the corresponding elements in more_values. size(: returns the size (number of key-value pairs of (held by H.

6 Hashmap-class Additionally, the following two convenience methods which do not require the use of $: [[ : equivalent to find(lookup_keys. [[<- : equivalent to insert(more_keys, more_values. x <- replicate(10e3, paste0(sample(letters, 12, TRUE, collapse = "" y <- rnorm(length(x z <- sample(x, 100 H <- hashmap(x, y H$empty( #[1] FALSE H$size( #[1] 10000 ## necessarily any(duplicated(h$keys( all.equal(h[[z]], H$find(z #[1] FALSE #[1] TRUE ## hash map ordering is random all.equal( sort(h[[x]], sort(h$values( #[1] TRUE ## a named vector head(h$data( ## redundant, but TRUE all.equal( H[[names(head(H$data(]], unname(head(h$data( ## setting values H2 <- hashmap(h$keys(, H$values( all.equal( sort(h[[h2$keys(]], sort(h2[[h$keys(]] #[1] TRUE H$insert("A", round(pi, 5 H2[["A"]] <- round(pi, 5 ## still true all.equal( sort(h[[h2$keys(]], sort(h2[[h$keys(]]

internal-functions 7 ## changing SEXPTYPE of key or value must be explicit H3 <- hashmap(c("a", "B", "C", c(1, 2, 3 H3$size( #[1] 3 H3$clear( H3$size( #[1] 0 ## not allowed class(try(h3[["d"]] <- "text", silent = TRUE #[1] "try-error" ## okay H3$renew("D", "text" H3$size( #[1] 1 internal-functions Hashmap internal functions Hashmap internal functions.left_outer_join_impl(x, y.right_outer_join_impl(x, y.inner_join_impl(x, y.full_outer_join_impl(x, y x y an external pointer to a HashMap an external pointer to a HashMap These functions are intended for internal use only; do not call them directly.

8 load_hashmap load_hashmap Load Hashmaps load_hashmap reads a file created by a call to save_hashmap and returns a Hashmap object. load_hashmap(file file the name of a file previously created by a call to save_hashmap. The object returned will contain all of the same key-value pairs that were present in the original Hashmap at the time save_hashmap was called, but they are not guaranteed to be in the same order, due to rehashing. Value A Hashmap object on success; an error on failure. See Also save_hashmap H <- hashmap(sample(letters[1:10], sample(1:10 tf <- tempfile( save_hashmap(h, tf H2 <- load_hashmap(tf all.equal( sort(h$find(h2$keys(, sort(h2$values( all.equal( H$data.frame(, readrds(tf

merge 9 merge Merge two Hashmaps merge method for Hashmap class ## S3 method for class 'Rcpp_Hashmap' merge(x, y, type = c("inner", "left", "right", "full",... x y type Value... not used. Valid arguments for type are: an object created by a call to hashmap. an object created by a call to hashmap. a character string specifying the type of join, with partial argument matching (abbreviation supported. "inner": similar to all = FALSE in base::merge "left": similar to all.x = TRUE in base::merge "right": similar to all.y = TRUE in base::merge "full": similar to all = TRUE in base::merge The default value for type is "inner". a data.frame. hx <- hashmap(letters[1:5], 1:5 hy <- hashmap(letters[4:8], 4:8 ## inner join merge(hx, hy merge( hx$data.frame(, hy$data.frame(,

10 plot by = "Keys", sort = FALSE ## left join merge(hx, hy, "left" merge( hx$data.frame(, hy$data.frame(, by = "Keys", all.x = TRUE, sort = FALSE ## right join merge(hx, hy, "right" merge( hx$data.frame(, hy$data.frame(, by = "Keys", all.y = TRUE, sort = FALSE ## full outer join merge(hx, hy, "full" merge( hx$data.frame(, hy$data.frame(, by = "Keys", all = TRUE, sort = FALSE plot Plot method for Hashmap class Plot method for Hashmap class ## S3 method for class 'Rcpp_Hashmap' plot(x,...

Rcpp_Hashmap-class 11 x an object created by a call to hashmap... arguments passed to plot A convenience function which simply calls plot using x$keys( and x$values( as plotting coordinates. x <- hashmap(1:20, rnorm(20 plot(x plot(x, type = 'p', pch = 20, col = 'red' y <- hashmap(sys.date( + 1:20, rnorm(20 plot(y, type = 'h', col = 'blue', lwd = 3 Rcpp_Hashmap-class Hashmap internal class Hashmap internal class save_hashmap Save Hashmaps save_hashmap writes a Hashmap s data to the specified file, which can be passed to load_hashmap at a later point in time to recreate the object. save_hashmap(x, file, overwrite = TRUE, compress = FALSE x file overwrite compress an object created by a call to hashmap. a filename where the object s data will be saved. if TRUE (default and file exists, it will be overwritten. If FALSE and file exists, an error is thrown. a logical value or the type of file compression to use; defaults to FALSE for better performance. See?saveRDS for details.

12 save_hashmap Value Saving is done by calling base::saverds on the object s data.frame representation, x$data.frame(. Attempting to save an empty Hashmap results in an error. See Also Nothing on success; an error on failure. load_hashmap, saverds H <- hashmap(sample(letters[1:10], sample(1:10 tf <- tempfile( save_hashmap(h, tf inherits( try(save_hashmap(h, tf, FALSE, silent = TRUE, "try-error" H$insert("zzzzz", 123L save_hashmap(h, tf load_hashmap(tf

Index.full_outer_join_impl (internal-functions, 7.inner_join_impl (internal-functions, 7.left_outer_join_impl (internal-functions, 7.right_outer_join_impl (internal-functions, 7 clone, 2 Hashmap (Hashmap-class, 4 hashmap, 2, 3 Hashmap-class, 4 internal-functions, 7 load_hashmap, 8, 11, 12 merge, 9 plot, 10 Rcpp_Hashmap (Rcpp_Hashmap-class, 11 Rcpp_Hashmap-class, 11 save_hashmap, 8, 11 saverds, 12 13