25 |
|
#define CHPATHSEP '\\' |
26 |
|
#undef off_t |
27 |
|
#define off_t int64_t |
28 |
+ |
#ifndef popen |
29 |
+ |
#define popen _popen |
30 |
+ |
#endif |
31 |
|
#ifdef _fseeki64 |
32 |
|
#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin) |
33 |
|
#else |
64 |
|
|
65 |
|
typedef int32_t int32; |
66 |
|
typedef uint32_t uint32; |
67 |
+ |
typedef int16_t int16; |
68 |
+ |
typedef uint16_t uint16; |
69 |
|
|
70 |
|
typedef unsigned char uchar; |
71 |
|
typedef unsigned char byte; |
172 |
|
return a-b; |
173 |
|
} |
174 |
|
|
175 |
< |
int Gstrcmp(char* a, char* b); |
175 |
> |
int Gstrcmp(const char* a, const char* b, int n=-1); |
176 |
|
//same as strcmp but doesn't crash on NULL pointers |
177 |
|
|
178 |
< |
int Gstricmp(const char* a, const char* b); |
178 |
> |
int Gstricmp(const char* a, const char* b, int n=-1); |
179 |
> |
|
180 |
> |
//basic swap template function |
181 |
> |
template<class T> void Gswap(T& lhs, T& rhs) { |
182 |
> |
//register T tmp=lhs; |
183 |
> |
T tmp=lhs; //requires copy operator |
184 |
> |
lhs=rhs; |
185 |
> |
rhs=tmp; |
186 |
> |
} |
187 |
|
|
175 |
– |
inline void swap(int &arg1, int &arg2){ |
176 |
– |
//arg1 ^= arg2; |
177 |
– |
//arg2 ^= arg1; |
178 |
– |
//arg1 ^= arg2; |
179 |
– |
register int swp=arg1; |
180 |
– |
arg1=arg2; arg2=swp; |
181 |
– |
} |
182 |
– |
|
183 |
– |
inline void swap(char* &arg1, char* &arg2){ //swap pointers! |
184 |
– |
register char* swp=arg1; |
185 |
– |
arg1=arg2; arg2=swp; |
186 |
– |
} |
187 |
– |
|
188 |
– |
inline void swap(uint &arg1, uint &arg2) { |
189 |
– |
register uint swp=arg1; |
190 |
– |
arg1=arg2; arg2=swp; |
191 |
– |
} |
192 |
– |
|
193 |
– |
inline void swap(short &arg1, short &arg2) { |
194 |
– |
register short swp=arg1; |
195 |
– |
arg1=arg2; arg2=swp; |
196 |
– |
} |
197 |
– |
|
198 |
– |
inline void swap(unsigned short &arg1, unsigned short &arg2) { |
199 |
– |
register unsigned short swp=arg1; |
200 |
– |
arg1=arg2; arg2=swp; |
201 |
– |
} |
202 |
– |
|
203 |
– |
inline void swap(long &arg1, long &arg2) { |
204 |
– |
register long swp=arg1; |
205 |
– |
arg1=arg2; arg2=swp; |
206 |
– |
} |
207 |
– |
|
208 |
– |
inline void swap(unsigned long &arg1, unsigned long &arg2) { |
209 |
– |
register unsigned long swp=arg1; |
210 |
– |
arg1=arg2; arg2=swp; |
211 |
– |
} |
212 |
– |
|
213 |
– |
|
214 |
– |
inline void swap(char &arg1, char &arg2) { |
215 |
– |
register char swp=arg1; |
216 |
– |
arg1=arg2; arg2=swp; |
217 |
– |
} |
218 |
– |
|
219 |
– |
inline void swap(unsigned char &arg1, unsigned char &arg2) { |
220 |
– |
register unsigned char swp=arg1; |
221 |
– |
arg1=arg2; arg2=swp; |
222 |
– |
} |
188 |
|
|
189 |
|
/**************** Memory management ***************************/ |
190 |
|
|
295 |
|
} |
296 |
|
|
297 |
|
bool overlap(uint s, uint e) { |
298 |
< |
if (s>e) { swap(s,e); } |
298 |
> |
if (s>e) { Gswap(s,e); } |
299 |
|
//return start<s ? (s<=end) : (start<=e); |
300 |
|
return (start<=e && end>=s); |
301 |
|
} |
312 |
|
} |
313 |
|
} |
314 |
|
int overlapLen(uint rstart, uint rend) { |
315 |
< |
if (rstart>rend) { swap(rstart,rend); } |
315 |
> |
if (rstart>rend) { Gswap(rstart,rend); } |
316 |
|
if (start<rstart) { |
317 |
|
if (rstart>end) return 0; |
318 |
|
return (rend>end) ? end-rstart+1 : rend-rstart+1; |
334 |
|
bool operator==(GSeg& d){ |
335 |
|
return (start==d.start && end==d.end); |
336 |
|
} |
372 |
– |
bool operator>(GSeg& d){ |
373 |
– |
return (start==d.start)?(end>d.end):(start>d.start); |
374 |
– |
} |
337 |
|
bool operator<(GSeg& d){ |
338 |
|
return (start==d.start)?(end<d.end):(start<d.start); |
339 |
|
} |