00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042 #ifndef DEF_ARRAY_H
00043 #define DEF_ARRAY_H
00044
00045
00046
00047
00048
00049
00050
00051
00052
00056 typedef struct ArrayStruct
00057 { char* base ;
00058 int dim ;
00059 int size ;
00060 int max ;
00061 } *Array ;
00062
00063
00064
00065
00066
00067 extern Array uArrayCreate (int n, int size) ;
00068 extern void uArrayDestroy (Array a) ;
00069 extern char *uArray (Array a, int index) ;
00070 extern char *uArrCheck (Array a, int index) ;
00071 extern char *uArrayCheck (Array a, int index) ;
00072 extern char *uArrPop(Array a) ;
00073
00077 #define arrayCreate(n,type) uArrayCreate(n,sizeof(type))
00078
00082 #define arrayDestroy(a) ((a) ? uArrayDestroy(a), a=NULL, 1 : 0)
00083
00087 #define arrayMax(ar) ((ar)->max)
00088
00089
00090 #if (defined(ARRAY_CHECK) && !defined(ARRAY_NO_CHECK))
00091 #define arrp(ar,i,type) ((type*)uArrCheck(ar,i))
00092 #define arru(ar,i,type) (*(type*)uArrCheck(ar,i))
00093 #define arrayp(ar,i,type) ((type*)uArrayCheck(ar,i))
00094 #define array(ar,i,type) (*(type*)uArrayCheck(ar,i))
00095 #else
00096 #define arru(ar,i,type) ((*(type*)((ar)->base + (i)*(ar)->size)))
00097 #define arrp(ar,i,type) (((type*)((ar)->base + (i)*(ar)->size)))
00098 #define arrayp(ar,i,type) ((type*)uArray(ar,i))
00099 #define array(ar,i,type) (*(type*)uArray(ar,i))
00100 #endif
00101
00102
00103
00104 extern Array arrayCopy (Array a) ;
00105 extern void arrayMove(Array from, int start, int end, Array to) ;
00106 extern void arrayClear(Array a) ;
00107
00108
00109 #define arraySetMax(ar,j) (uArray(ar,j), (ar)->max = (j))
00110
00111 extern int arrayNumber(void) ;
00112
00113
00114
00115 #define ARRAYORDERF int(*)(void *,void *)
00116 #define arrayInsert(a,elem,order) arrayFindInsert(a,elem,NULL,order)
00117 extern int arrayFindInsert(Array a, void *s, int *ip, int (*order)(void*,void*));
00118 extern int arrayRemove(Array a, void * s, int (*order)(void*,void*));
00119 extern int arrayRemoveD(Array a,int i);
00120 extern void arraySort(Array a, int (*order)(void*,void*)) ;
00121 extern int arrayFind(Array a, void *s, int *ip, int (*order)(void*,void*));
00122 extern int arrayIsEntry(Array a, int i, void *s);
00123 extern int arrayStrcmp(char **s1, char **s2) ;
00124 extern int arrayIntcmp(int *ip1, int *ip2) ;
00125 extern void arrayByteUniq(Array a) ;
00126 extern void arrayUniq(Array a, Array b, int (*order)(void*,void*)) ;
00127 extern int arrayDoublecmp(double *dp1, double *dp2) ;
00128
00129
00130
00131
00132
00133
00134
00135 #define Stacka Array
00136 #define stackCreate arrayCreate
00137 #define stackDestroy arrayDestroy
00138 #define stackDepth arrayMax
00139 #define stackPush(a,elem,type) (array(a,arrayMax(a),type)=(elem))
00140 #define stackTopp(a,type) (arrp(a,arrayMax(a)-1,type))
00141 #define stackTop(a,type) (arru(a,arrayMax(a)-1,type))
00142 #define stackPop(a,type) ((*(type*)uArrPop(a)))
00143
00144
00145 #endif
00146