Skip to content

Commit 3c6b286

Browse files
committed
interrup...t
1 parent 42e8c8a commit 3c6b286

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: TreeTools
22
Title: Create, Modify and Analyse Phylogenetic Trees
3-
Version: 2.2.0.9001
3+
Version: 2.2.0.9002
44
Authors@R: c(
55
person("Martin R.", 'Smith', role = c("aut", "cre", "cph"),
66
email = "martin.smith@durham.ac.uk",

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# TreeTools 2.2.0.9001 #
1+
# TreeTools 2.2.0.9002 #
22

33
## New functionality
44

55
- `Paste0()` provides a fast Rcpp-backed drop-in for `paste0()` / `stri_paste()`
66
with `NA` propagation. Exported for use by downstream packages.
77

8+
## Usability
9+
10+
- `Consensus()` and `SplitFrequency()` now respond to user interrupts during
11+
long-running computations.
12+
813
## Performance
914

1015
- Drop `stringi` dependency.

src/consensus.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include <Rcpp/Lightest>
2+
#include <Rcpp/Interrupt.h> /* for Rcpp::checkUserInterrupt() */
23
using namespace Rcpp;
34

45
#include "../inst/include/TreeTools/assert.h" /* for ASSERT */
56
#include "../inst/include/TreeTools/ClusterTable.h" /* for ClusterTable */
67

78
#include <algorithm> /* for fill */
89
#include <array> /* for array */
10+
#include <chrono> /* for steady_clock (interrupt timing) */
911
#include <string> /* for string (hash key) */
1012
#include <unordered_map> /* for unordered_map */
1113

@@ -57,8 +59,18 @@ RawMatrix calc_consensus_tree(
5759

5860
int32 i = 0;
5961
int32 splits_found = 0;
62+
auto lastInterrupt = std::chrono::steady_clock::now();
6063

6164
do {
65+
// ~1 s user-interrupt check
66+
{
67+
const auto now = std::chrono::steady_clock::now();
68+
if (std::chrono::duration_cast<std::chrono::seconds>(
69+
now - lastInterrupt).count() >= 1) {
70+
lastInterrupt = now;
71+
Rcpp::checkUserInterrupt();
72+
}
73+
}
6274
if (tables[i].NOSWX(ntip_3)) {
6375
continue;
6476
}
@@ -187,8 +199,18 @@ List calc_split_frequencies(
187199

188200
// Reusable key buffer — avoids per-split heap allocation
189201
std::string key(nbin, '\0');
202+
auto lastInterrupt = std::chrono::steady_clock::now();
190203

191204
for (int32 i = 0; i < n_trees; ++i) {
205+
// ~1 s user-interrupt check
206+
{
207+
const auto now = std::chrono::steady_clock::now();
208+
if (std::chrono::duration_cast<std::chrono::seconds>(
209+
now - lastInterrupt).count() >= 1) {
210+
lastInterrupt = now;
211+
Rcpp::checkUserInterrupt();
212+
}
213+
}
192214
if (tables[i].NOSWX(ntip_3)) {
193215
continue;
194216
}

0 commit comments

Comments
 (0)