diff options
| author | Heikki Linnakangas | 2015-02-17 20:55:53 +0000 |
|---|---|---|
| committer | Heikki Linnakangas | 2015-02-17 20:55:53 +0000 |
| commit | 931bf3eb9b203ca02d729f5122a44cc250c27695 (patch) | |
| tree | 1f0f81da92c9a07066e8090d186c9d2b4cf163bf /src/include/lib | |
| parent | d17b6df239e6eebf288969e931cdbe8076d1fe12 (diff) | |
Fix a bug in pairing heap removal code.
After removal, the next_sibling pointer of a node was sometimes incorrectly
left to point to another node in the heap, which meant that a node was
sometimes linked twice into the heap. Surprisingly that didn't cause any
crashes in my testing, but it was clearly wrong and could easily segfault
in other scenarios.
Also always keep the prev_or_parent pointer as NULL on the root node. That
was not a correctness issue AFAICS, but let's be tidy.
Add a debugging function, to dump the contents of a pairing heap as a
string. It's #ifdef'd out, as it's not used for anything in any normal
code, but it was highly useful in debugging this. Let's keep it handy for
further reference.
Diffstat (limited to 'src/include/lib')
| -rw-r--r-- | src/include/lib/pairingheap.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/include/lib/pairingheap.h b/src/include/lib/pairingheap.h index e3e320fc43..eb1856a7c1 100644 --- a/src/include/lib/pairingheap.h +++ b/src/include/lib/pairingheap.h @@ -11,6 +11,11 @@ #ifndef PAIRINGHEAP_H #define PAIRINGHEAP_H +#include "lib/stringinfo.h" + +/* Enable if you need the pairingheap_dump() debug function */ +/* #define PAIRINGHEAP_DEBUG */ + /* * This represents an element stored in the heap. Embed this in a larger * struct containing the actual data you're storing. @@ -78,6 +83,12 @@ extern pairingheap_node *pairingheap_first(pairingheap *heap); extern pairingheap_node *pairingheap_remove_first(pairingheap *heap); extern void pairingheap_remove(pairingheap *heap, pairingheap_node *node); +#ifdef PAIRINGHEAP_DEBUG +extern char *pairingheap_dump(pairingheap *heap, + void (*dumpfunc) (pairingheap_node *node, StringInfo buf, void *opaque), + void *opaque); +#endif + /* Resets the heap to be empty. */ #define pairingheap_reset(h) ((h)->ph_root = NULL) |
