Coverage Report

Created: 2026-10-28 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tmux/compat/tree.h
Line
Count
Source
1
/*  $OpenBSD: tree.h,v 1.13 2011/07/09 00:19:45 pirofti Exp $ */
2
/*
3
 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef _SYS_TREE_H_
28
#define _SYS_TREE_H_
29
30
/*
31
 * This file defines data structures for different types of trees:
32
 * splay trees and red-black trees.
33
 *
34
 * A splay tree is a self-organizing data structure.  Every operation
35
 * on the tree causes a splay to happen.  The splay moves the requested
36
 * node to the root of the tree and partly rebalances it.
37
 *
38
 * This has the benefit that request locality causes faster lookups as
39
 * the requested nodes move to the top of the tree.  On the other hand,
40
 * every lookup causes memory writes.
41
 *
42
 * The Balance Theorem bounds the total access time for m operations
43
 * and n inserts on an initially empty tree as O((m + n)lg n).  The
44
 * amortized cost for a sequence of m accesses to a splay tree is O(lg n);
45
 *
46
 * A red-black tree is a binary search tree with the node color as an
47
 * extra attribute.  It fulfills a set of conditions:
48
 *  - every search path from the root to a leaf consists of the
49
 *    same number of black nodes,
50
 *  - each red node (except for the root) has a black parent,
51
 *  - each leaf node is black.
52
 *
53
 * Every operation on a red-black tree is bounded as O(lg n).
54
 * The maximum height of a red-black tree is 2lg (n+1).
55
 */
56
57
#define SPLAY_HEAD(name, type)            \
58
struct name {               \
59
  struct type *sph_root; /* root of the tree */     \
60
}
61
62
#define SPLAY_INITIALIZER(root)           \
63
  { NULL }
64
65
#define SPLAY_INIT(root) do {           \
66
  (root)->sph_root = NULL;          \
67
} while (0)
68
69
#define SPLAY_ENTRY(type)           \
70
struct {                \
71
  struct type *spe_left; /* left element */     \
72
  struct type *spe_right; /* right element */     \
73
}
74
75
#define SPLAY_LEFT(elm, field)    (elm)->field.spe_left
76
#define SPLAY_RIGHT(elm, field)   (elm)->field.spe_right
77
#define SPLAY_ROOT(head)    (head)->sph_root
78
#define SPLAY_EMPTY(head)   (SPLAY_ROOT(head) == NULL)
79
80
/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */
81
#define SPLAY_ROTATE_RIGHT(head, tmp, field) do {     \
82
  SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field);  \
83
  SPLAY_RIGHT(tmp, field) = (head)->sph_root;     \
84
  (head)->sph_root = tmp;           \
85
} while (0)
86
  
87
#define SPLAY_ROTATE_LEFT(head, tmp, field) do {      \
88
  SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field);  \
89
  SPLAY_LEFT(tmp, field) = (head)->sph_root;      \
90
  (head)->sph_root = tmp;           \
91
} while (0)
92
93
#define SPLAY_LINKLEFT(head, tmp, field) do {       \
94
  SPLAY_LEFT(tmp, field) = (head)->sph_root;      \
95
  tmp = (head)->sph_root;           \
96
  (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);   \
97
} while (0)
98
99
#define SPLAY_LINKRIGHT(head, tmp, field) do {        \
100
  SPLAY_RIGHT(tmp, field) = (head)->sph_root;     \
101
  tmp = (head)->sph_root;           \
102
  (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);  \
103
} while (0)
104
105
#define SPLAY_ASSEMBLE(head, node, left, right, field) do {   \
106
  SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \
107
  SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\
108
  SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \
109
  SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \
110
} while (0)
111
112
/* Generates prototypes and inline functions */
113
114
#define SPLAY_PROTOTYPE(name, type, field, cmp)       \
115
void name##_SPLAY(struct name *, struct type *);      \
116
void name##_SPLAY_MINMAX(struct name *, int);       \
117
struct type *name##_SPLAY_INSERT(struct name *, struct type *);   \
118
struct type *name##_SPLAY_REMOVE(struct name *, struct type *);   \
119
                  \
120
/* Finds the node with the same key as elm */       \
121
static __inline struct type *           \
122
name##_SPLAY_FIND(struct name *head, struct type *elm)      \
123
{                 \
124
  if (SPLAY_EMPTY(head))            \
125
    return(NULL);           \
126
  name##_SPLAY(head, elm);          \
127
  if ((cmp)(elm, (head)->sph_root) == 0)        \
128
    return (head->sph_root);        \
129
  return (NULL);              \
130
}                 \
131
                  \
132
static __inline struct type *           \
133
name##_SPLAY_NEXT(struct name *head, struct type *elm)      \
134
{                 \
135
  name##_SPLAY(head, elm);          \
136
  if (SPLAY_RIGHT(elm, field) != NULL) {        \
137
    elm = SPLAY_RIGHT(elm, field);        \
138
    while (SPLAY_LEFT(elm, field) != NULL) {    \
139
      elm = SPLAY_LEFT(elm, field);     \
140
    }             \
141
  } else                \
142
    elm = NULL;           \
143
  return (elm);             \
144
}                 \
145
                  \
146
static __inline struct type *           \
147
name##_SPLAY_MIN_MAX(struct name *head, int val)      \
148
{                 \
149
  name##_SPLAY_MINMAX(head, val);         \
150
        return (SPLAY_ROOT(head));          \
151
}
152
153
/* Main splay operation.
154
 * Moves node close to the key of elm to top
155
 */
156
#define SPLAY_GENERATE(name, type, field, cmp)        \
157
struct type *               \
158
name##_SPLAY_INSERT(struct name *head, struct type *elm)    \
159
{                 \
160
    if (SPLAY_EMPTY(head)) {            \
161
      SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL;  \
162
    } else {                \
163
      int __comp;             \
164
      name##_SPLAY(head, elm);          \
165
      __comp = (cmp)(elm, (head)->sph_root);      \
166
      if(__comp < 0) {            \
167
        SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\
168
        SPLAY_RIGHT(elm, field) = (head)->sph_root;   \
169
        SPLAY_LEFT((head)->sph_root, field) = NULL;   \
170
      } else if (__comp > 0) {          \
171
        SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\
172
        SPLAY_LEFT(elm, field) = (head)->sph_root;    \
173
        SPLAY_RIGHT((head)->sph_root, field) = NULL;  \
174
      } else              \
175
        return ((head)->sph_root);        \
176
    }                 \
177
    (head)->sph_root = (elm);           \
178
    return (NULL);              \
179
}                 \
180
                  \
