Finds the intersection of the ordered region lists, stores in dest
| 739 | |
| 740 | // Finds the intersection of the ordered region lists, stores in dest |
| 741 | void TruncSilenceBase::Intersect(RegionList& dest, const RegionList& src) |
| 742 | { |
| 743 | RegionList::iterator destIter; |
| 744 | destIter = dest.begin(); |
| 745 | // Any time we reach the end of the dest list we're finished |
| 746 | if (destIter == dest.end()) |
| 747 | return; |
| 748 | RegionList::iterator curDest = destIter; |
| 749 | |
| 750 | // Operation: find non-silent regions in src, remove them from dest. |
| 751 | double nsStart = curDest->start; |
| 752 | double nsEnd; |
| 753 | bool lastRun = false; // must run the loop one extra time |
| 754 | |
| 755 | RegionList::const_iterator srcIter = src.begin(); |
| 756 | |
| 757 | // This logic, causing the loop to run once after end of src, must occur |
| 758 | // each time srcIter is updated |
| 759 | if (srcIter == src.end()) |
| 760 | { |
| 761 | lastRun = true; |
| 762 | } |
| 763 | |
| 764 | while (srcIter != src.end() || lastRun) |
| 765 | { |
| 766 | // Don't use curSrc unless lastRun is false! |
| 767 | RegionList::const_iterator curSrc; |
| 768 | |
| 769 | if (lastRun) |
| 770 | { |
| 771 | // The last non-silent region extends as far as possible |
| 772 | nsEnd = std::numeric_limits<double>::max(); |
| 773 | } |
| 774 | else |
| 775 | { |
| 776 | curSrc = srcIter; |
| 777 | nsEnd = curSrc->start; |
| 778 | } |
| 779 | |
| 780 | if (nsEnd > nsStart) |
| 781 | { |
| 782 | // Increment through dest until we have a region that could be affected |
| 783 | while (curDest->end <= nsStart) |
| 784 | { |
| 785 | ++destIter; |
| 786 | if (destIter == dest.end()) |
| 787 | { |
| 788 | return; |
| 789 | } |
| 790 | curDest = destIter; |
| 791 | } |
| 792 | |
| 793 | // Check for splitting dest region in two |
| 794 | if (nsStart > curDest->start && nsEnd < curDest->end) |
| 795 | { |
| 796 | // The second region |
| 797 | Region r(nsEnd, curDest->end); |
| 798 |
no test coverage detected