Skip to content

Commit

Permalink
cleanup bwt_occ()
Browse files Browse the repository at this point in the history
  • Loading branch information
lh3 committed Feb 26, 2013
1 parent 80e1137 commit aa92c72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions bwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,20 @@ static inline int __occ_aux(uint64_t y, int c)

bwtint_t bwt_occ(const bwt_t *bwt, bwtint_t k, ubyte_t c)
{
bwtint_t n, l, j;
uint32_t *p;
bwtint_t n;
uint32_t *p, *end;

if (k == bwt->seq_len) return bwt->L2[c+1] - bwt->L2[c];
if (k == (bwtint_t)(-1)) return 0;
if (k >= bwt->primary) --k; // because $ is not in bwt
k -= (k >= bwt->primary); // because $ is not in bwt

// retrieve Occ at k/OCC_INTERVAL
n = ((bwtint_t*)(p = bwt_occ_intv(bwt, k)))[c];
p += sizeof(bwtint_t); // jump to the start of the first BWT cell

// calculate Occ up to the last k/32
j = k >> 5 << 5;
for (l = k/OCC_INTERVAL*OCC_INTERVAL; l < j; l += 32, p += 2)
n += __occ_aux((uint64_t)p[0]<<32 | p[1], c);
end = p + (((k>>5) - ((k&~OCC_INTV_MASK)>>5))<<1);
for (; p < end; p += 2) n += __occ_aux((uint64_t)p[0]<<32 | p[1], c);

// calculate Occ
n += __occ_aux(((uint64_t)p[0]<<32 | p[1]) & ~((1ull<<((~k&31)<<1)) - 1), c);
Expand Down
4 changes: 2 additions & 2 deletions kopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static int ftp_open(const char *fn)
static char **cmd2argv(const char *cmd)
{
int i, beg, end, argc;
char **argv, *p, *q, *str;
char **argv, *str;
end = strlen(cmd);
for (i = end - 1; i >= 0; --i)
if (!isspace(cmd[i])) break;
Expand All @@ -217,7 +217,7 @@ static char **cmd2argv(const char *cmd)
argv = (char**)calloc(argc + 2, sizeof(void*));
argv[0] = str = (char*)calloc(end - beg + 1, 1);
strncpy(argv[0], cmd + beg, end - beg);
for (i = argc = 1, q = p = str; i < end - beg; ++i)
for (i = argc = 1; i < end - beg; ++i)
if (isspace(str[i])) str[i] = 0;
else if (str[i] && str[i-1] == 0) argv[argc++] = &str[i];
return argv;
Expand Down

0 comments on commit aa92c72

Please sign in to comment.