mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Merge pull request #1882 from Poita/bug5462
Fix Issue 5462 - Better errors in BinaryHeap
This commit is contained in:
commit
b402145a76
1 changed files with 5 additions and 5 deletions
|
@ -3820,7 +3820,7 @@ if (isRandomAccessRange!(Store) || isRandomAccessRange!(typeof(Store.init[])))
|
||||||
// @@@BUG@@@: add private here, std.algorithm doesn't unittest anymore
|
// @@@BUG@@@: add private here, std.algorithm doesn't unittest anymore
|
||||||
/*private*/ void pop(Store store)
|
/*private*/ void pop(Store store)
|
||||||
{
|
{
|
||||||
assert(!store.empty);
|
assert(!store.empty, "Cannot pop an empty store.");
|
||||||
if (store.length == 1) return;
|
if (store.length == 1) return;
|
||||||
auto t1 = moveFront(store[]);
|
auto t1 = moveFront(store[]);
|
||||||
auto t2 = moveBack(store[]);
|
auto t2 = moveBack(store[]);
|
||||||
|
@ -3964,7 +3964,7 @@ according to $(D less).
|
||||||
*/
|
*/
|
||||||
@property ElementType!Store front()
|
@property ElementType!Store front()
|
||||||
{
|
{
|
||||||
enforce(!empty);
|
enforce(!empty, "Cannot call front on an empty heap.");
|
||||||
return _store.front;
|
return _store.front;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4023,7 +4023,7 @@ Removes the largest element from the heap.
|
||||||
*/
|
*/
|
||||||
void removeFront()
|
void removeFront()
|
||||||
{
|
{
|
||||||
enforce(!empty);
|
enforce(!empty, "Cannot call removeFront on an empty heap.");
|
||||||
if (_length > 1)
|
if (_length > 1)
|
||||||
{
|
{
|
||||||
auto t1 = moveFront(_store[]);
|
auto t1 = moveFront(_store[]);
|
||||||
|
@ -4053,7 +4053,7 @@ Replaces the largest element in the store with $(D value).
|
||||||
void replaceFront(ElementType!Store value)
|
void replaceFront(ElementType!Store value)
|
||||||
{
|
{
|
||||||
// must replace the top
|
// must replace the top
|
||||||
assert(!empty);
|
assert(!empty, "Cannot call replaceFront on an empty heap.");
|
||||||
_store.front = value;
|
_store.front = value;
|
||||||
percolateDown(_store, 0, _length);
|
percolateDown(_store, 0, _length);
|
||||||
assertValid();
|
assertValid();
|
||||||
|
@ -4076,7 +4076,7 @@ must be collected.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// must replace the top
|
// must replace the top
|
||||||
assert(!_store.empty);
|
assert(!_store.empty, "Cannot replace front of an empty heap.");
|
||||||
if (!comp(value, _store.front)) return false; // value >= largest
|
if (!comp(value, _store.front)) return false; // value >= largest
|
||||||
_store.front = value;
|
_store.front = value;
|
||||||
percolateDown(_store, 0, _length);
|
percolateDown(_store, 0, _length);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue