AcePerl
view release on metacpan or search on metacpan
acelib/wh/array.h view on Meta::CPAN
#endif /* ARRAY_CHECK */
/* only use arr() when there is no danger of needing expansion */
Array arrayTruncatedCopy (Array a, int x1, int x2) ;
void arrayStatus (int *nmadep,int* nusedp, int *memAllocp, int *memUsedp) ;
int arrayReportMark (void) ; /* returns current array number */
void arrayReport (int j) ; /* write stderr about all arrays since j */
#define arrayMax(ar) ((ar)->max)
#define arrayForceFeed(ar,j) (uArray(ar,j), (ar)->max = (j))
#define arrayExists(ar) ((ar) && (ar)->magic == ARRAY_MAGIC ? (ar)->id : 0 )
/* JTM's package to hold sorted arrays of ANY TYPE */
BOOL arrayInsert(Array a, void * s, int (*order)(void*, void*));
BOOL arrayRemove(Array a, void * s, int (*order)(void*, void*));
void arraySort(Array a, int (*order)(void*, void*)) ;
void arraySortPos (Array a, int pos, int (*order)(void*, void*));
void arrayCompress(Array a) ;
BOOL arrayFind(Array a, void *s, int *ip, int (*order)(void*, void*));
BOOL arrayIsEntry(Array a, int i, void *s);
/************** Stack package **************/
typedef struct StackStruct /* assumes objects <= 16 bytes long */
{ Array a ;
int magic ;
char* ptr ; /* current end pointer */
char* pos ; /* potential internal pointer */
char* safe ; /* need to extend beyond here */
BOOL textOnly; /* If this is set, don't align the stack.
This (1) save space (esp on ALPHA) and
(2) provides stacks which can be stored and got
safely between architectures. Once you've set this,
using stackTextOnly() only pushText, popText, etc,
no other types. */
} *Stack ;
/* as with ArrayStruct, the user should NEVER access StackStruct
members directly - only through the subroutines/macros
*/
#if !defined(MEM_DEBUG)
Stack stackHandleCreate (int n, STORE_HANDLE handle) ;
#else
Stack stackHandleCreate_dbg (int n, STORE_HANDLE handle,
const char *hfname,int hlineno) ;
#define stackHandleCreate(n, h) stackHandleCreate_dbg(n, h, __FILE__, __LINE__)
#endif
#define stackCreate(n) stackHandleCreate(n, 0)
Stack stackReCreate (Stack s, int n) ;
Stack stackCopy (Stack, STORE_HANDLE handle) ;
void stackTextOnly(Stack s);
void uStackDestroy (Stack s);
#define stackDestroy(x) ((x) ? uStackDestroy(x), (x)=0, TRUE : FALSE)
void stackExtend (Stack s, int n) ;
void stackClear (Stack s) ;
#define stackEmpty(stk) ((stk)->ptr <= (stk)->a->base)
#define stackExists(stk) ((stk) && (stk)->magic == STACK_MAGIC ? arrayExists((stk)->a) : 0)
/* Stack alignment: we use two strategies: the smallest type we push is
a short, so if the required alignment is to 2 byte boundaries, we
push each type to its size, and alignments are kept.
Otherwise, we push each type to STACK_ALIGNMENT, this ensures
alignment but can waste space. On machines with 32 bits ints and
pointers, we make satck alignment 4 bytes, and do the consequent unaligned
access to doubles by steam.
Characters and strings are aligned separately to STACK_ALIGNMENT.
*/
#if (STACK_ALIGNMENT<=2)
#define push(stk,x,type) ((stk)->ptr < (stk)->safe ? \
( *(type *)((stk)->ptr) = (x) , (stk)->ptr += sizeof(type)) : \
(stackExtend (stk,16), \
*(type *)((stk)->ptr) = (x) , (stk)->ptr += sizeof(type)) )
#define pop(stk,type) ( ((stk)->ptr -= sizeof(type)) >= (stk)->a->base ? \
*((type*)((stk)->ptr)) : \
(messcrash ("User stack underflow"), *((type*)0)) )
#define stackNext(stk,type) (*((type*)( (stk)->pos += sizeof(type) ) - 1 ) )
#else
#define push(stk,x,type) ((stk)->ptr < (stk)->safe ? \
( *(type *)((stk)->ptr) = (x) , (stk)->ptr += STACK_ALIGNMENT) : \
(stackExtend (stk,16), \
*(type *)((stk)->ptr) = (x) , (stk)->ptr += STACK_ALIGNMENT) )
#define pop(stk,type) ( ((stk)->ptr -= STACK_ALIGNMENT) >= (stk)->a->base ? \
*((type*)((stk)->ptr)) : \
(messcrash ("User stack underflow"), *((type*)0)) )
#define stackNext(stk,type) (*((type*)( ((stk)->pos += STACK_ALIGNMENT ) - \
STACK_ALIGNMENT )) )
#endif
#if STACK_DOUBLE_ALIGNMENT > STACK_ALIGNMENT
void ustackDoublePush(Stack stk, double x);
double ustackDoublePop(Stack stk);
double stackDoubleNext(Stack stk);
#define pushDouble(stk,x) ustackDoublePush(stk, x)
#define popDouble(stk) ustackDoublePop(stk)
#define stackDoubleNext(stk) ustackDoubleNext(stk)
#else
#define pushDouble(stk,x) push(stk, x, double)
#define popDouble(stk) pop(stk, double)
#define stackDoubleNext(stk) stackNext(stk, double)
#endif
void pushText (Stack s, char *text) ;
char* popText (Stack s) ; /* returns last text and moves pointer before it */
void catText (Stack s, char *text) ; /* like strcat */
void stackTokeniseTextOn(Stack s, char *text, char *delimiters) ; /* tokeniser */
int stackMark (Stack s) ; /* returns a mark of current ptr */
int stackPos (Stack s) ; /* returns a mark of current pos, useful with stackNextText */
void stackCursor (Stack s, int mark) ; /* sets ->pos to mark */
#define stackAtEnd(stk) ((stk)->pos >= (stk)->ptr)
char* stackNextText (Stack s) ;
#define stackText(stk,mark) ((char*)((stk)->a->base + (mark)))
( run in 1.097 second using v1.01-cache-2.11-cpan-d8267643d1d )