* Updated the fs_shell version of DoublyLinkedList.h to contain the latest
fixes made by Ingo. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26696 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005-2006, Ingo Weinhold, [email protected]. All rights reserved.
|
* Copyright 2005-2007, Ingo Weinhold, [email protected]. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef KERNEL_UTIL_DOUBLY_LINKED_LIST_H
|
#ifndef KERNEL_UTIL_DOUBLY_LINKED_LIST_H
|
||||||
@@ -19,11 +19,11 @@ namespace FSShell {
|
|||||||
template<typename Element>
|
template<typename Element>
|
||||||
class DoublyLinkedListLink {
|
class DoublyLinkedListLink {
|
||||||
public:
|
public:
|
||||||
DoublyLinkedListLink() : previous(NULL), next(NULL) {}
|
DoublyLinkedListLink() : next(NULL), previous(NULL) {}
|
||||||
~DoublyLinkedListLink() {}
|
~DoublyLinkedListLink() {}
|
||||||
|
|
||||||
Element *previous;
|
|
||||||
Element *next;
|
Element *next;
|
||||||
|
Element *previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
// DoublyLinkedListLinkImpl
|
// DoublyLinkedListLinkImpl
|
||||||
@@ -141,6 +141,11 @@ public:
|
|||||||
return fCurrent;
|
return fCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Element *Current()
|
||||||
|
{
|
||||||
|
return fCurrent;
|
||||||
|
}
|
||||||
|
|
||||||
Element *Remove()
|
Element *Remove()
|
||||||
{
|
{
|
||||||
Element *element = fCurrent;
|
Element *element = fCurrent;
|
||||||
@@ -455,34 +460,20 @@ void
|
|||||||
DOUBLY_LINKED_LIST_CLASS_NAME::Swap(Element *a, Element *b)
|
DOUBLY_LINKED_LIST_CLASS_NAME::Swap(Element *a, Element *b)
|
||||||
{
|
{
|
||||||
if (a && b && a != b) {
|
if (a && b && a != b) {
|
||||||
Link *aLink = sGetLink(a);
|
Element *aNext = sGetLink(a)->next;
|
||||||
Link *bLink = sGetLink(b);
|
Element *bNext = sGetLink(b)->next;
|
||||||
Element *aPrev = aLink->previous;
|
if (a == bNext) {
|
||||||
Element *bPrev = bLink->previous;
|
Remove(a);
|
||||||
Element *aNext = aLink->next;
|
Insert(b, a);
|
||||||
Element *bNext = bLink->next;
|
} else if (b == aNext) {
|
||||||
// place a
|
Remove(b);
|
||||||
if (bPrev)
|
Insert(a, b);
|
||||||
sGetLink(bPrev)->next = a;
|
} else {
|
||||||
else
|
Remove(a);
|
||||||
fFirst = a;
|
Remove(b);
|
||||||
if (bNext)
|
Insert(aNext, b);
|
||||||
sGetLink(bNext)->previous = a;
|
Insert(bNext, a);
|
||||||
else
|
}
|
||||||
fLast = a;
|
|
||||||
aLink->previous = bPrev;
|
|
||||||
aLink->next = bNext;
|
|
||||||
// place b
|
|
||||||
if (aPrev)
|
|
||||||
sGetLink(aPrev)->next = b;
|
|
||||||
else
|
|
||||||
fFirst = b;
|
|
||||||
if (aNext)
|
|
||||||
sGetLink(aNext)->previous = b;
|
|
||||||
else
|
|
||||||
fLast = b;
|
|
||||||
bLink->previous = aPrev;
|
|
||||||
bLink->next = aNext;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,7 +485,7 @@ DOUBLY_LINKED_LIST_CLASS_NAME::MoveFrom(DOUBLY_LINKED_LIST_CLASS_NAME *fromList)
|
|||||||
if (fromList && fromList->fFirst) {
|
if (fromList && fromList->fFirst) {
|
||||||
if (fFirst) {
|
if (fFirst) {
|
||||||
sGetLink(fLast)->next = fromList->fFirst;
|
sGetLink(fLast)->next = fromList->fFirst;
|
||||||
sGetLink(fFirst)->previous = fLast;
|
sGetLink(fromList->fFirst)->previous = fLast;
|
||||||
fLast = fromList->fLast;
|
fLast = fromList->fLast;
|
||||||
} else {
|
} else {
|
||||||
fFirst = fromList->fFirst;
|
fFirst = fromList->fFirst;
|
||||||
|
|||||||
Reference in New Issue
Block a user