Add a pair of functions to count the number of set/unset bits in an opal_bitmap.
I found this useful on a branch, and thought others might as well. This commit was SVN r26171.
Этот коммит содержится в:
родитель
3324b9e451
Коммит
f7c66f54b6
@ -10,7 +10,7 @@
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2010-2011 Oak Ridge National Labs. All rights reserved.
|
||||
* Copyright (c) 2010-2012 Oak Ridge National Labs. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -412,3 +412,31 @@ char * opal_bitmap_get_string(opal_bitmap_t *bitmap)
|
||||
|
||||
return bitmap_str;
|
||||
}
|
||||
|
||||
int opal_bitmap_num_unset_bits(opal_bitmap_t *bm, int len)
|
||||
{
|
||||
return (len - opal_bitmap_num_set_bits(bm, len));
|
||||
}
|
||||
|
||||
int opal_bitmap_num_set_bits(opal_bitmap_t *bm, int len)
|
||||
{
|
||||
int i, cnt = 0;
|
||||
int index, offset;
|
||||
|
||||
#if OPAL_ENABLE_DEBUG
|
||||
if ((len < 0) || NULL == bm || (len >= (bm->array_size * SIZE_OF_CHAR))) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
for(i = 0; i < len; ++i) {
|
||||
index = i / SIZE_OF_CHAR;
|
||||
offset = i % SIZE_OF_CHAR;
|
||||
|
||||
if(0 != (bm->bitmap[index] & (1 << offset))) {
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2010-2011 Oak Ridge National Labs. All rights reserved.
|
||||
* Copyright (c) 2010-2012 Oak Ridge National Labs. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -228,6 +228,24 @@ OPAL_DECLSPEC bool opal_bitmap_are_different(opal_bitmap_t *left, opal_bitmap_t
|
||||
*/
|
||||
OPAL_DECLSPEC char * opal_bitmap_get_string(opal_bitmap_t *bitmap);
|
||||
|
||||
/**
|
||||
* Return the number of 'unset' bits, upto the specified length
|
||||
*
|
||||
* @param bitmap Pointer to the bitmap
|
||||
* @param len Number of bits to check
|
||||
* @return Integer
|
||||
*/
|
||||
OPAL_DECLSPEC int opal_bitmap_num_unset_bits(opal_bitmap_t *bm, int len);
|
||||
|
||||
/**
|
||||
* Return the number of 'set' bits, upto the specified length
|
||||
*
|
||||
* @param bitmap Pointer to the bitmap
|
||||
* @param len Number of bits to check
|
||||
* @return Integer
|
||||
*/
|
||||
OPAL_DECLSPEC int opal_bitmap_num_set_bits(opal_bitmap_t *bm, int len);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user