Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 295202
b: refs/heads/master
c: 742245d
h: refs/heads/master
v: v3
  • Loading branch information
Xiao Guangrong authored and Linus Torvalds committed Mar 23, 2012
1 parent ab9927e commit 8bb2377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f35368dd1cef11cdd310b07c74d74f45e3469c64
refs/heads/master: 742245d5c2ebd75c2a002f8fc2afbdc5c26edd8c
38 changes: 14 additions & 24 deletions trunk/lib/prio_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,43 +94,33 @@ static inline unsigned long prio_tree_maxindex(unsigned int bits)
static struct prio_tree_node *prio_tree_expand(struct prio_tree_root *root,
struct prio_tree_node *node, unsigned long max_heap_index)
{
struct prio_tree_node *first = NULL, *prev, *last = NULL;
struct prio_tree_node *prev;

if (max_heap_index > prio_tree_maxindex(root->index_bits))
root->index_bits++;

prev = node;
INIT_PRIO_TREE_NODE(node);

while (max_heap_index > prio_tree_maxindex(root->index_bits)) {
struct prio_tree_node *tmp = root->prio_tree_node;

root->index_bits++;

if (prio_tree_empty(root))
continue;

if (first == NULL) {
first = root->prio_tree_node;
prio_tree_remove(root, root->prio_tree_node);
INIT_PRIO_TREE_NODE(first);
last = first;
} else {
prev = last;
last = root->prio_tree_node;
prio_tree_remove(root, root->prio_tree_node);
INIT_PRIO_TREE_NODE(last);
prev->left = last;
last->parent = prev;
}
}

INIT_PRIO_TREE_NODE(node);
prio_tree_remove(root, root->prio_tree_node);
INIT_PRIO_TREE_NODE(tmp);

if (first) {
node->left = first;
first->parent = node;
} else
last = node;
prev->left = tmp;
tmp->parent = prev;
prev = tmp;
}

if (!prio_tree_empty(root)) {
last->left = root->prio_tree_node;
last->left->parent = last;
prev->left = root->prio_tree_node;
prev->left->parent = prev;
}

root->prio_tree_node = node;
Expand Down

0 comments on commit 8bb2377

Please sign in to comment.