Make SparseBitVector::set actually work properly when sets are not in ascending or descending order.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Berlin 2007-10-04 05:25:51 +00:00
parent 3b802476d2
commit c3a32d190c

View File

@ -334,9 +334,8 @@ class SparseBitVector {
--ElementIter;
} else {
while (ElementIter != Elements.end() &&
ElementIter->index() <= ElementIndex)
ElementIter->index() < ElementIndex)
++ElementIter;
--ElementIter;
}
CurrElementIter = ElementIter;
return ElementIter;
@ -536,10 +535,17 @@ public:
if (ElementIter == Elements.end() ||
ElementIter->index() != ElementIndex) {
Element = new SparseBitVectorElement<ElementSize>(ElementIndex);
// Insert does insert before, and lower bound gives the one before.
ElementIter = Elements.insert(++ElementIter, Element);
// We may have hit the beginning of our SparseBitVector, in which case,
// we may need to insert right after this element, which requires moving
// the current iterator forward one, because insert does insert before.
if (ElementIter->index() < ElementIndex)
ElementIter = Elements.insert(++ElementIter, Element);
else
ElementIter = Elements.insert(ElementIter, Element);
}
}
CurrElementIter = ElementIter;
ElementIter->set(Idx % ElementSize);
}