LQueue

Description Queue data structure
Header file LQueue.h
Author Camil Demetrescu
Created Dec 28, 2002
Last updated Sep 26, 2003

 

Contents


Introduction

The component LQueue provides support for maintaining a first-in-first-out (FIFO) queue data structure.


Interface

Constants

LQueue_ID
LQueue_EMPTY_QUEUE
LQueue_BASE_TYPE_MISMATCH

Types

LQueue

Functions

LQueue*      LQueue_New           (LType_TType inType)
void LQueue_Delete (LQueue** ThisA)
Bool LQueue_IsEmpty (LQueue* This)
void LQueue_EnqueueI1 (LQueue* This, i1 inVal)
void LQueue_EnqueueUI1 (LQueue* This, ui1 inVal)
void LQueue_EnqueueI2 (LQueue* This, i2 inVal)
void LQueue_EnqueueUI2 (LQueue* This, ui2 inVal)
void LQueue_EnqueueI4 (LQueue* This, i4 inVal)
void LQueue_EnqueueUI4 (LQueue* This, ui4 inVal)
void LQueue_EnqueueF4 (LQueue* This, f4 inVal)
void LQueue_EnqueueF8 (LQueue* This, f8 inVal)
void LQueue_EnqueueBool (LQueue* This, Bool inVal)
void LQueue_EnqueuePtr (LQueue* This, const void* inVal)
void LQueue_EnqueueItem (LQueue* This, const void* inItem)
i1 LQueue_DequeueI1 (LQueue* This)
ui1 LQueue_DequeueUI1 (LQueue* This)
i2 LQueue_DequeueI2 (LQueue* This)
ui2 LQueue_DequeueUI2 (LQueue* This)
i4 LQueue_DequeueI4 (LQueue* This)
ui4 LQueue_DequeueUI4 (LQueue* This)
f4 LQueue_DequeueF4 (LQueue* This)
f8 LQueue_DequeueF8 (LQueue* This)
Bool LQueue_DequeueBool (LQueue* This)
void* LQueue_DequeuePtr (LQueue* This)
void LQueue_DequeueItem (LQueue* This, void* outItem)
ui4 LQueue_GetUsedMem (LQueue* This)
LType_TType LQueue_GetBaseType (LQueue* This)


API Reference

Function Arguments Description Returns Throws
New
LType_TType inType
Creates object containing an empty queue with items of type inType. Caller is responsible of dellocating the created object using LQueue_Delete.

LQueue*

pointer to newly created object

-
Delete LQueue** ThisA Releases object *ThisA. *ThisA is set to NULL. - -
IsEmpty
LQueue* This Returns TRUE if the data structure is empty, and FALSE otherwise. Bool -
EnqueueI1
LQueue* This 
i1      inVal
Inserts value inVal of the specified type into the data structure. The item type of the queue must be the same as the type of the inserted element. -

BASE_TYPE_MISMATCH

if the item type of the queue is not compatible with the operation.

EnqueueUI1
LQueue* This 
ui1     inVal
EnqueueI2
LQueue* This 
i2      inVal
EnqueueUI2
LQueue* This 
ui2     inVal
EnqueueI4
LQueue* This 
i4      inVal
EnqueueUI4
LQueue* This 
ui4     inVal
EnqueueF4
LQueue* This 
f4      inVal
EnqueueF8
LQueue* This 
f8      inVal
EnqueueBool
LQueue* This 
Bool    inVal
EnqueuePtr
LQueue* This 
void*   inVal
EnqueueItem
LQueue* This
void*   inItem
Inserts item into the data structure. - -
DequeueI1
LQueue* This
Extracts the oldest-inserted value of the specified type from the data structure. The queue must not be empty.
i1

BASE_TYPE_MISMATCH

if the item type of the queue is not compatible with the operation.

EMPTY_QUEUE

if the queue is empty.

DequeueUI1
LQueue* This
ui1
DequeueI2
LQueue* This
i2
DequeueUI2
LQueue* This
ui2
DequeueI4
LQueue* This
i4
DequeueUI4
LQueue* This
ui4
DequeueF4
LQueue* This
f4
DequeueF8
LQueue* This
f8
DequeueBool
LQueue* This
Bool
DequeuePtr
LQueue* This
void*
DequeueItem
LQueue* This
void*   outItem
Extracts the oldest-inserted value from the data structure, copying it to buffer outItem. - -
GetUsedMem LQueue* This Returns the memory usage (in bytes) of the data structure. ui4 -
GetBaseType LQueue* This Returns the type of items. LType_TType -


Example

#include "LQueue.h"
#include "LException.h"
#include "LDebug.h"

int main() {
    ui4         i;
    LQueue*     theQueue = NULL;
    LException* theExcep;
    
    Try {
        /* create new queue */
        theQueue = LQueue_New(LType_UI4);
    
        /* enqueue values */
        for (i=100; i>0; --i)
            LQueue_EnqueueUI4(theQueue, i);
    
        /* extract all values from queue */
        while (!LQueue_IsEmpty(theQueue)) {
            ui4 theVal = LQueue_DequeueUI4(theQueue);
            LDebug_Print("Extracted value: %lu\n", theVal);
        }
    }
    
    Catch(theExcep) {
        LException_Dump(theExcep);
    }
    
    if (theQueue != NULL) LQueue_Delete(&theQueue);
    
    return 0;
}

Revision history