mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Debug consistency checker for RangeSet
This commit is contained in:
@@ -85,6 +85,7 @@ uint32 RangeSet::prevMissing (uint32 v) const
|
|||||||
{
|
{
|
||||||
if (it.second < (v - 1))
|
if (it.second < (v - 1))
|
||||||
return v - 1;
|
return v - 1;
|
||||||
|
|
||||||
if (it.first >= v)
|
if (it.first >= v)
|
||||||
return (it.first == 0) ? absent : (it.first - 1);
|
return (it.first == 0) ? absent : (it.first - 1);
|
||||||
}
|
}
|
||||||
@@ -97,6 +98,7 @@ void RangeSet::setValue (uint32 v)
|
|||||||
if (!hasValue (v))
|
if (!hasValue (v))
|
||||||
{
|
{
|
||||||
mRanges[v] = v;
|
mRanges[v] = v;
|
||||||
|
|
||||||
simplify ();
|
simplify ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +114,7 @@ void RangeSet::setRange (uint32 minV, uint32 maxV)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mRanges[minV] = maxV;
|
mRanges[minV] = maxV;
|
||||||
|
|
||||||
simplify ();
|
simplify ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,20 +127,30 @@ void RangeSet::clearValue (uint32 v)
|
|||||||
if (it->first == v)
|
if (it->first == v)
|
||||||
{
|
{
|
||||||
if (it->second == v)
|
if (it->second == v)
|
||||||
|
{
|
||||||
mRanges.erase (it);
|
mRanges.erase (it);
|
||||||
|
|
||||||
|
checkInternalConsistency ();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mRanges[v + 1] = it->second;
|
mRanges[v + 1] = it->second;
|
||||||
it->second = v - 1;
|
it->second = v - 1;
|
||||||
|
|
||||||
|
checkInternalConsistency ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (it->second == v)
|
else if (it->second == v)
|
||||||
|
{
|
||||||
-- (it->second);
|
-- (it->second);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32 oldEnd = it->second;
|
uint32 oldEnd = it->second;
|
||||||
it->second = v - 1;
|
it->second = v - 1;
|
||||||
mRanges[v + 1] = oldEnd;
|
mRanges[v + 1] = oldEnd;
|
||||||
|
|
||||||
|
checkInternalConsistency ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -170,6 +183,8 @@ void RangeSet::simplify ()
|
|||||||
{
|
{
|
||||||
iterator it = mRanges.begin ();
|
iterator it = mRanges.begin ();
|
||||||
|
|
||||||
|
checkInternalConsistency ();
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
iterator nit = it;
|
iterator nit = it;
|
||||||
@@ -182,8 +197,41 @@ void RangeSet::simplify ()
|
|||||||
// ranges overlap
|
// ranges overlap
|
||||||
it->second = nit->second;
|
it->second = nit->second;
|
||||||
mRanges.erase (nit);
|
mRanges.erase (nit);
|
||||||
|
|
||||||
|
checkInternalConsistency ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
it = nit;
|
it = nit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RangeSet::checkInternalConsistency () const noexcept
|
||||||
|
{
|
||||||
|
#if BEAST_DEBUG
|
||||||
|
if (mRanges.size () > 1)
|
||||||
|
{
|
||||||
|
const_iterator const last = std::prev (mRanges.end ());
|
||||||
|
|
||||||
|
for (const_iterator cur = mRanges.begin (); cur != last; ++cur)
|
||||||
|
{
|
||||||
|
const_iterator const next = std::next (cur);
|
||||||
|
|
||||||
|
bassert (cur->first <= cur->second);
|
||||||
|
|
||||||
|
bassert (next->first <= next->second);
|
||||||
|
|
||||||
|
bassert (cur->second + 1 < next->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mRanges.size () == 1)
|
||||||
|
{
|
||||||
|
const_iterator const iter = mRanges.begin ();
|
||||||
|
|
||||||
|
bassert (iter->first <= iter->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ public:
|
|||||||
|
|
||||||
std::string toString () const;
|
std::string toString () const;
|
||||||
|
|
||||||
|
/** Check invariants of the data.
|
||||||
|
|
||||||
|
This is for diagnostics, and does nothing in release builds.
|
||||||
|
*/
|
||||||
|
void checkInternalConsistency () const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void simplify ();
|
void simplify ();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user