.TH "globus_priority_q" 3 "Version 18.14" "globus_common" \" -*- nroff -*- .ad l .nh .SH NAME globus_priority_q \- Priority Queue .PP \- Priority Queue\&. .SH SYNOPSIS .br .PP .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBglobus_priority_q_s\fP" .br .RI "Priority Queue Structure\&. " .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef int(* \fBglobus_priority_q_cmp_func_t\fP) (void *priority_1, void *priority_2)" .br .RI "Priority Comparison Predicate\&. " .ti -1c .RI "typedef struct \fBglobus_priority_q_s\fP \fBglobus_priority_q_t\fP" .br .RI "Priority Queue Structure\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "int \fBglobus_priority_q_init\fP (\fBglobus_priority_q_t\fP *priority_q, \fBglobus_priority_q_cmp_func_t\fP cmp_func)" .br .RI "Initialize a priority queue\&. " .ti -1c .RI "int \fBglobus_priority_q_destroy\fP (\fBglobus_priority_q_t\fP *priority_q)" .br .RI "Destroy a Priority Queue\&. " .ti -1c .RI "\fBglobus_bool_t\fP \fBglobus_priority_q_empty\fP (\fBglobus_priority_q_t\fP *priority_q)" .br .RI "Priority Queue Empty Predicate\&. " .ti -1c .RI "int \fBglobus_priority_q_size\fP (\fBglobus_priority_q_t\fP *priority_q)" .br .RI "Priority Queue Size\&. " .ti -1c .RI "int \fBglobus_priority_q_enqueue\fP (\fBglobus_priority_q_t\fP *priority_q, void *datum, void *priority)" .br .RI "Add a Datum to a Priority Queue\&. " .ti -1c .RI "void * \fBglobus_priority_q_dequeue\fP (\fBglobus_priority_q_t\fP *priority_q)" .br .RI "Remove a Datum From A Priority Queue\&. " .ti -1c .RI "void * \fBglobus_priority_q_first\fP (\fBglobus_priority_q_t\fP *priority_q)" .br .RI "Get the Highest-Priority Datum From a Priority Queue\&. " .ti -1c .RI "void * \fBglobus_priority_q_first_priority\fP (\fBglobus_priority_q_t\fP *priority_q)" .br .RI "Get the Highest Priority in Priority Queue\&. " .ti -1c .RI "void * \fBglobus_priority_q_remove\fP (\fBglobus_priority_q_t\fP *priority_q, void *datum)" .br .RI "Remove an Arbitrary Datum from a Priority Queue\&. " .ti -1c .RI "void * \fBglobus_priority_q_modify\fP (\fBglobus_priority_q_t\fP *priority_q, void *datum, void *new_priority)" .br .RI "Modify the Priority of Datum\&. " .in -1c .SH "Detailed Description" .PP Priority Queue\&. This module defines a priority queue for globus\&. It is implemented using a binary heap (minheap) and does NOT have a fifo fallback for like priorities\&. If you need fifo fallback, you should use a compound priority with the primary priority being the 'real' priority and the secondary being a serial number\&. .PP To use this priority queue type, define a comparison function of type globus_priority_q_cmp_func_t and pass that to \fBglobus_priority_q_init()\fP\&. .PP To add and remove items in priority order, use \fBglobus_priority_q_enqueue()\fP and \fBglobus_priority_q_dequeue()\fP respectively\&. .PP To remove a datum ignoring its priority, use \fBglobus_priority_q_remove()\fP\&. .PP To inspect the first element and its priority, use \fBglobus_priority_q_first()\fP and \fBglobus_priority_q_first_priority()\fP respectively\&. .PP To determine whether a queue is empty or the number of data in it, use \fBglobus_priority_q_empty()\fP and \fBglobus_priority_q_size()\fP\&. .PP To modify the priority of a datum already in the queue, use \fBglobus_priority_q_modify()\fP\&. .PP When finished with the queue, use \fBglobus_priority_q_destroy()\fP to free data associated with the priority queue\&. .SH "Typedef Documentation" .PP .SS "typedef int(* globus_priority_q_cmp_func_t) (void *priority_1, void *priority_2)" .PP Priority Comparison Predicate\&. This type is used to implement comparison of two priorities for inserting items into the priority queue\&. A function of this type is passed to \fBglobus_priority_q_init()\fP to determine how priorities are computed in a newly created priority queue\&. .PP \fBParameters\fP .RS 4 \fIpriority_1\fP First priority to compare .br \fIpriority_2\fP Second priority to compare .RE .PP \fBReturn values\fP .RS 4 \fI>\fP 0 The priority of priority_1 is less than that of priority_2\&. .br \fI<\fP 0 The priority of priority_1 is greater than that of priority_2\&. .br \fI=\fP 0 The priorities of priority_1 and priority_2 are the same\&. .RE .PP .SS "typedef struct \fBglobus_priority_q_s\fP \fBglobus_priority_q_t\fP" .PP Priority Queue Structure\&. A pointer to a structure of this type is passed to all functions in the \fBPriority Queue \fP module\&. It is not intended to be inspected or modified outside of this API\&. .SH "Function Documentation" .PP .SS "void * globus_priority_q_dequeue (\fBglobus_priority_q_t\fP * priority_q)" .PP Remove a Datum From A Priority Queue\&. The \fBglobus_priority_q_dequeue()\fP function removes the highest-priority datum from the given priority queue and returns it\&. If the priority_q pointer is NULL or the priority queue is empty, this function returns NULL\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to remove from\&. .RE .PP \fBReturns\fP .RS 4 This function returns the highest-priority datum from the priority queue\&. .RE .PP .SS "int globus_priority_q_destroy (\fBglobus_priority_q_t\fP * priority_q)" .PP Destroy a Priority Queue\&. The \fBglobus_priority_q_destroy()\fP function destroys the contents of a priority queue\&. After this function returns, the structure pointed to by priority_q is invalid and must not be passed to any functions in the \fBPriority Queue \fP module other \fBglobus_priority_q_init()\fP\&. .PP Note that this function does not call any destructors for the data inserted into the priority queue, so the caller must be sure to either have other references to those data or free them before calling this function\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority_q to destroy\&. .RE .PP \fBReturn values\fP .RS 4 \fIGLOBUS_SUCCESS\fP Success .br \fIGLOBUS_FAILURE\fP Failure .RE .PP .SS "\fBglobus_bool_t\fP globus_priority_q_empty (\fBglobus_priority_q_t\fP * priority_q)" .PP Priority Queue Empty Predicate\&. The \fBglobus_priority_q_empty()\fP function checks the given priority queue to determine if it is empty\&. It is considered empty if it has been initialized via \fBglobus_priority_q_init()\fP and there are no items which have been inserted via \fBglobus_priority_q_enqueue()\fP which have not been removed by calling \fBglobus_priority_q_remove()\fP or \fBglobus_priority_q_dequeue()\fP\&. If it is empty, this function returns GLOBUS_TRUE; otherwise it returns GLOBUS_FALSE\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to check .RE .PP \fBReturn values\fP .RS 4 \fIGLOBUS_TRUE\fP The priority queue is empty .br \fIGLOBUS_FALSE\fP The priority queue is not empty, or the priority queue is invalid .RE .PP .SS "int globus_priority_q_enqueue (\fBglobus_priority_q_t\fP * priority_q, void * datum, void * priority)" .PP Add a Datum to a Priority Queue\&. The \fBglobus_priority_q_enqueue()\fP function inserts a datum into the priority queue based on its priority\&. When an item is inserted, the pointers to both the datum and the priority are copied into the priority_q data structure, so neither may be freed until the datum is removed from the priority queue, or undefined behavior may occur\&. .PP Note that there is no fifo fallback for priorities, so the order of two items with equivalent priorities is not specified relative to each other\&. To enable fifo fallback, use a compound priority that includes a priority level and a sequence number as the value pointed to by the priority parameter and pass a suitable comparison function to initialize the priority queue\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to insert datum into .br \fIdatum\fP The datum to insert into the queue .br \fIpriority\fP The priority of the datum .RE .PP \fBReturn values\fP .RS 4 \fIGLOBUS_SUCCESS\fP Success .br \fIGLOBUS_FAILURE\fP Failure .RE .PP .SS "void * globus_priority_q_first (\fBglobus_priority_q_t\fP * priority_q)" .PP Get the Highest-Priority Datum From a Priority Queue\&. The \fBglobus_priority_q_first()\fP function returns the highest-priority datum from the priority queue pointed to by priority_q\&. The datum is not removed from the queue; to do that, use \fBglobus_priority_q_dequeue()\fP instead\&. If the priority_q pointer is NULL or the queue is empty, this function returns NULL\&. The priority queue retains a reference to the returned datum, so the pointer value returned must not freed until the datum is removed from the queue\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to inspect .RE .PP \fBReturns\fP .RS 4 This function returns the highest-priority datum from the priority queue\&. .RE .PP .SS "void * globus_priority_q_first_priority (\fBglobus_priority_q_t\fP * priority_q)" .PP Get the Highest Priority in Priority Queue\&. The \fBglobus_priority_q_first_priority()\fP function returns the value of highest priority in the priority queue (not the datum associated with that priority)\&. If the priority_q pointer is NULL or empty, this function returns NULL\&. The priority queue retains a reference to the returned priority, so the pointer value returned must not be freed until the datum associated with it is removed from the queue\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to inspect .RE .PP \fBReturns\fP .RS 4 This function returns the highest priority value in the priority queue\&. .RE .PP .SS "int globus_priority_q_init (\fBglobus_priority_q_t\fP * priority_q, \fBglobus_priority_q_cmp_func_t\fP cmp_func)" .PP Initialize a priority queue\&. The \fBglobus_priority_q_init()\fP function initializes a globus_priority_q_t structure for use with the other functions in the \fBPriority Queue \fP module\&. If this function returns GLOBUS_SUCCESS, the caller is responsible for deallocating the members of this structure when it is no longer needed by passing it to \fBglobus_priority_q_destroy()\fP\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue structure to initialize\&. .br \fIcmp_func\fP Pointer to a function which computes the relative relationship between two priorities\&. See the documentation of \fBglobus_priority_q_cmp_func_t\fP for details on how to implement that function\&. .RE .PP \fBReturn values\fP .RS 4 \fIGLOBUS_SUCCESS\fP Success .br \fIGLOBUS_FAILURE\fP Failure .RE .PP .SS "void * globus_priority_q_modify (\fBglobus_priority_q_t\fP * priority_q, void * datum, void * new_priority)" .PP Modify the Priority of Datum\&. The \fBglobus_priority_q_modify()\fP function modifies the priority of the highest-priority instance of datum in the priority queue so that it new_priority\&. The old priority of the datum is returned\&. If the priority_q is NULL or the datum is not present, this function returns NULL\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to modify .br \fIdatum\fP Pointer to the datum whose priority is being modified .br \fInew_priority\fP Pointer to the new priority .RE .PP \fBReturns\fP .RS 4 This function returns the old priority of datum\&. .RE .PP .SS "void * globus_priority_q_remove (\fBglobus_priority_q_t\fP * priority_q, void * datum)" .PP Remove an Arbitrary Datum from a Priority Queue\&. The \fBglobus_priority_q_remove()\fP function removes the highest-priority instance of the specified datum from the priority queue and returns the datum if it is found\&. If the priority_q is NULL or the datum is not found, this function returns NULL\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to modify .br \fIdatum\fP Pointer to the datum to search for\&. .RE .PP \fBReturns\fP .RS 4 This function returns datum if it was present in the priority queue .RE .PP .SS "int globus_priority_q_size (\fBglobus_priority_q_t\fP * priority_q)" .PP Priority Queue Size\&. The \fBglobus_priority_q_size()\fP function returns the size of the priority queue, that is, the number of elements that are currently enqueued in it\&. The special value GLOBUS_FAILURE is returned if a null pointer is passed to this function\&. .PP \fBParameters\fP .RS 4 \fIpriority_q\fP Pointer to the priority queue to check .RE .PP \fBReturns\fP .RS 4 This function returns the number of elements in the queue, or GLOBUS_FAILURE if the priority_q pointer is invalid\&. .RE .PP .SH "Author" .PP Generated automatically by Doxygen for globus_common from the source code\&.