X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=libcds%2Fsrc%2Fbasics.h;h=3376902a1cd6ee129a1b9a45ba8e49e12a061e27;hb=1c40b498ddd6d66b09aff3a22b9f7ddd845250dc;hp=39cb81be5d9df432a266f5ceec206572ee8a6b23;hpb=9e8d96bc2eea5ec6ee7c9d4bb9b83315b9687c02;p=SXSI%2FXMLTree.git diff --git a/libcds/src/basics.h b/libcds/src/basics.h index 39cb81b..3376902 100644 --- a/libcds/src/basics.h +++ b/libcds/src/basics.h @@ -41,25 +41,22 @@ 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 */ -#ifndef W +#undef W #define W 32 -#endif /** W-1 */ -#ifndef Wminusone +#undef Wminusone #define Wminusone 31 -#endif /** 2W*/ -#ifndef WW +#undef WW #define WW 64 -#endif /** number of bits per uchar */ #define bitsM 8 @@ -236,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){