forked from jMotif/jmotif-R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisit_registry.cpp
More file actions
67 lines (61 loc) · 1.4 KB
/
visit_registry.cpp
File metadata and controls
67 lines (61 loc) · 1.4 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <RcppArmadillo.h>
using namespace Rcpp;
//
#include <jmotif.h>
//
// constructor
//
VisitRegistry::VisitRegistry( int capacity ) {
registry = new bool[capacity];
for( int i = 0; i < capacity; i++ ) {
registry[i] = false;
}
unvisited_count = capacity;
size = capacity;
}
// destructor
//
VisitRegistry::~VisitRegistry() {
delete[] registry;
}
// gets next unvisited position... following the HOTSAX heuristics this need to be a random
// position, so we can abandon the search earlier, if possible
//
int VisitRegistry::getNextUnvisited(){
if(0 == unvisited_count){
return -1;
} else {
int random_index = -1;
do{ // iterate over random indexes until we hit an unvisited position
random_index = armaRand() % size;
} while ( registry[random_index] );
return random_index;
}
}
// marks a position visited, takes care about the counter
//
void VisitRegistry::markVisited(int idx){
if(registry[idx]){
return;
}else{
unvisited_count = unvisited_count - 1;
registry[idx] = true;
}
}
// marks an interval as visited
//
void VisitRegistry::markVisited(int start, int end){
for(int i=start; i<end; i++){
if(registry[i]){
continue;
}else{
unvisited_count = unvisited_count - 1;
registry[i] = true;
}
}
}
// check if the position has been marked as visited
//
bool VisitRegistry::isVisited(int idx){
return(registry[idx]);
}