2003-10-13 05:57:05 +04:00
|
|
|
/*
|
2007-10-23 14:37:41 +04:00
|
|
|
* Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
|
2006-03-27 14:27:05 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2003-10-13 05:57:05 +04:00
|
|
|
#ifndef KERNEL_UTIL_DOUBLY_LINKED_LIST_H
|
|
|
|
#define KERNEL_UTIL_DOUBLY_LINKED_LIST_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
2007-03-11 16:56:45 +03:00
|
|
|
|
|
|
|
#ifdef _KERNEL_MODE
|
2007-10-04 02:22:21 +04:00
|
|
|
# include <debug.h>
|
2007-03-11 16:56:45 +03:00
|
|
|
# include <util/kernel_cpp.h>
|
2003-10-13 05:57:05 +04:00
|
|
|
|
2007-10-04 02:22:21 +04:00
|
|
|
# if !defined(_BOOT_MODE) && KDEBUG
|
|
|
|
# define DEBUG_DOUBLY_LINKED_LIST KDEBUG
|
|
|
|
# endif
|
|
|
|
#endif
|
2003-10-13 05:57:05 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
// DoublyLinkedListLink
|
|
|
|
template<typename Element>
|
|
|
|
class DoublyLinkedListLink {
|
|
|
|
public:
|
2007-10-23 14:37:41 +04:00
|
|
|
DoublyLinkedListLink() : next(NULL), previous(NULL) {}
|
2005-02-02 04:14:47 +03:00
|
|
|
~DoublyLinkedListLink() {}
|
|
|
|
|
|
|
|
Element *next;
|
2007-10-23 14:37:41 +04:00
|
|
|
Element *previous;
|
2005-02-02 04:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// DoublyLinkedListLinkImpl
|
|
|
|
template<typename Element>
|
|
|
|
class DoublyLinkedListLinkImpl {
|
|
|
|
private:
|
2005-02-02 05:31:06 +03:00
|
|
|
typedef DoublyLinkedListLink<Element> DLL_Link;
|
2005-02-02 04:14:47 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
DoublyLinkedListLinkImpl() : fDoublyLinkedListLink() {}
|
|
|
|
~DoublyLinkedListLinkImpl() {}
|
|
|
|
|
2005-02-02 05:31:06 +03:00
|
|
|
DLL_Link *GetDoublyLinkedListLink()
|
2005-02-02 04:14:47 +03:00
|
|
|
{ return &fDoublyLinkedListLink; }
|
2005-02-02 05:31:06 +03:00
|
|
|
const DLL_Link *GetDoublyLinkedListLink() const
|
2005-02-02 04:14:47 +03:00
|
|
|
{ return &fDoublyLinkedListLink; }
|
|
|
|
|
|
|
|
private:
|
2005-02-02 05:31:06 +03:00
|
|
|
DLL_Link fDoublyLinkedListLink;
|
2005-02-02 04:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// DoublyLinkedListStandardGetLink
|
|
|
|
template<typename Element>
|
|
|
|
class DoublyLinkedListStandardGetLink {
|
|
|
|
private:
|
|
|
|
typedef DoublyLinkedListLink<Element> Link;
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline Link *operator()(Element *element) const
|
|
|
|
{
|
|
|
|
return element->GetDoublyLinkedListLink();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Link *operator()(const Element *element) const
|
|
|
|
{
|
|
|
|
return element->GetDoublyLinkedListLink();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-02-02 04:48:43 +03:00
|
|
|
// DoublyLinkedListMemberGetLink
|
|
|
|
template<typename Element,
|
|
|
|
DoublyLinkedListLink<Element> Element::* LinkMember = &Element::fLink>
|
|
|
|
class DoublyLinkedListMemberGetLink {
|
|
|
|
private:
|
|
|
|
typedef DoublyLinkedListLink<Element> Link;
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline Link *operator()(Element *element) const
|
|
|
|
{
|
|
|
|
return &(element->*LinkMember);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Link *operator()(const Element *element) const
|
|
|
|
{
|
|
|
|
return &(element->*LinkMember);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-07-19 01:08:52 +04:00
|
|
|
// DoublyLinkedListCLink - interface to struct list
|
|
|
|
template<typename Element>
|
|
|
|
class DoublyLinkedListCLink {
|
|
|
|
private:
|
|
|
|
typedef DoublyLinkedListLink<Element> Link;
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline Link *operator()(Element *element) const
|
|
|
|
{
|
|
|
|
return (Link *)&element->link;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Link *operator()(const Element *element) const
|
|
|
|
{
|
|
|
|
return (const Link *)&element->link;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
// for convenience
|
|
|
|
#define DOUBLY_LINKED_LIST_TEMPLATE_LIST \
|
|
|
|
template<typename Element, typename GetLink>
|
|
|
|
#define DOUBLY_LINKED_LIST_CLASS_NAME DoublyLinkedList<Element, GetLink>
|
|
|
|
|
|
|
|
// DoublyLinkedList
|
|
|
|
template<typename Element,
|
|
|
|
typename GetLink = DoublyLinkedListStandardGetLink<Element> >
|
|
|
|
class DoublyLinkedList {
|
|
|
|
private:
|
|
|
|
typedef DoublyLinkedList<Element, GetLink> List;
|
|
|
|
typedef DoublyLinkedListLink<Element> Link;
|
|
|
|
|
|
|
|
public:
|
|
|
|
class Iterator {
|
|
|
|
public:
|
|
|
|
Iterator(List *list)
|
2006-03-27 14:27:05 +04:00
|
|
|
:
|
|
|
|
fList(list)
|
2005-02-02 04:14:47 +03:00
|
|
|
{
|
2006-03-27 14:27:05 +04:00
|
|
|
Rewind();
|
2005-02-02 04:14:47 +03:00
|
|
|
}
|
|
|
|
|
2007-08-01 18:28:50 +04:00
|
|
|
Iterator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
Iterator(const Iterator &other)
|
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasNext() const
|
|
|
|
{
|
|
|
|
return fNext;
|
|
|
|
}
|
2006-03-27 14:27:05 +04:00
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
Element *Next()
|
|
|
|
{
|
|
|
|
fCurrent = fNext;
|
|
|
|
if (fNext)
|
|
|
|
fNext = fList->GetNext(fNext);
|
|
|
|
return fCurrent;
|
|
|
|
}
|
2006-03-27 14:27:05 +04:00
|
|
|
|
2007-08-01 18:28:50 +04:00
|
|
|
Element *Current()
|
|
|
|
{
|
|
|
|
return fCurrent;
|
|
|
|
}
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
Element *Remove()
|
|
|
|
{
|
|
|
|
Element *element = fCurrent;
|
|
|
|
if (fCurrent) {
|
|
|
|
fList->Remove(fCurrent);
|
|
|
|
fCurrent = NULL;
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator &operator=(const Iterator &other)
|
|
|
|
{
|
|
|
|
fList = other.fList;
|
|
|
|
fCurrent = other.fCurrent;
|
|
|
|
fNext = other.fNext;
|
|
|
|
return *this;
|
|
|
|
}
|
2006-03-27 14:27:05 +04:00
|
|
|
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
fCurrent = NULL;
|
|
|
|
fNext = fList->First();
|
|
|
|
}
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
private:
|
|
|
|
List *fList;
|
|
|
|
Element *fCurrent;
|
|
|
|
Element *fNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConstIterator {
|
|
|
|
public:
|
|
|
|
ConstIterator(const List *list)
|
2006-03-27 14:27:05 +04:00
|
|
|
:
|
|
|
|
fList(list)
|
2005-02-02 04:14:47 +03:00
|
|
|
{
|
2006-03-27 14:27:05 +04:00
|
|
|
Rewind();
|
2005-02-02 04:14:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstIterator(const ConstIterator &other)
|
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasNext() const
|
|
|
|
{
|
|
|
|
return fNext;
|
|
|
|
}
|
2006-03-27 14:27:05 +04:00
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
Element *Next()
|
|
|
|
{
|
|
|
|
Element *element = fNext;
|
|
|
|
if (fNext)
|
|
|
|
fNext = fList->GetNext(fNext);
|
|
|
|
return element;
|
|
|
|
}
|
2006-03-27 14:27:05 +04:00
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
ConstIterator &operator=(const ConstIterator &other)
|
|
|
|
{
|
|
|
|
fList = other.fList;
|
|
|
|
fNext = other.fNext;
|
|
|
|
return *this;
|
|
|
|
}
|
2006-03-27 14:27:05 +04:00
|
|
|
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
fNext = fList->First();
|
|
|
|
}
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
private:
|
|
|
|
const List *fList;
|
|
|
|
Element *fNext;
|
|
|
|
};
|
|
|
|
|
2006-07-29 21:58:17 +04:00
|
|
|
class ReverseIterator {
|
|
|
|
public:
|
|
|
|
ReverseIterator(List *list)
|
|
|
|
:
|
|
|
|
fList(list)
|
|
|
|
{
|
|
|
|
Rewind();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReverseIterator(const ReverseIterator &other)
|
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasNext() const
|
|
|
|
{
|
|
|
|
return fNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element *Next()
|
|
|
|
{
|
|
|
|
fCurrent = fNext;
|
|
|
|
if (fNext)
|
|
|
|
fNext = fList->GetPrevious(fNext);
|
|
|
|
return fCurrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element *Remove()
|
|
|
|
{
|
|
|
|
Element *element = fCurrent;
|
|
|
|
if (fCurrent) {
|
|
|
|
fList->Remove(fCurrent);
|
|
|
|
fCurrent = NULL;
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReverseIterator &operator=(const ReverseIterator &other)
|
|
|
|
{
|
|
|
|
fList = other.fList;
|
|
|
|
fCurrent = other.fCurrent;
|
|
|
|
fNext = other.fNext;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
fCurrent = NULL;
|
|
|
|
fNext = fList->Last();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
List *fList;
|
|
|
|
Element *fCurrent;
|
|
|
|
Element *fNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConstReverseIterator {
|
|
|
|
public:
|
|
|
|
ConstReverseIterator(const List *list)
|
|
|
|
:
|
|
|
|
fList(list)
|
|
|
|
{
|
|
|
|
Rewind();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstReverseIterator(const ConstReverseIterator &other)
|
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasNext() const
|
|
|
|
{
|
|
|
|
return fNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element *Next()
|
|
|
|
{
|
|
|
|
Element *element = fNext;
|
|
|
|
if (fNext)
|
|
|
|
fNext = fList->GetPrevious(fNext);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstReverseIterator &operator=(const ConstReverseIterator &other)
|
|
|
|
{
|
|
|
|
fList = other.fList;
|
|
|
|
fNext = other.fNext;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
fNext = fList->Last();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const List *fList;
|
|
|
|
Element *fNext;
|
|
|
|
};
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
public:
|
|
|
|
DoublyLinkedList() : fFirst(NULL), fLast(NULL) {}
|
|
|
|
~DoublyLinkedList() {}
|
|
|
|
|
|
|
|
inline bool IsEmpty() const { return (fFirst == NULL); }
|
|
|
|
|
|
|
|
inline void Insert(Element *element, bool back = true);
|
2006-07-19 01:08:52 +04:00
|
|
|
inline void Insert(Element *before, Element *element);
|
2005-02-02 04:48:43 +03:00
|
|
|
inline void Add(Element *element, bool back = true);
|
2005-02-02 04:14:47 +03:00
|
|
|
inline void Remove(Element *element);
|
|
|
|
|
|
|
|
inline void Swap(Element *a, Element *b);
|
|
|
|
|
|
|
|
inline void MoveFrom(DOUBLY_LINKED_LIST_CLASS_NAME *fromList);
|
|
|
|
|
|
|
|
inline void RemoveAll();
|
|
|
|
inline void MakeEmpty() { RemoveAll(); }
|
|
|
|
|
|
|
|
inline Element *First() const { return fFirst; }
|
|
|
|
inline Element *Last() const { return fLast; }
|
|
|
|
|
|
|
|
inline Element *Head() const { return fFirst; }
|
|
|
|
inline Element *Tail() const { return fLast; }
|
|
|
|
|
2006-03-27 14:27:05 +04:00
|
|
|
inline Element *RemoveHead();
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
inline Element *GetPrevious(Element *element) const;
|
|
|
|
inline Element *GetNext(Element *element) const;
|
|
|
|
|
|
|
|
inline int32 Size() const;
|
|
|
|
// O(n)!
|
|
|
|
|
|
|
|
inline Iterator GetIterator() { return Iterator(this); }
|
|
|
|
inline ConstIterator GetIterator() const { return ConstIterator(this); }
|
|
|
|
|
2006-07-29 21:58:17 +04:00
|
|
|
inline ReverseIterator GetReverseIterator()
|
|
|
|
{ return ReverseIterator(this); }
|
|
|
|
inline ConstReverseIterator GetReverseIterator() const
|
|
|
|
{ return ConstReverseIterator(this); }
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
private:
|
|
|
|
Element *fFirst;
|
|
|
|
Element *fLast;
|
2005-02-02 04:48:43 +03:00
|
|
|
|
|
|
|
static GetLink sGetLink;
|
2005-02-02 04:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// inline methods
|
|
|
|
|
|
|
|
// Insert
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
void
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::Insert(Element *element, bool back)
|
|
|
|
{
|
|
|
|
if (element) {
|
2007-10-04 02:22:21 +04:00
|
|
|
#if DEBUG_DOUBLY_LINKED_LIST
|
|
|
|
ASSERT_PRINT(fFirst == NULL ? fLast == NULL : fLast != NULL,
|
|
|
|
"list: %p\n", this);
|
|
|
|
#endif
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
if (back) {
|
|
|
|
// append
|
2005-02-02 04:48:43 +03:00
|
|
|
Link *elLink = sGetLink(element);
|
2005-02-02 04:14:47 +03:00
|
|
|
elLink->previous = fLast;
|
|
|
|
elLink->next = NULL;
|
|
|
|
if (fLast)
|
2005-02-02 04:48:43 +03:00
|
|
|
sGetLink(fLast)->next = element;
|
2005-02-02 04:14:47 +03:00
|
|
|
else
|
|
|
|
fFirst = element;
|
|
|
|
fLast = element;
|
|
|
|
} else {
|
|
|
|
// prepend
|
2005-02-02 04:48:43 +03:00
|
|
|
Link *elLink = sGetLink(element);
|
2005-02-02 04:14:47 +03:00
|
|
|
elLink->previous = NULL;
|
|
|
|
elLink->next = fFirst;
|
|
|
|
if (fFirst)
|
2005-02-02 04:48:43 +03:00
|
|
|
sGetLink(fFirst)->previous = element;
|
2005-02-02 04:14:47 +03:00
|
|
|
else
|
|
|
|
fLast = element;
|
|
|
|
fFirst = element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-19 01:08:52 +04:00
|
|
|
// Insert
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
void
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::Insert(Element *before, Element *element)
|
|
|
|
{
|
|
|
|
if (before == NULL) {
|
2006-07-29 21:58:17 +04:00
|
|
|
Insert(element);
|
2006-07-19 01:08:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (element == NULL)
|
|
|
|
return;
|
|
|
|
|
2007-10-04 02:22:21 +04:00
|
|
|
#if DEBUG_DOUBLY_LINKED_LIST
|
|
|
|
ASSERT_PRINT(fFirst == NULL ? fLast == NULL : fLast != NULL,
|
|
|
|
"list: %p\n", this);
|
|
|
|
#endif
|
|
|
|
|
2006-07-19 01:08:52 +04:00
|
|
|
Link *beforeLink = sGetLink(before);
|
|
|
|
Link *link = sGetLink(element);
|
|
|
|
|
2006-07-29 21:58:17 +04:00
|
|
|
link->next = before;
|
|
|
|
link->previous = beforeLink->previous;
|
|
|
|
if (link->previous != NULL)
|
|
|
|
sGetLink(link->previous)->next = element;
|
|
|
|
beforeLink->previous = element;
|
2006-07-19 01:08:52 +04:00
|
|
|
|
2006-07-29 21:58:17 +04:00
|
|
|
if (fFirst == before)
|
|
|
|
fFirst = element;
|
2006-07-19 01:08:52 +04:00
|
|
|
}
|
|
|
|
|
2005-02-02 04:48:43 +03:00
|
|
|
// Add
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
void
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::Add(Element *element, bool back)
|
|
|
|
{
|
|
|
|
Insert(element, back);
|
|
|
|
}
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
// Remove
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
void
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::Remove(Element *element)
|
|
|
|
{
|
|
|
|
if (element) {
|
2007-10-04 02:22:21 +04:00
|
|
|
#if DEBUG_DOUBLY_LINKED_LIST
|
|
|
|
ASSERT_PRINT(fFirst != NULL && fLast != NULL
|
|
|
|
&& (fFirst != fLast || element == fFirst),
|
|
|
|
"list: %p, element: %p\n", this, element);
|
|
|
|
#endif
|
|
|
|
|
2005-02-02 04:48:43 +03:00
|
|
|
Link *elLink = sGetLink(element);
|
2005-02-02 04:14:47 +03:00
|
|
|
if (elLink->previous)
|
2005-02-02 04:48:43 +03:00
|
|
|
sGetLink(elLink->previous)->next = elLink->next;
|
2005-02-02 04:14:47 +03:00
|
|
|
else
|
|
|
|
fFirst = elLink->next;
|
|
|
|
if (elLink->next)
|
2005-02-02 04:48:43 +03:00
|
|
|
sGetLink(elLink->next)->previous = elLink->previous;
|
2005-02-02 04:14:47 +03:00
|
|
|
else
|
|
|
|
fLast = elLink->previous;
|
|
|
|
elLink->previous = NULL;
|
|
|
|
elLink->next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
void
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::Swap(Element *a, Element *b)
|
|
|
|
{
|
|
|
|
if (a && b && a != b) {
|
2008-07-23 00:36:32 +04:00
|
|
|
Element *aNext = sGetLink(a)->next;
|
|
|
|
Element *bNext = sGetLink(b)->next;
|
|
|
|
if (a == bNext) {
|
|
|
|
Remove(a);
|
|
|
|
Insert(b, a);
|
|
|
|
} else if (b == aNext) {
|
|
|
|
Remove(b);
|
|
|
|
Insert(a, b);
|
|
|
|
} else {
|
|
|
|
Remove(a);
|
|
|
|
Remove(b);
|
|
|
|
Insert(aNext, b);
|
|
|
|
Insert(bNext, a);
|
|
|
|
}
|
2005-02-02 04:14:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MoveFrom
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
void
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::MoveFrom(DOUBLY_LINKED_LIST_CLASS_NAME *fromList)
|
|
|
|
{
|
|
|
|
if (fromList && fromList->fFirst) {
|
|
|
|
if (fFirst) {
|
2005-02-02 04:48:43 +03:00
|
|
|
sGetLink(fLast)->next = fromList->fFirst;
|
2007-10-05 20:56:48 +04:00
|
|
|
sGetLink(fromList->fFirst)->previous = fLast;
|
2005-02-02 04:14:47 +03:00
|
|
|
fLast = fromList->fLast;
|
|
|
|
} else {
|
|
|
|
fFirst = fromList->fFirst;
|
|
|
|
fLast = fromList->fLast;
|
|
|
|
}
|
|
|
|
fromList->fFirst = NULL;
|
|
|
|
fromList->fLast = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveAll
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
void
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::RemoveAll()
|
|
|
|
{
|
|
|
|
Element *element = fFirst;
|
|
|
|
while (element) {
|
2005-02-02 04:48:43 +03:00
|
|
|
Link *elLink = sGetLink(element);
|
2005-02-02 04:14:47 +03:00
|
|
|
element = elLink->next;
|
|
|
|
elLink->previous = NULL;
|
|
|
|
elLink->next = NULL;
|
|
|
|
}
|
|
|
|
fFirst = NULL;
|
|
|
|
fLast = NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-27 14:27:05 +04:00
|
|
|
// RemoveHead
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
Element *
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::RemoveHead()
|
|
|
|
{
|
|
|
|
Element *element = Head();
|
|
|
|
Remove(element);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
// GetPrevious
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
Element *
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::GetPrevious(Element *element) const
|
|
|
|
{
|
|
|
|
Element *result = NULL;
|
|
|
|
if (element)
|
2005-02-02 04:48:43 +03:00
|
|
|
result = sGetLink(element)->previous;
|
2005-02-02 04:14:47 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNext
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
Element *
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::GetNext(Element *element) const
|
|
|
|
{
|
|
|
|
Element *result = NULL;
|
|
|
|
if (element)
|
2005-02-02 04:48:43 +03:00
|
|
|
result = sGetLink(element)->next;
|
2005-02-02 04:14:47 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Size
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
int32
|
|
|
|
DOUBLY_LINKED_LIST_CLASS_NAME::Size() const
|
|
|
|
{
|
|
|
|
int32 count = 0;
|
2005-02-02 05:12:35 +03:00
|
|
|
for (Element* element = First(); element; element = GetNext(element))
|
2005-02-02 04:14:47 +03:00
|
|
|
count++;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2005-02-02 04:48:43 +03:00
|
|
|
// sGetLink
|
|
|
|
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
|
|
|
GetLink DOUBLY_LINKED_LIST_CLASS_NAME::sGetLink;
|
|
|
|
|
2005-02-02 04:14:47 +03:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif // _KERNEL_UTIL_DOUBLY_LINKED_LIST_H
|