| 1198 cx_arl_iterator, |
1198 cx_arl_iterator, |
| 1199 }; |
1199 }; |
| 1200 |
1200 |
| 1201 CxList *cxArrayListCreate( |
1201 CxList *cxArrayListCreate( |
| 1202 const CxAllocator *allocator, |
1202 const CxAllocator *allocator, |
| 1203 cx_compare_func comparator, |
|
| 1204 size_t elem_size, |
1203 size_t elem_size, |
| 1205 size_t initial_capacity |
1204 size_t initial_capacity |
| 1206 ) { |
1205 ) { |
| 1207 if (allocator == NULL) { |
1206 if (allocator == NULL) { |
| 1208 allocator = cxDefaultAllocator; |
1207 allocator = cxDefaultAllocator; |
| 1209 } |
1208 } |
| 1210 |
1209 |
| 1211 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list)); |
1210 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list)); |
| 1212 if (list == NULL) return NULL; |
1211 if (list == NULL) return NULL; |
| 1213 cx_list_init((CxList*)list, &cx_array_list_class, |
1212 cx_list_init((CxList*)list, &cx_array_list_class, |
| 1214 allocator, comparator, elem_size); |
1213 allocator, elem_size); |
| 1215 list->capacity = initial_capacity; |
1214 list->capacity = initial_capacity; |
| 1216 |
1215 |
| 1217 // allocate the array after the real elem_size is known |
1216 // allocate the array after the real elem_size is known |
| 1218 list->data = cxCalloc(allocator, initial_capacity, |
1217 list->data = cxCalloc(allocator, initial_capacity, |
| 1219 list->base.collection.elem_size); |
1218 list->base.collection.elem_size); |