Call this with -1 to start checking from 0. Returns -1 at the end. */
| 1691 | |
| 1692 | /* Call this with -1 to start checking from 0. Returns -1 at the end. */ |
| 1693 | int bitbag_next_bit(struct bitbag *bb, int after) |
| 1694 | { |
| 1695 | uint32 bits, mask; |
| 1696 | int i, ndx = after + 1; |
| 1697 | int slot = ndx / BB_PER_SLOT_BITS; |
| 1698 | ndx %= BB_PER_SLOT_BITS; |
| 1699 | |
| 1700 | mask = (1u << (ndx % 32)) - 1; |
| 1701 | for (i = ndx / 32; slot < bb->slot_cnt; slot++, i = mask = 0) { |
| 1702 | if (!bb->bits[slot]) |
| 1703 | continue; |
| 1704 | for ( ; i < BB_PER_SLOT_INTS; i++, mask = 0) { |
| 1705 | if (!(bits = bb->bits[slot][i] & ~mask)) |
| 1706 | continue; |
| 1707 | /* The xor magic figures out the lowest enabled bit in |
| 1708 | * bits, and the switch quickly computes log2(bit). */ |
| 1709 | switch (bits ^ (bits & (bits-1))) { |
| 1710 | #define LOG2(n) case 1u << n: return slot*BB_PER_SLOT_BITS + i*32 + n |
| 1711 | LOG2(0); LOG2(1); LOG2(2); LOG2(3); |
| 1712 | LOG2(4); LOG2(5); LOG2(6); LOG2(7); |
| 1713 | LOG2(8); LOG2(9); LOG2(10); LOG2(11); |
| 1714 | LOG2(12); LOG2(13); LOG2(14); LOG2(15); |
| 1715 | LOG2(16); LOG2(17); LOG2(18); LOG2(19); |
| 1716 | LOG2(20); LOG2(21); LOG2(22); LOG2(23); |
| 1717 | LOG2(24); LOG2(25); LOG2(26); LOG2(27); |
| 1718 | LOG2(28); LOG2(29); LOG2(30); LOG2(31); |
| 1719 | } |
| 1720 | return -1; /* impossible... */ |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | return -1; |
| 1725 | } |
| 1726 | |
| 1727 | void flist_ndx_push(flist_ndx_list *lp, int ndx) |
| 1728 | { |
no outgoing calls
no test coverage detected