181
struct type *               \
182
name##_SPLAY_REMOVE(struct name *head, struct type *elm)    \
183
{                 \
184
  struct type *__tmp;           \
185
  if (SPLAY_EMPTY(head))            \
186
    return (NULL);            \
187
  name##_SPLAY(head, elm);          \
188
  if ((cmp)(elm, (head)->sph_root) == 0) {      \
189
    if (SPLAY_LEFT((head)->sph_root, field) == NULL) {  \
190
      (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\
191
    } else {            \
192
      __tmp = SPLAY_RIGHT((head)->sph_root, field); \
193
      (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\
194
      name##_SPLAY(head, elm);      \
195
      SPLAY_RIGHT((head)->sph_root, field) = __tmp; \
196
    }             \
197
    return (elm);           \
198
  }               \
199
  return (NULL);              \
200
}                 \
201
                  \
202
void                  \
203
name##_SPLAY(struct name *head, struct type *elm)     \
204
{                 \
205
  struct type __node, *__left, *__right, *__tmp;      \
206
  int __comp;             \
207
\
208
  SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
209
  __left = __right = &__node;         \
210
\
211
  while ((__comp = (cmp)(elm, (head)->sph_root))) {   \
212
    if (__comp < 0) {         \
213
      __tmp = SPLAY_LEFT((head)->sph_root, field);  \
214
      if (__tmp == NULL)        \
215
        break;          \
216
      if ((cmp)(elm, __tmp) < 0){     \
217
        SPLAY_ROTATE_RIGHT(head, __tmp, field); \
218
        if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
219
          break;        \
220
      }           \
221
      SPLAY_LINKLEFT(head, __right, field);   \
222
    } else if (__comp > 0) {        \
223
      __tmp = SPLAY_RIGHT((head)->sph_root, field); \
224
      if (__tmp == NULL)        \
225
        break;          \
226
      if ((cmp)(elm, __tmp) > 0){     \
227
        SPLAY_ROTATE_LEFT(head, __tmp, field);  \
228
        if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
229
          break;        \
230
      }           \
231
      SPLAY_LINKRIGHT(head, __left, field);   \
232
    }             \
233
  }               \
234
  SPLAY_ASSEMBLE(head, &__node, __left, __right, field);    \
235
}                 \
236
                  \
237
/* Splay with either the minimum or the maximum element     \
238
 * Used to find minimum or maximum element in tree.     \
239
 */                 \
240
void name##_SPLAY_MINMAX(struct name *head, int __comp) \
241
{                 \
242
  struct type __node, *__left, *__right, *__tmp;      \
243
\
244
  SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
245
  __left = __right = &__node;         \
246
\
247
  while (1) {             \
248
    if (__comp < 0) {         \
249
      __tmp = SPLAY_LEFT((head)->sph_root, field);  \
250
      if (__tmp == NULL)        \
251
        break;          \
252
      if (__comp < 0){        \
253
        SPLAY_ROTATE_RIGHT(head, __tmp, field); \
254
        if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
255
          break;        \
256
      }           \
257
      SPLAY_LINKLEFT(head, __right, field);   \
258
    } else if (__comp > 0) {        \
259
      __tmp = SPLAY_RIGHT((head)->sph_root, field); \
260
      if (__tmp == NULL)        \
261
        break;          \
262
      if (__comp > 0) {       \
263
        SPLAY_ROTATE_LEFT(head, __tmp, field);  \
264
        if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
265
          break;        \
266
      }           \
267
      SPLAY_LINKRIGHT(head, __left, field);   \
268
    }             \
269
  }               \
270
  SPLAY_ASSEMBLE(head, &__node, __left, __right, field);    \
271
}
272
273
#define SPLAY_NEGINF  -1
274
#define SPLAY_INF 1
275
276
#define SPLAY_INSERT(name, x, y)  name##_SPLAY_INSERT(x, y)
277
#define SPLAY_REMOVE(name, x, y)  name##_SPLAY_REMOVE(x, y)
278
#define SPLAY_FIND(name, x, y)    name##_SPLAY_FIND(x, y)
279
#define SPLAY_NEXT(name, x, y)    name##_SPLAY_NEXT(x, y)
280
#define SPLAY_MIN(name, x)    (SPLAY_EMPTY(x) ? NULL  \
281
          : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF))
282
#define SPLAY_MAX(name, x)    (SPLAY_EMPTY(x) ? NULL  \
283
          : name##_SPLAY_MIN_MAX(x, SPLAY_INF))
284
285
#define SPLAY_FOREACH(x, name, head)          \
286
  for ((x) = SPLAY_MIN(name, head);       \
287
       (x) != NULL;           \
288
       (x) = SPLAY_NEXT(name, head, x))
289
290
/* Macros that define a red-black tree */
291
#define RB_HEAD(name, type)           \
292
struct name {               \
293
  struct type *rbh_root; /* root of the tree */     \
294
}
295
296
#define RB_INITIALIZER(root)            \
297
  { NULL }
298
299
4.26M
#define RB_INIT(root) do {           \
300
4.26M
  (root)->rbh_root = NULL;          \
301
4.26M
} while (0)
302
303
218M
#define RB_BLACK  0
304
186M
#define RB_RED    1
305
#define RB_ENTRY(type)              \
306
struct {                \
307
  struct type *rbe_left;    /* left element */    \
308
  struct type *rbe_right;   /* right element */   \
309
  struct type *rbe_parent;  /* parent element */    \
310
  int rbe_color;      /* node color */    \
311
}
312
313
498M
#define RB_LEFT(elm, field)   (elm)->field.rbe_left
314
357M
#define RB_RIGHT(elm, field)    (elm)->field.rbe_right
315
427M
#define RB_PARENT(elm, field)   (elm)->field.rbe_parent
316
413M
#define RB_COLOR(elm, field)    (elm)->field.rbe_color
317
109M
#define RB_ROOT(head)     (head)->rbh_root
318
0
#define RB_EMPTY(head)      (RB_ROOT(head) == NULL)
319
320
41.0M
#define RB_SET(elm, parent, field) do {         \
321
41.0M
  RB_PARENT(elm, field) = parent;          \
322
41.0M
  RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL;    \
323
41.0M
  RB_COLOR(elm, field) = RB_RED;         \
324
41.0M
} while (0)
325
326
31.0M
#define RB_SET_BLACKRED(black, red, field) do {       \
327
31.0M
  RB_COLOR(black, field) = RB_BLACK;       \
328
31.0M
  RB_COLOR(red, field) = RB_RED;         \
329
31.0M
} while (0)
330
331
#ifndef RB_AUGMENT
332
130M
#define RB_AUGMENT(x) do {} while (0)
333
#endif
334
335
11.1M
#define RB_ROTATE_LEFT(head, elm, tmp, field) do {     \
336
11.1M
  (tmp) = RB_RIGHT(elm, field);         \
337
11.1M
  if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) {   \
338
6.89M
    RB_PARENT(RB_LEFT(tmp, field), field) = (elm);   \
339
6.89M
  }                \
340
11.1M
  RB_AUGMENT(elm);            \
341
11.1M
  if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) {   \
342
5.28M
    if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
343
5.28M
      RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
344
5.28M
    else              \
345
5.28M
      RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
346
5.28M
  } else               \
347
11.1M
    (head)->rbh_root = (tmp);       \
348
11.1M
  RB_LEFT(tmp, field) = (elm);         \
349
11.1M
  RB_PARENT(elm, field) = (tmp);         \
350
11.1M
  RB_AUGMENT(tmp);            \
351
11.1M
  if ((RB_PARENT(tmp, field)))          \
352
11.1M
    RB_AUGMENT(RB_PARENT(tmp, field));      \
353
11.1M
} while (0)
354
355
12.0M
#define RB_ROTATE_RIGHT(head, elm, tmp, field) do {     \
356
12.0M
  (tmp) = RB_LEFT(elm, field);         \
357
12.0M
  if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) {   \
358
2.59M
    RB_PARENT(RB_RIGHT(tmp, field), field) = (elm);    \
359
2.59M
  }                \
360
12.0M
  RB_AUGMENT(elm);            \
361
12.0M
  if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) {   \
362
9.44M
    if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
363
9.44M
      RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
364
9.44M
    else              \
365
9.44M
      RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
366
9.44M
  } else               \
367
12.0M
    (head)->rbh_root = (tmp);       \
368
12.0M
  RB_RIGHT(tmp, field) = (elm);         \
369
12.0M
  RB_PARENT(elm, field) = (tmp);         \
370
12.0M
  RB_AUGMENT(tmp);            \
371
12.0M
  if ((RB_PARENT(tmp, field)))          \
372
12.0M
    RB_AUGMENT(RB_PARENT(tmp, field));      \
373
12.0M
} while (0)
374
375
/* Generates prototypes and inline functions */
376
#define RB_PROTOTYPE(name, type, field, cmp)        \
377
  RB_PROTOTYPE_INTERNAL(name, type, field, cmp,)
378
#define RB_PROTOTYPE_STATIC(name, type, field, cmp)     \
379
  RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
