.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | Red Black Trees |
---|
3 | 4 | (C) 1999 Andrea Arcangeli <andrea@suse.de> |
---|
4 | 5 | (C) 2002 David Woodhouse <dwmw2@infradead.org> |
---|
5 | 6 | (C) 2012 Michel Lespinasse <walken@google.com> |
---|
6 | 7 | |
---|
7 | | - This program is free software; you can redistribute it and/or modify |
---|
8 | | - it under the terms of the GNU General Public License as published by |
---|
9 | | - the Free Software Foundation; either version 2 of the License, or |
---|
10 | | - (at your option) any later version. |
---|
11 | | - |
---|
12 | | - This program is distributed in the hope that it will be useful, |
---|
13 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - GNU General Public License for more details. |
---|
16 | | - |
---|
17 | | - You should have received a copy of the GNU General Public License |
---|
18 | | - along with this program; if not, write to the Free Software |
---|
19 | | - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
20 | 8 | |
---|
21 | 9 | linux/lib/rbtree.c |
---|
22 | 10 | */ |
---|
.. | .. |
---|
25 | 13 | #include <linux/export.h> |
---|
26 | 14 | |
---|
27 | 15 | /* |
---|
28 | | - * red-black trees properties: http://en.wikipedia.org/wiki/Rbtree |
---|
| 16 | + * red-black trees properties: https://en.wikipedia.org/wiki/Rbtree |
---|
29 | 17 | * |
---|
30 | 18 | * 1) A node is either red or black |
---|
31 | 19 | * 2) The root is black |
---|
.. | .. |
---|
95 | 83 | |
---|
96 | 84 | static __always_inline void |
---|
97 | 85 | __rb_insert(struct rb_node *node, struct rb_root *root, |
---|
98 | | - bool newleft, struct rb_node **leftmost, |
---|
99 | 86 | void (*augment_rotate)(struct rb_node *old, struct rb_node *new)) |
---|
100 | 87 | { |
---|
101 | 88 | struct rb_node *parent = rb_red_parent(node), *gparent, *tmp; |
---|
102 | | - |
---|
103 | | - if (newleft) |
---|
104 | | - *leftmost = node; |
---|
105 | 89 | |
---|
106 | 90 | while (true) { |
---|
107 | 91 | /* |
---|
.. | .. |
---|
449 | 433 | |
---|
450 | 434 | void rb_insert_color(struct rb_node *node, struct rb_root *root) |
---|
451 | 435 | { |
---|
452 | | - __rb_insert(node, root, false, NULL, dummy_rotate); |
---|
| 436 | + __rb_insert(node, root, dummy_rotate); |
---|
453 | 437 | } |
---|
454 | 438 | EXPORT_SYMBOL(rb_insert_color); |
---|
455 | 439 | |
---|
456 | 440 | void rb_erase(struct rb_node *node, struct rb_root *root) |
---|
457 | 441 | { |
---|
458 | 442 | struct rb_node *rebalance; |
---|
459 | | - rebalance = __rb_erase_augmented(node, root, |
---|
460 | | - NULL, &dummy_callbacks); |
---|
| 443 | + rebalance = __rb_erase_augmented(node, root, &dummy_callbacks); |
---|
461 | 444 | if (rebalance) |
---|
462 | 445 | ____rb_erase_color(rebalance, root, dummy_rotate); |
---|
463 | 446 | } |
---|
464 | 447 | EXPORT_SYMBOL(rb_erase); |
---|
465 | | - |
---|
466 | | -void rb_insert_color_cached(struct rb_node *node, |
---|
467 | | - struct rb_root_cached *root, bool leftmost) |
---|
468 | | -{ |
---|
469 | | - __rb_insert(node, &root->rb_root, leftmost, |
---|
470 | | - &root->rb_leftmost, dummy_rotate); |
---|
471 | | -} |
---|
472 | | -EXPORT_SYMBOL(rb_insert_color_cached); |
---|
473 | | - |
---|
474 | | -void rb_erase_cached(struct rb_node *node, struct rb_root_cached *root) |
---|
475 | | -{ |
---|
476 | | - struct rb_node *rebalance; |
---|
477 | | - rebalance = __rb_erase_augmented(node, &root->rb_root, |
---|
478 | | - &root->rb_leftmost, &dummy_callbacks); |
---|
479 | | - if (rebalance) |
---|
480 | | - ____rb_erase_color(rebalance, &root->rb_root, dummy_rotate); |
---|
481 | | -} |
---|
482 | | -EXPORT_SYMBOL(rb_erase_cached); |
---|
483 | 448 | |
---|
484 | 449 | /* |
---|
485 | 450 | * Augmented rbtree manipulation functions. |
---|
.. | .. |
---|
489 | 454 | */ |
---|
490 | 455 | |
---|
491 | 456 | void __rb_insert_augmented(struct rb_node *node, struct rb_root *root, |
---|
492 | | - bool newleft, struct rb_node **leftmost, |
---|
493 | 457 | void (*augment_rotate)(struct rb_node *old, struct rb_node *new)) |
---|
494 | 458 | { |
---|
495 | | - __rb_insert(node, root, newleft, leftmost, augment_rotate); |
---|
| 459 | + __rb_insert(node, root, augment_rotate); |
---|
496 | 460 | } |
---|
497 | 461 | EXPORT_SYMBOL(__rb_insert_augmented); |
---|
498 | 462 | |
---|
.. | .. |
---|
539 | 503 | if (node->rb_right) { |
---|
540 | 504 | node = node->rb_right; |
---|
541 | 505 | while (node->rb_left) |
---|
542 | | - node=node->rb_left; |
---|
| 506 | + node = node->rb_left; |
---|
543 | 507 | return (struct rb_node *)node; |
---|
544 | 508 | } |
---|
545 | 509 | |
---|
.. | .. |
---|
571 | 535 | if (node->rb_left) { |
---|
572 | 536 | node = node->rb_left; |
---|
573 | 537 | while (node->rb_right) |
---|
574 | | - node=node->rb_right; |
---|
| 538 | + node = node->rb_right; |
---|
575 | 539 | return (struct rb_node *)node; |
---|
576 | 540 | } |
---|
577 | 541 | |
---|
.. | .. |
---|
602 | 566 | __rb_change_child(victim, new, parent, root); |
---|
603 | 567 | } |
---|
604 | 568 | EXPORT_SYMBOL(rb_replace_node); |
---|
605 | | - |
---|
606 | | -void rb_replace_node_cached(struct rb_node *victim, struct rb_node *new, |
---|
607 | | - struct rb_root_cached *root) |
---|
608 | | -{ |
---|
609 | | - rb_replace_node(victim, new, &root->rb_root); |
---|
610 | | - |
---|
611 | | - if (root->rb_leftmost == victim) |
---|
612 | | - root->rb_leftmost = new; |
---|
613 | | -} |
---|
614 | | -EXPORT_SYMBOL(rb_replace_node_cached); |
---|
615 | 569 | |
---|
616 | 570 | void rb_replace_node_rcu(struct rb_node *victim, struct rb_node *new, |
---|
617 | 571 | struct rb_root *root) |
---|