| 712 | |
| 713 | template <typename T, typename InternalTypes> |
| 714 | SparseBitmap<T, InternalTypes>** |
| 715 | SparseBitmap<T, InternalTypes>::bit_and(SparseBitmap<T, InternalTypes>** bitmap1, |
| 716 | SparseBitmap<T, InternalTypes>** bitmap2 |
| 717 | ) |
| 718 | { |
| 719 | SparseBitmap *map1, *map2; |
| 720 | |
| 721 | // Handle the case when one or the other of the bitmaps is NULL |
| 722 | if (!bitmap1 || !bitmap2 || !(map1 = *bitmap1) || !(map2 = *bitmap2)) { |
| 723 | return NULL; |
| 724 | } |
| 725 | |
| 726 | // Make sure we work on 2 different bitmaps |
| 727 | fb_assert(map1 != map2); |
| 728 | |
| 729 | // First bitmap is singular. Test appropriate bit in second and return first |
| 730 | if (map1->singular) |
| 731 | { |
| 732 | if (map2->test(map1->singular_value)) |
| 733 | return bitmap1; |
| 734 | |
| 735 | return NULL; |
| 736 | } |
| 737 | |
| 738 | // Second bitmap is singular. Test appropriate bit in first and return second |
| 739 | if (map2->singular) |
| 740 | { |
| 741 | if (map1->test(map2->singular_value)) |
| 742 | return bitmap2; |
| 743 | |
| 744 | return NULL; |
| 745 | } |
| 746 | |
| 747 | SparseBitmap *source, *dest, **result; |
| 748 | |
| 749 | // If second bitmap seems smaller then use it as a target |
| 750 | if (map1->tree.seemsBiggerThan(map2->tree)) |
| 751 | { |
| 752 | dest = map2; |
| 753 | source = map1; |
| 754 | result = bitmap2; |
| 755 | } |
| 756 | else |
| 757 | { |
| 758 | dest = map1; |
| 759 | source = map2; |
| 760 | result = bitmap1; |
| 761 | } |
| 762 | |
| 763 | bool destFound = dest->tree.getFirst(); |
| 764 | |
| 765 | // Destination bitmap is empty. We have nothing to do thus return. |
| 766 | if (!destFound) |
| 767 | return result; |
| 768 | |
| 769 | bool sourceFound = source->tree.getFirst(); |
| 770 | |
| 771 | // Both source and destination are empty. Return destination FWIW. |
nothing calls this directly
no test coverage detected