Leptonica 1.68
C Image Processing Library
|
Implements a stack of generic pointers. More...
Go to the source code of this file.
Functions | |
L_STACK * | lstackCreate (l_int32 nalloc) |
void | lstackDestroy (L_STACK **plstack, l_int32 freeflag) |
l_int32 | lstackAdd (L_STACK *lstack, void *item) |
void * | lstackRemove (L_STACK *lstack) |
l_int32 | lstackExtendArray (L_STACK *lstack) |
l_int32 | lstackGetCount (L_STACK *lstack) |
l_int32 | lstackPrint (FILE *fp, L_STACK *lstack) |
Variables | |
static const l_int32 | INITIAL_PTR_ARRAYSIZE = 20 |
Implements a stack of generic pointers.
Generic stack The lstack is an array of void * ptrs, onto which objects can be stored. At any time, the number of stored objects is lstack->n. The object at the bottom of the lstack is at array[0]; the object at the top of the lstack is at array[n-1]. New objects are added to the top of the lstack; i.e., the first available location, which is at array[n]. The lstack is expanded by doubling, when needed. Objects are removed from the top of the lstack. When an attempt is made to remove an object from an empty lstack, the result is null. Create/Destroy L_STACK *lstackCreate() void lstackDestroy() Accessors l_int32 lstackAdd() void *lstackRemove() l_int32 lstackExtendArray() l_int32 lstackGetCount() Text description l_int32 lstackPrint()
Definition in file stack.c.
Input: nalloc (initial ptr array size; use 0 for default) Return: lstack, or null on error
Definition at line 64 of file stack.c.
References L_Stack::array, CALLOC, ERROR_PTR, INITIAL_PTR_ARRAYSIZE, L_Stack::n, L_Stack::nalloc, NULL, and PROCNAME.
Referenced by identifyWatershedBasin(), pixConnCompBB(), pixConnCompPixa(), pixCountConnComp(), and wshedApply().
Input: &lstack (<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 lstack. So if the items require their own destroy function, they must be destroyed before the lstack. (3) To destroy the lstack, we destroy the ptr array, then the lstack, and then null the contents of the input ptr.
Definition at line 104 of file stack.c.
References L_Stack::array, L_Stack::auxstack, FREE, L_WARNING, L_WARNING_INT, lstackDestroy(), lstackRemove(), L_Stack::n, NULL, and PROCNAME.
Referenced by lqueueDestroy(), lstackDestroy(), pixConnCompBB(), pixConnCompPixa(), pixCountConnComp(), and wshedApply().
Input: lstack item to be added to the lstack Return: 0 if OK; 1 on error.
Definition at line 150 of file stack.c.
References L_Stack::array, ERROR_INT, lstackExtendArray(), L_Stack::n, L_Stack::nalloc, and PROCNAME.
Referenced by popFillseg(), popNewPixel(), popWSPixel(), pushFillseg(), and pushFillsegBB().
void* lstackRemove | ( | L_STACK * | lstack | ) |
Input: lstack Return: ptr to item popped from the top of the lstack, or null if the lstack is empty or on error
Definition at line 180 of file stack.c.
References L_Stack::array, ERROR_PTR, L_Stack::n, NULL, and PROCNAME.
Referenced by lstackDestroy(), popFillseg(), pushFillseg(), pushFillsegBB(), pushNewPixel(), and pushWSPixel().
Input: lstack Return: 0 if OK; 1 on error
Definition at line 206 of file stack.c.
References L_Stack::array, ERROR_INT, L_Stack::nalloc, NULL, PROCNAME, and reallocNew().
Referenced by lstackAdd().
Input: lstack Return: count, or 0 on error
Definition at line 230 of file stack.c.
References ERROR_INT, L_Stack::n, and PROCNAME.
Referenced by pixSeedfill4(), pixSeedfill4BB(), pixSeedfill8(), pixSeedfill8BB(), pushFillseg(), pushFillsegBB(), pushNewPixel(), and pushWSPixel().
Input: stream lstack Return: 0 if OK; 1 on error
Definition at line 253 of file stack.c.
References L_Stack::array, ERROR_INT, L_Stack::n, L_Stack::nalloc, and PROCNAME.
const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static] |
Definition at line 51 of file stack.c.
Referenced by lstackCreate().