380
#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr)   \
381
attr void name##_RB_INSERT_COLOR(struct name *, struct type *);   \
382
attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\
383
attr struct type *name##_RB_REMOVE(struct name *, struct type *); \
384
attr struct type *name##_RB_INSERT(struct name *, struct type *); \
385
attr struct type *name##_RB_FIND(struct name *, struct type *);   \
386
attr struct type *name##_RB_NFIND(struct name *, struct type *);  \
387
attr struct type *name##_RB_NEXT(struct type *);      \
388
attr struct type *name##_RB_PREV(struct type *);      \
389
attr struct type *name##_RB_MINMAX(struct name *, int);     \
390
                  \
391
392
/* Main rb operation.
393
 * Moves node close to the key of elm to top
394
 */
395
#define RB_GENERATE(name, type, field, cmp)       \
396
  RB_GENERATE_INTERNAL(name, type, field, cmp,)
397
#define RB_GENERATE_STATIC(name, type, field, cmp)      \
398
  RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
399
#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr)    \
400
attr void               \
401
41.0M
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
41.0M
{                 \
403
41.0M
  struct type *parent, *gparent, *tmp;        \
404
67.8M
  while ((parent = RB_PARENT(elm, field)) &&      \
405
67.8M
      RB_COLOR(parent, field) == RB_RED) {     \
406
26.7M
    gparent = RB_PARENT(parent, field);      \
407
26.7M
    if (parent == RB_LEFT(gparent, field)) {   \
408
20.7M
      tmp = RB_RIGHT(gparent, field);     \
409
20.7M
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
10.3M
        RB_COLOR(tmp, field) = RB_BLACK; \
411
10.3M
        RB_SET_BLACKRED(parent, gparent, field);\
412
10.3M
        elm = gparent;        \
413
10.3M
        continue;       \
414
10.3M
      }            \
415
20.7M
      if (RB_RIGHT(parent, field) == elm) {   \
416
2.60M
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
2.60M
        tmp = parent;       \
418
2.60M
        parent = elm;       \
419
2.60M
        elm = tmp;        \
420
2.60M
      }            \
421
10.3M
      RB_SET_BLACKRED(parent, gparent, field); \
422
10.3M
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
10.3M
    } else {           \
424
6.02M
      tmp = RB_LEFT(gparent, field);     \
425
6.02M
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
5.96M
        RB_COLOR(tmp, field) = RB_BLACK; \
427
5.96M
        RB_SET_BLACKRED(parent, gparent, field);\
428
5.96M
        elm = gparent;        \
429
5.96M
        continue;       \
430
5.96M
      }            \
431
6.02M
      if (RB_LEFT(parent, field) == elm) {   \
432
4.73k
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
4.73k
        tmp = parent;       \
434
4.73k
        parent = elm;       \
435
4.73k
        elm = tmp;        \
436
4.73k
      }            \
437
61.1k
      RB_SET_BLACKRED(parent, gparent, field); \
438
61.1k
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
61.1k
    }              \
440
26.7M
  }                \
441
41.0M
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
41.0M
}                  \
arguments.c:args_tree_RB_INSERT_COLOR
Line
Count
Source
401
22.9k
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
22.9k
{                 \
403
22.9k
  struct type *parent, *gparent, *tmp;        \
404
37.3k
  while ((parent = RB_PARENT(elm, field)) &&      \
405
37.3k
      RB_COLOR(parent, field) == RB_RED) {     \
406
14.4k
    gparent = RB_PARENT(parent, field);      \
407
14.4k
    if (parent == RB_LEFT(gparent, field)) {   \
408
7.37k
      tmp = RB_RIGHT(gparent, field);     \
409
7.37k
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
3.18k
        RB_COLOR(tmp, field) = RB_BLACK; \
411
3.18k
        RB_SET_BLACKRED(parent, gparent, field);\
412
3.18k
        elm = gparent;        \
413
3.18k
        continue;       \
414
3.18k
      }            \
415
7.37k
      if (RB_RIGHT(parent, field) == elm) {   \
416
2.52k
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
2.52k
        tmp = parent;       \
418
2.52k
        parent = elm;       \
419
2.52k
        elm = tmp;        \
420
2.52k
      }            \
421
4.18k
      RB_SET_BLACKRED(parent, gparent, field); \
422
4.18k
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
7.06k
    } else {           \
424
7.06k
      tmp = RB_LEFT(gparent, field);     \
425
7.06k
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
3.62k
        RB_COLOR(tmp, field) = RB_BLACK; \
427
3.62k
        RB_SET_BLACKRED(parent, gparent, field);\
428
3.62k
        elm = gparent;        \
429
3.62k
        continue;       \
430
3.62k
      }            \
431
7.06k
      if (RB_LEFT(parent, field) == elm) {   \
432
1.48k
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
1.48k
        tmp = parent;       \
434
1.48k
        parent = elm;       \
435
1.48k
        elm = tmp;        \
436
1.48k
      }            \
437
3.43k
      RB_SET_BLACKRED(parent, gparent, field); \
438
3.43k
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
3.43k
    }              \
440
14.4k
  }                \
441
22.9k
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
22.9k
}                  \
Unexecuted instantiation: cmd-wait-for.c:wait_channels_RB_INSERT_COLOR
Unexecuted instantiation: control.c:control_windows_RB_INSERT_COLOR
Unexecuted instantiation: control.c:control_panes_RB_INSERT_COLOR
environ.c:environ_RB_INSERT_COLOR
Line
Count
Source
401
2.06k
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
2.06k
{                 \
403
2.06k
  struct type *parent, *gparent, *tmp;        \
404
4.71k
  while ((parent = RB_PARENT(elm, field)) &&      \
405
4.71k
      RB_COLOR(parent, field) == RB_RED) {     \
406
2.65k
    gparent = RB_PARENT(parent, field);      \
407
2.65k
    if (parent == RB_LEFT(gparent, field)) {   \
408
1.36k
      tmp = RB_RIGHT(gparent, field);     \
409
1.36k
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
784
        RB_COLOR(tmp, field) = RB_BLACK; \
411
784
        RB_SET_BLACKRED(parent, gparent, field);\
412
784
        elm = gparent;        \
413
784
        continue;       \
414
784
      }            \
415
1.36k
      if (RB_RIGHT(parent, field) == elm) {   \
416
281
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
281
        tmp = parent;       \
418
281
        parent = elm;       \
419
281
        elm = tmp;        \
420
281
      }            \
421
584
      RB_SET_BLACKRED(parent, gparent, field); \
422
584
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
1.28k
    } else {           \
424
1.28k
      tmp = RB_LEFT(gparent, field);     \
425
1.28k
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
559
        RB_COLOR(tmp, field) = RB_BLACK; \
427
559
        RB_SET_BLACKRED(parent, gparent, field);\
428
559
        elm = gparent;        \
429
559
        continue;       \
430
559
      }            \
431
1.28k
      if (RB_LEFT(parent, field) == elm) {   \
432
451
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
451
        tmp = parent;       \
434
451
        parent = elm;       \
435
451
        elm = tmp;        \
436
451
      }            \
437
728
      RB_SET_BLACKRED(parent, gparent, field); \
438
728
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
728
    }              \
440
2.65k
  }                \
