TeoCCl library  0.1.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
queue.h File Reference

Queue module. More...

#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  teoQueueData
 Queue module, linked list with data in body. More...
 
struct  teoQueue
 
struct  teoQueueIterator
 

Typedefs

typedef struct teoQueueData teoQueueData
 Queue module, linked list with data in body. More...
 
typedef struct teoQueue teoQueue
 
typedef struct teoQueueIterator teoQueueIterator
 
typedef int(* teoQueueForeachFunction )(teoQueue *q, int idx, teoQueueData *data, void *user_data)
 

Functions

teoQueueteoQueueNew ()
 Create new Teo Queue. More...
 
int teoQueueDestroy (teoQueue *q)
 Destroy Teo Queue. More...
 
int teoQueueFree (teoQueue *q)
 Remove all elements from Teo queue. More...
 
teoQueueDatateoQueueNewData (void *data, size_t data_length)
 Create new teoQueueData buffer. More...
 
teoQueueDatateoQueueAdd (teoQueue *q, void *data, size_t data_length)
 Add new element to the end of Teo queue. More...
 
teoQueueDatateoQueueAddTop (teoQueue *q, void *data, size_t data_length)
 Add new element to the top of Teo queue. More...
 
teoQueueDatateoQueueAddAfter (teoQueue *q, void *data, size_t data_length, teoQueueData *qd)
 Add new element after selected in qd field. More...
 
teoQueueDatateoQueueUpdate (teoQueue *q, void *data, size_t data_length, teoQueueData *qd)
 Update element: remove selected and set new one to it place. More...
 
teoQueueDatateoQueueRemove (teoQueue *q, teoQueueData *qd)
 Remove element from queue but not free it. More...
 
int teoQueueDelete (teoQueue *q, teoQueueData *qd)
 Delete element from queue and free it. More...
 
int teoQueueDeleteFirst (teoQueue *q)
 Delete first element from queue and free it. More...
 
int teoQueueDeleteLast (teoQueue *q)
 Delete last element from queue and free it. More...
 
teoQueueDatateoQueueMoveToTop (teoQueue *q, teoQueueData *qd)
 Move element from this queue to the top of queue. More...
 
teoQueueDatateoQueueMoveToEnd (teoQueue *q, teoQueueData *qd)
 Move element from this queue to the end of queue. More...
 
teoQueueDatateoQueuePut (teoQueue *q, teoQueueData *qd)
 Put (add, copy) existing queue record to the end of selected queue. More...
 
size_t teoQueueSize (teoQueue *q)
 Get number of elements in Teo queue. More...
 
teoQueueIteratorteoQueueIteratorNew (teoQueue *q)
 Create new Teo Queue iterator. More...
 
teoQueueDatateoQueueIteratorNext (teoQueueIterator *it)
 Get next element from Teo Queue iterator. More...
 
teoQueueDatateoQueueIteratorPrev (teoQueueIterator *it)
 Get previous element from Teo Queue iterator. More...
 
teoQueueDatateoQueueIteratorElement (teoQueueIterator *it)
 Get current Teo Queue iterator element. More...
 
teoQueueIteratorteoQueueIteratorReset (teoQueueIterator *it, teoQueue *q)
 Reset iterator (or swith to new Queue) More...
 
int teoQueueIteratorFree (teoQueueIterator *it)
 Free (destroy) Teo Queue iterator. More...
 
int teoQueueForeach (teoQueue *q, teoQueueForeachFunction callback, void *user_data)
 Loop through queue and call callback function with index and data in parameters. More...
 

Detailed Description

Queue module.

Author
Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Queue container

Created on May 30, 2016, 11:56 AM

Typedef Documentation

typedef struct teoQueue teoQueue
typedef struct teoQueueData teoQueueData

Queue module, linked list with data in body.

typedef int(* teoQueueForeachFunction)(teoQueue *q, int idx, teoQueueData *data, void *user_data)

Function Documentation

teoQueueData* teoQueueAdd ( teoQueue q,
void *  data,
size_t  data_length 
)

Add new element to the end of Teo queue.

Parameters
qPointer to existing Teo Queue
dataPointer to data of new element
data_lengthLength of new element data
Returns
Pointer to teoQueueData of added element

References teoQueueNewData(), and teoQueuePut().

