Файл src/queue.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "allheaders.h"

Функции

L_QUEUElqueueCreate (l_int32 nalloc)
void lqueueDestroy (L_QUEUE **plq, l_int32 freeflag)
l_int32 lqueueAdd (L_QUEUE *lq, void *item)
l_int32 lqueueExtendArray (L_QUEUE *lq)
void * lqueueRemove (L_QUEUE *lq)
l_int32 lqueueGetCount (L_QUEUE *lq)
l_int32 lqueuePrint (FILE *fp, L_QUEUE *lq)

Переменные

static const l_int32 MIN_BUFFER_SIZE = 20
static const l_int32 INITIAL_BUFFER_ARRAYSIZE = 1024

Функции

l_int32 lqueueAdd ( L_QUEUE lq,
void *  item 
)

lqueueAdd()

Input: lqueue item to be added to the tail of the queue Return: 0 if OK, 1 on error

Notes: (1) The algorithm is as follows. If the queue is populated to the end of the allocated array, shift all ptrs toward the beginning of the array, so that the head of the queue is at the beginning of the array. Then, if the array is more than 0.75 full, realloc with double the array size. Finally, add the item to the tail of the queue.

L_QUEUE* lqueueCreate ( l_int32  nalloc  ) 

lqueueCreate()

Input: size of ptr array to be alloc'd (0 for default) Return: lqueue, or null on error

Notes: (1) Allocates a ptr array of given size, and initializes counters.

void lqueueDestroy ( L_QUEUE **  plq,
l_int32  freeflag 
)

lqueueDestroy()

Input: &lqueue (<to be="" nulled>="">) freeflag (TRUE to free each remaining struct in the array) Return: void

Notes: (1) If freeflag is TRUE, frees each struct in the array. (2) If freeflag is FALSE but there are elements on the array, gives a warning and destroys the array. This will cause a memory leak of all the items that were on the queue. So if the items require their own destroy function, they must be destroyed before the queue. The same applies to the auxiliary stack, if it is used. (3) To destroy the L_Queue, we destroy the ptr array, then the lqueue, and then null the contents of the input ptr.

l_int32 lqueueExtendArray ( L_QUEUE lq  ) 

lqueueExtendArray()

Input: lqueue Return: 0 if OK, 1 on error

l_int32 lqueueGetCount ( L_QUEUE lq  ) 

lqueueGetCount()

Input: lqueue Return: count, or 0 on error

l_int32 lqueuePrint ( FILE *  fp,
L_QUEUE lq 
)

lqueuePrint()

Input: stream lqueue Return: 0 if OK; 1 on error

void* lqueueRemove ( L_QUEUE lq  ) 

lqueueRemove()

Input: lqueue Return: ptr to item popped from the head of the queue, or null if the queue is empty or on error

Notes: (1) If this is the last item on the queue, so that the queue becomes empty, nhead is reset to the beginning of the array.


Переменные

const l_int32 INITIAL_BUFFER_ARRAYSIZE = 1024 [static]

const l_int32 MIN_BUFFER_SIZE = 20 [static]


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:38 2009. Создано системой  doxygen 1.5.9