-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtype.h
87 lines (73 loc) · 1.77 KB
/
dtype.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef PLS_CHAIN_DTYPE_H
#define PLS_CHAIN_DTYPE_H
#include <zlib.h>
#include "khash.h"
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define true 1
#define false 0
#define ARR_SIZE 5
#define STEP_SIZE 3
typedef struct _tuple_t {
int comp_idx;
int s_idx;
} tuple_t;
typedef struct _item_t {
tuple_t value;
int count;
} item_t;
void init_item(item_t * item, int comp_idx, int s_idx, int count){
item->count = count;
item->value.comp_idx = comp_idx;
item->value.s_idx = s_idx;
}
int ieq_item(item_t * item, tuple_t value){
if (item->value.comp_idx == value.comp_idx && item->value.s_idx == value.s_idx) {
item->count ++;
return true;
} else {
return false;
}
}
typedef struct _tetra_t {
int alpha;
int beta;
int q_pos;
int count;
} tetra_t;
void init_tetra(tetra_t * tetra, int alpha, int beta, int q_pos, int count){
tetra->alpha = alpha; // i
tetra->beta = beta; // j
tetra->q_pos = q_pos; // q
tetra->count = count; // c
}
typedef struct _layer_t {
size_t l, m;
tetra_t * tetras;
} layer_t;
void append_layer(layer_t * layer, item_t item, int q_pos){
if (layer->m == 0) {
layer->m = ARR_SIZE;
layer->tetras = (tetra_t *) calloc(layer->m, sizeof(tetra_t));
}
if (layer->m == layer->l) {
layer->m += STEP_SIZE;
layer->tetras = (tetra_t *) realloc(layer->tetras, layer->m *sizeof(tetra_t));
}
layer->tetras[layer->l] = (tetra_t) {item.value.comp_idx, item.value.s_idx, q_pos, item.count};
layer->l ++;
}
void free_layer(layer_t * layers, int num_comp){
for (int i = 0; i < num_comp; i ++){
if (layers[i].tetras != NULL) {
free(layers[i].tetras);
}
}
free(layers);
}
khint64_t get_mask(size_t k){
khint64_t mask = 0;
for (int i = 0; i < k; i ++) mask = ((mask << 2) | 0b11);
return mask;
}
#endif