441
2.06k
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
2.06k
}                  \
Unexecuted instantiation: events-payload.c:event_payload_tree_RB_INSERT_COLOR
Unexecuted instantiation: client_files_RB_INSERT_COLOR
format.c:format_entry_tree_RB_INSERT_COLOR
Line
Count
Source
401
40.9M
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
40.9M
{                 \
403
40.9M
  struct type *parent, *gparent, *tmp;        \
404
67.5M
  while ((parent = RB_PARENT(elm, field)) &&      \
405
67.5M
      RB_COLOR(parent, field) == RB_RED) {     \
406
26.5M
    gparent = RB_PARENT(parent, field);      \
407
26.5M
    if (parent == RB_LEFT(gparent, field)) {   \
408
20.7M
      tmp = RB_RIGHT(gparent, field);     \
409
20.7M
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
10.3M
        RB_COLOR(tmp, field) = RB_BLACK; \
411
10.3M
        RB_SET_BLACKRED(parent, gparent, field);\
412
10.3M
        elm = gparent;        \
413
10.3M
        continue;       \
414
10.3M
      }            \
415
20.7M
      if (RB_RIGHT(parent, field) == elm) {   \
416
2.58M
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
2.58M
        tmp = parent;       \
418
2.58M
        parent = elm;       \
419
2.58M
        elm = tmp;        \
420
2.58M
      }            \
421
10.3M
      RB_SET_BLACKRED(parent, gparent, field); \
422
10.3M
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
10.3M
    } else {           \
424
5.89M
      tmp = RB_LEFT(gparent, field);     \
425
5.89M
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
5.89M
        RB_COLOR(tmp, field) = RB_BLACK; \
427
5.89M
        RB_SET_BLACKRED(parent, gparent, field);\
428
5.89M
        elm = gparent;        \
429
5.89M
        continue;       \
430
5.89M
      }           \
431
5.89M
      if (RB_LEFT(parent, field) == elm) {   \
432
0
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
0
        tmp = parent;       \
434
0
        parent = elm;       \
435
0
        elm = tmp;        \
436
0
      }           \
437
0
      RB_SET_BLACKRED(parent, gparent, field); \
438
0
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
0
    }              \
440
26.5M
  }                \
441
40.9M
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
40.9M
}                  \
Unexecuted instantiation: format.c:format_job_tree_RB_INSERT_COLOR
hyperlinks.c:hyperlinks_by_uri_tree_RB_INSERT_COLOR
Line
Count
Source
401
42.9k
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
42.9k
{                 \
403
42.9k
  struct type *parent, *gparent, *tmp;        \
404
94.3k
  while ((parent = RB_PARENT(elm, field)) &&      \
405
94.3k
      RB_COLOR(parent, field) == RB_RED) {     \
406
51.3k
    gparent = RB_PARENT(parent, field);      \
407
51.3k
    if (parent == RB_LEFT(gparent, field)) {   \
408
15.0k
      tmp = RB_RIGHT(gparent, field);     \
409
15.0k
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
3.13k
        RB_COLOR(tmp, field) = RB_BLACK; \
411
3.13k
        RB_SET_BLACKRED(parent, gparent, field);\
412
3.13k
        elm = gparent;        \
413
3.13k
        continue;       \
414
3.13k
      }            \
415
15.0k
      if (RB_RIGHT(parent, field) == elm) {   \
416
11.0k
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
11.0k
        tmp = parent;       \
418
11.0k
        parent = elm;       \
419
11.0k
        elm = tmp;        \
420
11.0k
      }            \
421
11.8k
      RB_SET_BLACKRED(parent, gparent, field); \
422
11.8k
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
36.3k
    } else {           \
424
36.3k
      tmp = RB_LEFT(gparent, field);     \
425
36.3k
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
22.6k
        RB_COLOR(tmp, field) = RB_BLACK; \
427
22.6k
        RB_SET_BLACKRED(parent, gparent, field);\
428
22.6k
        elm = gparent;        \
429
22.6k
        continue;       \
430
22.6k
      }            \
431
36.3k
      if (RB_LEFT(parent, field) == elm) {   \
432
2.77k
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
2.77k
        tmp = parent;       \
434
2.77k
        parent = elm;       \
435
2.77k
        elm = tmp;        \
436
2.77k
      }            \
437
13.6k
      RB_SET_BLACKRED(parent, gparent, field); \
438
13.6k
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
13.6k
    }              \
440
51.3k
  }                \
441
42.9k
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
42.9k
}                  \
hyperlinks.c:hyperlinks_by_inner_tree_RB_INSERT_COLOR
Line
Count
Source
401
42.9k
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
42.9k
{                 \
403
42.9k
  struct type *parent, *gparent, *tmp;        \
404
128k
  while ((parent = RB_PARENT(elm, field)) &&      \
405
128k
      RB_COLOR(parent, field) == RB_RED) {     \
406
85.8k
    gparent = RB_PARENT(parent, field);      \
407
85.8k
    if (parent == RB_LEFT(gparent, field)) {   \
408
0
      tmp = RB_RIGHT(gparent, field);     \
409
0
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
0
        RB_COLOR(tmp, field) = RB_BLACK; \
411
0
        RB_SET_BLACKRED(parent, gparent, field);\
412
0
        elm = gparent;        \
413
0
        continue;       \
414
0
      }           \
415
0
      if (RB_RIGHT(parent, field) == elm) {   \
416
0
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
0
        tmp = parent;       \
418
0
        parent = elm;       \
419
0
        elm = tmp;        \
420
0
      }           \
421
0
      RB_SET_BLACKRED(parent, gparent, field); \
422
0
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
85.8k
    } else {           \
424
85.8k
      tmp = RB_LEFT(gparent, field);     \
425
85.8k
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
42.9k
        RB_COLOR(tmp, field) = RB_BLACK; \
427
42.9k
        RB_SET_BLACKRED(parent, gparent, field);\
428
42.9k
        elm = gparent;        \
429
42.9k
        continue;       \
430
42.9k
      }            \
431
85.8k
      if (RB_LEFT(parent, field) == elm) {   \
432
0
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
0
        tmp = parent;       \
434
0
        parent = elm;       \
435
0
        elm = tmp;        \
436
0
      }            \
437
42.9k
      RB_SET_BLACKRED(parent, gparent, field); \
438
42.9k
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
42.9k
    }              \
440
85.8k
  }                \
441
42.9k
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
42.9k
}                  \
Unexecuted instantiation: input-keys.c:input_key_tree_RB_INSERT_COLOR
Unexecuted instantiation: json.c:json_fields_RB_INSERT_COLOR
Unexecuted instantiation: key-bindings.c:key_tables_RB_INSERT_COLOR
Unexecuted instantiation: key-bindings.c:key_bindings_RB_INSERT_COLOR
Unexecuted instantiation: monitor.c:monitor_items_RB_INSERT_COLOR
Unexecuted instantiation: monitor.c:monitor_panes_RB_INSERT_COLOR
Unexecuted instantiation: monitor.c:monitor_windows_RB_INSERT_COLOR
options.c:options_tree_RB_INSERT_COLOR
Line
Count
Source
401
550
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
550
{                 \
403
550
  struct type *parent, *gparent, *tmp;        \
404
1.31k
  while ((parent = RB_PARENT(elm, field)) &&      \
405
1.31k
      RB_COLOR(parent, field) == RB_RED) {     \
406
768
    gparent = RB_PARENT(parent, field);      \
407
768
    if (parent == RB_LEFT(gparent, field)) {   \
408
138
      tmp = RB_RIGHT(gparent, field);     \
409
138
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
34
        RB_COLOR(tmp, field) = RB_BLACK; \
411
34
        RB_SET_BLACKRED(parent, gparent, field);\
412
34
        elm = gparent;        \
413
34
        continue;       \
414
34
      }            \
415
138
      if (RB_RIGHT(parent, field) == elm) {   \
416
94
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
94
        tmp = parent;       \
418
94
        parent = elm;       \
419
94
        elm = tmp;        \
420
94
      }            \
421
104
      RB_SET_BLACKRED(parent, gparent, field); \
422
104
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
630
    } else {           \
424
630
      tmp = RB_LEFT(gparent, field);     \
425
630
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
342
        RB_COLOR(tmp, field) = RB_BLACK; \
427
342
        RB_SET_BLACKRED(parent, gparent, field);\
428
342
        elm = gparent;        \
429
342
        continue;       \
430
342
      }            \
431
630
      if (RB_LEFT(parent, field) == elm) {   \
432
26
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
26
        tmp = parent;       \
434
26
        parent = elm;       \
435
26
        elm = tmp;        \
436
26
      }            \
437
288
      RB_SET_BLACKRED(parent, gparent, field); \
438
288
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
288
    }              \
