diff --git a/.gitignore b/.gitignore index f7184d9..04e62a6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ src/*.o src/*.so src/*.dll *.DS_Store +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index f6f5b82..c7bbee8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sparsepp Type: Package -Title: Rcpp Interface to Sparsepp +Title: 'Rcpp' Interface to 'sparsepp' Version: 0.1.0 Date: 2016-12-29 Authors@R: c( @@ -8,15 +8,14 @@ Authors@R: c( person("Google Inc", role = c("aut", "cph")), person("Dmitriy", "Selivanov", role = "cre", email = "selivanov.dmitriy@gmail.com") ) -Description: Provides interface to sparsepp - fast, memory efficient hash map. - It is derived from Google's excellent sparsehash implementation. - We believe Sparsepp provides an unparalleled combination of performance and memory usage, +Description: Provides interface to 'sparsepp' - fast, memory efficient hash map. + It is derived from Google's excellent 'sparsehash' implementation. + We believe 'sparsepp' provides an unparalleled combination of performance and memory usage, and will outperform your compiler's unordered_map on both counts. - Only Google's dense_hash_map is consistently faster, at the cost of much greater + Only Google's 'dense_hash_map' is consistently faster, at the cost of much greater memory usage (especially when the final size of the map is not known in advance). License: BSD_3_clause + file LICENSE Encoding: UTF-8 -URL: https://github.com/dselivanov/sparsepp, https://github.com/greg7mdp/ - sparsepp +URL: https://github.com/greg7mdp/sparsepp, https://github.com/dselivanov/sparsepp BugReports: https://github.com/dselivanov/sparsepp/issues RoxygenNote: 5.0.1 diff --git a/LICENSE b/LICENSE index 865d273..2dd2361 100644 --- a/LICENSE +++ b/LICENSE @@ -1,36 +1,3 @@ -// ---------------------------------------------------------------------- -// Copyright (c) 2016, Gregory Popovitch - greg7mdp@gmail.com -// All rights reserved. -// -// This work is derived from Google's sparsehash library -// -// Copyright (c) 2005, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// ---------------------------------------------------------------------- - +YEAR: 2005, 2016 +COPYRIGHT HOLDER: Google Inc., Gregory Popovitch +ORGANIZATION: Google Inc. diff --git a/R/package-sparsepp.R b/R/package-sparsepp.R index ceaa5f9..ccd44b2 100644 --- a/R/package-sparsepp.R +++ b/R/package-sparsepp.R @@ -1,9 +1,10 @@ #' sparsepp #' #' \code{sparsepp} provides bindings to the -#' \href{https://github.com/greg7mdp/sparsepp}{sparsepp} - fast, memory efficient hash map for C++ +#' \href{https://github.com/greg7mdp/sparsepp}{sparsepp} - fast, memory efficient hash map for C++. #' \code{sparsepp} is an open source C++ library derived from Google's -#' excellent sparsehash implementation. It aims to achieve the following objectives: +#' excellent sparsehash implementation, but considerably outperform it - \url{https://github.com/greg7mdp/sparsepp/blob/master/bench.md}. +#' It aims to achieve the following objectives: #' \itemize{ #' \item A drop-in alternative for unordered_map and unordered_set. #' \item Extremely low memory usage (typically about one byte overhead per entry). @@ -11,5 +12,38 @@ #' \item C++11 support (if supported by compiler). #' \item Single header implementation - just copy sparsepp.h to your project and include it. #' \item Tested on Windows (vs2010-2015, g++), linux (g++, clang++) and MacOS (clang++). +#' } +#' @examples +#' \dontrun{ +#' library(Rcpp) +#' code = " +#' #include +#' using namespace std; +#' using namespace Rcpp; +#' // drop-in replacement for unordered_map +#' //#include +#' #include +#' using spp::sparse_hash_map; +#' // @export +#' // [[Rcpp::export]] +#' IntegerVector word_count(CharacterVector v) { +#' //unordered_map smap; +#' sparse_hash_map smap; +#' for(auto x: v) { +#' smap[as(x)] ++; +#' } +#' IntegerVector res(smap.size()); +#' int i = 0; +#' for(auto s:smap) { +#' res[i]=s.second; +#' i++; +#' } +#' return(res); +#' }" +#' f = tempfile(, fileext = ".cpp") +#' writeLines(code, f) +#' sourceCpp(f) +#' unlink(f) +#' word_count(sample(letters, 100, T)) #'} "_PACKAGE" diff --git a/README.md b/README.md index 689b7e9..a867c12 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,30 @@ -# Use `sparsepp` from another package +## Benchmarks + +Check original [sparsepp](https://github.com/greg7mdp/sparsepp) repository and [write-up](https://github.com/greg7mdp/sparsepp/blob/master/bench.md) which compares hashmap implementations. + +![insert-benchmark](https://raw.githubusercontent.com/greg7mdp2/img/master/sparsepp/insert_large_0.PNG) + +## Use sparsepp from another package To use C++ code from `sparsepp`: 1. In DESCRIPTION, add `LinkingTo: sparsepp`. 1. In the C++ file, add: `#include ` -# Simple example +## Simple example ```c++ #include using spp::sparse_hash_map; sparse_hash_map smap; ``` -# Defining custom hash function +## Defining custom hash function ```c++ #include #include #include -#include "sparsepp.h" +#include using std::string; diff --git a/cran-comments.md b/cran-comments.md index ee1fe2d..fea99ba 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,10 @@ +## Resubmission +This is a resubmission. In this version: + +* Put single quote around package names in Title and Description fields. +* Fixed URLs +* Added example to doc + ## Test environments * local OS X install, R 3.3.1 @@ -7,3 +14,4 @@ R CMD check results 0 errors | 0 warnings | 0 notes + diff --git a/man/sparsepp-package.Rd b/man/sparsepp-package.Rd index 9ba8b83..b0955f0 100644 --- a/man/sparsepp-package.Rd +++ b/man/sparsepp-package.Rd @@ -7,9 +7,10 @@ \title{sparsepp} \description{ \code{sparsepp} provides bindings to the -\href{https://github.com/greg7mdp/sparsepp}{sparsepp} - fast, memory efficient hash map for C++ +\href{https://github.com/greg7mdp/sparsepp}{sparsepp} - fast, memory efficient hash map for C++. \code{sparsepp} is an open source C++ library derived from Google's -excellent sparsehash implementation. It aims to achieve the following objectives: +excellent sparsehash implementation, but considerably outperform it - \url{https://github.com/greg7mdp/sparsepp/blob/master/bench.md}. +It aims to achieve the following objectives: \itemize{ \item A drop-in alternative for unordered_map and unordered_set. \item Extremely low memory usage (typically about one byte overhead per entry). @@ -19,4 +20,38 @@ excellent sparsehash implementation. It aims to achieve the following objectives \item Tested on Windows (vs2010-2015, g++), linux (g++, clang++) and MacOS (clang++). } } +\examples{ +\dontrun{ +library(Rcpp) +code = " +#include +using namespace std; +using namespace Rcpp; +// drop-in replacement for unordered_map +//#include +#include +using spp::sparse_hash_map; +// @export +// [[Rcpp::export]] +IntegerVector word_count(CharacterVector v) { + //unordered_map smap; + sparse_hash_map smap; + for(auto x: v) { + smap[as(x)] ++; + } + IntegerVector res(smap.size()); + int i = 0; + for(auto s:smap) { + res[i]=s.second; + i++; + } + return(res); +}" +f = tempfile(, fileext = ".cpp") +writeLines(code, f) +sourceCpp(f) +unlink(f) +word_count(sample(letters, 100, T)) +} +}