- /*
- * A small example (for cleaning bits in the same unit).
- * from = 7
- * to = 19
- * do_set = 0
- * result: xxxxxxx000000000000xxxxxxxxxxxxx
- * from_unit_mask: 00000001111111111111111111111111
- * to_unit_mask: 11111111111111111110000000000000
- * scale: 01234567890123456789012345678901
- * 1 2 3
- */
-
- from_unit = from / BS_UNIT_SIZE_BITS;
- from_unit_mask = ~((1 << from) - 1);
- from = from & BS_UNIT_MASK;
-
- to_unit = to / BS_UNIT_SIZE_BITS;
- to_unit_mask = (1 << to) - 1;
- to = to & BS_UNIT_MASK;
-
- /* do we want to set the bits in the range? */
- if (do_set) {
- /* If from and to are in the same unit: */
- if (from_unit == to_unit)
- BS_DATA(a)[from_unit] |= from_unit_mask & to_unit_mask;
-
- /* Else, we have to treat the from and to units seperately */
- else {
- BS_DATA(a)[from_unit] |= from_unit_mask;
- BS_DATA(a)[to_unit] |= to_unit_mask;
- for (i = from_unit + 1; i < to_unit; i++)
- BS_DATA(a)[i] = BITSET_UNIT_ALL_ONE;
- }
- }
-
- /* ... or clear them? */
- else {
- if (from_unit == to_unit)
- BS_DATA(a)[from_unit] &= ~(from_unit_mask & to_unit_mask);
-
- else {
- BS_DATA(a)[from_unit] &= ~from_unit_mask;
- BS_DATA(a)[to_unit] &= ~to_unit_mask;
- for (i = from_unit + 1; i < to_unit; i++)
- BS_DATA(a)[i] = 0;
- }
- }