1 diff -urN v2.2.21/linux/Makefile linux/Makefile
2 --- v2.2.21/linux/Makefile Tue May 21 23:26:01 2002
3 +++ linux/Makefile Sat Aug 10 20:52:16 2002
5 DRIVERS := $(DRIVERS) drivers/telephony/telephony.a
8 +ifeq ($(CONFIG_NET_SCHED),y)
9 +LIBS := $(TOPDIR)/lib/lib_extra_objs.o $(LIBS)
12 include arch/$(ARCH)/Makefile
15 diff -urN v2.2.21/linux/include/linux/rbtree.h linux/include/linux/rbtree.h
16 --- v2.2.21/linux/include/linux/rbtree.h Thu Jan 1 00:00:00 1970
17 +++ linux/include/linux/rbtree.h Sat Aug 10 20:39:46 2002
21 + (C) 1999 Andrea Arcangeli <andrea@suse.de>
23 + This program is free software; you can redistribute it and/or modify
24 + it under the terms of the GNU General Public License as published by
25 + the Free Software Foundation; either version 2 of the License, or
26 + (at your option) any later version.
28 + This program is distributed in the hope that it will be useful,
29 + but WITHOUT ANY WARRANTY; without even the implied warranty of
30 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 + GNU General Public License for more details.
33 + You should have received a copy of the GNU General Public License
34 + along with this program; if not, write to the Free Software
35 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 + linux/include/linux/rbtree.h
39 + To use rbtrees you'll have to implement your own insert and search cores.
40 + This will avoid us to use callbacks and to drop drammatically performances.
41 + I know it's not the cleaner way, but in C (not in C++) to get
42 + performances and genericity...
44 + Some example of insert and search follows here. The search is a plain
45 + normal search over an ordered tree. The insert instead must be implemented
46 + int two steps: as first thing the code must insert the element in
47 + order as a red leaf in the tree, then the support library function
48 + rb_insert_color() must be called. Such function will do the
49 + not trivial work to rebalance the rbtree if necessary.
51 +-----------------------------------------------------------------------
52 +static inline struct page * rb_search_page_cache(struct inode * inode,
53 + unsigned long offset)
55 + rb_node_t * n = inode->i_rb_page_cache.rb_node;
60 + page = rb_entry(n, struct page, rb_page_cache);
62 + if (offset < page->offset)
64 + else if (offset > page->offset)
72 +static inline struct page * __rb_insert_page_cache(struct inode * inode,
73 + unsigned long offset,
76 + rb_node_t ** p = &inode->i_rb_page_cache.rb_node;
77 + rb_node_t * parent = NULL;
83 + page = rb_entry(parent, struct page, rb_page_cache);
85 + if (offset < page->offset)
87 + else if (offset > page->offset)
88 + p = &(*p)->rb_right;
93 + rb_link_node(node, parent, p);
98 +static inline struct page * rb_insert_page_cache(struct inode * inode,
99 + unsigned long offset,
103 + if ((ret = __rb_insert_page_cache(inode, offset, node)))
105 + rb_insert_color(node, &inode->i_rb_page_cache);
109 +-----------------------------------------------------------------------
112 +#ifndef _LINUX_RBTREE_H
113 +#define _LINUX_RBTREE_H
115 +#include <linux/kernel.h>
116 +#include <linux/stddef.h>
118 +typedef struct rb_node_s
120 + struct rb_node_s * rb_parent;
124 + struct rb_node_s * rb_right;
125 + struct rb_node_s * rb_left;
129 +typedef struct rb_root_s
131 + struct rb_node_s * rb_node;
135 +#define RB_ROOT (rb_root_t) { NULL, }
136 +#define rb_entry(ptr, type, member) \
137 + ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
139 +extern void rb_insert_color(rb_node_t *, rb_root_t *);
140 +extern void rb_erase(rb_node_t *, rb_root_t *);
142 +static inline void rb_link_node(rb_node_t * node, rb_node_t * parent, rb_node_t ** rb_link)
144 + node->rb_parent = parent;
145 + node->rb_color = RB_RED;
146 + node->rb_left = node->rb_right = NULL;
151 +#endif /* _LINUX_RBTREE_H */
152 diff -urN v2.2.21/linux/lib/Makefile linux/lib/Makefile
153 --- v2.2.21/linux/lib/Makefile Mon Nov 27 13:54:00 1995
154 +++ linux/lib/Makefile Sat Aug 10 20:43:42 2002
156 # unless it's something special (ie not a .c file).
159 +# Currently, rbtree.o is used only from net/sched/sch_htb.c
160 +ifeq ($(CONFIG_NET_SCHED),y)
161 +O_TARGET := lib_extra_objs.o
166 L_OBJS := errno.o ctype.o string.o vsprintf.o
168 diff -urN v2.2.21/linux/lib/rbtree.c linux/lib/rbtree.c
169 --- v2.2.21/linux/lib/rbtree.c Thu Jan 1 00:00:00 1970
170 +++ linux/lib/rbtree.c Sat Aug 10 20:39:46 2002
174 + (C) 1999 Andrea Arcangeli <andrea@suse.de>
176 + This program is free software; you can redistribute it and/or modify
177 + it under the terms of the GNU General Public License as published by
178 + the Free Software Foundation; either version 2 of the License, or
179 + (at your option) any later version.
181 + This program is distributed in the hope that it will be useful,
182 + but WITHOUT ANY WARRANTY; without even the implied warranty of
183 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
184 + GNU General Public License for more details.
186 + You should have received a copy of the GNU General Public License
187 + along with this program; if not, write to the Free Software
188 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
193 +#include <linux/rbtree.h>
194 +#include <linux/module.h>
196 +static void __rb_rotate_left(rb_node_t * node, rb_root_t * root)
198 + rb_node_t * right = node->rb_right;
200 + if ((node->rb_right = right->rb_left))
201 + right->rb_left->rb_parent = node;
202 + right->rb_left = node;
204 + if ((right->rb_parent = node->rb_parent))
206 + if (node == node->rb_parent->rb_left)
207 + node->rb_parent->rb_left = right;
209 + node->rb_parent->rb_right = right;
212 + root->rb_node = right;
213 + node->rb_parent = right;
216 +static void __rb_rotate_right(rb_node_t * node, rb_root_t * root)
218 + rb_node_t * left = node->rb_left;
220 + if ((node->rb_left = left->rb_right))
221 + left->rb_right->rb_parent = node;
222 + left->rb_right = node;
224 + if ((left->rb_parent = node->rb_parent))
226 + if (node == node->rb_parent->rb_right)
227 + node->rb_parent->rb_right = left;
229 + node->rb_parent->rb_left = left;
232 + root->rb_node = left;
233 + node->rb_parent = left;
236 +void rb_insert_color(rb_node_t * node, rb_root_t * root)
238 + rb_node_t * parent, * gparent;
240 + while ((parent = node->rb_parent) && parent->rb_color == RB_RED)
242 + gparent = parent->rb_parent;
244 + if (parent == gparent->rb_left)
247 + register rb_node_t * uncle = gparent->rb_right;
248 + if (uncle && uncle->rb_color == RB_RED)
250 + uncle->rb_color = RB_BLACK;
251 + parent->rb_color = RB_BLACK;
252 + gparent->rb_color = RB_RED;
258 + if (parent->rb_right == node)
260 + register rb_node_t * tmp;
261 + __rb_rotate_left(parent, root);
267 + parent->rb_color = RB_BLACK;
268 + gparent->rb_color = RB_RED;
269 + __rb_rotate_right(gparent, root);
272 + register rb_node_t * uncle = gparent->rb_left;
273 + if (uncle && uncle->rb_color == RB_RED)
275 + uncle->rb_color = RB_BLACK;
276 + parent->rb_color = RB_BLACK;
277 + gparent->rb_color = RB_RED;
283 + if (parent->rb_left == node)
285 + register rb_node_t * tmp;
286 + __rb_rotate_right(parent, root);
292 + parent->rb_color = RB_BLACK;
293 + gparent->rb_color = RB_RED;
294 + __rb_rotate_left(gparent, root);
298 + root->rb_node->rb_color = RB_BLACK;
300 +EXPORT_SYMBOL(rb_insert_color);
302 +static void __rb_erase_color(rb_node_t * node, rb_node_t * parent,
307 + while ((!node || node->rb_color == RB_BLACK) && node != root->rb_node)
309 + if (parent->rb_left == node)
311 + other = parent->rb_right;
312 + if (other->rb_color == RB_RED)
314 + other->rb_color = RB_BLACK;
315 + parent->rb_color = RB_RED;
316 + __rb_rotate_left(parent, root);
317 + other = parent->rb_right;
319 + if ((!other->rb_left ||
320 + other->rb_left->rb_color == RB_BLACK)
321 + && (!other->rb_right ||
322 + other->rb_right->rb_color == RB_BLACK))
324 + other->rb_color = RB_RED;
326 + parent = node->rb_parent;
330 + if (!other->rb_right ||
331 + other->rb_right->rb_color == RB_BLACK)
333 + register rb_node_t * o_left;
334 + if ((o_left = other->rb_left))
335 + o_left->rb_color = RB_BLACK;
336 + other->rb_color = RB_RED;
337 + __rb_rotate_right(other, root);
338 + other = parent->rb_right;
340 + other->rb_color = parent->rb_color;
341 + parent->rb_color = RB_BLACK;
342 + if (other->rb_right)
343 + other->rb_right->rb_color = RB_BLACK;
344 + __rb_rotate_left(parent, root);
345 + node = root->rb_node;
351 + other = parent->rb_left;
352 + if (other->rb_color == RB_RED)
354 + other->rb_color = RB_BLACK;
355 + parent->rb_color = RB_RED;
356 + __rb_rotate_right(parent, root);
357 + other = parent->rb_left;
359 + if ((!other->rb_left ||
360 + other->rb_left->rb_color == RB_BLACK)
361 + && (!other->rb_right ||
362 + other->rb_right->rb_color == RB_BLACK))
364 + other->rb_color = RB_RED;
366 + parent = node->rb_parent;
370 + if (!other->rb_left ||
371 + other->rb_left->rb_color == RB_BLACK)
373 + register rb_node_t * o_right;
374 + if ((o_right = other->rb_right))
375 + o_right->rb_color = RB_BLACK;
376 + other->rb_color = RB_RED;
377 + __rb_rotate_left(other, root);
378 + other = parent->rb_left;
380 + other->rb_color = parent->rb_color;
381 + parent->rb_color = RB_BLACK;
382 + if (other->rb_left)
383 + other->rb_left->rb_color = RB_BLACK;
384 + __rb_rotate_right(parent, root);
385 + node = root->rb_node;
391 + node->rb_color = RB_BLACK;
394 +void rb_erase(rb_node_t * node, rb_root_t * root)
396 + rb_node_t * child, * parent;
399 + if (!node->rb_left)
400 + child = node->rb_right;
401 + else if (!node->rb_right)
402 + child = node->rb_left;
405 + rb_node_t * old = node, * left;
407 + node = node->rb_right;
408 + while ((left = node->rb_left))
410 + child = node->rb_right;
411 + parent = node->rb_parent;
412 + color = node->rb_color;
415 + child->rb_parent = parent;
418 + if (parent->rb_left == node)
419 + parent->rb_left = child;
421 + parent->rb_right = child;
424 + root->rb_node = child;
426 + if (node->rb_parent == old)
428 + node->rb_parent = old->rb_parent;
429 + node->rb_color = old->rb_color;
430 + node->rb_right = old->rb_right;
431 + node->rb_left = old->rb_left;
433 + if (old->rb_parent)
435 + if (old->rb_parent->rb_left == old)
436 + old->rb_parent->rb_left = node;
438 + old->rb_parent->rb_right = node;
440 + root->rb_node = node;
442 + old->rb_left->rb_parent = node;
444 + old->rb_right->rb_parent = node;
448 + parent = node->rb_parent;
449 + color = node->rb_color;
452 + child->rb_parent = parent;
455 + if (parent->rb_left == node)
456 + parent->rb_left = child;
458 + parent->rb_right = child;
461 + root->rb_node = child;
464 + if (color == RB_BLACK)
465 + __rb_erase_color(child, parent, root);
467 +EXPORT_SYMBOL(rb_erase);