mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(lv_rb): add drop_node and remove_node api (#4996)
This commit is contained in:
parent
ebcdb26e29
commit
f9135d5498
@ -166,8 +166,11 @@ void * lv_lru_rb_get_or_create(lv_lru_rb_t * lru, const void * key, void * user_
|
||||
}
|
||||
|
||||
while(lru->size >= lru->max_size) {
|
||||
lv_rb_node_t * tail = *(lv_rb_node_t **)_lv_ll_get_tail(&lru->lru_ll);
|
||||
lv_lru_rb_drop(lru, tail->data, user_data);
|
||||
void * tail = _lv_ll_get_tail(&lru->lru_ll);
|
||||
lv_rb_node_t * tail_node = *(lv_rb_node_t **)tail;
|
||||
void * search_key = tail_node->data;
|
||||
|
||||
lv_lru_rb_drop(lru, search_key, user_data);
|
||||
}
|
||||
|
||||
/*cache miss*/
|
||||
@ -197,7 +200,7 @@ void lv_lru_rb_drop(lv_lru_rb_t * lru, const void * key, void * user_data)
|
||||
lru->free_cb(node->data, user_data);
|
||||
|
||||
void * lru_node = *get_lru_node(lru, node);
|
||||
lv_rb_drop(&lru->rb, key);
|
||||
lv_rb_drop_node(&lru->rb, node);
|
||||
_lv_ll_remove(&lru->lru_ll, lru_node);
|
||||
|
||||
lv_free(lru_node);
|
||||
@ -299,8 +302,8 @@ static void * alloc_new_node(lv_lru_rb_t * lru, void * key, void * user_data)
|
||||
FAILED_HANDLER1:
|
||||
lru->free_cb(node->data, user_data);
|
||||
FAILED_HANDLER2:
|
||||
lv_rb_drop_node(&lru->rb, node);
|
||||
node = NULL;
|
||||
lv_rb_drop(&lru->rb, key);
|
||||
FAILED_HANDLER3:
|
||||
return node;
|
||||
}
|
||||
|
@ -126,20 +126,8 @@ lv_rb_node_t * lv_rb_find(lv_rb_t * tree, const void * key)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void * lv_rb_remove(lv_rb_t * tree, const void * key)
|
||||
void * lv_rb_remove_node(lv_rb_t * tree, lv_rb_node_t * node)
|
||||
{
|
||||
LV_ASSERT_NULL(tree);
|
||||
if(tree == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lv_rb_node_t * node = lv_rb_find(tree, key);
|
||||
LV_ASSERT_NULL(node);
|
||||
if(node == NULL) {
|
||||
LV_LOG_WARN("rb delete %d not found", (int)(uintptr_t)key);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lv_rb_node_t * child = NULL;
|
||||
lv_rb_node_t * parent = NULL;
|
||||
lv_rb_color_t color = LV_RB_COLOR_BLACK;
|
||||
@ -219,6 +207,38 @@ void * lv_rb_remove(lv_rb_t * tree, const void * key)
|
||||
return data;
|
||||
}
|
||||
|
||||
void * lv_rb_remove(lv_rb_t * tree, const void * key)
|
||||
{
|
||||
LV_ASSERT_NULL(tree);
|
||||
if(tree == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lv_rb_node_t * node = lv_rb_find(tree, key);
|
||||
LV_ASSERT_NULL(node);
|
||||
if(node == NULL) {
|
||||
LV_LOG_WARN("rb delete %d not found", (int)(uintptr_t)key);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return lv_rb_remove_node(tree, node);
|
||||
}
|
||||
|
||||
bool lv_rb_drop_node(lv_rb_t * tree, lv_rb_node_t * node)
|
||||
{
|
||||
LV_ASSERT_NULL(tree);
|
||||
if(tree == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void * data = lv_rb_remove_node(tree, node);
|
||||
if(data) {
|
||||
lv_free(data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool lv_rb_drop(lv_rb_t * tree, const void * key)
|
||||
{
|
||||
LV_ASSERT_NULL(tree);
|
||||
|
@ -55,7 +55,9 @@ typedef struct {
|
||||
bool lv_rb_init(lv_rb_t * tree, lv_rb_compare_t compare, size_t node_size);
|
||||
lv_rb_node_t * lv_rb_insert(lv_rb_t * tree, void * key);
|
||||
lv_rb_node_t * lv_rb_find(lv_rb_t * tree, const void * key);
|
||||
void * lv_rb_remove_node(lv_rb_t * tree, lv_rb_node_t * node);
|
||||
void * lv_rb_remove(lv_rb_t * tree, const void * key);
|
||||
bool lv_rb_drop_node(lv_rb_t * tree, lv_rb_node_t * node);
|
||||
bool lv_rb_drop(lv_rb_t * tree, const void * key);
|
||||
lv_rb_node_t * lv_rb_minimum(lv_rb_t * node);
|
||||
lv_rb_node_t * lv_rb_maximum(lv_rb_t * node);
|
||||
|
Loading…
x
Reference in New Issue
Block a user