an alternative bwt_invPsi() implementation

Cleaner, but not necessarily faster.
This commit is contained in:
Heng Li 2013-02-23 13:59:18 -05:00
parent 904c3205c0
commit dd85c528d6
1 changed files with 17 additions and 7 deletions

24
bwt.h
View File

@ -74,13 +74,6 @@ typedef struct { size_t n, m; bwtintv_t *a; } bwtintv_v;
* called bwt_B0 instead of bwt_B */
#define bwt_B0(b, k) (bwt_bwt(b, k)>>((~(k)&0xf)<<1)&3)
// inverse Psi function
#define bwt_invPsi(bwt, k) \
(((k) == (bwt)->primary)? 0 : \
((k) < (bwt)->primary)? \
(bwt)->L2[bwt_B0(bwt, k)] + bwt_occ(bwt, k, bwt_B0(bwt, k)) \
: (bwt)->L2[bwt_B0(bwt, (k)-1)] + bwt_occ(bwt, k, bwt_B0(bwt, (k)-1)))
#define bwt_set_intv(bwt, c, ik) ((ik).x[0] = (bwt)->L2[(int)(c)]+1, (ik).x[2] = (bwt)->L2[(int)(c)+1]-(bwt)->L2[(int)(c)], (ik).x[1] = (bwt)->L2[3-(c)]+1, (ik).info = 0)
#ifdef __cplusplus
@ -129,4 +122,21 @@ extern "C" {
}
#endif
// inverse Psi function
#if 0
#define bwt_invPsi(bwt, k) \
(((k) == (bwt)->primary)? 0 : \
((k) < (bwt)->primary)? \
(bwt)->L2[bwt_B0(bwt, k)] + bwt_occ(bwt, k, bwt_B0(bwt, k)) \
: (bwt)->L2[bwt_B0(bwt, (k)-1)] + bwt_occ(bwt, k, bwt_B0(bwt, (k)-1)))
#else
static inline bwtint_t bwt_invPsi(const bwt_t *bwt, bwtint_t k)
{
register int64_t x = k - (k > bwt->primary);
x = bwt_B0(bwt, x);
x = bwt->L2[x] + bwt_occ(bwt, k, x);
return k == bwt->primary? 0 : x;
}
#endif
#endif