| 1 |
|
| 2 |
#ifndef INTERVALDB_HEADER_INCLUDED |
| 3 |
#define INTERVALDB_HEADER_INCLUDED 1 |
| 4 |
#include "default.h" |
| 5 |
#include <limits.h> |
| 6 |
|
| 7 |
#include <stdint.h> |
| 8 |
|
| 9 |
typedef struct { |
| 10 |
int32_t start; |
| 11 |
int32_t end; |
| 12 |
int32_t target_id; |
| 13 |
int32_t sublist; |
| 14 |
} IntervalMap; |
| 15 |
|
| 16 |
|
| 17 |
typedef struct { |
| 18 |
int start; |
| 19 |
int end; |
| 20 |
} IntervalIndex; |
| 21 |
|
| 22 |
typedef struct { |
| 23 |
int start; |
| 24 |
int len; |
| 25 |
} SublistHeader; |
| 26 |
|
| 27 |
typedef struct IntervalIterator_S { |
| 28 |
int i; |
| 29 |
int n; |
| 30 |
int nii; |
| 31 |
int ntop; |
| 32 |
int i_div; |
| 33 |
IntervalMap *im; |
| 34 |
struct IntervalIterator_S *up; |
| 35 |
struct IntervalIterator_S *down; |
| 36 |
} IntervalIterator; |
| 37 |
|
| 38 |
extern int *alloc_array(int n); |
| 39 |
|
| 40 |
extern int find_overlap_start(int start,int end,IntervalMap im[],int n); |
| 41 |
extern int find_suboverlap_start(int start,int end,int isub,IntervalMap im[],SublistHeader subheader[]); |
| 42 |
extern int imstart_qsort_cmp(const void *void_a,const void *void_b); |
| 43 |
extern int target_qsort_cmp(const void *void_a,const void *void_b); |
| 44 |
extern SublistHeader *build_nested_list(IntervalMap im[],int n, |
| 45 |
int *p_n,int *p_nlists); |
| 46 |
extern IntervalMap *interval_map_alloc(int n); |
| 47 |
extern IntervalIterator *interval_iterator_alloc(void); |
| 48 |
extern int free_interval_iterator(IntervalIterator *it); |
| 49 |
extern IntervalIterator *reset_interval_iterator(IntervalIterator *it); |
| 50 |
extern int find_intervals(IntervalIterator *it0, int32_t start, int32_t end,IntervalMap im[],int n,SublistHeader subheader[],int nlists,IntervalMap buf[],int nbuf,int *p_nreturn,IntervalIterator **it_return); |
| 51 |
|
| 52 |
#define FIND_FILE_MALLOC_ERR -2 |
| 53 |
|
| 54 |
#define ITERATOR_STACK_TOP(it) while (it->up) it=it->up; |
| 55 |
#define FREE_ITERATOR_STACK(it,it2,it_next) \ |
| 56 |
for (it2=it->down;it2;it2=it_next) { \ |
| 57 |
it_next=it2->down; \ |
| 58 |
if (it2->im) \ |
| 59 |
free(it2->im); \ |
| 60 |
free(it2); \ |
| 61 |
} \ |
| 62 |
for (it2=it;it2;it2=it_next) { \ |
| 63 |
it_next=it2->up; \ |
| 64 |
if (it2->im) \ |
| 65 |
free(it2->im); \ |
| 66 |
free(it2); \ |
| 67 |
} |
| 68 |
|
| 69 |
#define PUSH_ITERATOR_STACK(it,it2,TYPE) \ |
| 70 |
if (it->down) \ |
| 71 |
it2=it->down; \ |
| 72 |
else { \ |
| 73 |
CALLOC(it2,1,TYPE); \ |
| 74 |
it2->up = it; \ |
| 75 |
it->down= it2; \ |
| 76 |
} |
| 77 |
|
| 78 |
/* IF it->up NON-NULL, MOVE UP, EVAL FALSE. |
| 79 |
IF NULL, DON'T ASSIGN it, BUT EVAL TRUE */ |
| 80 |
#define POP_ITERATOR_STACK_DONE(it) (it->up==NULL || (it=it->up)==NULL) |
| 81 |
|
| 82 |
#define POP_ITERATOR_STACK(it) (it->up && (it=it->up)) |
| 83 |
|
| 84 |
/* #define MALLOC_INT_ARRAY(n) ((int*) malloc (n)) */ |
| 85 |
|
| 86 |
|
| 87 |
#ifdef MERGE_INTERVAL_ORIENTATIONS |
| 88 |
/* MACROS FOR MERGING POSITIVE AND NEGATIVE ORIENTATIONS */ |
| 89 |
#define START_POSITIVE(IM) (((IM).start>=0) ? ((IM).start) : -((IM).end)) |
| 90 |
#define END_POSITIVE(IM) (((IM).start>=0) ? ((IM).end) : -((IM).start)) |
| 91 |
#define SET_INTERVAL_POSITIVE(IM,START,END) if ((IM).start>=0) {\ |
| 92 |
START= (IM).start; \ |
| 93 |
END= (IM).end; \ |
| 94 |
} else { \ |
| 95 |
START= -((IM).end); \ |
| 96 |
END= -((IM).start); \ |
| 97 |
} |
| 98 |
|
| 99 |
#define HAS_OVERLAP_POSITIVE(IM,START,END) (((IM).start>=0) ? \ |
| 100 |
((IM).start<(END) && (START)<(IM).end) \ |
| 101 |
: (-((IM).end)<(END) && (START) < -((IM).start))) |
| 102 |
/* ????? MERGE_INTERVAL_ORIENTATIONS ??????? */ |
| 103 |
|
| 104 |
#else |
| 105 |
/* STANDARD MACROS */ |
| 106 |
#define START_POSITIVE(IM) ((IM).start) |
| 107 |
#define END_POSITIVE(IM) ((IM).end) |
| 108 |
#define HAS_OVERLAP_POSITIVE(IM,START,END) ((IM).start<(END) && (START)<(IM).end) |
| 109 |
|
| 110 |
#endif |
| 111 |
|
| 112 |
/* STORE ALL INTERVALS IN POSITIVE SOURCE ORIENTATION */ |
| 113 |
#define ALL_POSITIVE_ORIENTATION 1 |
| 114 |
/* ONLY LOAD SUBLISTS INDIVIDUALLY WHEN NEEDED */ |
| 115 |
#define ON_DEMAND_SUBLIST_HEADER 1 |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
#endif |