sparsepp-package: sparsepp

Description Author(s) See Also Examples

Description

sparsepp provides bindings to the sparsepp - fast, memory efficient hash map for C++. sparsepp is an open source C++ library derived from Google's excellent sparsehash implementation, but considerably outperform it - https://github.com/greg7mdp/sparsepp/blob/master/bench.md. It aims to achieve the following objectives:

Author(s)

Maintainer: Dmitriy Selivanov selivanov.dmitriy@gmail.com

Authors:

See Also

Useful links:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Not run: 
library(Rcpp)
code = "
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
using namespace std;
using namespace Rcpp;
// drop-in replacement for unordered_map
//#include <unordered_map>
#include <sparsepp/spp.h>
//[[Rcpp::depends(sparsepp)]]
using spp::sparse_hash_map;
// @export
// [[Rcpp::export]]
IntegerVector word_count(CharacterVector v) {
  //unordered_map<string, int> smap;
  sparse_hash_map<string, int> smap;
  for(auto x: v) {
    smap[as<string>(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))

## End(Not run)

sparsepp documentation built on May 2, 2019, 9:16 a.m.