From: Kim Nguyễn Date: Thu, 1 Mar 2012 13:21:41 +0000 (+0100) Subject: Put bp_darray_rank in header so that it has a chance to be inlined. X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2Flibbp.git;a=commitdiff_plain;h=9614bef67d59eaa2413e2b06e5587c6caec57840 Put bp_darray_rank in header so that it has a chance to be inlined. --- diff --git a/bp-darray.c b/bp-darray.c index a4aec4b..800ebb1 100644 --- a/bp-darray.c +++ b/bp-darray.c @@ -1,7 +1,6 @@ #include #include #include "bp-darray.h" -#include "bp-utils.h" #define PBS (sizeof(pb)*8) #define D (1<> logRR; - i_rrr = i >> logRRR; - r = da->rl[i>>logR] + da->rm[i_rr]; - - j = (i_rrr) & (RR/RRR-1); - while (j > 0) { - r += da->rs[((i_rr)<<(logRR-logRRR))+j-1]; - j--; - } - - p = da->buf + ((i_rrr)<<(logRRR-logD)); - j = i & (RRR-1); - while (j >= D) { - r += popcount(*p++); - j -= D; - } - r += popcount(*p >> (D-1-j)); - - return r; -} - int bp_darray_select_bsearch(darray *da, int i, pb (*getpat)(pb *)) { int j; diff --git a/bp-darray.h b/bp-darray.h index 23d44a4..4224dba 100644 --- a/bp-darray.h +++ b/bp-darray.h @@ -4,6 +4,7 @@ #ifdef __cplusplus extern "C" { #endif +#include "bp-utils.h" typedef unsigned char byte; typedef unsigned short word; @@ -36,7 +37,31 @@ darray * bp_darray_construct(int n, pb *buf,int opt); void bp_darray_free(darray *da); int bp_darray_select(darray *da, int i,int f); -int bp_darray_rank(darray *da, int i); +static int bp_darray_rank(darray *da, int i) +{ + int r,j,i_rr, i_rrr; + pb *p; + i_rr = i >> logRR; + i_rrr = i >> logRRR; + r = da->rl[i>>logR] + da->rm[i_rr]; + + j = (i_rrr) & (RR/RRR-1); + while (j > 0) { + r += da->rs[((i_rr)<<(logRR-logRRR))+j-1]; + j--; + } + + p = da->buf + ((i_rrr)<<(logRRR-logD)); + j = i & (RRR-1); + while (j >= D) { + r += popcount(*p++); + j -= D; + } + r += popcount(*p >> (D-1-j)); + + return r; +} + darray * bp_darray_pat_construct(int n, pb *buf, int k, pb pat, int opt); int bp_darray_pat_select(darray *da, int i, pb (*getpat)(pb *)); int bp_darray_pat_rank(darray *da, int i, pb (*getpat)(pb *));