Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ListOfArrays
view ListOfArrays.h @ 1:fd441e4d0908
bugfix
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 19 Dec 2011 17:11:22 +0100 |
| parents | bc4b3434367f |
| children | ef1712d6d7d8 |
line source
1 /*
2 * File: ListOfArrays.h
3 * Author: Nina Engelhardt
4 *
5 * Created on December 16, 2011, 2:06 PM
6 */
8 #ifndef LISTOFARRAYS_H
9 #define LISTOFARRAYS_H
11 #include<stddef.h>
13 typedef struct {
14 void* next;
15 void* data;
16 } ArrayFragment;
18 typedef struct {
19 ArrayFragment* first;
20 ArrayFragment* last;
21 size_t entry_size;
22 int num_entries_per_fragment;
23 int next_free_index;
24 } ListOfArrays;
26 ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block);
28 #define addToListOfArrays(type,value,list) do { \
29 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
30 if(offset_in_fragment == 0){ \
31 ArrayFragment* newBlock = (ArrayFragment*) VMS__malloc(sizeof(ArrayFragment*) + list->entry_size * list->num_entries_per_fragment); \
32 newBlock->next == NULL; \
33 if(list->first == NULL) {\
34 list->first = newBlock; \
35 } \
36 if(list->last != NULL) { \
37 list->last->next = newBlock; \
38 } \
39 list->last = newBlock; \
40 } \
41 type* typedFragment = (type*) &(list->last->data); \
42 typedFragment[offset_in_fragment] = value; \
43 list->next_free_index++; \
44 } while (0)
46 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void *
48 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr);
50 #define getValuefromListOfArrays(type,index,list)
52 #define setValueInListOfArrays(type,index,value,list)
54 #endif /* LISTOFARRAYS_H */