440
768
  }                \
441
550
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
550
}                  \
options.c:options_array_RB_INSERT_COLOR
Line
Count
Source
401
54
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)   \
402
54
{                 \
403
54
  struct type *parent, *gparent, *tmp;        \
404
96
  while ((parent = RB_PARENT(elm, field)) &&      \
405
96
      RB_COLOR(parent, field) == RB_RED) {     \
406
42
    gparent = RB_PARENT(parent, field);      \
407
42
    if (parent == RB_LEFT(gparent, field)) {   \
408
0
      tmp = RB_RIGHT(gparent, field);     \
409
0
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
410
0
        RB_COLOR(tmp, field) = RB_BLACK; \
411
0
        RB_SET_BLACKRED(parent, gparent, field);\
412
0
        elm = gparent;        \
413
0
        continue;       \
414
0
      }           \
415
0
      if (RB_RIGHT(parent, field) == elm) {   \
416
0
        RB_ROTATE_LEFT(head, parent, tmp, field);\
417
0
        tmp = parent;       \
418
0
        parent = elm;       \
419
0
        elm = tmp;        \
420
0
      }           \
421
0
      RB_SET_BLACKRED(parent, gparent, field); \
422
0
      RB_ROTATE_RIGHT(head, gparent, tmp, field);  \
423
42
    } else {           \
424
42
      tmp = RB_LEFT(gparent, field);     \
425
42
      if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
426
16
        RB_COLOR(tmp, field) = RB_BLACK; \
427
16
        RB_SET_BLACKRED(parent, gparent, field);\
428
16
        elm = gparent;        \
429
16
        continue;       \
430
16
      }            \
431
42
      if (RB_LEFT(parent, field) == elm) {   \
432
0
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
433
0
        tmp = parent;       \
434
0
        parent = elm;       \
435
0
        elm = tmp;        \
436
0
      }            \
437
26
      RB_SET_BLACKRED(parent, gparent, field); \
438
26
      RB_ROTATE_LEFT(head, gparent, tmp, field);  \
439
26
    }              \
440
42
  }                \
441
54
  RB_COLOR(head->rbh_root, field) = RB_BLACK;     \
442
54
}                  \
Unexecuted instantiation: paste.c:paste_name_tree_RB_INSERT_COLOR
Unexecuted instantiation: paste.c:paste_time_tree_RB_INSERT_COLOR
Unexecuted instantiation: server-acl.c:server_acl_entries_RB_INSERT_COLOR
Unexecuted instantiation: sessions_RB_INSERT_COLOR
Unexecuted instantiation: session_groups_RB_INSERT_COLOR
Unexecuted instantiation: utf8.c:utf8_width_cache_RB_INSERT_COLOR
Unexecuted instantiation: utf8.c:utf8_index_tree_RB_INSERT_COLOR
Unexecuted instantiation: utf8.c:utf8_data_tree_RB_INSERT_COLOR
Unexecuted instantiation: windows_RB_INSERT_COLOR
Unexecuted instantiation: winlinks_RB_INSERT_COLOR
Unexecuted instantiation: window_pane_tree_RB_INSERT_COLOR
443
                  \
444
attr void               \
445
38.4M
name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \
446
38.4M
{                 \
447
38.4M
  struct type *tmp;           \
448
54.7M
  while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) &&  \
