X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=libcds%2Fsrc%2Fbasics.h;h=85bfe22e6f3b0702bcd4fc170004b0a0b79322cc;hb=a75155efc2ed07c1907ef017360bd719a47f9c06;hp=6412228d63d670b4a027039873bc22e99e65fc8f;hpb=e76100fc86bf4681cc6de5b0d80f3e00ade660a5;p=SXSI%2FXMLTree.git diff --git a/libcds/src/basics.h b/libcds/src/basics.h index 6412228..85bfe22 100644 --- a/libcds/src/basics.h +++ b/libcds/src/basics.h @@ -32,7 +32,7 @@ #include #include #include -using namespace std; +////using namespace std; #include #include @@ -41,18 +41,21 @@ using namespace std; #define mask31 0x0000001F /** max function */ -#define max(x,y) ((x)>(y)?(x):(y)) +//#define max(x,y) ((x)>(y)?(x):(y)) /** min function */ -#define min(x,y) ((x)<(y)?(x):(y)) +//#define min(x,y) ((x)<(y)?(x):(y)) /** number of bits in a uint */ +#undef W #define W 32 /** W-1 */ +#undef Wminusone #define Wminusone 31 /** 2W*/ +#undef WW #define WW 64 /** number of bits per uchar */ @@ -230,6 +233,20 @@ inline uint popcount(int x){ return __popcount_tab[(x >> 0) & 0xff] + __popcount_tab[(x >> 8) & 0xff] + __popcount_tab[(x >> 16) & 0xff] + __popcount_tab[(x >> 24) & 0xff]; } +inline unsigned int +fast_popcount(int x) +{ + uint m1 = 0x55555555; + uint m2 = 0x33333333; + uint m4 = 0x0f0f0f0f; + x -= (x >> 1) & m1; + x = (x & m2) + ((x >> 2) & m2); + x = (x + (x >> 4)) & m4; + x += x >> 8; + return (x + (x >> 16)) & 0x3f; +} + + /** Counts the number of 1s in the first 16 bits of x */ inline uint popcount16(int x){