rbtree.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. Red Black Trees
  3. (C) 1999 Andrea Arcangeli <andrea@suse.de>
  4. (C) 2002 David Woodhouse <dwmw2@infradead.org>
  5. (C) 2012 Michel Lespinasse <walken@google.com>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. linux/lib/rbtree.c
  18. */
  19. #include <linux/rbtree_augmented.h>
  20. #include <linux/export.h>
  21. /*
  22. * red-black trees properties: http://en.wikipedia.org/wiki/Rbtree
  23. *
  24. * 1) A node is either red or black
  25. * 2) The root is black
  26. * 3) All leaves (NULL) are black
  27. * 4) Both children of every red node are black
  28. * 5) Every simple path from root to leaves contains the same number
  29. * of black nodes.
  30. *
  31. * 4 and 5 give the O(log n) guarantee, since 4 implies you cannot have two
  32. * consecutive red nodes in a path and every red node is therefore followed by
  33. * a black. So if B is the number of black nodes on every simple path (as per
  34. * 5), then the longest possible path due to 4 is 2B.
  35. *
  36. * We shall indicate color with case, where black nodes are uppercase and red
  37. * nodes will be lowercase. Unknown color nodes shall be drawn as red within
  38. * parentheses and have some accompanying text comment.
  39. */
  40. /*
  41. * Notes on lockless lookups:
  42. *
  43. * All stores to the tree structure (rb_left and rb_right) must be done using
  44. * WRITE_ONCE(). And we must not inadvertently cause (temporary) loops in the
  45. * tree structure as seen in program order.
  46. *
  47. * These two requirements will allow lockless iteration of the tree -- not
  48. * correct iteration mind you, tree rotations are not atomic so a lookup might
  49. * miss entire subtrees.
  50. *
  51. * But they do guarantee that any such traversal will only see valid elements
  52. * and that it will indeed complete -- does not get stuck in a loop.
  53. *
  54. * It also guarantees that if the lookup returns an element it is the 'correct'
  55. * one. But not returning an element does _NOT_ mean it's not present.
  56. *
  57. * NOTE:
  58. *
  59. * Stores to __rb_parent_color are not important for simple lookups so those
  60. * are left undone as of now. Nor did I check for loops involving parent
  61. * pointers.
  62. */
  63. static inline void rb_set_black(struct rb_node *rb)
  64. {
  65. rb->__rb_parent_color |= RB_BLACK;
  66. }
  67. static inline struct rb_node *rb_red_parent(struct rb_node *red)
  68. {
  69. return (struct rb_node *)red->__rb_parent_color;
  70. }
  71. /*
  72. * Helper function for rotations:
  73. * - old's parent and color get assigned to new
  74. * - old gets assigned new as a parent and 'color' as a color.
  75. */
  76. static inline void
  77. __rb_rotate_set_parents(struct rb_node *old, struct rb_node *new,
  78. struct rb_root *root, int color)
  79. {
  80. struct rb_node *parent = rb_parent(old);
  81. new->__rb_parent_color = old->__rb_parent_color;
  82. rb_set_parent_color(old, new, color);
  83. __rb_change_child(old, new, parent, root);
  84. }
  85. static __always_inline void
  86. __rb_insert(struct rb_node *node, struct rb_root *root,
  87. bool newleft, struct rb_node **leftmost,
  88. void (*augment_rotate)(struct rb_node *old, struct rb_node *new))
  89. {
  90. struct rb_node *parent = rb_red_parent(node), *gparent, *tmp;
  91. if (newleft)
  92. *leftmost = node;
  93. while (true) {
  94. /*
  95. * Loop invariant: node is red.
  96. */
  97. if (unlikely(!parent)) {
  98. /*
  99. * The inserted node is root. Either this is the
  100. * first node, or we recursed at Case 1 below and
  101. * are no longer violating 4).
  102. */
  103. rb_set_parent_color(node, NULL, RB_BLACK);
  104. break;
  105. }
  106. /*
  107. * If there is a black parent, we are done.
  108. * Otherwise, take some corrective action as,
  109. * per 4), we don't want a red root or two
  110. * consecutive red nodes.
  111. */
  112. if(rb_is_black(parent))
  113. break;
  114. gparent = rb_red_parent(parent);
  115. tmp = gparent->rb_right;
  116. if (parent != tmp) { /* parent == gparent->rb_left */
  117. if (tmp && rb_is_red(tmp)) {
  118. /*
  119. * Case 1 - color flips
  120. *
  121. * G g
  122. * / \ / \
  123. * p u --> P U
  124. * / /
  125. * n n
  126. *
  127. * However, since g's parent might be red, and
  128. * 4) does not allow this, we need to recurse
  129. * at g.
  130. */
  131. rb_set_parent_color(tmp, gparent, RB_BLACK);
  132. rb_set_parent_color(parent, gparent, RB_BLACK);
  133. node = gparent;
  134. parent = rb_parent(node);
  135. rb_set_parent_color(node, parent, RB_RED);
  136. continue;
  137. }
  138. tmp = parent->rb_right;
  139. if (node == tmp) {
  140. /*
  141. * Case 2 - left rotate at parent
  142. *
  143. * G G
  144. * / \ / \
  145. * p U --> n U
  146. * \ /
  147. * n p
  148. *
  149. * This still leaves us in violation of 4), the
  150. * continuation into Case 3 will fix that.
  151. */
  152. tmp = node->rb_left;
  153. WRITE_ONCE(parent->rb_right, tmp);
  154. WRITE_ONCE(node->rb_left, parent);
  155. if (tmp)
  156. rb_set_parent_color(tmp, parent,
  157. RB_BLACK);
  158. rb_set_parent_color(parent, node, RB_RED);
  159. augment_rotate(parent, node);
  160. parent = node;
  161. tmp = node->rb_right;
  162. }
  163. /*
  164. * Case 3 - right rotate at gparent
  165. *
  166. * G P
  167. * / \ / \
  168. * p U --> n g
  169. * / \
  170. * n U
  171. */
  172. WRITE_ONCE(gparent->rb_left, tmp); /* == parent->rb_right */
  173. WRITE_ONCE(parent->rb_right, gparent);
  174. if (tmp)
  175. rb_set_parent_color(tmp, gparent, RB_BLACK);
  176. __rb_rotate_set_parents(gparent, parent, root, RB_RED);
  177. augment_rotate(gparent, parent);
  178. break;
  179. } else {
  180. tmp = gparent->rb_left;
  181. if (tmp && rb_is_red(tmp)) {
  182. /* Case 1 - color flips */
  183. rb_set_parent_color(tmp, gparent, RB_BLACK);
  184. rb_set_parent_color(parent, gparent, RB_BLACK);
  185. node = gparent;
  186. parent = rb_parent(node);
  187. rb_set_parent_color(node, parent, RB_RED);
  188. continue;
  189. }
  190. tmp = parent->rb_left;
  191. if (node == tmp) {
  192. /* Case 2 - right rotate at parent */
  193. tmp = node->rb_right;
  194. WRITE_ONCE(parent->rb_left, tmp);
  195. WRITE_ONCE(node->rb_right, parent);
  196. if (tmp)
  197. rb_set_parent_color(tmp, parent,
  198. RB_BLACK);
  199. rb_set_parent_color(parent, node, RB_RED);
  200. augment_rotate(parent, node);
  201. parent = node;
  202. tmp = node->rb_left;
  203. }
  204. /* Case 3 - left rotate at gparent */
  205. WRITE_ONCE(gparent->rb_right, tmp); /* == parent->rb_left */
  206. WRITE_ONCE(parent->rb_left, gparent);
  207. if (tmp)
  208. rb_set_parent_color(tmp, gparent, RB_BLACK);
  209. __rb_rotate_set_parents(gparent, parent, root, RB_RED);
  210. augment_rotate(gparent, parent);
  211. break;
  212. }
  213. }
  214. }
  215. /*
  216. * Inline version for rb_erase() use - we want to be able to inline
  217. * and eliminate the dummy_rotate callback there
  218. */
  219. static __always_inline void
  220. ____rb_erase_color(struct rb_node *parent, struct rb_root *root,
  221. void (*augment_rotate)(struct rb_node *old, struct rb_node *new))
  222. {
  223. struct rb_node *node = NULL, *sibling, *tmp1, *tmp2;
  224. while (true) {
  225. /*
  226. * Loop invariants:
  227. * - node is black (or NULL on first iteration)
  228. * - node is not the root (parent is not NULL)
  229. * - All leaf paths going through parent and node have a
  230. * black node count that is 1 lower than other leaf paths.
  231. */
  232. sibling = parent->rb_right;
  233. if (node != sibling) { /* node == parent->rb_left */
  234. if (rb_is_red(sibling)) {
  235. /*
  236. * Case 1 - left rotate at parent
  237. *
  238. * P S
  239. * / \ / \
  240. * N s --> p Sr
  241. * / \ / \
  242. * Sl Sr N Sl
  243. */
  244. tmp1 = sibling->rb_left;
  245. WRITE_ONCE(parent->rb_right, tmp1);
  246. WRITE_ONCE(sibling->rb_left, parent);
  247. rb_set_parent_color(tmp1, parent, RB_BLACK);
  248. __rb_rotate_set_parents(parent, sibling, root,
  249. RB_RED);
  250. augment_rotate(parent, sibling);
  251. sibling = tmp1;
  252. }
  253. tmp1 = sibling->rb_right;
  254. if (!tmp1 || rb_is_black(tmp1)) {
  255. tmp2 = sibling->rb_left;
  256. if (!tmp2 || rb_is_black(tmp2)) {
  257. /*
  258. * Case 2 - sibling color flip
  259. * (p could be either color here)
  260. *
  261. * (p) (p)
  262. * / \ / \
  263. * N S --> N s
  264. * / \ / \
  265. * Sl Sr Sl Sr
  266. *
  267. * This leaves us violating 5) which
  268. * can be fixed by flipping p to black
  269. * if it was red, or by recursing at p.
  270. * p is red when coming from Case 1.
  271. */
  272. rb_set_parent_color(sibling, parent,
  273. RB_RED);
  274. if (rb_is_red(parent))
  275. rb_set_black(parent);
  276. else {
  277. node = parent;
  278. parent = rb_parent(node);
  279. if (parent)
  280. continue;
  281. }
  282. break;
  283. }
  284. /*
  285. * Case 3 - right rotate at sibling
  286. * (p could be either color here)
  287. *
  288. * (p) (p)
  289. * / \ / \
  290. * N S --> N sl
  291. * / \ \
  292. * sl Sr S
  293. * \
  294. * Sr
  295. *
  296. * Note: p might be red, and then both
  297. * p and sl are red after rotation(which
  298. * breaks property 4). This is fixed in
  299. * Case 4 (in __rb_rotate_set_parents()
  300. * which set sl the color of p
  301. * and set p RB_BLACK)
  302. *
  303. * (p) (sl)
  304. * / \ / \
  305. * N sl --> P S
  306. * \ / \
  307. * S N Sr
  308. * \
  309. * Sr
  310. */
  311. tmp1 = tmp2->rb_right;
  312. WRITE_ONCE(sibling->rb_left, tmp1);
  313. WRITE_ONCE(tmp2->rb_right, sibling);
  314. WRITE_ONCE(parent->rb_right, tmp2);
  315. if (tmp1)
  316. rb_set_parent_color(tmp1, sibling,
  317. RB_BLACK);
  318. augment_rotate(sibling, tmp2);
  319. tmp1 = sibling;
  320. sibling = tmp2;
  321. }
  322. /*
  323. * Case 4 - left rotate at parent + color flips
  324. * (p and sl could be either color here.
  325. * After rotation, p becomes black, s acquires
  326. * p's color, and sl keeps its color)
  327. *
  328. * (p) (s)
  329. * / \ / \
  330. * N S --> P Sr
  331. * / \ / \
  332. * (sl) sr N (sl)
  333. */
  334. tmp2 = sibling->rb_left;
  335. WRITE_ONCE(parent->rb_right, tmp2);
  336. WRITE_ONCE(sibling->rb_left, parent);
  337. rb_set_parent_color(tmp1, sibling, RB_BLACK);
  338. if (tmp2)
  339. rb_set_parent(tmp2, parent);
  340. __rb_rotate_set_parents(parent, sibling, root,
  341. RB_BLACK);
  342. augment_rotate(parent, sibling);
  343. break;
  344. } else {
  345. sibling = parent->rb_left;
  346. if (rb_is_red(sibling)) {
  347. /* Case 1 - right rotate at parent */
  348. tmp1 = sibling->rb_right;
  349. WRITE_ONCE(parent->rb_left, tmp1);
  350. WRITE_ONCE(sibling->rb_right, parent);
  351. rb_set_parent_color(tmp1, parent, RB_BLACK);
  352. __rb_rotate_set_parents(parent, sibling, root,
  353. RB_RED);
  354. augment_rotate(parent, sibling);
  355. sibling = tmp1;
  356. }
  357. tmp1 = sibling->rb_left;
  358. if (!tmp1 || rb_is_black(tmp1)) {
  359. tmp2 = sibling->rb_right;
  360. if (!tmp2 || rb_is_black(tmp2)) {
  361. /* Case 2 - sibling color flip */
  362. rb_set_parent_color(sibling, parent,
  363. RB_RED);
  364. if (rb_is_red(parent))
  365. rb_set_black(parent);
  366. else {
  367. node = parent;
  368. parent = rb_parent(node);
  369. if (parent)
  370. continue;
  371. }
  372. break;
  373. }
  374. /* Case 3 - left rotate at sibling */
  375. tmp1 = tmp2->rb_left;
  376. WRITE_ONCE(sibling->rb_right, tmp1);
  377. WRITE_ONCE(tmp2->rb_left, sibling);
  378. WRITE_ONCE(parent->rb_left, tmp2);
  379. if (tmp1)
  380. rb_set_parent_color(tmp1, sibling,
  381. RB_BLACK);
  382. augment_rotate(sibling, tmp2);
  383. tmp1 = sibling;
  384. sibling = tmp2;
  385. }
  386. /* Case 4 - right rotate at parent + color flips */
  387. tmp2 = sibling->rb_right;
  388. WRITE_ONCE(parent->rb_left, tmp2);
  389. WRITE_ONCE(sibling->rb_right, parent);
  390. rb_set_parent_color(tmp1, sibling, RB_BLACK);
  391. if (tmp2)
  392. rb_set_parent(tmp2, parent);
  393. __rb_rotate_set_parents(parent, sibling, root,
  394. RB_BLACK);
  395. augment_rotate(parent, sibling);
  396. break;
  397. }
  398. }
  399. }
  400. /* Non-inline version for rb_erase_augmented() use */
  401. void __rb_erase_color(struct rb_node *parent, struct rb_root *root,
  402. void (*augment_rotate)(struct rb_node *old, struct rb_node *new))
  403. {
  404. ____rb_erase_color(parent, root, augment_rotate);
  405. }
  406. EXPORT_SYMBOL(__rb_erase_color);
  407. /*
  408. * Non-augmented rbtree manipulation functions.
  409. *
  410. * We use dummy augmented callbacks here, and have the compiler optimize them
  411. * out of the rb_insert_color() and rb_erase() function definitions.
  412. */
  413. static inline void dummy_propagate(struct rb_node *node, struct rb_node *stop) {}
  414. static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
  415. static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
  416. static const struct rb_augment_callbacks dummy_callbacks = {
  417. .propagate = dummy_propagate,
  418. .copy = dummy_copy,
  419. .rotate = dummy_rotate
  420. };
  421. void rb_insert_color(struct rb_node *node, struct rb_root *root)
  422. {
  423. __rb_insert(node, root, false, NULL, dummy_rotate);
  424. }
  425. EXPORT_SYMBOL(rb_insert_color);
  426. void rb_erase(struct rb_node *node, struct rb_root *root)
  427. {
  428. struct rb_node *rebalance;
  429. rebalance = __rb_erase_augmented(node, root,
  430. NULL, &dummy_callbacks);
  431. if (rebalance)
  432. ____rb_erase_color(rebalance, root, dummy_rotate);
  433. }
  434. EXPORT_SYMBOL(rb_erase);
  435. void rb_insert_color_cached(struct rb_node *node,
  436. struct rb_root_cached *root, bool leftmost)
  437. {
  438. __rb_insert(node, &root->rb_root, leftmost,
  439. &root->rb_leftmost, dummy_rotate);
  440. }
  441. EXPORT_SYMBOL(rb_insert_color_cached);
  442. void rb_erase_cached(struct rb_node *node, struct rb_root_cached *root)
  443. {
  444. struct rb_node *rebalance;
  445. rebalance = __rb_erase_augmented(node, &root->rb_root,
  446. &root->rb_leftmost, &dummy_callbacks);
  447. if (rebalance)
  448. ____rb_erase_color(rebalance, &root->rb_root, dummy_rotate);
  449. }
  450. EXPORT_SYMBOL(rb_erase_cached);
  451. /*
  452. * Augmented rbtree manipulation functions.
  453. *
  454. * This instantiates the same __always_inline functions as in the non-augmented
  455. * case, but this time with user-defined callbacks.
  456. */
  457. void __rb_insert_augmented(struct rb_node *node, struct rb_root *root,
  458. bool newleft, struct rb_node **leftmost,
  459. void (*augment_rotate)(struct rb_node *old, struct rb_node *new))
  460. {
  461. __rb_insert(node, root, newleft, leftmost, augment_rotate);
  462. }
  463. EXPORT_SYMBOL(__rb_insert_augmented);
  464. /*
  465. * This function returns the first node (in sort order) of the tree.
  466. */
  467. struct rb_node *rb_first(const struct rb_root *root)
  468. {
  469. struct rb_node *n;
  470. n = root->rb_node;
  471. if (!n)
  472. return NULL;
  473. while (n->rb_left)
  474. n = n->rb_left;
  475. return n;
  476. }
  477. EXPORT_SYMBOL(rb_first);
  478. struct rb_node *rb_last(const struct rb_root *root)
  479. {
  480. struct rb_node *n;
  481. n = root->rb_node;
  482. if (!n)
  483. return NULL;
  484. while (n->rb_right)
  485. n = n->rb_right;
  486. return n;
  487. }
  488. EXPORT_SYMBOL(rb_last);
  489. struct rb_node *rb_next(const struct rb_node *node)
  490. {
  491. struct rb_node *parent;
  492. if (RB_EMPTY_NODE(node))
  493. return NULL;
  494. /*
  495. * If we have a right-hand child, go down and then left as far
  496. * as we can.
  497. */
  498. if (node->rb_right) {
  499. node = node->rb_right;
  500. while (node->rb_left)
  501. node=node->rb_left;
  502. return (struct rb_node *)node;
  503. }
  504. /*
  505. * No right-hand children. Everything down and left is smaller than us,
  506. * so any 'next' node must be in the general direction of our parent.
  507. * Go up the tree; any time the ancestor is a right-hand child of its
  508. * parent, keep going up. First time it's a left-hand child of its
  509. * parent, said parent is our 'next' node.
  510. */
  511. while ((parent = rb_parent(node)) && node == parent->rb_right)
  512. node = parent;
  513. return parent;
  514. }
  515. EXPORT_SYMBOL(rb_next);
  516. struct rb_node *rb_prev(const struct rb_node *node)
  517. {
  518. struct rb_node *parent;
  519. if (RB_EMPTY_NODE(node))
  520. return NULL;
  521. /*
  522. * If we have a left-hand child, go down and then right as far
  523. * as we can.
  524. */
  525. if (node->rb_left) {
  526. node = node->rb_left;
  527. while (node->rb_right)
  528. node=node->rb_right;
  529. return (struct rb_node *)node;
  530. }
  531. /*
  532. * No left-hand children. Go up till we find an ancestor which
  533. * is a right-hand child of its parent.
  534. */
  535. while ((parent = rb_parent(node)) && node == parent->rb_left)
  536. node = parent;
  537. return parent;
  538. }
  539. EXPORT_SYMBOL(rb_prev);
  540. void rb_replace_node(struct rb_node *victim, struct rb_node *new,
  541. struct rb_root *root)
  542. {
  543. struct rb_node *parent = rb_parent(victim);
  544. /* Copy the pointers/colour from the victim to the replacement */
  545. *new = *victim;
  546. /* Set the surrounding nodes to point to the replacement */
  547. if (victim->rb_left)
  548. rb_set_parent(victim->rb_left, new);
  549. if (victim->rb_right)
  550. rb_set_parent(victim->rb_right, new);
  551. __rb_change_child(victim, new, parent, root);
  552. }
  553. EXPORT_SYMBOL(rb_replace_node);
  554. void rb_replace_node_rcu(struct rb_node *victim, struct rb_node *new,
  555. struct rb_root *root)
  556. {
  557. struct rb_node *parent = rb_parent(victim);
  558. /* Copy the pointers/colour from the victim to the replacement */
  559. *new = *victim;
  560. /* Set the surrounding nodes to point to the replacement */
  561. if (victim->rb_left)
  562. rb_set_parent(victim->rb_left, new);
  563. if (victim->rb_right)
  564. rb_set_parent(victim->rb_right, new);
  565. /* Set the parent's pointer to the new node last after an RCU barrier
  566. * so that the pointers onwards are seen to be set correctly when doing
  567. * an RCU walk over the tree.
  568. */
  569. __rb_change_child_rcu(victim, new, parent, root);
  570. }
  571. EXPORT_SYMBOL(rb_replace_node_rcu);
  572. static struct rb_node *rb_left_deepest_node(const struct rb_node *node)
  573. {
  574. for (;;) {
  575. if (node->rb_left)
  576. node = node->rb_left;
  577. else if (node->rb_right)
  578. node = node->rb_right;
  579. else
  580. return (struct rb_node *)node;
  581. }
  582. }
  583. struct rb_node *rb_next_postorder(const struct rb_node *node)
  584. {
  585. const struct rb_node *parent;
  586. if (!node)
  587. return NULL;
  588. parent = rb_parent(node);
  589. /* If we're sitting on node, we've already seen our children */
  590. if (parent && node == parent->rb_left && parent->rb_right) {
  591. /* If we are the parent's left node, go to the parent's right
  592. * node then all the way down to the left */
  593. return rb_left_deepest_node(parent->rb_right);
  594. } else
  595. /* Otherwise we are the parent's right node, and the parent
  596. * should be next */
  597. return (struct rb_node *)parent;
  598. }
  599. EXPORT_SYMBOL(rb_next_postorder);
  600. struct rb_node *rb_first_postorder(const struct rb_root *root)
  601. {
  602. if (!root->rb_node)
  603. return NULL;
  604. return rb_left_deepest_node(root->rb_node);
  605. }
  606. EXPORT_SYMBOL(rb_first_postorder);