CAFE
Computational Analysis of gene Family Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utils.h
Go to the documentation of this file.
1 #ifndef __UTILS_H__
2 #define __UTILS_H__
3 
4 #include <stdio.h>
5 
6 #include<stdint.h>
7 
8 typedef void (*freefunc)(void*);
9 /********************************************************************
10  * ArrayList
11  ********************************************************************/
12 typedef struct
13 {
14  void** array;
15  int size;
16  int remain;
17  int step;
18 }ArrayList;
20 
21 extern pArrayList arraylist_new(int step);
22 extern pArrayList arraylist_add(pArrayList pal, void* data);
23 extern void* arraylist_get(pArrayList pal, int idx);
24 extern void arraylist_free(pArrayList pal, freefunc datafree );
25 extern void arraylist_trim(pArrayList pal);
26 extern void arraylist_clear(pArrayList pal);
27 extern void arraylist_sort(pArrayList pal, int (*compar)(const void*, const void*) );
28 extern void arraylist_shuffle(pArrayList pal);
29 
30 
31 /********************************************************************
32  * LinkedLIstItem
33  ********************************************************************/
35 typedef struct tagLinkedListItem
36 {
37  void* data;
38  pLinkedListItem prev;
39  pLinkedListItem next;
41 
42 extern pLinkedListItem linkedlistitem_new(void* data);
43 extern void linkedlistitem_free(pLinkedListItem pitem);
44 
45 /********************************************************************
46  * Vector
47  ********************************************************************/
48 typedef struct tagVector* pVector;
49 typedef struct tagVector
50 {
51  int size;
52  pLinkedListItem head;
53  pLinkedListItem tail;
54  pLinkedListItem cur;
55 }Vector;
56 
57 extern pVector vector_new();
58 extern void vector_free(pVector pvec, freefunc func);
59 extern void vector_add(pVector pvec, void* data);
60 extern void* vector_get(pVector pvec, int idx);
61 extern void vector_rewind(pVector pvec);
62 extern void* vector_next(pVector pvec);
63 extern void vector_sort(pVector pvec, int (*cmp)(const void*,const void*) );
64 extern void* vector_get_by_cmp( pVector pvec, void* data, size_t (*cmp)(const void*,const void*) ) ;
65 extern void vector_remove_by_data(pVector pvec, void* data);
66 extern void vector_dereference_by_data(pVector pvec, void* data);
67 extern pArrayList vector_to_arraylist(pVector pvec);
68 
69 typedef Vector Stack;
70 typedef pVector pStack;
71 
72 extern pStack stack_new();
73 extern void stack_free(pStack pstack);
74 extern void stack_push(pStack pstack, void* data);
75 extern void* stack_pop(pStack pstack);
76 extern int stack_has_items(pStack pstack);
77 
78 
79 /********************************************************************
80  * Etc
81  ********************************************************************/
82 extern void print_error(char* file, char* function, int line, char* message, ... );
83 extern int __cmp_int(const void* a, const void* b);
84 extern int __cmp_double(const void* a, const void* b);
85 
86 #endif
void vector_remove_by_data(pVector pvec, void *data)
Definition: utils.c:245
Definition: utils.h:49
Definition: utils.h:35
void vector_free(pVector pvec, freefunc func)
Definition: utils.c:170
pStack stack_new()
Definition: utils.c:316
pLinkedListItem tail
Definition: utils.h:53
struct tagVector * pVector
Definition: utils.h:48
pLinkedListItem cur
Definition: utils.h:54
void print_error(char *file, char *function, int line, char *message,...)
Definition: utils.c:21
void(* freefunc)(void *)
Definition: utils.h:8
pLinkedListItem prev
Definition: utils.h:38
ArrayList * pArrayList
Definition: utils.h:19
void vector_add(pVector pvec, void *data)
Definition: utils.c:186
void stack_push(pStack pstack, void *data)
Definition: utils.c:326
void arraylist_sort(pArrayList pal, int(*compar)(const void *, const void *))
Definition: utils.c:81
void * data
Definition: utils.h:37
void vector_sort(pVector pvec, int(*cmp)(const void *, const void *))
Definition: utils.c:231
void * stack_pop(pStack pstack)
Definition: utils.c:342
void arraylist_clear(pArrayList pal)
Definition: utils.c:69
struct tagLinkedListItem * pLinkedListItem
Definition: utils.h:34
void * vector_next(pVector pvec)
Definition: utils.c:305
pVector pStack
Definition: utils.h:70
void stack_free(pStack pstack)
Definition: utils.c:321
pLinkedListItem linkedlistitem_new(void *data)
Definition: utils.c:123
pLinkedListItem next
Definition: utils.h:39
void linkedlistitem_free(pLinkedListItem pitem)
Definition: utils.c:132
void * vector_get(pVector pvec, int idx)
Definition: utils.c:202
void ** array
Definition: utils.h:14
void * arraylist_get(pArrayList pal, int idx)
Definition: utils.c:86
pArrayList arraylist_add(pArrayList pal, void *data)
Definition: utils.c:52
int size
Definition: utils.h:51
void * vector_get_by_cmp(pVector pvec, void *data, size_t(*cmp)(const void *, const void *))
Definition: utils.c:215
void arraylist_shuffle(pArrayList pal)
Definition: utils.c:110
Definition: utils.h:12
int __cmp_double(const void *a, const void *b)
Definition: utils.c:14
struct tagLinkedListItem LinkedListItem
int remain
Definition: utils.h:16
int stack_has_items(pStack pstack)
Definition: utils.c:360
void arraylist_free(pArrayList pal, freefunc datafree)
Definition: utils.c:92
pArrayList vector_to_arraylist(pVector pvec)
Definition: utils.c:285
void vector_rewind(pVector pvec)
Definition: utils.c:300
int __cmp_int(const void *a, const void *b)
Definition: utils.c:9
pVector vector_new()
Definition: utils.c:161
Vector Stack
Definition: utils.h:69
void vector_dereference_by_data(pVector pvec, void *data)
Definition: utils.c:265
struct tagVector Vector
pArrayList arraylist_new(int step)
Definition: utils.c:38
pLinkedListItem head
Definition: utils.h:52
void arraylist_trim(pArrayList pal)
Definition: utils.c:75
int size
Definition: utils.h:15
int step
Definition: utils.h:17