mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-16 00:21:29 +00:00
add functions to move to start/end of list
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@31442 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
fa6594c545
commit
b6d8004050
2 changed files with 134 additions and 82 deletions
|
@ -260,6 +260,16 @@ GSLinkedListInsertAfter(GSListLink *link, GSLinkedList *list, GSListLink *at);
|
|||
extern void
|
||||
GSLinkedListInsertBefore(GSListLink *link, GSLinkedList *list, GSListLink *at);
|
||||
|
||||
/** Moves the link to the head of the list if it is not already there.
|
||||
*/
|
||||
extern void
|
||||
GSLinkedListMoveToHead(GSListLink *link, GSLinkedList *list);
|
||||
|
||||
/** Moves the link to the tail of the list if it is not already there.
|
||||
*/
|
||||
extern void
|
||||
GSLinkedListMoveToTail(GSListLink *link, GSLinkedList *list);
|
||||
|
||||
/** Removes link from the list.<br />
|
||||
* Updates the head, tail and count variables of list.<br />
|
||||
* Does not release link.
|
||||
|
|
206
GSLinkedList.m
206
GSLinkedList.m
|
@ -282,88 +282,6 @@
|
|||
|
||||
@end
|
||||
|
||||
void
|
||||
GSLinkedListInsertBefore(GSListLink *link, GSLinkedList *list, GSListLink *at)
|
||||
{
|
||||
if (nil == list->head)
|
||||
{
|
||||
list->head = list->tail = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->previous = at->previous;
|
||||
if (nil == link->previous)
|
||||
{
|
||||
list->head = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->previous->next = link;
|
||||
}
|
||||
at->previous = link;
|
||||
link->next = at;
|
||||
}
|
||||
link->owner = list;
|
||||
list->count++;
|
||||
}
|
||||
|
||||
void
|
||||
GSLinkedListInsertAfter(GSListLink *link, GSLinkedList *list, GSListLink *at)
|
||||
{
|
||||
if (nil == list->head)
|
||||
{
|
||||
list->head = list->tail = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next = at->next;
|
||||
if (nil == link->next)
|
||||
{
|
||||
list->tail = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next->previous = link;
|
||||
}
|
||||
at->next = link;
|
||||
link->previous = at;
|
||||
}
|
||||
link->owner = list;
|
||||
list->count++;
|
||||
}
|
||||
|
||||
void
|
||||
GSLinkedListRemove(GSListLink *link, GSLinkedList *list)
|
||||
{
|
||||
if (list->head == link)
|
||||
{
|
||||
list->head = link->next;
|
||||
if (nil != list->head)
|
||||
{
|
||||
list->head->previous = nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
link->previous->next = link->next;
|
||||
}
|
||||
if (list->tail == link)
|
||||
{
|
||||
list->tail = link->previous;
|
||||
if (nil != list->tail)
|
||||
{
|
||||
list->tail->next = nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next->previous = link->previous;
|
||||
}
|
||||
link->next = link->previous = nil;
|
||||
link->owner = nil;
|
||||
list->count--;
|
||||
}
|
||||
|
||||
GSListLink*
|
||||
GSLinkedListFindEqual(NSObject *object, GSLinkedList *list,
|
||||
GSListLink *from, BOOL back)
|
||||
|
@ -451,3 +369,127 @@ GSLinkedListFindIdentical(NSObject *object, GSLinkedList *list,
|
|||
return nil;
|
||||
}
|
||||
|
||||
void
|
||||
GSLinkedListInsertBefore(GSListLink *link, GSLinkedList *list, GSListLink *at)
|
||||
{
|
||||
if (nil == list->head)
|
||||
{
|
||||
list->head = list->tail = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->previous = at->previous;
|
||||
if (nil == link->previous)
|
||||
{
|
||||
list->head = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->previous->next = link;
|
||||
}
|
||||
at->previous = link;
|
||||
link->next = at;
|
||||
}
|
||||
link->owner = list;
|
||||
list->count++;
|
||||
}
|
||||
|
||||
void
|
||||
GSLinkedListInsertAfter(GSListLink *link, GSLinkedList *list, GSListLink *at)
|
||||
{
|
||||
if (nil == list->head)
|
||||
{
|
||||
list->head = list->tail = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next = at->next;
|
||||
if (nil == link->next)
|
||||
{
|
||||
list->tail = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next->previous = link;
|
||||
}
|
||||
at->next = link;
|
||||
link->previous = at;
|
||||
}
|
||||
link->owner = list;
|
||||
list->count++;
|
||||
}
|
||||
|
||||
void
|
||||
GSLinkedListRemove(GSListLink *link, GSLinkedList *list)
|
||||
{
|
||||
if (list->head == link)
|
||||
{
|
||||
list->head = link->next;
|
||||
if (nil != list->head)
|
||||
{
|
||||
list->head->previous = nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
link->previous->next = link->next;
|
||||
}
|
||||
if (list->tail == link)
|
||||
{
|
||||
list->tail = link->previous;
|
||||
if (nil != list->tail)
|
||||
{
|
||||
list->tail->next = nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next->previous = link->previous;
|
||||
}
|
||||
link->next = link->previous = nil;
|
||||
link->owner = nil;
|
||||
list->count--;
|
||||
}
|
||||
|
||||
extern void
|
||||
GSLinkedListMoveToHead(GSListLink *link, GSLinkedList *list)
|
||||
{
|
||||
if (link != list->head)
|
||||
{
|
||||
if (link == list->tail)
|
||||
{
|
||||
list->tail = link->previous;
|
||||
list->tail->next = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next->previous = link->previous;
|
||||
link->previous->next = link->next;
|
||||
}
|
||||
link->next = list->head;
|
||||
link->previous = nil;
|
||||
list->head = link;
|
||||
}
|
||||
}
|
||||
|
||||
extern void
|
||||
GSLinkedListMoveToTail(GSListLink *link, GSLinkedList *list)
|
||||
{
|
||||
if (link != list->tail)
|
||||
{
|
||||
if (link == list->head)
|
||||
{
|
||||
list->head = link->next;
|
||||
list->head->previous = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
link->next->previous = link->previous;
|
||||
link->previous->next = link->next;
|
||||
}
|
||||
link->next = nil;
|
||||
link->previous = list->tail;
|
||||
list->tail = link;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue