bitvector - population count
This commit is contained in:
1 parent
77e508a161
commit
f2aeb6ff9c
1 file changed
+10
-1
+10
-1
@@ -260,11 +260,20 @@ zero_padding();
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//with before>0 only the ones at positions 0..before-1 are counted
|
||||||
unsigned int bitvector::population(const unsigned int before) const
|
unsigned int bitvector::population(const unsigned int before) const
|
||||||
{
|
{
|
||||||
if(before) laerror("before parameter in population() not implemented yet");
|
|
||||||
int i;
|
int i;
|
||||||
unsigned int s=0;
|
unsigned int s=0;
|
||||||
|
if(before)
|
||||||
|
{
|
||||||
|
if(before>size()) laerror("before parameter beyond the size in population()");
|
||||||
|
int full=before/blockbits;
|
||||||
|
for(i=0; i<full; ++i) s+=word_popul(v[i]);
|
||||||
|
int rest=before%blockbits;
|
||||||
|
if(rest) s+=word_popul(v[full] & ((((bitvector_block)1)<<rest)-1));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
for(i=0; i<nn-1; ++i) s+=word_popul(v[i]);
|
for(i=0; i<nn-1; ++i) s+=word_popul(v[i]);
|
||||||
bitvector_block a=v[nn-1];
|
bitvector_block a=v[nn-1];
|
||||||
if(modulo)
|
if(modulo)
|
||||||
|
|||||||
Reference in new issue
Block a user