mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 20:10:29 +01:00
WINGs: merge bagtree duplicate code
This patch is adding a new static function treeDeleteNode to factorize some code. Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
committed by
Carlos R. Mafra
parent
2a3c11e202
commit
09761a75f0
@@ -420,10 +420,8 @@ void WMInsertInBag(WMBag * self, int index, void *item)
|
|||||||
self->count++;
|
self->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WMRemoveFromBag(WMBag * self, void *item)
|
static int treeDeleteNode(WMBag * self, W_Node *ptr)
|
||||||
{
|
{
|
||||||
W_Node *ptr = treeFind(self->root, self->nil, item);
|
|
||||||
|
|
||||||
if (ptr != self->nil) {
|
if (ptr != self->nil) {
|
||||||
W_Node *tmp;
|
W_Node *tmp;
|
||||||
|
|
||||||
@@ -439,11 +437,15 @@ int WMRemoveFromBag(WMBag * self, void *item)
|
|||||||
if (self->destructor)
|
if (self->destructor)
|
||||||
self->destructor(ptr->data);
|
self->destructor(ptr->data);
|
||||||
wfree(ptr);
|
wfree(ptr);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WMRemoveFromBag(WMBag * self, void *item)
|
||||||
|
{
|
||||||
|
W_Node *ptr = treeFind(self->root, self->nil, item);
|
||||||
|
return treeDeleteNode(self, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WMEraseFromBag(WMBag * self, int index)
|
int WMEraseFromBag(WMBag * self, int index)
|
||||||
@@ -470,29 +472,7 @@ int WMEraseFromBag(WMBag * self, int index)
|
|||||||
int WMDeleteFromBag(WMBag * self, int index)
|
int WMDeleteFromBag(WMBag * self, int index)
|
||||||
{
|
{
|
||||||
W_Node *ptr = treeSearch(self->root, self->nil, index);
|
W_Node *ptr = treeSearch(self->root, self->nil, index);
|
||||||
|
return treeDeleteNode(self, ptr);
|
||||||
if (ptr != self->nil) {
|
|
||||||
W_Node *tmp;
|
|
||||||
|
|
||||||
self->count--;
|
|
||||||
|
|
||||||
tmp = treeSuccessor(ptr, self->nil);
|
|
||||||
while (tmp != self->nil) {
|
|
||||||
tmp->index--;
|
|
||||||
tmp = treeSuccessor(tmp, self->nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = rbTreeDelete(self, ptr);
|
|
||||||
if (self->destructor)
|
|
||||||
self->destructor(ptr->data);
|
|
||||||
wfree(ptr);
|
|
||||||
|
|
||||||
wassertrv(self->count == 0 || self->root->index >= 0, 1);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *WMGetFromBag(WMBag * self, int index)
|
void *WMGetFromBag(WMBag * self, int index)
|
||||||
|
|||||||
Reference in New Issue
Block a user