![]() |
Leptonica 1.85.0
Image processing and image analysis suite
|
#include "allheaders.h"Go to the source code of this file.
Functions | |
| static l_int32 | lstackExtendArray (L_STACK *lstack) |
| L_STACK * | lstackCreate (l_int32 n) |
| void | lstackDestroy (L_STACK **plstack, l_int32 freeflag) |
| l_ok | lstackAdd (L_STACK *lstack, void *item) |
| void * | lstackRemove (L_STACK *lstack) |
| l_int32 | lstackGetCount (L_STACK *lstack) |
| l_ok | lstackPrint (FILE *fp, L_STACK *lstack) |
Variables | |
| static const l_uint32 | MaxPtrArraySize = 100000 |
| static const l_int32 | InitialPtrArraySize = 20 |
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()
static l_int32 lstackExtendArray()
l_int32 lstackGetCount()
Text description
l_int32 lstackPrint()
Definition in file stack.c.
| l_ok lstackAdd | ( | L_STACK * | lstack, |
| void * | item ) |
| [in] | lstack | |
| [in] | item | to be added to the lstack |
Definition at line 166 of file stack.c.
References L_Stack::array, lstackExtendArray(), L_Stack::n, and L_Stack::nalloc.
| L_STACK * lstackCreate | ( | l_int32 | n | ) |
| [in] | n | initial ptr array size; use 0 for default |
Definition at line 82 of file stack.c.
References L_Stack::array, InitialPtrArraySize, lstackDestroy(), L_Stack::n, and L_Stack::nalloc.
| void lstackDestroy | ( | L_STACK ** | plstack, |
| l_int32 | freeflag ) |
| [in,out] | plstack | will be set to null before returning |
| [in] | freeflag | TRUE to free each remaining struct in the array |
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 122 of file stack.c.
References L_Stack::array, L_Stack::auxstack, lstackDestroy(), lstackRemove(), and L_Stack::n.
Referenced by lstackCreate(), and lstackDestroy().
|
static |
| [in] | lstack |
Definition at line 220 of file stack.c.
References L_Stack::array, and L_Stack::nalloc.
Referenced by lstackAdd().
| l_int32 lstackGetCount | ( | L_STACK * | lstack | ) |
| [in] | lstack |
Definition at line 242 of file stack.c.
References L_Stack::n.
| l_ok lstackPrint | ( | FILE * | fp, |
| L_STACK * | lstack ) |
| [in] | fp | file stream |
| [in] | lstack |
Definition at line 263 of file stack.c.
References L_Stack::array, L_Stack::n, and L_Stack::nalloc.
| void * lstackRemove | ( | L_STACK * | lstack | ) |
| [in] | lstack |
Definition at line 196 of file stack.c.
References L_Stack::array, and L_Stack::n.
Referenced by lstackDestroy().
|
static |