1 /*====================================================================* 2 - Copyright (C) 2001 Leptonica. All rights reserved. 3 - This software is distributed in the hope that it will be 4 - useful, but with NO WARRANTY OF ANY KIND. 5 - No author or distributor accepts responsibility to anyone for the 6 - consequences of using this software, or for whether it serves any 7 - particular purpose or works at all, unless he or she says so in 8 - writing. Everyone is granted permission to copy, modify and 9 - redistribute this source code, for commercial or non-commercial 10 - purposes, with the following restrictions: (1) the origin of this 11 - source code must not be misrepresented; (2) modified versions must 12 - be plainly marked as such; and (3) this notice may not be removed 13 - or altered from any source or modified source distribution. 14 *====================================================================*/ 15 16 #ifndef LEPTONICA_STACK_H 17 #define LEPTONICA_STACK_H 18 19 /* 20 * stack.h 21 * 22 * Expandable pointer stack for arbitrary void* data. 23 * 24 * The L_Stack is an array of void * ptrs, onto which arbitrary 25 * objects can be stored. At any time, the number of 26 * stored objects is stack->n. The object at the bottom 27 * of the stack is at array[0]; the object at the top of 28 * the stack is at array[n-1]. New objects are added 29 * to the top of the stack, at the first available location, 30 * which is array[n]. Objects are removed from the top of the 31 * stack. When an attempt is made to remove an object from an 32 * empty stack, the result is null. When the stack becomes 33 * filled, so that n = nalloc, the size is doubled. 34 * 35 * The auxiliary stack can be used to store and remove 36 * objects for re-use. It must be created by a separate 37 * call to pstackCreate(). [Just imagine the chaos if 38 * pstackCreate() created the auxiliary stack!] 39 * pstackDestroy() checks for the auxiliary stack and removes it. 40 */ 41 42 43 /* Note that array[n] is the first null ptr in the array */ 44 struct L_Stack 45 { 46 l_int32 nalloc; /* size of ptr array */ 47 l_int32 n; /* number of stored elements */ 48 void **array; /* ptr array */ 49 struct L_Stack *auxstack; /* auxiliary stack */ 50 }; 51 typedef struct L_Stack L_STACK; 52 53 54 #endif /* LEPTONICA_STACK_H */ 55 56