LibCDS
queue.h File Reference

The FIFO queue. More...

Go to the source code of this file.

Data Structures

struct  Queue
 The implementation for queue. More...
 

Typedefs

typedef struct _QueueData QueueData
 QueueData is the data type for the container private information. More...
 

Functions

int32_t QueueInit (Queue **ppObj)
 The constructor for Queue. More...
 
void QueueDeinit (Queue **ppObj)
 The destructor for Queue. More...
 
int32_t QueuePush (Queue *self, Item item)
 Insert an item to the tail of the queue. More...
 
int32_t QueuePop (Queue *self)
 Delete item from top of the queue. More...
 
int32_t QueueFront (Queue *self, Item *pItem)
 Retrieve item from the head of the queue. More...
 
int32_t QueueBack (Queue *self, Item *pItem)
 Retrieve item from the tail of the queue. More...
 
int32_t QueueSize (Queue *self)
 Return the number of stored items. More...
 
int32_t QueueSetDestroy (Queue *self, void(*pFunc)(Item))
 Set the custom item resource clean method. More...
 

Detailed Description

The FIFO queue.

Definition in file queue.h.

Typedef Documentation

typedef struct _QueueData QueueData

QueueData is the data type for the container private information.

Definition at line 11 of file queue.h.

Function Documentation

int32_t QueueInit ( Queue **  ppObj)

The constructor for Queue.

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

The destructor for Queue.

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 QueuePush ( Queue self,
Item  item 
)

Insert an item to the tail of the queue.

This function inserts an item to the tail of the queue with the corresponding queue size extension.

Parameters
selfThe pointer to Queue structure
itemThe designated item
Return values
SUCC
ERR_NOINITUninitialized container
ERR_NOMEMInsufficient memory for queue extension
int32_t QueuePop ( Queue 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 Queue structure
Return values
SUCC
ERR_NOINITUninitialized container
ERR_IDXEmpty queue
int32_t QueueFront ( Queue self,
Item *  pItem 
)

Retrieve item from the head of the queue.

This function retrieves item from the head 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 Queue 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 QueueBack ( Queue self,
Item *  pItem 
)

Retrieve item from the tail of the queue.

This function retrieves item from the tail 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 Queue 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 QueueSize ( Queue self)

Return the number of stored items.

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

Set the custom item resource clean method.

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