Accessor position must be establised via successful call to getFirst(), getLast() or locate() before you can call this method
| 524 | // Accessor position must be establised via successful call to getFirst(), |
| 525 | // getLast() or locate() before you can call this method |
| 526 | bool getPrev() |
| 527 | { |
| 528 | if (bitmap->singular) |
| 529 | return false; |
| 530 | |
| 531 | // Use temporaries to avoid corrupting position if there is no next item in bitmap |
| 532 | BUNCH_T try_mask = bit_mask; |
| 533 | T try_value = current_value; |
| 534 | |
| 535 | // Proceed to next value |
| 536 | try_mask >>= 1; |
| 537 | try_value--; |
| 538 | |
| 539 | // Scan bucket backwards looking for a match |
| 540 | BUNCH_T tree_bits = treeAccessor.current().bits; |
| 541 | while (try_mask) |
| 542 | { |
| 543 | if (tree_bits & try_mask) |
| 544 | { |
| 545 | bit_mask = try_mask; |
| 546 | current_value = try_value; |
| 547 | return true; |
| 548 | } |
| 549 | try_mask >>= 1; |
| 550 | try_value--; |
| 551 | } |
| 552 | |
| 553 | // We scanned bucket, but found no match. |
| 554 | // No problem, scan the next bucket (there should be at least one bit set for a bucket) |
| 555 | if (!treeAccessor.getPrev()) |
| 556 | return false; |
| 557 | |
| 558 | tree_bits = treeAccessor.current().bits; |
| 559 | try_mask = BUNCH_ONE << (BUNCH_BITS - 1); |
| 560 | try_value = treeAccessor.current().start_value + BUNCH_BITS - 1; |
| 561 | do { |
| 562 | if (tree_bits & try_mask) |
| 563 | { |
| 564 | bit_mask = try_mask; |
| 565 | current_value = try_value; |
| 566 | return true; |
| 567 | } |
| 568 | try_mask >>= 1; |
| 569 | try_value--; |
| 570 | } while (bit_mask); |
| 571 | |
| 572 | // Bucket must contain one bit at least |
| 573 | fb_assert(false); |
| 574 | } |
| 575 | |
| 576 | T current() const { return current_value; } |
| 577 | private: |