]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - repair/avl.h
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / repair / avl.h
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
da23017d
NS
2/*
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
da23017d 5 */
2bd0ea18
NS
6#ifndef __SYS_AVL_H__
7#define __SYS_AVL_H__
8
9
10typedef struct avlnode {
dfc130f3
RC
11 struct avlnode *avl_forw; /* pointer to right child (> parent) */
12 struct avlnode *avl_back; /* pointer to left child (< parent) */
2bd0ea18
NS
13 struct avlnode *avl_parent; /* parent pointer */
14 struct avlnode *avl_nextino; /* next in-order; NULL terminated list*/
15 char avl_balance; /* tree balance */
16} avlnode_t;
17
18/*
19 * avl-tree operations
20 */
21typedef struct avlops {
ee6cd73e
CH
22 uintptr_t (*avl_start)(avlnode_t *);
23 uintptr_t (*avl_end)(avlnode_t *);
2bd0ea18
NS
24} avlops_t;
25
26#define AVL_START(tree, n) (*(tree)->avl_ops->avl_start)(n)
27#define AVL_END(tree, n) (*(tree)->avl_ops->avl_end)(n)
28
dfc130f3 29/*
2bd0ea18
NS
30 * tree descriptor:
31 * root points to the root of the tree.
32 * firstino points to the first in the ordered list.
33 */
34typedef struct avltree_desc {
35 avlnode_t *avl_root;
36 avlnode_t *avl_firstino;
37 avlops_t *avl_ops;
38 short avl_flags;
39} avltree_desc_t;
40
41/* possible values for avl_balance */
42
43#define AVL_BACK 1
44#define AVL_BALANCE 0
45#define AVL_FORW 2
46
47/* possible values for avl_flags */
48
49#define AVLF_DUPLICITY 0x0001 /* no warnings on insert dups */
50
51/*
52 * 'Exported' avl tree routines
53 */
54avlnode_t
55*avl_insert(
56 avltree_desc_t *tree,
57 avlnode_t *newnode);
58
59void
60avl_delete(
61 avltree_desc_t *tree,
62 avlnode_t *np);
63
64void
65avl_insert_immediate(
66 avltree_desc_t *tree,
67 avlnode_t *afterp,
68 avlnode_t *newnode);
dfc130f3 69
2bd0ea18
NS
70void
71avl_init_tree(
72 avltree_desc_t *tree,
73 avlops_t *ops);
74
78a0dc91 75static inline avlnode_t *
2bd0ea18
NS
76avl_findrange(
77 avltree_desc_t *tree,
ee6cd73e 78 uintptr_t value)
1e77098c 79{
0c2a7d46 80 avlnode_t *np = tree->avl_root;
1e77098c
MV
81
82 while (np) {
83 if (value < AVL_START(tree, np)) {
84 np = np->avl_back;
85 continue;
86 }
87 if (value >= AVL_END(tree, np)) {
88 np = np->avl_forw;
89 continue;
90 }
91 ASSERT(AVL_START(tree, np) <= value &&
92 value < AVL_END(tree, np));
93 return np;
94 }
95 return NULL;
96}
2bd0ea18
NS
97
98avlnode_t *
99avl_find(
100 avltree_desc_t *tree,
ee6cd73e 101 uintptr_t value);
2bd0ea18
NS
102
103avlnode_t *
104avl_findanyrange(
105 avltree_desc_t *tree,
ee6cd73e
CH
106 uintptr_t start,
107 uintptr_t end,
2bd0ea18
NS
108 int checklen);
109
110
111avlnode_t *
112avl_findadjacent(
113 avltree_desc_t *tree,
ee6cd73e 114 uintptr_t value,
2bd0ea18
NS
115 int dir);
116
2bd0ea18
NS
117void
118avl_findranges(
0c2a7d46 119 avltree_desc_t *tree,
ee6cd73e
CH
120 uintptr_t start,
121 uintptr_t end,
dfc130f3 122 avlnode_t **startp,
2bd0ea18 123 avlnode_t **endp);
2bd0ea18 124
52cb19dc
CH
125avlnode_t *
126avl_firstino(
127 avlnode_t *root);
128
129avlnode_t *
130avl_lastino(
131 avlnode_t *root);
132
133
2bd0ea18
NS
134#define AVL_PRECEED 0x1
135#define AVL_SUCCEED 0x2
136
137#define AVL_INCLUDE_ZEROLEN 0x0000
138#define AVL_EXCLUDE_ZEROLEN 0x0001
139
140#endif /* __SYS_AVL_H__ */