src/array_list.c

changeset 763
741a2040fa33
parent 735
b686d0c98c62
child 764
ccbdbd088455
equal deleted inserted replaced
762:4523f6d42512 763:741a2040fa33
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
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 #include "cx/compare.h"
30 #include <assert.h> 31 #include <assert.h>
31 #include <string.h> 32 #include <string.h>
32 33
33 // LOW LEVEL ARRAY LIST FUNCTIONS 34 // LOW LEVEL ARRAY LIST FUNCTIONS
34 35
520 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list)); 521 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list));
521 if (list == NULL) return NULL; 522 if (list == NULL) return NULL;
522 523
523 list->base.cl = &cx_array_list_class; 524 list->base.cl = &cx_array_list_class;
524 list->base.allocator = allocator; 525 list->base.allocator = allocator;
525 list->base.cmpfunc = comparator;
526 list->capacity = initial_capacity; 526 list->capacity = initial_capacity;
527 527
528 if (item_size > 0) { 528 if (item_size > 0) {
529 list->base.item_size = item_size; 529 list->base.item_size = item_size;
530 list->base.cmpfunc = comparator;
530 } else { 531 } else {
531 item_size = sizeof(void *); 532 item_size = sizeof(void *);
533 list->base.cmpfunc = comparator == NULL ? cx_cmp_ptr : comparator;
532 cxListStorePointers((CxList *) list); 534 cxListStorePointers((CxList *) list);
533 } 535 }
534 536
535 // allocate the array after the real item_size is known 537 // allocate the array after the real item_size is known
536 list->data = cxCalloc(allocator, initial_capacity, item_size); 538 list->data = cxCalloc(allocator, initial_capacity, item_size);

mercurial