MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _dfs_page_insert

Function _dfs_page_insert

components/dfs/dfs_v2/src/dfs_pcache.c:1127–1153  ·  view source on GitHub ↗

* @brief Insert a page into the AVL tree of an address space * * This function inserts a page into the AVL tree of the specified address space. * The tree is ordered by the file position (fpos) of pages. If a page with the * same fpos already exists, the insertion fails. * * @param[in] aspace Pointer to the address space containing the AVL tree * @param[in,out] page Pointer to the page stru

Source from the content-addressed store, hash-verified

1125 * - Uses file position (fpos) as the ordering key
1126 */
1127static int _dfs_page_insert(struct dfs_aspace *aspace, struct dfs_page *page)
1128{
1129 struct dfs_page *tmp;
1130 struct util_avl_struct *current = NULL;
1131 struct util_avl_struct **next = &(aspace->avl_root.root_node);
1132
1133 /* Figure out where to put new node */
1134 while (*next)
1135 {
1136 current = *next;
1137 tmp = rt_container_of(current, struct dfs_page, avl_node);
1138
1139 if (page->fpos < tmp->fpos)
1140 next = &(current->avl_left);
1141 else if (page->fpos > tmp->fpos)
1142 next = &(current->avl_right);
1143 else
1144 return -1;
1145 }
1146
1147 /* Add new node and rebalance tree. */
1148 util_avl_link(&page->avl_node, current, next);
1149 util_avl_rebalance(current, &aspace->avl_root);
1150 aspace->avl_page = page;
1151
1152 return 0;
1153}
1154
1155/**
1156 * @brief Remove a page from the AVL tree of an address space

Callers 1

dfs_page_insertFunction · 0.85

Calls 2

util_avl_linkFunction · 0.85
util_avl_rebalanceFunction · 0.85

Tested by

no test coverage detected