aboutsummaryrefslogtreecommitdiff
path: root/src/include/lib/binaryheap.h
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2023-09-18 14:06:08 -0700
committerNathan Bossart <nathan@postgresql.org>2023-09-18 14:06:08 -0700
commitc103d073819a2189d849c0a93d51c726be524c48 (patch)
treec590a7adbbc8de211687517da7fca32dfcffe2d9 /src/include/lib/binaryheap.h
parent83223f5f714482dd44883c68ecac2ae8c2d838e8 (diff)
downloadpostgresql-c103d073819a2189d849c0a93d51c726be524c48.tar.gz
postgresql-c103d073819a2189d849c0a93d51c726be524c48.zip
Add function for removing arbitrary nodes in binaryheap.
This commit introduces binaryheap_remove_node(), which can be used to remove any node from a binary heap. The implementation is straightforward. The target node is replaced with the last node in the heap, and then we sift as needed to preserve the heap property. This new function is intended for use in a follow-up commit that will improve the performance of pg_restore. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/3612876.1689443232%40sss.pgh.pa.us
Diffstat (limited to 'src/include/lib/binaryheap.h')
-rw-r--r--src/include/lib/binaryheap.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/include/lib/binaryheap.h b/src/include/lib/binaryheap.h
index 3647aeae657..9525dcaec44 100644
--- a/src/include/lib/binaryheap.h
+++ b/src/include/lib/binaryheap.h
@@ -59,8 +59,11 @@ extern void binaryheap_build(binaryheap *heap);
extern void binaryheap_add(binaryheap *heap, bh_node_type d);
extern bh_node_type binaryheap_first(binaryheap *heap);
extern bh_node_type binaryheap_remove_first(binaryheap *heap);
+extern void binaryheap_remove_node(binaryheap *heap, int n);
extern void binaryheap_replace_first(binaryheap *heap, bh_node_type d);
#define binaryheap_empty(h) ((h)->bh_size == 0)
+#define binaryheap_size(h) ((h)->bh_size)
+#define binaryheap_get_node(h, n) ((h)->bh_nodes[n])
#endif /* BINARYHEAP_H */