Referenced by teo::Queue::add(), teoMapAdd(), teoQueueAddAfter(), and teoQueueAddTop().

teoQueueData* teoQueueAddAfter ( teoQueue q,
void *  data,
size_t  data_length,
teoQueueData qd 
)

Add new element after selected in qd field.

Parameters
qPointer to existing Teo Queue
dataPointer to data of new element
data_lengthLength of new element data
qdPointer to teoQueueData of existing element
Returns

References teoQueue::last, teoQueue::length, teoQueueData::next, teoQueueData::prev, teoQueueAdd(), teoQueueAddTop(), and teoQueueNewData().

Referenced by teo::Queue::addAfter().

teoQueueData* teoQueueAddTop ( teoQueue q,
void *  data,
size_t  data_length 
)

Add new element to the top of Teo queue.

Parameters
qPointer to existing Teo Queue
dataPointer to data of new element
data_lengthLength of new element data
Returns
Pointer to teoQueueData of added element

References teoQueueAdd(), and teoQueueMoveToTop().

Referenced by teo::Queue::addTop(), cclLruRefer(), and teoQueueAddAfter().

int teoQueueDelete ( teoQueue q,
teoQueueData qd 
)

Delete element from queue and free it.

Parameters
qPointer to teoQueue
qdPointer to teoQueueData
Returns
Zero at success

References teoQueueRemove().

Referenced by teo::Queue::del(), teoMapDelete(), teoQueueDeleteFirst(), and teoQueueDeleteLast().

int teoQueueDeleteFirst ( teoQueue q)

Delete first element from queue and free it.

Parameters
qPointer to teoQueue
Returns
Zero at success

References teoQueue::first, and teoQueueDelete().

Referenced by teo::Queue::delFirst().

int teoQueueDeleteLast ( teoQueue q)

Delete last element from queue and free it.

Parameters
qPointer to teoQueue
Returns
Zero at success

References teoQueue::last, and teoQueueDelete().

Referenced by teo::Queue::delLast().

int teoQueueDestroy ( teoQueue q)

Destroy Teo Queue.

Parameters
qPointer to existing Teo Queue
Returns
Zero at success

References teoQueueFree().

Referenced by cclLruDestroy(), teoMapDestroy(), and teo::Queue::~Queue().

int teoQueueForeach ( teoQueue q,
teoQueueForeachFunction  callback,
void *  user_data 
)

Loop through queue and call callback function with index and data in parameters.

Parameters
qPointer to teoQueue
callbackPointer to callback function teoQueueForeachFunction
Returns
Number of elements processed

References teoQueueIteratorElement(), teoQueueIteratorNext(), and teoQueueIteratorReset().

Referenced by teo::Queue::foreach().

int teoQueueFree ( teoQueue q)

Remove all elements from Teo queue.

Parameters
qPointer to existing Teo Queue
Returns
Zero at success

References teoQueue::first, and teoQueueData::next.

Referenced by teo::Queue::freeAll(), teoMapClear(), and teoQueueDestroy().

teoQueueData* teoQueueIteratorElement ( teoQueueIterator it)

Get current Teo Queue iterator element.

Parameters
itPointer to teoQueueIterator
Returns
Pointer to the teoQueueData or NULL if not exists

References teoQueueIterator::qd.

Referenced by cclLruForeach(), teo::Queue::iteratorElement(), and teoQueueForeach().

int teoQueueIteratorFree ( teoQueueIterator it)

Free (destroy) Teo Queue iterator.

Parameters
itPointer to teoQueueIterator
Returns
Zero at success

Referenced by teo::Queue::iteratorFree().

teoQueueIterator* teoQueueIteratorNew ( teoQueue q)

Create new Teo Queue iterator.

Parameters
qPointer to teoQueue
Returns

References ccl_malloc(), teoQueueIterator::q, and teoQueueIterator::qd.

Referenced by teo::Queue::iterator().

teoQueueData* teoQueueIteratorNext ( teoQueueIterator it)

Get next element from Teo Queue iterator.

Parameters
itPointer to teoQueueIterator
Returns
Pointer to the teoQueueData or NULL if not exists

References teoQueue::first, teoQueueData::next, teoQueueIterator::q, and teoQueueIterator::qd.

Referenced by cclLruForeach(), teo::Queue::iteratorNext(), teoMapIteratorNext(), and teoQueueForeach().

