* @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
| 1125 | * - Uses file position (fpos) as the ordering key |
| 1126 | */ |
| 1127 | static 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 |
no test coverage detected