150 } |
150 } |
151 |
151 |
152 static void *cx_ll_at(cx_list_s *list, size_t index) { |
152 static void *cx_ll_at(cx_list_s *list, size_t index) { |
153 cx_linked_list *ll = (cx_linked_list *) list; |
153 cx_linked_list *ll = (cx_linked_list *) list; |
154 struct cx_linked_list_node *node; |
154 struct cx_linked_list_node *node; |
155 if (index > list->size / 2) { |
155 if (index >= list->size) { |
|
156 node = NULL; |
|
157 } else if (index > list->size / 2) { |
|
158 node = cx_linked_list_at(ll->end, list->size, CX_LL_LOC_PREV, index); |
|
159 } else { |
156 node = cx_linked_list_at(ll->begin, 0, CX_LL_LOC_NEXT, index); |
160 node = cx_linked_list_at(ll->begin, 0, CX_LL_LOC_NEXT, index); |
157 } else { |
161 } |
158 node = cx_linked_list_at(ll->end, list->size, CX_LL_LOC_PREV, index); |
162 return node == NULL ? NULL : &node->payload; |
159 } |
|
160 return &node->payload; |
|
161 } |
163 } |
162 |
164 |
163 static size_t cx_ll_find(cx_list_s *list, void *elem) { |
165 static size_t cx_ll_find(cx_list_s *list, void *elem) { |
164 CxListComparator cmp = list->cmpfunc; |
166 CxListComparator cmp = list->cmpfunc; |
165 cx_linked_list *ll = (cx_linked_list *) list; |
167 cx_linked_list *ll = (cx_linked_list *) list; |