| 693 | } |
| 694 | |
| 695 | uint SetRepositoryAlgorithms::set_intersect(uint firstNode, uint secondNode, const SetNodeData* first, |
| 696 | const SetNodeData* second, uchar splitBit) |
| 697 | { |
| 698 | if (firstNode == secondNode) |
| 699 | return firstNode; |
| 700 | |
| 701 | if (first->start() >= second->end()) |
| 702 | return 0; |
| 703 | |
| 704 | if (second->start() >= first->end()) |
| 705 | return 0; |
| 706 | |
| 707 | //The ranges of first and second do intersect |
| 708 | uint firstStart = first->start(), firstEnd = first->end(), secondStart = second->start(), secondEnd = second->end(); |
| 709 | |
| 710 | uint newStart = firstStart < secondStart ? firstStart : secondStart; |
| 711 | uint newEnd = firstEnd > secondEnd ? firstEnd : secondEnd; |
| 712 | |
| 713 | //Compute the split-position for the resulting merged node |
| 714 | uint splitPosition = splitPositionForRange(newStart, newEnd, splitBit); |
| 715 | |
| 716 | //Since the ranges overlap, we can be sure that either first or second contain splitPosition. |
| 717 | //The node that contains it, will also be split by it. |
| 718 | |
| 719 | if (splitPosition > firstStart && splitPosition < firstEnd && splitPosition > secondStart && |
| 720 | splitPosition < secondEnd) { |
| 721 | //The split-position intersect with both first and second. Continue the intersection on both sides |
| 722 | |
| 723 | uint firstLeftNode = first->leftNode(); |
| 724 | uint firstRightNode = first->rightNode(); |
| 725 | |
| 726 | uint secondLeftNode = second->leftNode(); |
| 727 | uint secondRightNode = second->rightNode(); |
| 728 | |
| 729 | const SetNodeData* firstLeft = repository.itemFromIndex(firstLeftNode); |
| 730 | const SetNodeData* firstRight = repository.itemFromIndex(firstRightNode); |
| 731 | const SetNodeData* secondLeft = repository.itemFromIndex(secondLeftNode); |
| 732 | const SetNodeData* secondRight = repository.itemFromIndex(secondRightNode); |
| 733 | |
| 734 | Q_ASSERT(splitPosition >= firstLeft->end() && splitPosition <= firstRight->start()); |
| 735 | Q_ASSERT(splitPosition >= secondLeft->end() && splitPosition <= secondRight->start()); |
| 736 | |
| 737 | uint newLeftNode = set_intersect(firstLeftNode, secondLeftNode, firstLeft, secondLeft, splitBit); |
| 738 | uint newRightNode = set_intersect(firstRightNode, secondRightNode, firstRight, secondRight, splitBit); |
| 739 | |
| 740 | if (newLeftNode && newRightNode) |
| 741 | return createSetFromNodes(newLeftNode, newRightNode); |
| 742 | else if (newLeftNode) |
| 743 | return newLeftNode; |
| 744 | else |
| 745 | return newRightNode; |
| 746 | } else if (splitPosition > firstStart && splitPosition < firstEnd) { |
| 747 | uint firstLeftNode = first->leftNode(); |
| 748 | uint firstRightNode = first->rightNode(); |
| 749 | |
| 750 | const SetNodeData* firstLeft = repository.itemFromIndex(firstLeftNode); |
| 751 | const SetNodeData* firstRight = repository.itemFromIndex(firstRightNode); |
| 752 |
no test coverage detected