449
54.7M
      elm != RB_ROOT(head)) {         \
450
20.5M
    if (RB_LEFT(parent, field) == elm) {     \
451
20.5M
      tmp = RB_RIGHT(parent, field);      \
452
20.5M
      if (RB_COLOR(tmp, field) == RB_RED) {   \
453
4.26M
        RB_SET_BLACKRED(tmp, parent, field); \
454
4.26M
        RB_ROTATE_LEFT(head, parent, tmp, field);\
455
4.26M
        tmp = RB_RIGHT(parent, field);    \
456
4.26M
      }            \
457
20.5M
      if ((RB_LEFT(tmp, field) == NULL ||   \
458
20.5M
          RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
459
20.5M
          (RB_RIGHT(tmp, field) == NULL ||   \
460
18.8M
          RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
461
16.3M
        RB_COLOR(tmp, field) = RB_RED;   \
462
16.3M
        elm = parent;       \
463
16.3M
        parent = RB_PARENT(elm, field);   \
464
16.3M
      } else {         \
465
4.25M
        if (RB_RIGHT(tmp, field) == NULL || \
466
4.25M
            RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\
467
1.65M
          struct type *oleft;   \
468
1.65M
          if ((oleft = RB_LEFT(tmp, field)))\
469
1.65M
            RB_COLOR(oleft, field) = RB_BLACK;\
470
1.65M
          RB_COLOR(tmp, field) = RB_RED; \
471
1.65M
          RB_ROTATE_RIGHT(head, tmp, oleft, field);\
472
1.65M
          tmp = RB_RIGHT(parent, field);  \
473
1.65M
        }          \
474
4.25M
        RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
475
4.25M
        RB_COLOR(parent, field) = RB_BLACK; \
476
4.25M
        if (RB_RIGHT(tmp, field))   \
477
4.25M
          RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\
478
4.25M
        RB_ROTATE_LEFT(head, parent, tmp, field);\
479
4.25M
        elm = RB_ROOT(head);     \
480
4.25M
        break;          \
481
4.25M
      }            \
482
20.5M
    } else {           \
483
6.82k
      tmp = RB_LEFT(parent, field);      \
484
6.82k
      if (RB_COLOR(tmp, field) == RB_RED) {   \
485
757
        RB_SET_BLACKRED(tmp, parent, field); \
486
757
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
487
757
        tmp = RB_LEFT(parent, field);    \
488
757
      }            \
489
6.82k
      if ((RB_LEFT(tmp, field) == NULL ||   \
490
6.82k
          RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
491
6.82k
          (RB_RIGHT(tmp, field) == NULL ||   \
492
5.21k
          RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
493
4.51k
        RB_COLOR(tmp, field) = RB_RED;   \
494
4.51k
        elm = parent;       \
495
4.51k
        parent = RB_PARENT(elm, field);   \
496
4.51k
      } else {         \
497
2.30k
        if (RB_LEFT(tmp, field) == NULL || \
498
2.30k
            RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\
499
692
          struct type *oright;    \
500
692
          if ((oright = RB_RIGHT(tmp, field)))\
501
692
            RB_COLOR(oright, field) = RB_BLACK;\
502
692
          RB_COLOR(tmp, field) = RB_RED; \
503
692
          RB_ROTATE_LEFT(head, tmp, oright, field);\
504
692
          tmp = RB_LEFT(parent, field);  \
505
692
        }          \
506
2.30k
        RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
507
2.30k
        RB_COLOR(parent, field) = RB_BLACK; \
508
2.30k
        if (RB_LEFT(tmp, field))   \
509
2.30k
          RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\
510
2.30k
        RB_ROTATE_RIGHT(head, parent, tmp, field);\
511
2.30k
        elm = RB_ROOT(head);     \
512
2.30k
        break;          \
513
2.30k
      }            \
514
6.82k
    }              \
515
20.5M
  }                \
516
38.4M
  if (elm)             \
517
38.4M
    RB_COLOR(elm, field) = RB_BLACK;     \
518
38.4M
}                  \
Unexecuted instantiation: input-keys.c:input_key_tree_RB_REMOVE_COLOR
Unexecuted instantiation: utf8.c:utf8_data_tree_RB_REMOVE_COLOR
Unexecuted instantiation: utf8.c:utf8_index_tree_RB_REMOVE_COLOR
519
                  \
520
attr struct type *              \
521
41.0M
name##_RB_REMOVE(struct name *head, struct type *elm)     \
522
41.0M
{                 \
523
41.0M
  struct type *child, *parent, *old = elm;      \
524
41.0M
  int color;              \
525
41.0M
  if (RB_LEFT(elm, field) == NULL)       \
526
41.0M
    child = RB_RIGHT(elm, field);       \
527
41.0M
  else if (RB_RIGHT(elm, field) == NULL)       \
528
29.6k
    child = RB_LEFT(elm, field);       \
529
29.6k
  else {               \
530
29.0k
    struct type *left;          \
531
29.0k
    elm = RB_RIGHT(elm, field);       \
532
109k
    while ((left = RB_LEFT(elm, field)))     \
533
80.5k
      elm = left;         \
534
29.0k
    child = RB_RIGHT(elm, field);       \
535
29.0k
    parent = RB_PARENT(elm, field);       \
536
29.0k
    color = RB_COLOR(elm, field);       \
537
29.0k
    if (child)           \
538
29.0k
      RB_PARENT(child, field) = parent;   \
539
29.0k
    if (parent) {           \
540
29.0k
      if (RB_LEFT(parent, field) == elm)   \
541
29.0k
        RB_LEFT(parent, field) = child;   \
542
29.0k
      else            \
543
29.0k
        RB_RIGHT(parent, field) = child; \
544
29.0k
      RB_AUGMENT(parent);       \
545
29.0k
    } else              \
546
29.0k
      RB_ROOT(head) = child;       \
547
29.0k
    if (RB_PARENT(elm, field) == old)     \
548
29.0k
      parent = elm;         \
549
29.0k
    (elm)->field = (old)->field;        \
550
29.0k
    if (RB_PARENT(old, field)) {       \
551
28.9k
      if (RB_LEFT(RB_PARENT(old, field), field) == old)\
552
28.9k
        RB_LEFT(RB_PARENT(old, field), field) = elm;\
553
28.9k
      else            \
554
28.9k
        RB_RIGHT(RB_PARENT(old, field), field) = elm;\
555
28.9k
      RB_AUGMENT(RB_PARENT(old, field));    \
556
28.9k
    } else             \
557
29.0k
      RB_ROOT(head) = elm;       \
558
29.0k
    RB_PARENT(RB_LEFT(old, field), field) = elm;   \
559
29.0k
    if (RB_RIGHT(old, field))       \
560
29.0k
      RB_PARENT(RB_RIGHT(old, field), field) = elm; \
561
29.0k
    if (parent) {           \
562
29.0k
      left = parent;          \
563
309k
      do {           \
564
309k
        RB_AUGMENT(left);     \
565
309k
      } while ((left = RB_PARENT(left, field)));  \
566
29.0k
    }             \
567
29.0k
    goto color;           \
568
29.0k
  }                \
569
41.0M
  parent = RB_PARENT(elm, field);         \
570
41.0M
  color = RB_COLOR(elm, field);         \
571
41.0M
  if (child)             \
572
41.0M
    RB_PARENT(child, field) = parent;     \
573
41.0M
  if (parent) {             \
574
32.5M
    if (RB_LEFT(parent, field) == elm)     \
575
32.5M
      RB_LEFT(parent, field) = child;     \
576
32.5M
    else              \
577
32.5M
      RB_RIGHT(parent, field) = child;   \
578
32.5M
    RB_AUGMENT(parent);         \
579
32.5M
  } else               \
580
41.0M
    RB_ROOT(head) = child;         \
581
41.0M
color:                  \
582
41.0M
  if (color == RB_BLACK)           \
583
41.0M
    name##_RB_REMOVE_COLOR(head, parent, child);   \
584
41.0M
  return (old);             \
585
41.0M
}                  \
Unexecuted instantiation: input-keys.c:input_key_tree_RB_REMOVE
Unexecuted instantiation: utf8.c:utf8_data_tree_RB_REMOVE
Unexecuted instantiation: utf8.c:utf8_index_tree_RB_REMOVE
586
                  \
587
/* Inserts a node into the RB tree */         \
588
attr struct type *              \
589
41.0M
name##_RB_INSERT(struct name *head, struct type *elm)     \
590
41.0M
{                 \
591
41.0M
  struct type *tmp;           \
592
41.0M
  struct type *parent = NULL;         \
593
41.0M
  int comp = 0;             \
594
41.0M
  tmp = RB_ROOT(head);           \
595
143M
  while (tmp) {             \
596
101M
    parent = tmp;           \
597
101M
    comp = (cmp)(elm, parent);        \
598
101M
    if (comp < 0)           \
599
101M
      tmp = RB_LEFT(tmp, field);     \
600
101M
    else if (comp > 0)         \
601
29.4M
      tmp = RB_RIGHT(tmp, field);     \
602
29.4M
    else              \
603
29.4M
      return (tmp);         \
604
101M
  }                \
605
41.0M
  RB_SET(elm, parent, field);         \
606
41.0M
  if (parent != NULL) {           \
607
36.8M
    if (comp < 0)           \
608
36.8M
      RB_LEFT(parent, field) = elm;     \
609
36.8M
    else              \
610
36.8M
      RB_RIGHT(parent, field) = elm;     \
611
36.8M
    RB_AUGMENT(parent);         \
612
36.8M
  } else               \
613
41.0M
    RB_ROOT(head) = elm;         \
614
41.0M
  name##_RB_INSERT_COLOR(head, elm);        \
615
41.0M
  return (NULL);              \
616
41.0M
}                  \
617
                  \
618
/* Finds the node with the same key as elm */       \
619
attr struct type *              \
620
8.71M
name##_RB_FIND(struct name *head, struct type *elm)     \
621
8.71M
{                 \
622
8.71M
  struct type *tmp = RB_ROOT(head);       \
623
8.71M
  int comp;             \
624
64.0M
  while (tmp) {             \
625
56.4M
    comp = cmp(elm, tmp);         \
626
56.4M
    if (comp < 0)           \
627
56.4M
      tmp = RB_LEFT(tmp, field);     \
628
56.4M
    else if (comp > 0)         \
629
25.1M
      tmp = RB_RIGHT(tmp, field);     \
630
25.1M
    else              \
631
25.1M
      return (tmp);         \
632
56.4M
  }                \
633
8.71M
  return (NULL);             \
634
8.71M
}                  \
635
                  \
636
/* Finds the first node greater than or equal to the search key */  \
637
attr struct type *              \
638
0
name##_RB_NFIND(struct name *head, struct type *elm)      \
639
0
{                 \
640
0
  struct type *tmp = RB_ROOT(head);       \
641
0
  struct type *res = NULL;          \
642
0
  int comp;             \
643
0
  while (tmp) {             \
644
0
    comp = cmp(elm, tmp);         \
645
0
    if (comp < 0) {           \
646
0
      res = tmp;          \
647
0
      tmp = RB_LEFT(tmp, field);     \
648
0
    }             \
649
0
    else if (comp > 0)         \
650
0
      tmp = RB_RIGHT(tmp, field);     \
651
0
    else              \
652
0
      return (tmp);         \
653
0
  }               \
654
0
  return (res);             \
655
0
}                  \
Unexecuted instantiation: arguments.c:args_tree_RB_NFIND
Unexecuted instantiation: cmd-wait-for.c:wait_channels_RB_NFIND
Unexecuted instantiation: control.c:control_panes_RB_NFIND
Unexecuted instantiation: control.c:control_windows_RB_NFIND
Unexecuted instantiation: environ.c:environ_RB_NFIND
Unexecuted instantiation: events-payload.c:event_payload_tree_RB_NFIND
Unexecuted instantiation: format.c:format_job_tree_RB_NFIND
Unexecuted instantiation: format.c:format_entry_tree_RB_NFIND
Unexecuted instantiation: hyperlinks.c:hyperlinks_by_uri_tree_RB_NFIND
Unexecuted instantiation: hyperlinks.c:hyperlinks_by_inner_tree_RB_NFIND
Unexecuted instantiation: input-keys.c:input_key_tree_RB_NFIND
Unexecuted instantiation: json.c:json_fields_RB_NFIND
Unexecuted instantiation: key-bindings.c:key_bindings_RB_NFIND
Unexecuted instantiation: key-bindings.c:key_tables_RB_NFIND
Unexecuted instantiation: monitor.c:monitor_items_RB_NFIND
Unexecuted instantiation: monitor.c:monitor_panes_RB_NFIND
Unexecuted instantiation: monitor.c:monitor_windows_RB_NFIND
Unexecuted instantiation: options.c:options_array_RB_NFIND
Unexecuted instantiation: options.c:options_tree_RB_NFIND
Unexecuted instantiation: paste.c:paste_name_tree_RB_NFIND
Unexecuted instantiation: paste.c:paste_time_tree_RB_NFIND
Unexecuted instantiation: server-acl.c:server_acl_entries_RB_NFIND
Unexecuted instantiation: utf8.c:utf8_width_cache_RB_NFIND
Unexecuted instantiation: utf8.c:utf8_data_tree_RB_NFIND
Unexecuted instantiation: utf8.c:utf8_index_tree_RB_NFIND
656
                  \
657
/* ARGSUSED */                \
658
attr struct type *              \
659
50.3M
name##_RB_NEXT(struct type *elm)          \
660
50.3M
{                 \
661
50.3M
  if (RB_RIGHT(elm, field)) {         \
662
20.7M
    elm = RB_RIGHT(elm, field);       \
663
24.7M
    while (RB_LEFT(elm, field))       \
664
20.7M
      elm = RB_LEFT(elm, field);     \
665
29.5M
  } else {             \
666
29.5M
    if (RB_PARENT(elm, field) &&       \
667
29.5M
        (elm == RB_LEFT(RB_PARENT(elm, field), field))) \
668
29.5M
      elm = RB_PARENT(elm, field);     \
669
29.5M
    else {             \
670
11.0M
      while (RB_PARENT(elm, field) &&     \
671
11.0M
          (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
672
6.55M
        elm = RB_PARENT(elm, field);   \
673
6.55M
      elm = RB_PARENT(elm, field);     \
674
6.55M
    }              \
675
29.5M
  }                \
676
50.3M
  return (elm);             \
677
50.3M
}                  \
arguments.c:args_tree_RB_NEXT
Line
Count
Source
659
50.9k
name##_RB_NEXT(struct type *elm)          \
660
50.9k
{                 \
661
50.9k
  if (RB_RIGHT(elm, field)) {         \
662
19.4k
    elm = RB_RIGHT(elm, field);       \
663
22.3k
    while (RB_LEFT(elm, field))       \
664
19.4k
      elm = RB_LEFT(elm, field);     \
665
31.4k
  } else {             \
666
31.4k
    if (RB_PARENT(elm, field) &&       \
667
31.4k
        (elm == RB_LEFT(RB_PARENT(elm, field), field))) \
668
31.4k
      elm = RB_PARENT(elm, field);     \
669
31.4k
    else {             \
670
25.4k
      while (RB_PARENT(elm, field) &&     \
671
25.4k
          (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
672
14.6k
        elm = RB_PARENT(elm, field);   \
673
14.6k
      elm = RB_PARENT(elm, field);     \
674
14.6k
    }              \
675
31.4k
  }                \
676
50.9k
  return (elm);             \
677
50.9k
}                  \
Unexecuted instantiation: cmd-wait-for.c:wait_channels_RB_NEXT
Unexecuted instantiation: control.c:control_panes_RB_NEXT
Unexecuted instantiation: control.c:control_windows_RB_NEXT
environ.c:environ_RB_NEXT
Line
Count
Source
659
3.30M
name##_RB_NEXT(struct type *elm)          \
660
3.30M
{                 \
661
3.30M
  if (RB_RIGHT(elm, field)) {         \
662
1.64M
    elm = RB_RIGHT(elm, field);       \
663
3.20M
    while (RB_LEFT(elm, field))       \
664
1.64M
      elm = RB_LEFT(elm, field);     \
665
1.66M
  } else {             \
666
1.66M
    if (RB_PARENT(elm, field) &&       \
667
1.66M
        (elm == RB_LEFT(RB_PARENT(elm, field), field)))  \
668
1.66M
      elm = RB_PARENT(elm, field);     \
669
1.66M
    else {             \
670
2.45M
      while (RB_PARENT(elm, field) &&     \
671
2.45M
          (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
672
1.64M
        elm = RB_PARENT(elm, field);   \
673
806k
      elm = RB_PARENT(elm, field);     \
674
806k
    }              \
675
1.66M
  }                \
676
3.30M
  return (elm);             \
677
3.30M
}                  \
Unexecuted instantiation: events-payload.c:event_payload_tree_RB_NEXT
Unexecuted instantiation: client_files_RB_NEXT
Unexecuted instantiation: format.c:format_job_tree_RB_NEXT
format.c:format_entry_tree_RB_NEXT
Line
Count
Source
659
40.9M
name##_RB_NEXT(struct type *elm)          \
660
40.9M
{                 \
661
40.9M
  if (RB_RIGHT(elm, field)) {         \
662
16.2M
    elm = RB_RIGHT(elm, field);       \
663
16.2M
    while (RB_LEFT(elm, field))       \
664
16.2M
      elm = RB_LEFT(elm, field);     \
665
24.7M
  } else {             \
666
24.7M
    if (RB_PARENT(elm, field) &&       \
667
24.7M
        (elm == RB_LEFT(RB_PARENT(elm, field), field))) \
668
24.7M
      elm = RB_PARENT(elm, field);     \
669
24.7M
    else {             \
670
4.24M
      while (RB_PARENT(elm, field) &&     \
671
4.24M
          (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
672
4.24M
        elm = RB_PARENT(elm, field);   \
673
4.24M
      elm = RB_PARENT(elm, field);     \
674
4.24M
    }              \
675
24.7M
  }                \
676
40.9M
  return (elm);             \
677
40.9M
}                  \
Unexecuted instantiation: hyperlinks.c:hyperlinks_by_inner_tree_RB_NEXT
Unexecuted instantiation: hyperlinks.c:hyperlinks_by_uri_tree_RB_NEXT
Unexecuted instantiation: input-keys.c:input_key_tree_RB_NEXT
Unexecuted instantiation: json.c:json_fields_RB_NEXT
Unexecuted instantiation: key-bindings.c:key_tables_RB_NEXT
Unexecuted instantiation: key-bindings.c:key_bindings_RB_NEXT
Unexecuted instantiation: monitor.c:monitor_items_RB_NEXT
Unexecuted instantiation: monitor.c:monitor_panes_RB_NEXT
Unexecuted instantiation: monitor.c:monitor_windows_RB_NEXT
options.c:options_tree_RB_NEXT
Line
Count
Source
659
4.64M
name##_RB_NEXT(struct type *elm)          \
660
4.64M
{                 \
661
4.64M
  if (RB_RIGHT(elm, field)) {         \
662
2.27M
    elm = RB_RIGHT(elm, field);       \
663
4.37M
    while (RB_LEFT(elm, field))       \
664
2.27M
      elm = RB_LEFT(elm, field);     \
665
2.36M
  } else {             \
666
2.36M
    if (RB_PARENT(elm, field) &&       \
667
2.36M
        (elm == RB_LEFT(RB_PARENT(elm, field), field)))  \
668
2.36M
      elm = RB_PARENT(elm, field);     \
669
2.36M
    else {             \
670
3.42M
      while (RB_PARENT(elm, field) &&     \
671
3.42M
          (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
672
2.27M
        elm = RB_PARENT(elm, field);   \
673
1.14M
      elm = RB_PARENT(elm, field);     \
674
1.14M
    }              \
675
2.36M
  }                \
676
4.64M
  return (elm);             \
677
4.64M
}                  \
options.c:options_array_RB_NEXT
Line
Count
Source
659
1.36M
name##_RB_NEXT(struct type *elm)          \
660
1.36M
{                 \
661
1.36M
  if (RB_RIGHT(elm, field)) {         \
662
561k
    elm = RB_RIGHT(elm, field);       \
663
873k
    while (RB_LEFT(elm, field))       \
664
561k
      elm = RB_LEFT(elm, field);     \
665
801k
  } else {             \
666
801k
    if (RB_PARENT(elm, field) &&       \
667
801k
        (elm == RB_LEFT(RB_PARENT(elm, field), field))) \
668
801k
      elm = RB_PARENT(elm, field);     \
669
801k
    else {             \
670
903k
      while (RB_PARENT(elm, field) &&     \
671
903k
          (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
672
560k
        elm = RB_PARENT(elm, field);   \
673
343k
      elm = RB_PARENT(elm, field);     \
674
343k
    }              \
675
801k
  }                \
676
1.36M
  return (elm);             \
677
1.36M
}                  \
Unexecuted instantiation: paste.c:paste_time_tree_RB_NEXT
Unexecuted instantiation: paste.c:paste_name_tree_RB_NEXT
Unexecuted instantiation: server-acl.c:server_acl_entries_RB_NEXT
Unexecuted instantiation: sessions_RB_NEXT
Unexecuted instantiation: session_groups_RB_NEXT
Unexecuted instantiation: utf8.c:utf8_width_cache_RB_NEXT
Unexecuted instantiation: utf8.c:utf8_data_tree_RB_NEXT
Unexecuted instantiation: utf8.c:utf8_index_tree_RB_NEXT
Unexecuted instantiation: windows_RB_NEXT
Unexecuted instantiation: winlinks_RB_NEXT
Unexecuted instantiation: window_pane_tree_RB_NEXT
678
                  \
679
/* ARGSUSED */                \
680
attr struct type *              \
681
0
name##_RB_PREV(struct type *elm)          \
682
0
{                 \
683
0
  if (RB_LEFT(elm, field)) {         \
684
0
    elm = RB_LEFT(elm, field);       \
685
0
    while (RB_RIGHT(elm, field))       \
686
0
      elm = RB_RIGHT(elm, field);     \
687
0
  } else {             \
688
0
    if (RB_PARENT(elm, field) &&       \
689
0
        (elm == RB_RIGHT(RB_PARENT(elm, field), field)))  \
690
0
      elm = RB_PARENT(elm, field);     \
691
0
    else {             \
692
0
      while (RB_PARENT(elm, field) &&     \
693
0
          (elm == RB_LEFT(RB_PARENT(elm, field), field)))\
694
0
        elm = RB_PARENT(elm, field);   \
695
0
      elm = RB_PARENT(elm, field);     \
696
0
    }             \
697
0
  }               \
698
0
  return (elm);             \
699
0
}                  \
Unexecuted instantiation: arguments.c:args_tree_RB_PREV
Unexecuted instantiation: cmd-wait-for.c:wait_channels_RB_PREV
Unexecuted instantiation: control.c:control_panes_RB_PREV
Unexecuted instantiation: control.c:control_windows_RB_PREV
Unexecuted instantiation: environ.c:environ_RB_PREV
Unexecuted instantiation: events-payload.c:event_payload_tree_RB_PREV
Unexecuted instantiation: client_files_RB_PREV
Unexecuted instantiation: format.c:format_job_tree_RB_PREV
Unexecuted instantiation: format.c:format_entry_tree_RB_PREV
Unexecuted instantiation: hyperlinks.c:hyperlinks_by_uri_tree_RB_PREV
Unexecuted instantiation: hyperlinks.c:hyperlinks_by_inner_tree_RB_PREV
Unexecuted instantiation: input-keys.c:input_key_tree_RB_PREV
Unexecuted instantiation: json.c:json_fields_RB_PREV
Unexecuted instantiation: key-bindings.c:key_bindings_RB_PREV
Unexecuted instantiation: key-bindings.c:key_tables_RB_PREV
Unexecuted instantiation: monitor.c:monitor_items_RB_PREV
Unexecuted instantiation: monitor.c:monitor_panes_RB_PREV
Unexecuted instantiation: monitor.c:monitor_windows_RB_PREV
Unexecuted instantiation: options.c:options_array_RB_PREV
Unexecuted instantiation: options.c:options_tree_RB_PREV
Unexecuted instantiation: paste.c:paste_time_tree_RB_PREV
Unexecuted instantiation: paste.c:paste_name_tree_RB_PREV
Unexecuted instantiation: server-acl.c:server_acl_entries_RB_PREV
Unexecuted instantiation: sessions_RB_PREV
Unexecuted instantiation: session_groups_RB_PREV
Unexecuted instantiation: utf8.c:utf8_width_cache_RB_PREV
Unexecuted instantiation: utf8.c:utf8_data_tree_RB_PREV
Unexecuted instantiation: utf8.c:utf8_index_tree_RB_PREV
Unexecuted instantiation: windows_RB_PREV
Unexecuted instantiation: winlinks_RB_PREV
Unexecuted instantiation: window_pane_tree_RB_PREV
700
                  \
701
attr struct type *              \
702
10.9M
name##_RB_MINMAX(struct name *head, int val)        \
703
10.9M
{                 \
704
10.9M
  struct type *tmp = RB_ROOT(head);       \
705
10.9M
  struct type *parent = NULL;         \
706
28.5M
  while (tmp) {             \
707
17.5M
    parent = tmp;           \
708
17.5M
    if (val < 0)           \
709
17.5M
      tmp = RB_LEFT(tmp, field);     \
710
17.5M
    else              \
711
17.5M
      tmp = RB_RIGHT(tmp, field);     \
712
17.5M
  }                \
713
10.9M
  return (parent);            \
714
10.9M
}
Unexecuted instantiation: hyperlinks.c:hyperlinks_by_uri_tree_RB_MINMAX
Unexecuted instantiation: paste.c:paste_name_tree_RB_MINMAX
Unexecuted instantiation: utf8.c:utf8_data_tree_RB_MINMAX
Unexecuted instantiation: utf8.c:utf8_index_tree_RB_MINMAX
715
716
10.9M
#define RB_NEGINF -1
717
0
#define RB_INF  1
718
719
41.0M
#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y)
720
41.0M
#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y)
721
8.71M
#define RB_FIND(name, x, y) name##_RB_FIND(x, y)
722
#define RB_NFIND(name, x, y)  name##_RB_NFIND(x, y)
723
9.30M
#define RB_NEXT(name, x, y) name##_RB_NEXT(y)
724
0
#define RB_PREV(name, x, y) name##_RB_PREV(y)
725
10.9M
#define RB_MIN(name, x)   name##_RB_MINMAX(x, RB_NEGINF)
726
0
#define RB_MAX(name, x)   name##_RB_MINMAX(x, RB_INF)
727
728
#define RB_FOREACH(x, name, head)         \
729
1.07M
  for ((x) = RB_MIN(name, head);         \
730
1.11M
       (x) != NULL;           \
731
1.07M
       (x) = name##_RB_NEXT(x))
732
733
#define RB_FOREACH_SAFE(x, name, head, y)       \
734
4.26M
  for ((x) = RB_MIN(name, head);         \
735
45.2M
      ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1);   \
736
40.9M
       (x) = (y))
737
738
#define RB_FOREACH_REVERSE(x, name, head)       \
739
  for ((x) = RB_MAX(name, head);          \
740
       (x) != NULL;           \
741
       (x) = name##_RB_PREV(x))
742
743
#define RB_FOREACH_REVERSE_SAFE(x, name, head, y)     \
744
0
  for ((x) = RB_MAX(name, head);         \
745
0
      ((x) != NULL) && ((y) = name##_RB_PREV(x), 1);    \
746
0
       (x) = (y))
747
748
#endif  /* _SYS_TREE_H_ */