Debian Codegraph @

ncls/src/intervaldb.h

raw
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 extern int C_int_max;
10
11 typedef struct {
12 int64_t start;
13 int64_t end;
14 int64_t target_id;
15 /* int target_start; */
16 /* int target_end; */
17 int64_t sublist;
18 } IntervalMap;
19
20
21 typedef struct {
22 int64_t start;
23 int64_t end;
24 } IntervalIndex;
25
26 typedef struct {
27 int start;
28 int len;
29 } SublistHeader;
30
31 typedef struct {
32 int n;
33 int ntop;
34 int nlists;
35 IntervalMap *im;
36 SublistHeader *subheader;
37 } IntervalDB;
38
39 typedef struct { /* FOR REAL-TIME DISK ACCESS TO SUBLIST HEADER FILE*/
40 SublistHeader *subheader;
41 int nblock;
42 int start;
43 FILE *ifile;
44 } SubheaderFile;
45
46 typedef struct {
47 int n;
48 int ntop;
49 int nlists;
50 int div;
51 int nii;
52 IntervalIndex *ii;
53 SublistHeader *subheader;
54 SubheaderFile subheader_file;
55 FILE *ifile_idb;
56 } IntervalDBFile;
57
58 typedef struct IntervalIterator_S {
59 int i;
60 int n;
61 int nii;
62 int ntop;
63 int i_div;
64 IntervalMap *im;
65 struct IntervalIterator_S *up;
66 struct IntervalIterator_S *down;
67 } IntervalIterator;
68
69
70 typedef struct {
71 FILE *ifile;
72 int left;
73 int right;
74 int ihead;
75 char *filename;
76 } FilePtrRecord;
77
78 extern int *alloc_array(int n);
79
80 extern int64_t find_overlap_start(int64_t start, int64_t end, IntervalMap im[],int n);
81 extern int64_t find_suboverlap_start(int64_t start, int64_t end,int isub, IntervalMap im[], SublistHeader subheader[]);
82 extern int imstart_qsort_cmp(const void *void_a,const void *void_b);
83 extern int target_qsort_cmp(const void *void_a,const void *void_b);
84 extern IntervalMap *read_intervals(int n,FILE *ifile);
85 extern SublistHeader *build_nested_list(IntervalMap im[],int n,
86 int *p_n,int *p_nlists);
87 extern SublistHeader *build_nested_list_inplace(IntervalMap im[],int n,
88 int *p_n,int *p_nlists);
89 extern IntervalMap *interval_map_alloc(int n);
90 extern IntervalDB *build_interval_db(IntervalMap im[],int n);
91 extern IntervalIterator *interval_iterator_alloc(void);
92 extern int free_interval_iterator(IntervalIterator *it);
93 extern IntervalIterator *reset_interval_iterator(IntervalIterator *it);
94 extern int64_t find_intervals(IntervalIterator *it0,int64_t start,int64_t end,IntervalMap im[],int n,SublistHeader subheader[],int nlists,IntervalMap buf[],int nbuf,int *p_nreturn,IntervalIterator **it_return);
95 extern int read_imdiv(FILE *ifile,IntervalMap imdiv[],int div,int i_div,int ntop);
96 extern IntervalMap *read_sublist(FILE *ifile,SublistHeader *subheader,IntervalMap *im);
97 extern int find_file_intervals(IntervalIterator *it0,int start,int end,
98 IntervalIndex ii[],int nii,
99 SublistHeader subheader[],int nlists,
100 SubheaderFile *subheader_file,
101 int ntop,int div,FILE *ifile,
102 IntervalMap buf[],int nbuf,
103 int *p_nreturn,IntervalIterator **it_return);
104 extern int write_padded_binary(IntervalMap im[],int n,int div,FILE *ifile);
105 extern char *write_binary_files(IntervalMap im[],int n,int ntop,int div,
106 SublistHeader *subheader,int nlists,char filestem[]);
107 extern IntervalDBFile *read_binary_files(char filestem[],char err_msg[],
108 int subheader_nblock);
109 extern int free_interval_dbfile(IntervalDBFile *db_file);
110
111 extern int save_text_file(char filestem[],char err_msg[],
112 char basestem[],FILE *ofile);
113 extern int text_file_to_binaries(FILE *infile,char buildpath[],char err_msg[]);
114 extern void reorient_intervals(int n,IntervalMap im[],int ori_sign);
115
116 /* extern int find_k_next(int start, int end, */
117 /* IntervalMap im[], int n, */
118 /* SublistHeader subheader[], int nlists, */
119 /* IntervalMap buf[], int ktofind, */
120 /* int *p_nreturn); */
121
122 #define FIND_FILE_MALLOC_ERR -2
123
124 #define ITERATOR_STACK_TOP(it) while (it->up) it=it->up;
125 #define FREE_ITERATOR_STACK(it,it2,it_next) \
126 for (it2=it->down;it2;it2=it_next) { \
127 it_next=it2->down; \
128 if (it2->im) \
129 free(it2->im); \
130 free(it2); \
131 } \
132 for (it2=it;it2;it2=it_next) { \
133 it_next=it2->up; \
134 if (it2->im) \
135 free(it2->im); \
136 free(it2); \
137 }
138
139 #define PUSH_ITERATOR_STACK(it,it2,TYPE) \
140 if (it->down) \
141 it2=it->down; \
142 else { \
143 CALLOC(it2,1,TYPE); \
144 it2->up = it; \
145 it->down= it2; \
146 }
147
148 /* IF it->up NON-NULL, MOVE UP, EVAL FALSE.
149 IF NULL, DON'T ASSIGN it, BUT EVAL TRUE */
150 #define POP_ITERATOR_STACK_DONE(it) (it->up==NULL || (it=it->up)==NULL)
151
152 #define POP_ITERATOR_STACK(it) (it->up && (it=it->up))
153
154 /* #define MALLOC_INT_ARRAY(n) ((int*) malloc (n)) */
155
156
157 #ifdef MERGE_INTERVAL_ORIENTATIONS
158 /* MACROS FOR MERGING POSITIVE AND NEGATIVE ORIENTATIONS */
159 #define START_POSITIVE(IM) (((IM).start>=0) ? ((IM).start) : -((IM).end))
160 #define END_POSITIVE(IM) (((IM).start>=0) ? ((IM).end) : -((IM).start))
161 #define SET_INTERVAL_POSITIVE(IM,START,END) if ((IM).start>=0) {\
162 START= (IM).start; \
163 END= (IM).end; \
164 } else { \
165 START= -((IM).end); \
166 END= -((IM).start); \
167 }
168
169 #define HAS_OVERLAP_POSITIVE(IM,START,END) (((IM).start>=0) ? \
170 ((IM).start<(END) && (START)<(IM).end) \
171 : (-((IM).end)<(END) && (START) < -((IM).start)))
172 /* ????? MERGE_INTERVAL_ORIENTATIONS ??????? */
173
174 #else
175 /* STANDARD MACROS */
176 #define START_POSITIVE(IM) ((IM).start)
177 #define END_POSITIVE(IM) ((IM).end)
178 #define HAS_OVERLAP_POSITIVE(IM,START,END) ((IM).start<(END) && (START)<(IM).end)
179
180 #endif
181
182 /* STORE ALL INTERVALS IN POSITIVE SOURCE ORIENTATION */
183 #define ALL_POSITIVE_ORIENTATION 1
184 /* ONLY LOAD SUBLISTS INDIVIDUALLY WHEN NEEDED */
185 #define ON_DEMAND_SUBLIST_HEADER 1
186
187
188
189 #endif