Distances on Directed Graphs in R
1#include "sc-as-network.h"
2
3// Function to generate IDs for the edges in each way
4std::string sc::random_id (size_t len) {
5 auto randchar = []() -> char
6 {
7 const char charset[] = \
8 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
9 const size_t max_index = (sizeof(charset) - 1);
10 //return charset [ rand() % max_index ];
11 size_t i = static_cast <size_t> (floor (Rcpp::runif (1) [0] * max_index));
12 return charset [i];
13 };
14 std::string str (len, 0);
15 std::generate_n (str.begin(), len, randchar);
16 return str;
17}
18
19//' rcpp_gen_hash
20//'
21//' Efficient generation of long sequences of hash keys
22//'
23//' @noRd
24// [[Rcpp::export]]
25Rcpp::CharacterVector rcpp_gen_hash (const int n, const size_t hash_len)
26{
27 Rcpp::CharacterVector res (n);
28 for (int i = 0; i < n; i++)
29 res [i] = sc::random_id (hash_len);
30 return res;
31}