1 /* glpavl.h (binary search tree) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
30 typedef struct AVL AVL;
31 typedef struct AVLNODE AVLNODE;
34 { /* AVL tree (Adelson-Velsky & Landis binary search tree) */
36 /* memory pool for allocating nodes */
38 /* pointer to the root node */
39 int (*fcmp)(void *info, const void *key1, const void *key2);
40 /* application-defined key comparison routine */
42 /* transit pointer passed to the routine fcmp */
44 /* the tree size (the total number of nodes) */
50 { /* node of AVL tree */
52 /* pointer to the node key (data structure for representing keys
53 is supplied by the application) */
55 /* node rank = relative position of the node in its own subtree =
56 the number of nodes in the left subtree plus one */
58 /* reserved for the application specific information */
60 /* reserved for the application specific information */
62 /* pointer to the parent node */
65 0 - this node is the left child of its parent (or this node is
66 the root of the tree and has no parent)
67 1 - this node is the right child of its parent */
69 /* node balance = the difference between heights of the right and
71 -1 - the left subtree is higher than the right one;
72 0 - the left and right subtrees have the same height;
73 +1 - the left subtree is lower than the right one */
75 /* pointer to the root of the left subtree */
77 /* pointer to the root of the right subtree */
80 #define avl_create_tree _glp_avl_create_tree
81 AVL *avl_create_tree(int (*fcmp)(void *info, const void *key1,
82 const void *key2), void *info);
85 #define avl_strcmp _glp_avl_strcmp
86 int avl_strcmp(void *info, const void *key1, const void *key2);
87 /* compare character string keys */
89 #define avl_insert_node _glp_avl_insert_node
90 AVLNODE *avl_insert_node(AVL *tree, const void *key);
91 /* insert new node into AVL tree */
93 #define avl_set_node_type _glp_avl_set_node_type
94 void avl_set_node_type(AVLNODE *node, int type);
95 /* assign the type field of specified node */
97 #define avl_set_node_link _glp_avl_set_node_link
98 void avl_set_node_link(AVLNODE *node, void *link);
99 /* assign the link field of specified node */
101 #define avl_find_node _glp_avl_find_node
102 AVLNODE *avl_find_node(AVL *tree, const void *key);
103 /* find node in AVL tree */
105 #define avl_get_node_type _glp_avl_get_node_type
106 int avl_get_node_type(AVLNODE *node);
107 /* retrieve the type field of specified node */
109 #define avl_get_node_link _glp_avl_get_node_link
110 void *avl_get_node_link(AVLNODE *node);
111 /* retrieve the link field of specified node */
113 #define avl_delete_node _glp_avl_delete_node
114 void avl_delete_node(AVL *tree, AVLNODE *node);
115 /* delete specified node from AVL tree */
117 #define avl_delete_tree _glp_avl_delete_tree
118 void avl_delete_tree(AVL *tree);
119 /* delete AVL tree */