Skip to content

Commit

Permalink
Add API to check priority queue node status
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Ambrose committed Oct 25, 2023
1 parent 8c24f42 commit 9134018
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
26 changes: 18 additions & 8 deletions include/aws/common/priority_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions source/priority_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 9134018

Please sign in to comment.