You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be safer to use UniqueStash instead of Stash in order to prevent decreasing an unwanted item with an outdated Handle. Consider the following example:
letmut heap = DefaultPairingHeap::new();let h1 = heap.push('a',1);
heap.pop();// we pop the item `h1` was referring tolet _h2 = heap.push('b',1);
heap.decrease_key(h1,0);// here `h1` should no longer be validprintln!("{:?}", heap)
It shows that we have actually accidentally decreased the element indexed by h2, and not the the no longer existing item 'a', which originally gave us the handle.
I think the current implementation breaks the usual guarantees of rust, namely that references should not accidentally change the object they are referring to (and yes, the Handle plays the role of a reference; it's only a trick to circumvent the impossibility of using an actual reference)
The text was updated successfully, but these errors were encountered:
I think it would be safer to use
UniqueStash
instead ofStash
in order to prevent decreasing an unwanted item with an outdatedHandle
. Consider the following example:which outputs
It shows that we have actually accidentally decreased the element indexed by
h2
, and not the the no longer existing item'a'
, which originally gave us the handle.I think the current implementation breaks the usual guarantees of
rust
, namely that references should not accidentally change the object they are referring to (and yes, theHandle
plays the role of a reference; it's only a trick to circumvent the impossibility of using an actual reference)The text was updated successfully, but these errors were encountered: