本文整理汇总了C++中IntervalSet::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ IntervalSet::isEmpty方法的具体用法?C++ IntervalSet::isEmpty怎么用?C++ IntervalSet::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntervalSet
的用法示例。
在下文中一共展示了IntervalSet::isEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: subtract
IntervalSet IntervalSet::subtract(const IntervalSet &left, const IntervalSet &right) {
if (left.isEmpty()) {
return IntervalSet();
}
if (right.isEmpty()) {
// right set has no elements; just return the copy of the current set
return left;
}
IntervalSet result(left);
size_t resultI = 0;
size_t rightI = 0;
while (resultI < result._intervals.size() && rightI < right._intervals.size()) {
Interval &resultInterval = result._intervals[resultI];
const Interval &rightInterval = right._intervals[rightI];
// operation: (resultInterval - rightInterval) and update indexes
if (rightInterval.b < resultInterval.a) {
rightI++;
continue;
}
if (rightInterval.a > resultInterval.b) {
resultI++;
continue;
}
Interval beforeCurrent;
Interval afterCurrent;
if (rightInterval.a > resultInterval.a) {
beforeCurrent = Interval(resultInterval.a, rightInterval.a - 1);
}
if (rightInterval.b < resultInterval.b) {
afterCurrent = Interval(rightInterval.b + 1, resultInterval.b);
}
if (beforeCurrent.a > -1) { // -1 is the default value
if (afterCurrent.a > -1) {
// split the current interval into two
result._intervals[resultI] = beforeCurrent;
result._intervals.insert(result._intervals.begin() + resultI + 1, afterCurrent);
resultI++;
rightI++;
} else {
// replace the current interval
result._intervals[resultI] = beforeCurrent;
resultI++;
}
} else {
if (afterCurrent.a > -1) {
// replace the current interval
result._intervals[resultI] = afterCurrent;
rightI++;
} else {
// remove the current interval (thus no need to increment resultI)
result._intervals.erase(result._intervals.begin() + resultI);
}
}
}
// If rightI reached right.intervals.size(), no more intervals to subtract from result.
// If resultI reached result.intervals.size(), we would be subtracting from an empty set.
// Either way, we are done.
return result;
}