Permalink
Browse files

cleanup bwt_occ()

  • Loading branch information...
1 parent 80e1137 commit aa92c720b5ddf2d6107a537ed8f7bb6d94fbc1bb @lh3 committed Feb 26, 2013
Showing with 7 additions and 8 deletions.
  1. +5 −6 bwt.c
  2. +2 −2 kopen.c
View
11 bwt.c
@@ -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);
View
@@ -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;
@@ -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;

0 comments on commit aa92c72

Please sign in to comment.