]> Pileus Git - ~andy/gtk/blob - gtk/gtkrbtree.h
remove validation idle
[~andy/gtk] / gtk / gtkrbtree.h
1 /* gtkrbtree.h
2  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GTK_RBTREE_H__
21 #define __GTK_RBTREE_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26
27 #include <glib.h>
28 typedef enum
29 {
30   GTK_RBNODE_BLACK = 1 << 0,
31   GTK_RBNODE_RED = 1 << 1,
32   GTK_RBNODE_IS_PARENT = 1 << 2,
33   GTK_RBNODE_IS_SELECTED = 1 << 3,
34   GTK_RBNODE_IS_PRELIT = 1 << 4,
35   GTK_RBNODE_IS_VIEW = 1 << 5
36
37 } GtkRBNodeColor;
38
39 typedef struct _GtkRBTree GtkRBTree;
40 typedef struct _GtkRBNode GtkRBNode;
41 typedef struct _GtkRBTreeView GtkRBTreeView;
42
43 typedef void (*GtkRBTreeTraverseFunc) (GtkRBTree  *tree,
44                                        GtkRBNode  *node,
45                                        gpointer  data);
46
47 struct _GtkRBTree
48 {
49   GtkRBNode *root;
50   GtkRBNode *nil;
51   GtkRBTree *parent_tree;
52   GtkRBNode *parent_node;
53 };
54
55 struct _GtkRBNode
56 {
57   guint flags : 14;
58
59   /* We keep track of whether the aggregate count of children plus 1
60    * for the node itself comes to an even number.  The parity flag is
61    * the total count of children mod 2, where the total count of
62    * children gets computed in the same way that the total offset gets
63    * computed. i.e. not the same as the "count" field below which
64    * doesn't include children. We could replace parity with a
65    * full-size int field here, and then take % 2 to get the parity flag,
66    * but that would use extra memory.
67    */
68
69   guint parity : 1;
70   
71   GtkRBNode *left;
72   GtkRBNode *right;
73   GtkRBNode *parent;
74
75   /* count is the number of nodes beneath us, plus 1 for ourselves.
76    * i.e. node->left->count + node->right->count + 1
77    */
78   gint count;
79   
80   /* this is the total of sizes of
81    * node->left, node->right, our own height, and the height
82    * of all trees in ->children, iff children exists because
83    * the thing is expanded.
84    */
85   gint offset;
86
87   /* Child trees */
88   GtkRBTree *children;
89 };
90
91 #define GTK_RBNODE_GET_COLOR(node)              (node?(((node->flags&GTK_RBNODE_RED)==GTK_RBNODE_RED)?GTK_RBNODE_RED:GTK_RBNODE_BLACK):GTK_RBNODE_BLACK)
92 #define GTK_RBNODE_SET_COLOR(node,color)        if((node->flags&color)!=color)node->flags=node->flags^(GTK_RBNODE_RED|GTK_RBNODE_BLACK)
93 #define GTK_RBNODE_GET_HEIGHT(node)             (node->offset-(node->left->offset+node->right->offset+(node->children?node->children->root->offset:0)))
94 #define GTK_RBNODE_SET_FLAG(node, flag)         G_STMT_START{ (node->flags|=flag); }G_STMT_END
95 #define GTK_RBNODE_UNSET_FLAG(node, flag)       G_STMT_START{ (node->flags&=~(flag)); }G_STMT_END
96 #define GTK_RBNODE_FLAG_SET(node, flag)         (node?(((node->flags&flag)==flag)?TRUE:FALSE):FALSE)
97
98
99 void       _gtk_rbtree_push_allocator   (GAllocator             *allocator);
100 void       _gtk_rbtree_pop_allocator    (void);
101 GtkRBTree *_gtk_rbtree_new              (void);
102 void       _gtk_rbtree_free             (GtkRBTree              *tree);
103 void       _gtk_rbtree_remove           (GtkRBTree              *tree);
104 void       _gtk_rbtree_destroy          (GtkRBTree              *tree);
105 GtkRBNode *_gtk_rbtree_insert_before    (GtkRBTree              *tree,
106                                          GtkRBNode              *node,
107                                          gint                    height);
108 GtkRBNode *_gtk_rbtree_insert_after     (GtkRBTree              *tree,
109                                          GtkRBNode              *node,
110                                          gint                    height);
111 void       _gtk_rbtree_remove_node      (GtkRBTree              *tree,
112                                          GtkRBNode              *node);
113 GtkRBNode *_gtk_rbtree_find_count       (GtkRBTree              *tree,
114                                          gint                    count);
115 void       _gtk_rbtree_node_set_height  (GtkRBTree              *tree,
116                                          GtkRBNode              *node,
117                                          gint                    height);
118 gint       _gtk_rbtree_node_find_offset (GtkRBTree              *tree,
119                                          GtkRBNode              *node);
120 gint       _gtk_rbtree_node_find_parity (GtkRBTree              *tree,
121                                          GtkRBNode              *node);
122 gint       _gtk_rbtree_find_offset      (GtkRBTree              *tree,
123                                          gint                    offset,
124                                          GtkRBTree             **new_tree,
125                                          GtkRBNode             **new_node);
126 void       _gtk_rbtree_traverse         (GtkRBTree              *tree,
127                                          GtkRBNode              *node,
128                                          GTraverseType           order,
129                                          GtkRBTreeTraverseFunc   func,
130                                          gpointer                data);
131 GtkRBNode *_gtk_rbtree_next             (GtkRBTree              *tree,
132                                          GtkRBNode              *node);
133 GtkRBNode *_gtk_rbtree_prev             (GtkRBTree              *tree,
134                                          GtkRBNode              *node);
135 void       _gtk_rbtree_next_full        (GtkRBTree              *tree,
136                                          GtkRBNode              *node,
137                                          GtkRBTree             **new_tree,
138                                          GtkRBNode             **new_node);
139 void       _gtk_rbtree_prev_full        (GtkRBTree              *tree,
140                                          GtkRBNode              *node,
141                                          GtkRBTree             **new_tree,
142                                          GtkRBNode             **new_node);
143
144 gint       _gtk_rbtree_get_depth        (GtkRBTree              *tree);
145
146 /* This func just checks the integrity of the tree */
147 /* It will go away later. */
148 void       _gtk_rbtree_test             (const gchar            *where,
149                                          GtkRBTree              *tree);
150
151
152 #ifdef __cplusplus
153 }
154 #endif /* __cplusplus */
155
156 #endif /* __GTK_RBTREE_H__ */