Leptonica  1.82.0
Image processing and image analysis suite
stack.c File Reference
#include "allheaders.h"

Go to the source code of this file.

Functions

static l_int32 lstackExtendArray (L_STACK *lstack)
 
L_STACKlstackCreate (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
 

Detailed Description

     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.

Function Documentation

◆ lstackAdd()

l_ok lstackAdd ( L_STACK lstack,
void *  item 
)

lstackAdd()

Parameters
[in]lstack
[in]itemto be added to the lstack
Returns
0 if OK; 1 on error.

Definition at line 170 of file stack.c.

References L_Stack::array, lstackExtendArray(), L_Stack::n, and L_Stack::nalloc.

Referenced by popFillseg(), pushFillseg(), and pushFillsegBB().

◆ lstackCreate()

L_STACK* lstackCreate ( l_int32  n)

lstackCreate()

Parameters
[in]ninitial ptr array size; use 0 for default
Returns
lstack, or NULL on error

Definition at line 82 of file stack.c.

Referenced by identifyWatershedBasin(), and wshedApply().

◆ lstackDestroy()

void lstackDestroy ( L_STACK **  plstack,
l_int32  freeflag 
)

lstackDestroy()

Parameters
[in,out]plstackwill be set to null before returning
[in]freeflagTRUE to free each remaining struct in the array
Returns
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 124 of file stack.c.

References L_Stack::array, L_Stack::auxstack, lstackRemove(), and L_Stack::n.

Referenced by lqueueDestroy().

◆ lstackExtendArray()

static l_int32 lstackExtendArray ( L_STACK lstack)
static

lstackExtendArray()

Parameters
[in]lstack
Returns
0 if OK; 1 on error

Definition at line 228 of file stack.c.

References L_Stack::array, L_Stack::nalloc, and reallocNew().

Referenced by lstackAdd().

◆ lstackGetCount()

l_int32 lstackGetCount ( L_STACK lstack)

lstackGetCount()

Parameters
[in]lstack
Returns
count, or 0 on error

Definition at line 252 of file stack.c.

References L_Stack::n.

Referenced by pushFillseg(), and pushFillsegBB().

◆ lstackPrint()

l_ok lstackPrint ( FILE *  fp,
L_STACK lstack 
)

lstackPrint()

Parameters
[in]fpfile stream
[in]lstack
Returns
0 if OK; 1 on error

Definition at line 275 of file stack.c.

References L_Stack::array, L_Stack::n, and L_Stack::nalloc.

◆ lstackRemove()

void* lstackRemove ( L_STACK lstack)

lstackRemove()

Parameters
[in]lstack
Returns
ptr to item popped from the top of the lstack, or NULL if the lstack is empty or on error

Definition at line 202 of file stack.c.

References L_Stack::array, and L_Stack::n.

Referenced by lstackDestroy(), popFillseg(), pushFillseg(), and pushFillsegBB().

Variable Documentation

◆ InitialPtrArraySize

const l_int32 InitialPtrArraySize = 20
static

n'importe quoi

Definition at line 67 of file stack.c.