summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
c7f3c30)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7803
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
#include <stddef.h>
#include <stdio.h>
#include <stddef.h>
#include <stdio.h>
#include "setset_private.h"
#include "xbt/sysdep.h"
#include "setset_private.h"
#include "xbt/sysdep.h"
-/* Get the cursor to point to the first element of a set */
void xbt_setset_cursor_first(xbt_setset_set_t set, xbt_setset_cursor_t *cursor)
{
void xbt_setset_cursor_first(xbt_setset_set_t set, xbt_setset_cursor_t *cursor)
{
(*cursor) = xbt_new0(s_xbt_setset_cursor_t, 1);
(*cursor)->set = set;
(*cursor) = xbt_new0(s_xbt_setset_cursor_t, 1);
(*cursor)->set = set;
- int i,k;
- /* Traverse the set and point the cursor to the first element */
- for(i=0; i < set->size; i++){
+
+ for(i = 0; i < set->size; i++){
- for(k=0; k < BITS_INT; k++){
- if(_is_bit_set(k, set->bitmap[i])){
- (*cursor)->idx = i * BITS_INT + k;
- return;
- }
- }
+ (*cursor)->idx = i * BITS_INT + ffs(set->bitmap[i]) - 1;
+ break;
/* Advance a cursor to the next element */
void xbt_setset_cursor_next(xbt_setset_cursor_t cursor)
{
/* Advance a cursor to the next element */
void xbt_setset_cursor_next(xbt_setset_cursor_t cursor)
{
+ unsigned int mask;
+ unsigned int data;
cursor->idx++;
while(cursor->idx < cursor->set->size * BITS_INT)
{
cursor->idx++;
while(cursor->idx < cursor->set->size * BITS_INT)
{
- if(_is_bit_set(cursor->idx % BITS_INT, cursor->set->bitmap[cursor->idx / BITS_INT])){
- return;
+ if((data = cursor->set->bitmap[cursor->idx / BITS_INT])){
+ mask = 1 << cursor->idx % BITS_INT;
+ while(mask){
+ if(data & mask){
+ return;
+ }else{
+ cursor->idx++;
+ mask <<= 1;
+ }
+ }
- cursor->idx += cursor->set->bitmap[cursor->idx / BITS_INT] ? 1 : BITS_INT;
+ cursor->idx += BITS_INT;