source: mainline/kernel/generic/include/adt/avl.h@ df1cbb3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since df1cbb3 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (C) 2007 Vojtech Mencl
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup genericadt
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_AVLTREE_H_
36#define KERN_AVLTREE_H_
37
38#include <stdbool.h>
39#include <stddef.h>
40#include <stdint.h>
41#include <trace.h>
42
43/**
44 * Macro for getting a pointer to the structure which contains the avltree
45 * structure.
46 *
47 * @param link Pointer to the avltree structure.
48 * @param type Name of the outer structure.
49 * @param member Name of avltree attribute in the outer structure.
50 */
51#define avltree_get_instance(node, type, member) \
52 ((type *)(((uint8_t *)(node)) - ((uint8_t *) &(((type *) NULL)->member))))
53
54typedef struct avltree_node avltree_node_t;
55typedef struct avltree avltree_t;
56
57typedef uint64_t avltree_key_t;
58
59typedef bool (* avltree_walker_t)(avltree_node_t *, void *);
60
61/** AVL tree node structure. */
62struct avltree_node
63{
64 /**
65 * Pointer to the left descendant of this node.
66 *
67 * All keys of nodes in the left subtree are less than the key of this
68 * node.
69 */
70 struct avltree_node *lft;
71
72 /**
73 * Pointer to the right descendant of this node.
74 *
75 * All keys of nodes in the right subtree are greater than the key of
76 * this node.
77 */
78 struct avltree_node *rgt;
79
80 /** Pointer to the parent node. Root node has NULL parent. */
81 struct avltree_node *par;
82
83 /** Node's key. */
84 avltree_key_t key;
85
86 /**
87 * Difference between the heights of the left and the right subtree of
88 * this node.
89 */
90 int8_t balance;
91};
92
93/** AVL tree structure. */
94struct avltree
95{
96 /** AVL root node pointer */
97 struct avltree_node *root;
98
99 /**
100 * Base of the tree is a value that is smaller or equal than every value
101 * in the tree (valid for positive keys otherwise ignore this atribute).
102 *
103 * The base is added to the current key when a new node is inserted into
104 * the tree. The base is changed to the key of the node which is deleted
105 * with avltree_delete_min().
106 */
107 avltree_key_t base;
108};
109
110
111/** Create empty AVL tree.
112 *
113 * @param t AVL tree.
114 */
115NO_TRACE static inline void avltree_create(avltree_t *t)
116{
117 t->root = NULL;
118 t->base = 0;
119}
120
121/** Initialize node.
122 *
123 * @param node Node which is initialized.
124 */
125NO_TRACE static inline void avltree_node_initialize(avltree_node_t *node)
126{
127 node->key = 0;
128 node->lft = NULL;
129 node->rgt = NULL;
130 node->par = NULL;
131 node->balance = 0;
132}
133
134extern avltree_node_t *avltree_find_min(avltree_t *t);
135extern avltree_node_t *avltree_search(avltree_t *t, avltree_key_t key);
136extern void avltree_insert(avltree_t *t, avltree_node_t *newnode);
137extern void avltree_delete(avltree_t *t, avltree_node_t *node);
138extern bool avltree_delete_min(avltree_t *t);
139extern void avltree_walk(avltree_t *t, avltree_walker_t walker, void *arg);
140
141#endif
142
143/** @}
144 */
Note: See TracBrowser for help on using the repository browser.