An helper function we need.

This commit is contained in:
JoelKatz
2012-10-24 20:03:48 -07:00
parent 13ba14d573
commit 6c0916beb4
2 changed files with 17 additions and 0 deletions

View File

@@ -52,6 +52,20 @@ int RangeSet::getPrev(int v) const
return RangeSetAbsent;
}
int RangeSet::prevMissing(int v) const
{ // largest number not in the set that is less than the given number
for (const_reverse_iterator it = rbegin(); it != rend(); ++it)
{
if (lower(it) <= v)
{
if (upper(it) < v)
return upper(it) + 1;
return lower(it) - 1;
}
}
return RangeSetAbsent;
}
void RangeSet::setValue(int v)
{
setRange(v, v);

View File

@@ -33,11 +33,14 @@ public:
int getLast() const;
int getPrev(int) const;
int prevMissing(int) const; // largest number not in the set that is less than the given number
void setValue(int);
void setRange(int, int);
void clearValue(int);
void clearRange(int, int);
void clear() { mRanges.clear(); }
// iterator stuff