teoQueueData* teoQueueIteratorPrev ( teoQueueIterator it)

Get previous element from Teo Queue iterator.

Parameters
itPointer to teoQueueIterator
Returns
Pointer to the teoQueueData or NULL if not exists

References teoQueue::last, teoQueueData::prev, teoQueueIterator::q, and teoQueueIterator::qd.

Referenced by teo::Queue::iteratorPrev(), and teoMapIteratorPrev().

teoQueueIterator* teoQueueIteratorReset ( teoQueueIterator it,
teoQueue q 
)

Reset iterator (or swith to new Queue)

Parameters
itPointer to teoQueueIterator
qPointer to teoQueue to switch to or NULL to reset current queue
Returns
Pointer to input teoQueueIterator

References teoQueueIterator::q, and teoQueueIterator::qd.

Referenced by cclLruForeach(), teo::Queue::iteratorElement(), teoMapIteratorNext(), teoMapIteratorPrev(), teoMapIteratorReset(), teoMapIteratorReverseReset(), and teoQueueForeach().

teoQueueData* teoQueueMoveToEnd ( teoQueue q,
teoQueueData qd 
)

Move element from this queue to the end of queue.

Parameters
qPointer to teoQueue
qdPointer to teoQueueData
Returns
Pointer to input teoQueueData

References teoQueue::last, teoQueue::length, teoQueueData::next, teoQueueData::prev, and teoQueueRemove().

Referenced by teo::Queue::moveToEnd().

teoQueueData* teoQueueMoveToTop ( teoQueue q,
teoQueueData qd 
)

Move element from this queue to the top of queue.

Parameters
qPointer to teoQueue
qdPointer to teoQueueData
Returns
Pointer to input teoQueueData

References teoQueue::first, teoQueue::length, teoQueueData::next, teoQueueData::prev, and teoQueueRemove().

Referenced by teo::Queue::moveToTop(), and teoQueueAddTop().

teoQueue* teoQueueNew ( )

Create new Teo Queue.

Returns
Pointer to new Teo Queue or NULL if memory allocate error

References ccl_calloc(), teoQueue::first, teoQueue::last, and teoQueue::length.

Referenced by cclLruInit(), teo::Queue::Queue(), and teoMapNew().

teoQueueData* teoQueueNewData ( void *  data,
size_t  data_length 
)

Create new teoQueueData buffer.

Parameters
dataPointer to data
data_lengthData length
Returns

References ccl_malloc(), teoQueueData::data, teoQueueData::data_length, teoQueueData::next, and teoQueueData::prev.

Referenced by teo::Queue::newData(), teoQueueAdd(), teoQueueAddAfter(), and teoQueueUpdate().

teoQueueData* teoQueuePut ( teoQueue q,
teoQueueData qd 
)

Put (add, copy) existing queue record to the end of selected queue.

Parameters
qPointer to teoQueue
qdPointer to teoQueueData
Returns
Zero at success

References teoQueue::first, teoQueue::last, teoQueue::length, teoQueueData::next, and teoQueueData::prev.

Referenced by teo::Queue::put(), and teoQueueAdd().

teoQueueData* teoQueueRemove ( teoQueue q,
teoQueueData qd 
)

Remove element from queue but not free it.

Parameters
qPointer to teoQueue
qdPointer to teoQueueData
Returns
Pointer to teoQueueData

References teoQueue::first, teoQueue::last, teoQueue::length, teoQueueData::next, and teoQueueData::prev.

Referenced by cclLruRefer(), teo::Queue::remove(), teoQueueDelete(), teoQueueMoveToEnd(), and teoQueueMoveToTop().

size_t teoQueueSize ( teoQueue q)

Get number of elements in Teo queue.

Parameters
q
Returns
Number of elements in Teo queue

References teoQueue::length.

Referenced by cclLruRefer(), and teo::Queue::size().

teoQueueData* teoQueueUpdate ( teoQueue q,
void *  data,
size_t  data_length,
teoQueueData qd 
)

Update element: remove selected and set new one to it place.

Parameters
qPointer to existing Teo Queue
dataPointer to data of new element
data_lengthLength of new element data
qdPointer to teoQueueData of existing element
Returns

References teoQueue::first, teoQueue::last, teoQueueData::next, teoQueueData::prev, and teoQueueNewData().

Referenced by teoMapAdd().