-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwzcbs.h
68 lines (53 loc) · 1.23 KB
/
wzcbs.h
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
68
#ifndef WZCBS_H
#define WZCBS_H
/**
* Circular Binary Segmentation
***/
#include "wvec.h"
#include "math.h"
#define MAX(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _b : _a; })
typedef struct psum_t {
double max;
double min;
int max_index;
int min_index;
} psum_t;
/* for grouping segments when there are too many segments */
typedef struct block1_t {
int beg;
int end;
psum_t psum;
} block1_t;
typedef struct block_pair_t {
block1_t *b, *d;
double t, t_max;
int alen; /* arc length */
} block_pair_t;
DEFINE_VECTOR(block_pair_v, block_pair_t)
typedef struct block_t {
block1_t *a;
int n;
int bsize;
} block_t;
static inline block_t *init_blocks(int n) {
block_t *bk = calloc(1,sizeof(block_t));
bk->n = n>50 ? (int)sqrt((double)n) : 1;
bk->bsize = (n-1) / bk->n+1;
bk->a = calloc(bk->n, sizeof(block1_t));
int bi;
for (bi=0; bi<bk->n; ++bi) {
block1_t *b = bk->a+bi;
b->beg = bi*bk->bsize;
b->end = (bi+1)*bk->bsize-1;
}
bk->a[bk->n-1].end = n-1;
return bk;
}
#endif /* WZCBS_H */