src/linked_list.c

changeset 509
0d3c6075f82c
parent 508
8aea65ae1eaf
child 521
e5dc54131d55
equal deleted inserted replaced
508:8aea65ae1eaf 509:0d3c6075f82c
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/linked_list.h" 29 #include "cx/linked_list.h"
30 #include "cx/utils.h"
30 #include <stdint.h> 31 #include <stdint.h>
31 #include <string.h> 32 #include <string.h>
32 #include <assert.h> 33 #include <assert.h>
33 34
34 /* LOW LEVEL LINKED LIST FUNCTIONS */ 35 /* LOW LEVEL LINKED LIST FUNCTIONS */
321 n++; 322 n++;
322 } 323 }
323 324
324 // Update pointer 325 // Update pointer
325 if (loc_prev >= 0) ll_prev(sorted[0]) = NULL; 326 if (loc_prev >= 0) ll_prev(sorted[0]) = NULL;
326 for (size_t i = 0; i < length - 1; i++) { 327 cx_for_n (i, length - 1) {
327 cx_linked_list_link(sorted[i], sorted[i + 1], loc_prev, loc_next); 328 cx_linked_list_link(sorted[i], sorted[i + 1], loc_prev, loc_next);
328 } 329 }
329 ll_next(sorted[length - 1]) = NULL; 330 ll_next(sorted[length - 1]) = NULL;
330 331
331 void *ret = sorted[0]; 332 void *ret = sorted[0];
816 size_t num_items, 817 size_t num_items,
817 void const *array 818 void const *array
818 ) { 819 ) {
819 CxList *list = cxLinkedListCreate(allocator, comparator, item_size); 820 CxList *list = cxLinkedListCreate(allocator, comparator, item_size);
820 if (list == NULL) return NULL; 821 if (list == NULL) return NULL;
821 for (size_t i = 0; i < num_items; i++) { 822 cx_for_n (i, num_items) {
822 if (0 != cxListAdd(list, ((const unsigned char *) array) + i * item_size)) { 823 if (0 != cxListAdd(list, ((const unsigned char *) array) + i * item_size)) {
823 return cx_ll_default_destructor(list); 824 return cx_ll_default_destructor(list);
824 } 825 }
825 } 826 }
826 return list; 827 return list;

mercurial