-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <Rcpp.h> | ||
#include <string> | ||
|
||
// [[Rcpp::export]] | ||
bool has_repeats(const Rcpp::NumericVector vec1, const Rcpp::NumericVector vec2) { | ||
std::unordered_set<double> s; | ||
|
||
for (int i = 0; i < vec1.size(); i++) { | ||
if (s.count(vec1[i]) > 0) { | ||
return true; | ||
} | ||
s.insert(vec1[i]); | ||
} | ||
|
||
for (int i = 0; i < vec2.size(); i++) { | ||
if (s.count(vec2[i]) > 0) { | ||
return true; | ||
} | ||
s.insert(vec2[i]); | ||
} | ||
return false; | ||
} | ||
|
||
// check if two string vectors has common elements or if the second vector has | ||
// repeated elements | ||
// [[Rcpp::export]] | ||
bool has_common_strs( | ||
const std::vector<std::string>& vec1, const std::vector<std::string>& vec2 | ||
) { | ||
// Create a hash set to store strings from vec1 | ||
std::unordered_set<std::string> hashSet; | ||
for (const std::string& str : vec1) { | ||
hashSet.insert(str); | ||
} | ||
|
||
// Check if any string from vec2 is present in the hash set | ||
for (const std::string& str : vec2) { | ||
if (hashSet.count(str) > 0) { | ||
return true; | ||
} | ||
hashSet.insert(str); | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// ensure export of `run_testthat_tests()` | ||
#define TESTTHAT_TEST_RUNNER | ||
#include <testthat.h> | ||
#include <testthat.h> | ||
|
||
// tests (bad practisce) | ||
#include "tests/helper-testfunctions.hpp" | ||
#include "tests/test-cpp_circle_layout.hpp" | ||
#include "tests/test-repulsion.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <Rcpp.h> | ||
#include <string> | ||
|
||
bool approx_equal(double a, double b, double epsilon = 5e-5) { | ||
return std::abs(a - b) <= epsilon; | ||
} | ||
|
||
bool elements_are_equal( | ||
Rcpp::NumericVector vec1, Rcpp::NumericVector vec2, double epsilon = 5e-5 | ||
) { | ||
for (int i = 0; i < vec1.size(); i++) { | ||
if (!approx_equal(vec1[i], vec2[i], epsilon)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.