Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ddf6b08

Browse files
author
Chenxi Zhou
committed
support >2G sequences
1 parent b98236d commit ddf6b08

File tree

2 files changed

+158
-130
lines changed

2 files changed

+158
-130
lines changed

kseq.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define AC_KSEQ_H
3030

3131
#include <ctype.h>
32+
#include <stdint.h>
3233
#include <string.h>
3334
#include <stdlib.h>
3435

@@ -90,8 +91,12 @@ typedef struct __kstring_t {
9091
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
9192
#endif
9293

94+
#ifndef kroundup64
95+
#define kroundup64(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, (x)|=(x)>>32, ++(x))
96+
#endif
97+
9398
#define __KS_GETUNTIL(__read, __bufsize) \
94-
static int ks_getuntil2(kstream_t *ks, int delimiter, kstring_t *str, int *dret, int append) \
99+
static int64_t ks_getuntil2(kstream_t *ks, int delimiter, kstring_t *str, int *dret, int append) \
95100
{ \
96101
int gotany = 0; \
97102
if (dret) *dret = 0; \
@@ -122,7 +127,7 @@ typedef struct __kstring_t {
122127
} else i = 0; /* never come to here! */ \
123128
if (str->m - str->l < (size_t)(i - ks->begin + 1)) { \
124129
str->m = str->l + (i - ks->begin) + 1; \
125-
kroundup32(str->m); \
130+
kroundup64(str->m); \
126131
str->s = (char*)realloc(str->s, str->m); \
127132
} \
128133
gotany = 1; \
@@ -175,7 +180,7 @@ typedef struct __kstring_t {
175180
-3 error reading stream
176181
*/
177182
#define __KSEQ_READ(SCOPE) \
178-
SCOPE int kseq_read(kseq_t *seq) \
183+
SCOPE int64_t kseq_read(kseq_t *seq) \
179184
{ \
180185
int c,r; \
181186
kstream_t *ks = seq->f; \
@@ -199,7 +204,7 @@ typedef struct __kstring_t {
199204
if (c == '>' || c == '@') seq->last_char = c; /* the first header char has been read */ \
200205
if (seq->seq.l + 1 >= seq->seq.m) { /* seq->seq.s[seq->seq.l] below may be out of boundary */ \
201206
seq->seq.m = seq->seq.l + 2; \
202-
kroundup32(seq->seq.m); /* rounded to the next closest 2^k */ \
207+
kroundup64(seq->seq.m); /* rounded to the next closest 2^k */ \
203208
seq->seq.s = (char*)realloc(seq->seq.s, seq->seq.m); \
204209
} \
205210
seq->seq.s[seq->seq.l] = 0; /* null terminated string */ \
@@ -238,6 +243,6 @@ typedef struct __kstring_t {
238243
__KSEQ_TYPE(type_t) \
239244
extern kseq_t *kseq_init(type_t fd); \
240245
void kseq_destroy(kseq_t *ks); \
241-
int kseq_read(kseq_t *seq);
246+
int64_t kseq_read(kseq_t *seq);
242247

243248
#endif

0 commit comments

Comments
 (0)