LibCDS
priority_queue.h File Reference

The priority queue implemented with binary heap. More...

Go to the source code of this file.

Data Structures

struct  PriorityQueue
 The implementation for priority queue. More...
 

Typedefs

typedef struct _PriorityQueueData PriorityQueueData
 PriorityQueueData is the data type for the container private information. More...
 

Functions

int32_t PriorityQueueInit (PriorityQueue **ppObj)
 The constructor for PriorityQueue. More...
 
void PriorityQueueDeinit (PriorityQueue **ppObj)
 The destructor for PriorityQueue. More...
 
int32_t PriorityQueuePush (PriorityQueue *self, Item item)
 Push an item onto the queue. More...
 
int32_t PriorityQueuePop (PriorityQueue *self)
 Delete item from top of the queue. More...
 
int32_t PriorityQueueTop (PriorityQueue *self, Item *pItem)
 Retrieve item from top of the queue. More...
 
int32_t PriorityQueueSize (PriorityQueue *self)
 Return the number of stored items. More...
 
int32_t PriorityQueueSetCompare (PriorityQueue *self, int32_t(*pFunc)(Item, Item))
 Set the custom item comparison method. More...
 
int32_t PriorityQueueSetDestroy (PriorityQueue *self, void(*pFunc)(Item))
 Set the custom item resource clean method. More...
 

Detailed Description

The priority queue implemented with binary heap.

Definition in file priority_queue.h.

Typedef Documentation

typedef struct _PriorityQueueData PriorityQueueData

PriorityQueueData is the data type for the container private information.

Definition at line 11 of file priority_queue.h.

Function Documentation

int32_t PriorityQueueInit ( PriorityQueue **  ppObj)

The constructor for PriorityQueue.

Parameters
ppObjThe double pointer to the to be constructed queue
Return values
SUCC
ERR_NOMEMInsufficient memory for queue construction
void PriorityQueueDeinit ( PriorityQueue **  ppObj)

The destructor for PriorityQueue.

If the custom resource clean method is set, it also runs the clean method for all the items.

Parameters
ppObjThe double pointer to the to be destructed queue
int32_t PriorityQueuePush ( PriorityQueue self,
Item  item 
)

Push an item onto the queue.

This function pushes an item onto the queue with the corresponding queue size extension.

Parameters
selfThe pointer to PriorityQueue structure
itemThe designated item
Return values
SUCC
ERR_NOINITUninitialized container
ERR_NOMEMInsufficient memory for queue extension
int32_t PriorityQueuePop ( PriorityQueue self)

Delete item from top of the queue.

This function deletes item from top of the queue. If the custom resource clean method is set, it also runs the clean method for the deleted item.

Parameters
selfThe pointer to PriorityQueue structure
Return values
SUCC
ERR_NOINITUninitialized container
ERR_IDXEmpty queue
int32_t PriorityQueueTop ( PriorityQueue self,
Item *  pItem 
)

Retrieve item from top of the queue.

This function retrieves item from top of the queue. If the queue is not empty, the item is returned by the second parameter. Otherwise, the error code is returned and the second parameter is updated with NULL.

Parameters
selfThe pointer to PriorityQueue structure
pItemThe pointer to the returned item
Return values
SUCC
ERR_NOINITUninitialized container
ERR_IDXEmpty queue
ERR_GETInvalid parameter to store returned item
int32_t PriorityQueueSize ( PriorityQueue self)

Return the number of stored items.

Parameters
selfThe pointer to PriorityQueue structure
Returns
The number of items
Return values
ERR_NOINITUninitialized container
int32_t PriorityQueueSetCompare ( PriorityQueue self,
int32_t(*)(Item, Item)  pFunc 
)

Set the custom item comparison method.

Parameters
selfThe pointer to PriorityQueue structure
pFuncThe function pointer to the custom method
Return values
SUCC
ERR_NOINITUninitialized container
int32_t PriorityQueueSetDestroy ( PriorityQueue self,
void(*)(Item)  pFunc 
)

Set the custom item resource clean method.

Parameters
selfThe pointer to PriorityQueue structure
pFuncThe function pointer to the custom method
Return values
SUCC
ERR_NOINITUninitialized container