src/array_list.c

changeset 607
2d99e978dc34
parent 606
314e9288af2f
child 610
de5d3ee6435f
equal deleted inserted replaced
606:314e9288af2f 607:2d99e978dc34
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "cx/array_list.h" 29 #include "cx/array_list.h"
30 30
31 /* LOW LEVEL ARRAY LIST FUNCTIONS */
32
33
34
35 /* HIGH LEVEL ARRAY LIST FUNCTIONS */
36
37 typedef struct {
38 struct cx_list_s base;
39 void *data;
40 } cx_array_list;
41
42 static void cx_arl_destructor(struct cx_list_s *list) {
43 cx_array_list *arl = (cx_array_list*) list;
44 cxFree(list->allocator, arl->data);
45 }
46
47 static int cx_arl_add(
48 struct cx_list_s *list,
49 void const *elem
50 ) {
51 return 1;
52 }
53
54 static int cx_arl_insert(
55 struct cx_list_s *list,
56 size_t index,
57 void const *elem
58 ) {
59 return 1;
60 }
61
62 static int cx_arl_insert_iter(
63 struct cx_iterator_s *iter,
64 void const *elem,
65 int prepend
66 ) {
67 return 1;
68 }
69
70 static int cx_arl_remove(
71 struct cx_list_s *list,
72 size_t index
73 ) {
74 return 1;
75 }
76
77 static void * cx_arl_at(
78 struct cx_list_s const *list,
79 size_t index
80 ) {
81 return NULL;
82 }
83
84 static size_t cx_arl_find(
85 struct cx_list_s const *list,
86 void const *elem
87 ) {
88 return 0;
89 }
90
91 static void cx_arl_sort(struct cx_list_s *list) {
92
93 }
94
95 static int cx_arl_compare(
96 struct cx_list_s const *list,
97 struct cx_list_s const *other
98 ) {
99
100 }
101
102 static void cx_arl_reverse(struct cx_list_s *list) {
103
104 }
105
106 static struct cx_iterator_s cx_arl_iterator(
107 struct cx_list_s *list,
108 size_t index
109 ) {
110 struct cx_iterator_s iter;
111
112 return iter;
113 }
114
115 static cx_list_class cx_array_list_class = {
116 cx_arl_destructor,
117 cx_arl_add,
118 cx_arl_insert,
119 cx_arl_insert_iter,
120 cx_arl_remove,
121 cx_arl_at,
122 cx_arl_find,
123 cx_arl_sort,
124 cx_arl_compare,
125 cx_arl_reverse,
126 cx_arl_iterator,
127 };
128
31 CxList *cxArrayListCreate( 129 CxList *cxArrayListCreate(
32 CxAllocator const *allocator, 130 CxAllocator const *allocator,
33 CxListComparator comparator, 131 CxListComparator comparator,
34 size_t item_size, 132 size_t item_size,
35 size_t initial_capacity 133 size_t initial_capacity
36 ) { 134 ) {
37 return NULL; 135 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list));
136 if (list == NULL) return NULL;
137
138 list->data = cxCalloc(allocator, initial_capacity, item_size);
139 if (list->data == NULL) {
140 cxFree(allocator, list);
141 return NULL;
142 }
143
144 list->base.cl = &cx_array_list_class;
145 list->base.allocator = allocator;
146 list->base.cmpfunc = comparator;
147 list->base.itemsize = item_size;
148 list->base.capacity = initial_capacity;
149
150 return (CxList *) list;
38 } 151 }

mercurial