utility functions to reverse and rotate linklists.

This commit is contained in:
2013-05-11 12:18:12 +00:00
parent a919b0e4c3
commit a19f7899fb
2 changed files with 41 additions and 1 deletions

View File

@@ -71,6 +71,8 @@ void BLI_freelinkN(struct ListBase *listbase, void *vlink);
void BLI_movelisttolist(struct ListBase *dst, struct ListBase *src);
void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src);
void BLI_reverselist(struct ListBase *lb);
void BLI_rotatelist(struct ListBase *lb, LinkData *vlink);
/* create a generic list node containing link to provided data */
struct LinkData *BLI_genericNodeN(void *data);

View File

@@ -543,8 +543,10 @@ int BLI_findstringindex(const ListBase *listbase, const char *id, const int offs
return -1;
}
/**
* Sets dst to a duplicate of the entire contents of src. dst may be the same as src.
*/
void BLI_duplicatelist(ListBase *dst, const ListBase *src)
/* sets dst to a duplicate of the entire contents of src. dst may be the same as src. */
{
struct Link *dst_link, *src_link;
@@ -560,6 +562,42 @@ void BLI_duplicatelist(ListBase *dst, const ListBase *src)
}
}
void BLI_reverselist(ListBase *lb)
{
struct Link *curr = lb->first;
struct Link *prev = NULL;
struct Link *next = NULL;
while(curr) {
next = curr->next;
curr->next = prev;
curr->prev = next;
prev = curr;
curr = next;
}
/* swap first/last */
curr = lb->first;
lb->first = lb->last;
lb->last = curr;
}
/**
* \param vlink Link to make first.
*/
void BLI_rotatelist(ListBase *lb, LinkData *vlink)
{
/* make circular */
((LinkData *)lb->first)->prev = lb->last;
((LinkData *)lb->last)->next = lb->first;
lb->first = vlink;
lb->last = vlink->prev;
((LinkData *)lb->first)->prev = NULL;
((LinkData *)lb->last)->next = NULL;
}
/* create a generic list node containing link to provided data */
LinkData *BLI_genericNodeN(void *data)
{