コード例 #1
0
ファイル: MCRange.cpp プロジェクト: duoleimi/mailcore2
IndexSet * mailcore::RangeUnion(Range range1, Range range2)
{
    if (!RangeHasIntersection(range1, range2)) {
        IndexSet * result = IndexSet::indexSet();
        
        result->addRange(range1);
        result->addRange(range2);
        
        return result;
    }
    else {
        uint64_t left1;
        uint64_t right1;
        uint64_t left2;
        uint64_t right2;
        uint64_t resultLeft;
        uint64_t resultRight;
        
        left1 = range1.location;
        right1 = RangeRightBound(range1);
        left2 = range2.location;
        right2 = RangeRightBound(range2);
        
        resultLeft = MIN(left1, left2);
        resultRight = MAX(right1, right2);
        if (resultRight == UINT64_MAX) {
            return IndexSet::indexSetWithRange(RangeMake(resultLeft, UINT64_MAX));
        }
        else {
            return IndexSet::indexSetWithRange(RangeMake(resultLeft, resultRight - resultLeft));
        }
    }
}
コード例 #2
0
ファイル: MCRange.cpp プロジェクト: duoleimi/mailcore2
IndexSet * mailcore::RangeRemoveRange(Range range1, Range range2)
{
    uint64_t left1;
    uint64_t right1;
    uint64_t left2;
    uint64_t right2;
    IndexSet * result;
    
    if (!RangeHasIntersection(range1, range2))
        return IndexSet::indexSetWithRange(range1);
    
    result = IndexSet::indexSet();
    
    range2 = RangeIntersection(range1, range2);
    
    left1 = range1.location;
    right1 = RangeRightBound(range1);
    left2 = range2.location;
    right2 = RangeRightBound(range2);
    
    if (left2 > left1) {
        result->addRange(RangeMake(left1, left2 - left1 - 1));
    }
    
    if (right2 != UINT64_MAX) {
        if (right1 == UINT64_MAX) {
            result->addRange(RangeMake(right2 + 1, UINT64_MAX));
        }
        else {
            if (right2 < right1) {
                result->addRange(RangeMake(right2 + 1, right1 - (right2 + 1)));
            }
        }
    }
    
    return result;
}