comparison ListOfArrays.h @ 0:bc4b3434367f

bare bones - create, add, iter
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Mon, 19 Dec 2011 13:25:30 +0100
parents
children fd441e4d0908
comparison
equal deleted inserted replaced
-1:000000000000 0:5a2d77f93c8e
1 /*
2 * File: ListOfArrays.h
3 * Author: Nina Engelhardt
4 *
5 * Created on December 16, 2011, 2:06 PM
6 */
7
8 #ifndef LISTOFARRAYS_H
9 #define LISTOFARRAYS_H
10
11 typedef struct {
12 ArrayFragment* next;
13 void* data;
14 } ArrayFragment;
15
16 typedef struct {
17 ArrayFragment* first;
18 ArrayFragment* last;
19 size_t entry_size;
20 int num_entries_per_fragment;
21 int next_free_index;
22 } ListOfArrays;
23
24 #define addToListOfArrays(type,value,list) do { \
25 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
26 if(offset_in_fragment == 0){ \
27 ArrayFragment* newBlock = (ArrayFragment*) VMS__malloc(sizeof(ArrayFragment*) + list->entry_size * list->num_entries_per_fragment); \
28 newBlock->next == NULL; \
29 if(list->first == NULL) {\
30 list->first = newBlock; \
31 } \
32 if(list->last != NULL) { \
33 list->last->next = newBlock; \
34 } \
35 list->last = newBlock; \
36 } \
37 (type*) typedFragment = (type*) list->last->data; \
38 typedFragment[offset_in_fragment] = value; \
39 } while (0)
40
41 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void *
42
43 #endif /* LISTOFARRAYS_H */
44