ListRet list_insert(TinyList *thiz, size_t index, void *data) { TinyListNode *node = NULL; TinyListNode *cursor = NULL; if((node = list_node_create(data)) == NULL) { return LIST_RET_FAIL; } if(thiz->first == NULL) { thiz->first = node; return LIST_RET_OK; } cursor = list_get_node(thiz, index, 1); if(index < list_length(thiz)) { if(thiz->first == cursor) { thiz->first = node; } else { cursor->prev->next = node; node->prev = cursor->prev; } node->next = cursor; cursor->prev = node; } else { cursor->next = node; node->prev = cursor; } return LIST_RET_OK; }
void list_prepend(list_t *list, void *element) { list_node_t *node = list_node_create(element); node->next = list->head; node->prev = list->tail; list->head = node; list->atcache.headdirt++; list->length++; }
/* _list_append_locked() * * Append an item to the list. The function assumes * the list is already locked. */ static void * _list_append_locked(List l, void *x) { void *v; v = list_node_create(l, l->tail, x); return v; }
/* Creates a new list node and inserts it in the beginning of the list * Arguments: The list the node will be inserted to and the data the node will * contain */ list_node* list_insert_beginning(llist *l, void *data) { if (!l) return NULL; list_node *new_node = list_node_create(data); if (new_node) { new_node->next = l->node; l->node = new_node; } return new_node; }
/* Creates a list node and inserts it after the specified node * Arguments: A node to insert after and the data the new node will contain */ list_node* list_insert_after(list_node *node, void *data) { if (!node) return NULL; list_node *new_node = list_node_create(data); if (new_node) { new_node->next = node->next; node->next = new_node; } return new_node; }
void * list_enqueue(List l, void *x) { void *v; assert(l != NULL); assert(x != NULL); list_mutex_lock(&l->mutex); assert(l->magic == LIST_MAGIC); v = list_node_create(l, l->tail, x); list_mutex_unlock(&l->mutex); return(v); }
void * list_push(List l, void *x) { void *v; assert(l != NULL); assert(x != NULL); list_mutex_lock(&l->mutex); assert(l->magic == LIST_MAGIC); v = list_node_create(l, &l->head, x); list_mutex_unlock(&l->mutex); return(v); }
static void list_insert(list_t l, list_node_t pos, element_t e) { list_node_t new_node; new_node = list_node_create(e); new_node->prev = pos->prev; new_node->next = pos; pos->prev->next = new_node; pos->prev = new_node; ++l->size; }
void * list_insert(ListIterator i, void *x) { void *v; assert(i != NULL); assert(x != NULL); assert(i->magic == LIST_MAGIC); list_mutex_lock(&i->list->mutex); assert(i->list->magic == LIST_MAGIC); v = list_node_create(i->list, i->prev, x); list_mutex_unlock(&i->list->mutex); return(v); }
void list_push(list_t *list, void *element) { list_node_t *node = list_node_create(element); if (!list->head) list->head = node; else { list->tail->next = node; node->prev = list->tail; } list->tail = node; list_atcache_cache(list, node); list->length++; }
void list_insert(list_t l, element_t e) { list_node_t new_node; ASSERT_LIST(l); new_node = list_node_create(e); if (NULL == l->front) l->front = l->rear = new_node; else { l->rear->next = new_node; l->rear = new_node; } ++l->size; }
/* list_prepend() */ void * list_prepend (List l, void *x) { void *v; assert(l != NULL); assert(x != NULL); slurm_mutex_lock(&l->mutex); assert(l->magic == LIST_MAGIC); v = list_node_create(l, &l->head, x); slurm_mutex_unlock(&l->mutex); return v; }
/* Creates a new list node and inserts it at the end of the list * Arguments: The list the node will be inserted to and the data the node will * contain */ list_node* list_insert_end(llist *l, void *data) { list_node *new_node = list_node_create(data); if (l->node == NULL){ l->node = new_node; } else { if (new_node) { list_node *it; for(it = l->node; it; it = it->next) { if (it->next == NULL) { it->next = new_node; break; } } } } return new_node; }