diff options
Diffstat (limited to 'source/blender/blenlib/intern/BLI_linklist.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_linklist.c | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index 4631d9e6bf2..c903e66057e 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -29,14 +29,9 @@ */ #include "MEM_guardedalloc.h" -#include "BLI_blenlib.h" #include "BLI_linklist.h" #include "BLI_memarena.h" -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - int BLI_linklist_length(LinkNode *list) { if (0) { return list?(1+BLI_linklist_length(list->next)):0; @@ -50,18 +45,28 @@ int BLI_linklist_length(LinkNode *list) { } } -int BLI_linklist_index(struct LinkNode *list, void *ptr) +int BLI_linklist_index(LinkNode *list, void *ptr) { int index; - for (index = 0; list; list= list->next, index++) { + for (index = 0; list; list= list->next, index++) if (list->link == ptr) return index; - } return -1; } +LinkNode *BLI_linklist_find(LinkNode *list, int index) +{ + int i; + + for (i = 0; list; list= list->next, i++) + if (i == index) + return list; + + return NULL; +} + void BLI_linklist_reverse(LinkNode **listp) { LinkNode *rhead= NULL, *cur= *listp; @@ -93,13 +98,13 @@ void BLI_linklist_append(LinkNode **listp, void *ptr) { nlink->next = NULL; if(node == NULL){ - *listp = nlink; - } else { - while(node->next != NULL){ - node = node->next; - } - node->next = nlink; - } + *listp = nlink; + } else { + while(node->next != NULL){ + node = node->next; + } + node->next = nlink; + } } void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) { @@ -110,6 +115,22 @@ void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) { *listp= nlink; } +void BLI_linklist_insert_after(LinkNode **listp, void *ptr) { + LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); + LinkNode *node = *listp; + + nlink->link = ptr; + + if(node) { + nlink->next = node->next; + node->next = nlink; + } + else { + nlink->next = NULL; + *listp = nlink; + } +} + void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) { while (list) { LinkNode *next= list->next; |