From 9134018a56ad6410ed634046a072fc56c292e54a Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Wed, 25 Oct 2023 11:15:38 -0700 Subject: [PATCH] Add API to check priority queue node status --- include/aws/common/priority_queue.h | 26 ++++++++++++++++++-------- source/priority_queue.c | 4 ++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/aws/common/priority_queue.h b/include/aws/common/priority_queue.h index e29347782..b240e19ca 100644 --- a/include/aws/common/priority_queue.h +++ b/include/aws/common/priority_queue.h @@ -83,14 +83,6 @@ void aws_priority_queue_init_static( size_t item_size, aws_priority_queue_compare_fn *pred); -/** - * Initializes a queue node to a default value that indicates the node is not in the queue. - * - * @param node priority queue node to initialize with a default value - */ -AWS_COMMON_API -void aws_priority_queue_node_init(struct aws_priority_queue_node *node); - /** * Checks that the backpointer at a specific index of the queue is * NULL or points to a correctly allocated aws_priority_queue_node. @@ -183,6 +175,24 @@ size_t aws_priority_queue_size(const struct aws_priority_queue *queue); AWS_COMMON_API size_t aws_priority_queue_capacity(const struct aws_priority_queue *queue); +/** + * Initializes a queue node to a default value that indicates the node is not in the queue. + * + * @param node priority queue node to initialize with a default value + */ +AWS_COMMON_API +void aws_priority_queue_node_init(struct aws_priority_queue_node *node); + +/** + * Checks if a priority queue node is currently in a priority queue. + * + * @param node priority queue node to check usage for + * + * @return true if the node is in a queue, false otherwise + */ +AWS_COMMON_API +bool aws_priority_queue_node_is_in_queue(const struct aws_priority_queue_node *node); + AWS_EXTERN_C_END AWS_POP_SANE_WARNING_LEVEL diff --git a/source/priority_queue.c b/source/priority_queue.c index dfa071f75..0c7efa6a7 100644 --- a/source/priority_queue.c +++ b/source/priority_queue.c @@ -404,3 +404,7 @@ size_t aws_priority_queue_capacity(const struct aws_priority_queue *queue) { void aws_priority_queue_node_init(struct aws_priority_queue_node *node) { node->current_index = SIZE_MAX; } + +bool aws_priority_queue_node_is_in_queue(const struct aws_priority_queue_node *node) { + return node->current_index != SIZE_MAX; +}