29 #define DISABLE_DEBUGLOG 32 #include <gwenhywfar/quicksort.h> 33 #include <gwenhywfar/misc.h> 34 #include <gwenhywfar/debug.h> 40 static int _compare(
const void *a,
const void *b,
void *f);
75 el->prevElement->nextElement=el->nextElement;
79 el->nextElement->prevElement=el->prevElement;
83 if (el->parent->firstChild==el)
84 el->parent->firstChild=el->nextElement;
85 if (el->parent->lastChild==el)
86 el->parent->lastChild=el->prevElement;
98 elReplacement->nextElement=
NULL;
99 elReplacement->prevElement=
NULL;
100 elReplacement->parent=
NULL;
103 if (elToReplace->prevElement)
104 elToReplace->prevElement->nextElement=elReplacement;
105 elReplacement->prevElement=elToReplace->prevElement;
108 if (elToReplace->nextElement)
109 elToReplace->nextElement->prevElement=elReplacement;
110 elReplacement->nextElement=elToReplace->nextElement;
113 if (elToReplace->parent) {
114 elReplacement->parent=elToReplace->parent;
115 if (elToReplace->parent->firstChild==elToReplace)
116 elToReplace->parent->firstChild=elReplacement;
117 if (elToReplace->parent->lastChild==elToReplace)
118 elToReplace->parent->lastChild=elReplacement;
121 elToReplace->nextElement=
NULL;
122 elToReplace->prevElement=
NULL;
123 elToReplace->parent=
NULL;
130 if (where->firstChild==
NULL)
131 where->firstChild=el;
133 el->prevElement=where->lastChild;
134 if (where->lastChild)
135 where->lastChild->nextElement=el;
145 el->nextElement=where->firstChild;
146 where->firstChild=el;
148 if (where->lastChild==
NULL)
159 return el->prevElement->data;
168 return el->nextElement->data;
177 return el->firstChild->data;
178 else if (el->nextElement)
179 return el->nextElement->data;
182 while (el && el->parent) {
183 if (el->parent->nextElement)
184 return el->parent->nextElement->data;
202 child=el->firstChild;
205 child=child->nextElement;
216 return el->firstChild->data;
225 return el->lastChild->data;
234 return el->parent->data;
254 sortArrayPtr=tmpEntries;
255 while( (child=el->firstChild) ) {
257 *(sortArrayPtr++)=child;
262 sortArrayPtr=tmpEntries;
263 for (i=0; i<numChildren; i++) {
273 int _compare(
const void *a,
const void *b,
void *f)
282 return cb(elA->data, elB->data);
uint32_t GWEN_Tree2Element_GetChildrenCount(const GWEN_TREE2_ELEMENT *el)
#define DBG_ERROR(dbg_logger, format,...)
int(* GWEN_TREE2_COMPARE_CB)(void *p1, void *p2)
void GWEN_Tree2_AddChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el)
struct GWEN_TREE2_ELEMENT GWEN_TREE2_ELEMENT
#define GWEN_FREE_OBJECT(varname)
void * GWEN_Tree2Element_GetParent(const GWEN_TREE2_ELEMENT *el)
void * GWEN_Tree2Element_GetLastChild(const GWEN_TREE2_ELEMENT *el)
void GWEN_Tree2Element_free(GWEN_TREE2_ELEMENT *el)
#define GWEN_NEW_OBJECT(typ, varname)
void GWEN_Tree2_Unlink(GWEN_TREE2_ELEMENT *el)
void GWEN_Tree2Element_SortChildren(GWEN_TREE2_ELEMENT *el, GWEN_TREE2_COMPARE_CB cb)
void * GWEN_Tree2Element_GetNext(const GWEN_TREE2_ELEMENT *el)
void GWEN_QuickSort(void *array, int numElems, int sizeElems, GWEN_QUICKSORT_COMPARE_CB cb, void *arg)
void GWEN_Tree2_InsertChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el)
void GWEN_Tree2_Replace(GWEN_TREE2_ELEMENT *elToReplace, GWEN_TREE2_ELEMENT *elReplacement)
void * GWEN_Tree2Element_GetFirstChild(const GWEN_TREE2_ELEMENT *el)
void * GWEN_Tree2Element_GetBelow(const GWEN_TREE2_ELEMENT *el)
void * GWEN_Tree2Element_GetPrevious(const GWEN_TREE2_ELEMENT *el)
static int _compare(const void *a, const void *b, void *f)
GWEN_TREE2_ELEMENT * GWEN_Tree2Element_new(void *d)