00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00022 #ifndef XANLIB_H
00023 #define XANLIB_H
00024
00025 #include <semaphore.h>
00026 #include <pthread.h>
00027 #include <stddef.h>
00028 #include <stdbool.h>
00029
00088 typedef struct XanListItem{
00089 void * data;
00090 struct XanListItem * next;
00091 struct XanListItem * prev;
00092 } XanListItem;
00093
00099 typedef struct XanList{
00100
00101
00102 void * (*alloc) (size_t size);
00103 void (*free) (void *address);
00104 void * (*clone) (void *data);
00105 int len;
00106 XanListItem *firstItem;
00107 XanListItem *lastItem;
00108 pthread_mutex_t itemsMutex;
00109
00110
00111 void (*synchAppendList) (struct XanList *list, struct XanList *listToAppend);
00112 XanListItem * (*synchAppend) (struct XanList *list, void *data);
00113 XanListItem * (*synchInsert) (struct XanList *list, void *data);
00114 XanListItem * (*synchInsertBefore) (struct XanList *list, XanListItem *prev, void *data);
00115 XanListItem * (*synchInsertAfter) (struct XanList *list, XanListItem *prev, void *data);
00116 void (*synchDelete) (struct XanList *list, void *data);
00117 void (*synchDeleteAll) (struct XanList *list, void *data);
00118 void (*synchDeleteItem) (struct XanList *list, XanListItem *item);
00119 XanListItem * (*synchFirst) (struct XanList *list);
00120 XanListItem * (*synchLast) (struct XanList *list);
00121 void (*synchDestroyList) (struct XanList *list);
00122 void (*synchDestroyListAndData) (struct XanList *list);
00123 void (*synchEmptyOutList) (struct XanList *list);
00124 void * (*synchData) (struct XanList *list, XanListItem *item);
00125 void ** (*synchGetSlotData) (struct XanList *list, XanListItem *item);
00126 XanListItem * (*synchNext) (struct XanList *list, XanListItem *item);
00127 XanListItem * (*synchPrev) (struct XanList *list, XanListItem *item);
00128 int (*synchLength) (struct XanList *list);
00129 struct XanList * (*synchCloneList) (struct XanList *list);
00130 void (*synchSetCloneFunction) (struct XanList *list, void * (*cloneFunction) (void *data));
00131 void * (*synchGetCloneFunction) (struct XanList *list);
00132 XanListItem * (*synchFind) (struct XanList *list, void *data);
00133 int (*synchEqualsInstancesNumber) (struct XanList *list, void *data);
00134 XanListItem * (*synchGetElementFromPositionNumber) (struct XanList *list, int positionNumber);
00135 XanListItem * (*synchMoveToBegin) (struct XanList *list, XanListItem *item);
00136 int (*synchContainsTheSameElements) (struct XanList *list, struct XanList *otherList);
00137 int (*synchShareSomeElements) (struct XanList *list, struct XanList *otherList);
00138 void (*synchDeleteClones) (struct XanList *list);
00140
00141 XanListItem * (*append) (struct XanList *list, void *data);
00142 void (*appendList) (struct XanList *list, struct XanList *listToAppend);
00143 XanListItem * (*insert) (struct XanList *list, void *data);
00144 XanListItem * (*insertBefore) (struct XanList *list, XanListItem *prev, void *data);
00145 XanListItem * (*insertAfter) (struct XanList *list, XanListItem *prev, void *data);
00146 void (*delete) (struct XanList *list, void *data);
00147 void (*deleteAll) (struct XanList *list, void *data);
00148 void (*deleteItem) (struct XanList *list, XanListItem *item);
00149 XanListItem * (*first) (struct XanList *list);
00150 XanListItem * (*last) (struct XanList *list);
00151 void (*destroyList) (struct XanList *list);
00152 void (*destroyListAndData) (struct XanList *list);
00153 void (*emptyOutList) (struct XanList *list);
00154 void * (*data) (struct XanList *list, XanListItem *item);
00155 void ** (*getSlotData) (struct XanList *list, XanListItem *item);
00156 XanListItem * (*next) (struct XanList *list, XanListItem *item);
00157 XanListItem * (*prev) (struct XanList *list, XanListItem *item);
00158 int (*length) (struct XanList *list);
00159 struct XanList * (*cloneList) (struct XanList *list);
00160 void (*setCloneFunction) (struct XanList *list, void * (*cloneFunction) (void *data));
00161 void * (*getCloneFunction) (struct XanList *list);
00162 XanListItem * (*find) (struct XanList *list, void *data);
00163 int (*equalsInstancesNumber) (struct XanList *list, void *data);
00164 XanListItem * (*getElementFromPositionNumber) (struct XanList *list, int positionNumber);
00165 XanListItem * (*moveToBegin) (struct XanList *list, XanListItem *item);
00166 int (*containsTheSameElements) (struct XanList *list, struct XanList *otherList);
00167 int (*shareSomeElements) (struct XanList *list, struct XanList *otherList);
00168 void (*deleteClones) (struct XanList *list);
00169 void (*lock) (struct XanList *list);
00170 void (*unlock) (struct XanList *list);
00171 } XanList;
00172
00178 typedef struct XanVar{
00179
00180 void *data;
00181 sem_t mutex;
00182 void * (*alloc) (size_t size);
00183 void (*free) (void *address);
00184
00185
00186 void * (*synchRead) (struct XanVar *var);
00187 void (*synchWrite) (struct XanVar *var, void *data);
00188
00189 void * (*read) (struct XanVar *var);
00190 void (*write) (struct XanVar *var, void *data);
00191 void (*lock) (struct XanVar *var);
00192 void (*unlock) (struct XanVar *var);
00193 void (*destroyVarAndData) (struct XanVar *var);
00194 } XanVar;
00195
00201 typedef struct XanPipe{
00202
00203
00204 void * (*alloc) (size_t size);
00205 void (*free) (void *addr);
00206 XanList *items;
00207 pthread_mutex_t itemsMutex;
00208 pthread_cond_t itemsCond;
00209
00210
00211 void * (*synchGet) (struct XanPipe *pipe);
00212 XanListItem * (*synchPut) (struct XanPipe *pipe, void *item);
00213 XanListItem * (*synchPutAtEnd) (struct XanPipe *pipe, void *item);
00214 XanListItem * (*synchMoveToEnd) (struct XanPipe *pipe, void *item);
00215 void (*synchDeleteItem) (struct XanPipe *pipe, XanListItem *item);
00216 int (*synchIsEmpty) (struct XanPipe *pipe);
00218 void * (*get) (struct XanPipe *pipe);
00219 XanListItem * (*put) (struct XanPipe *pipe, void *item);
00220 XanListItem * (*putAtEnd) (struct XanPipe *pipe, void *item);
00221 XanListItem * (*moveToEnd) (struct XanPipe *pipe, void *item);
00222 void (*deleteItem) (struct XanPipe *pipe, XanListItem *item);
00223 int (*isEmpty) (struct XanPipe *pipe);
00224 void (*lock) (struct XanPipe *pipe);
00225 void (*unlock) (struct XanPipe *pipe);
00226 void (*destroyPipe) (struct XanPipe *pipe);
00227 } XanPipe;
00228
00234 typedef struct XanStack{
00235
00236
00237 XanList *internalList;
00238 sem_t mutex;
00239
00240
00241 void * (*synchPop) (struct XanStack *stack);
00242 void (*synchPush) (struct XanStack *stack, void *newElement);
00243 int (*synchGetSize) (struct XanStack *stack);
00245 void * (*pop) (struct XanStack *stack);
00246 void (*push) (struct XanStack *stack, void *newElement);
00247 int (*getSize) (struct XanStack *stack);
00248 void (*destroyStack) (struct XanStack *stack);
00249 } XanStack;
00250
00251 bool xanStackSynchContains (XanStack *stack, void *element);
00252 bool xanStackContains (XanStack *stack, void *element);
00253
00259 typedef struct XanNode{
00260
00261
00262 XanList *childrens;
00263 void *data;
00264 struct XanNode *parent;
00265 sem_t mutex;
00266 void * (*alloc) (size_t size);
00267 void (*free) (void *address);
00268 void * (*clone) (void *data);
00269
00270
00271 struct XanNode * (*synchGetParent) (struct XanNode *node);
00272 struct XanNode * (*synchGetNextChildren) (struct XanNode *node, struct XanNode *child);
00273 struct XanNode * (*synchAddNewChildren) (struct XanNode *node, void *childData);
00274 struct XanNode * (*synchCloneTree) (struct XanNode *node);
00275 void (*synchAddChildren) (struct XanNode *node, struct XanNode *child);
00276 void (*synchDeleteChildren) (struct XanNode *node, struct XanNode *child);
00277 void (*synchSetParent) (struct XanNode *node, struct XanNode *parent);
00278 void (*synchSetData) (struct XanNode *node, void *data);
00279 void * (*synchGetData) (struct XanNode *node);
00280 XanList * (*synchGetChildrens) (struct XanNode *node);
00281 void (*synchSetCloneFunction)(struct XanNode *node, void * (*cloneFunction) (void *data));
00282 void (*synchDestroyTree) (struct XanNode *node);
00283 void (*synchDestroyTreeAndData)(struct XanNode *node);
00284 XanList * (*synchToPreOrderList) (struct XanNode *rootNode);
00285 XanList * (*synchToPostOrderList) (struct XanNode *rootNode);
00286 XanList * (*synchToInOrderList) (struct XanNode *rootNode);
00287 struct XanNode * (*synchFind) (struct XanNode *rootNode, void *data);
00289
00290 struct XanNode * (*getParent) (struct XanNode *node);
00291 struct XanNode * (*getNextChildren) (struct XanNode *node, struct XanNode *child);
00292 struct XanNode * (*addNewChildren) (struct XanNode *node, void *childData);
00293 struct XanNode * (*cloneTree) (struct XanNode *node);
00294 void (*addChildren) (struct XanNode *node, struct XanNode *child);
00295 void (*deleteChildren) (struct XanNode *node, struct XanNode *child);
00296 void (*setParent) (struct XanNode *node, struct XanNode *parent);
00297 void (*setData) (struct XanNode *node, void *data);
00298 void * (*getData) (struct XanNode *node);
00299 XanList * (*getChildrens) (struct XanNode *node);
00300 void (*setCloneFunction) (struct XanNode *node, void * (*cloneFunction) (void *data));
00301 void (*destroyTree) (struct XanNode *node);
00302 void (*destroyNode) (struct XanNode *node);
00303 void (*destroyTreeAndData) (struct XanNode *node);
00304 XanList * (*toPreOrderList) (struct XanNode *rootNode);
00305 XanList * (*toPostOrderList) (struct XanNode *rootNode);
00306 XanList * (*toInOrderList) (struct XanNode *rootNode);
00307 struct XanNode * (*find) (struct XanNode *rootNode, void *data);
00308 } XanNode;
00309
00313 typedef struct XanHashTableItem{
00314 bool used;
00315 void *elementID;
00316 void *element;
00317 struct XanHashTableItem *next;
00318 } XanHashTableItem;
00319
00325 typedef struct XanHashTable{
00326
00327
00328 XanHashTableItem *table;
00329 unsigned int primeIndex;
00330 unsigned int length;
00331 unsigned int size;
00332 int hasFixedLength;
00333 float currentLoadFactor;
00334 sem_t mutex;
00335 void * (*alloc) (size_t size);
00336 void * (*realloc) (void *oldAddress, size_t newSize);
00337 void (*free) (void *addr);
00338 unsigned int (*hash) (void *element);
00339 int (*equals) (void *key1, void *key2);
00340 void * (*clone) (void *data);
00341
00342
00343 void (*synchInsert) (struct XanHashTable *table, void *key, void *element);
00344 void * (*synchLookup) (struct XanHashTable *table, void *key);
00345 void (*synchDelete) (struct XanHashTable *table, void *key);
00346 void (*synchDestroy) (struct XanHashTable *table);
00347 XanList * (*synchToList) (struct XanHashTable *table);
00348 XanList * (*synchToSlotList) (struct XanHashTable *table);
00349 int (*synchElementsInside) (struct XanHashTable *table);
00350 struct XanHashTable * (*synchCloneHashTable) (struct XanHashTable *table);
00351 void (*synchSetCloneFunction)(struct XanHashTable *table, void * (*cloneFunction) (void *data));
00352 void * (*synchGetCloneFunction)(struct XanHashTable *table);
00354
00355 void (*lock) (struct XanHashTable *table);
00356 void (*unlock) (struct XanHashTable *table);
00357 void (*insert) (struct XanHashTable *table, void *key, void *element);
00358 void * (*lookup) (struct XanHashTable *table, void *key);
00359 void (*delete) (struct XanHashTable *table, void *key);
00360 void (*destroy) (struct XanHashTable *table);
00361 XanList * (*toList) (struct XanHashTable *table);
00362 XanList * (*toSlotList) (struct XanHashTable *table);
00363 struct XanHashTable * (*cloneHashTable) (struct XanHashTable *table);
00364 int (*elementsInside) (struct XanHashTable *table);
00365 void (*setCloneFunction) (struct XanHashTable *table, void * (*cloneFunction) (void *data));
00366 void * (*getCloneFunction) (struct XanHashTable *table);
00367 } XanHashTable;
00368
00377 XanList * XanHashTable_ToItemList (XanHashTable *table);
00378
00379
00391 XanList * xanListNew(void *(*allocFunction) (size_t size), void (*freeFunction) (void *addr), void * (*cloneFunction) (void *addr));
00392
00393
00402 XanVar * xanVarNew(void *(*allocFunction) (size_t size), void (*freeFunction) (void *addr));
00403
00404
00413 XanPipe * xanPipeNew (void *(*allocFunction) (size_t size), void (*freeFunction) (void *addr));
00414
00415
00425 XanNode * xanNodeNew (void *(*allocFunction) (size_t size), void (*freeFunction) (void *addr), void * (*cloneFunction) (void *data));
00426
00427
00428 XanStack * xanStackNew (void *(*allocFunction) (size_t size), void (*freeFunction) (void *addr), void * (*cloneFunction) (void *data));
00429
00430
00436 XanHashTable * xanHashTableNew(unsigned int length, int hasFixedLength, void *(*allocFunction) (size_t size), void *(*reallocFunction)(void *addr, size_t newSize), void (*freeFunction) (void *addr), unsigned int (*hashFunction) (void *element), int (*equalsFunction) (void *key1, void *key2));
00437
00438
00446 void print_err (char * message, int err);
00447
00455 void print_ascii_err (signed char * message, int err);
00456
00465 int str_has_suffix(char *string, char *suffix);
00466
00467 void libxanCompilationFlags(char *buffer, int bufferLength);
00468
00469 void libxanCompilationTime (char *buffer, int bufferLength);
00470
00471 char * libxanVersion();
00472
00473
00474
00475
00482 typedef struct XanBitSet {
00483 size_t *data;
00484 size_t length;
00485 } XanBitSet;
00486
00490 XanBitSet *XanBitSet_Alloc(size_t length);
00491
00495 void XanBitSet_ClearAll(XanBitSet *set);
00496
00500 void XanBitSet_SetAll(XanBitSet *set);
00501
00506 void XanBitSet_Subtract(XanBitSet *fromThis, XanBitSet *subtractThis);
00507
00511 void XanBitSet_Free(XanBitSet *set);
00512
00516 void XanBitSet_Intersect(XanBitSet *dest, XanBitSet *src);
00517
00521 int XanBitSet_GetCountOfBitsSet(XanBitSet *set);
00522
00526 bool XanBitSet_Equal(XanBitSet *bs1, XanBitSet *bs2);
00527
00531 XanBitSet* XanBitSet_Clone(XanBitSet *src);
00532
00533 void XanBitSet_Copy(XanBitSet *dest, XanBitSet *src);
00534
00538 void XanBitSet_ClearBit(XanBitSet *set, size_t pos);
00539
00543 void XanBitSet_SetBit(XanBitSet *set, size_t pos);
00544
00548 bool XanBitSet_IsBitSet(XanBitSet *set, size_t pos);
00549
00554 bool XanBitSet_IsSubSetOf(XanBitSet *setA, XanBitSet *setB);
00555
00559 void XanBitSet_Print(XanBitSet *set, int cr);
00560
00561 #endif