1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/glpavl.h Mon Dec 06 13:09:21 2010 +0100
1.3 @@ -0,0 +1,123 @@
1.4 +/* glpavl.h (binary search tree) */
1.5 +
1.6 +/***********************************************************************
1.7 +* This code is part of GLPK (GNU Linear Programming Kit).
1.8 +*
1.9 +* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
1.10 +* 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
1.11 +* Moscow Aviation Institute, Moscow, Russia. All rights reserved.
1.12 +* E-mail: <mao@gnu.org>.
1.13 +*
1.14 +* GLPK is free software: you can redistribute it and/or modify it
1.15 +* under the terms of the GNU General Public License as published by
1.16 +* the Free Software Foundation, either version 3 of the License, or
1.17 +* (at your option) any later version.
1.18 +*
1.19 +* GLPK is distributed in the hope that it will be useful, but WITHOUT
1.20 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1.21 +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
1.22 +* License for more details.
1.23 +*
1.24 +* You should have received a copy of the GNU General Public License
1.25 +* along with GLPK. If not, see <http://www.gnu.org/licenses/>.
1.26 +***********************************************************************/
1.27 +
1.28 +#ifndef GLPAVL_H
1.29 +#define GLPAVL_H
1.30 +
1.31 +#include "glpdmp.h"
1.32 +
1.33 +typedef struct AVL AVL;
1.34 +typedef struct AVLNODE AVLNODE;
1.35 +
1.36 +struct AVL
1.37 +{ /* AVL tree (Adelson-Velsky & Landis binary search tree) */
1.38 + DMP *pool;
1.39 + /* memory pool for allocating nodes */
1.40 + AVLNODE *root;
1.41 + /* pointer to the root node */
1.42 + int (*fcmp)(void *info, const void *key1, const void *key2);
1.43 + /* application-defined key comparison routine */
1.44 + void *info;
1.45 + /* transit pointer passed to the routine fcmp */
1.46 + int size;
1.47 + /* the tree size (the total number of nodes) */
1.48 + int height;
1.49 + /* the tree height */
1.50 +};
1.51 +
1.52 +struct AVLNODE
1.53 +{ /* node of AVL tree */
1.54 + const void *key;
1.55 + /* pointer to the node key (data structure for representing keys
1.56 + is supplied by the application) */
1.57 + int rank;
1.58 + /* node rank = relative position of the node in its own subtree =
1.59 + the number of nodes in the left subtree plus one */
1.60 + int type;
1.61 + /* reserved for the application specific information */
1.62 + void *link;
1.63 + /* reserved for the application specific information */
1.64 + AVLNODE *up;
1.65 + /* pointer to the parent node */
1.66 + short int flag;
1.67 + /* node flag:
1.68 + 0 - this node is the left child of its parent (or this node is
1.69 + the root of the tree and has no parent)
1.70 + 1 - this node is the right child of its parent */
1.71 + short int bal;
1.72 + /* node balance = the difference between heights of the right and
1.73 + left subtrees:
1.74 + -1 - the left subtree is higher than the right one;
1.75 + 0 - the left and right subtrees have the same height;
1.76 + +1 - the left subtree is lower than the right one */
1.77 + AVLNODE *left;
1.78 + /* pointer to the root of the left subtree */
1.79 + AVLNODE *right;
1.80 + /* pointer to the root of the right subtree */
1.81 +};
1.82 +
1.83 +#define avl_create_tree _glp_avl_create_tree
1.84 +AVL *avl_create_tree(int (*fcmp)(void *info, const void *key1,
1.85 + const void *key2), void *info);
1.86 +/* create AVL tree */
1.87 +
1.88 +#define avl_strcmp _glp_avl_strcmp
1.89 +int avl_strcmp(void *info, const void *key1, const void *key2);
1.90 +/* compare character string keys */
1.91 +
1.92 +#define avl_insert_node _glp_avl_insert_node
1.93 +AVLNODE *avl_insert_node(AVL *tree, const void *key);
1.94 +/* insert new node into AVL tree */
1.95 +
1.96 +#define avl_set_node_type _glp_avl_set_node_type
1.97 +void avl_set_node_type(AVLNODE *node, int type);
1.98 +/* assign the type field of specified node */
1.99 +
1.100 +#define avl_set_node_link _glp_avl_set_node_link
1.101 +void avl_set_node_link(AVLNODE *node, void *link);
1.102 +/* assign the link field of specified node */
1.103 +
1.104 +#define avl_find_node _glp_avl_find_node
1.105 +AVLNODE *avl_find_node(AVL *tree, const void *key);
1.106 +/* find node in AVL tree */
1.107 +
1.108 +#define avl_get_node_type _glp_avl_get_node_type
1.109 +int avl_get_node_type(AVLNODE *node);
1.110 +/* retrieve the type field of specified node */
1.111 +
1.112 +#define avl_get_node_link _glp_avl_get_node_link
1.113 +void *avl_get_node_link(AVLNODE *node);
1.114 +/* retrieve the link field of specified node */
1.115 +
1.116 +#define avl_delete_node _glp_avl_delete_node
1.117 +void avl_delete_node(AVL *tree, AVLNODE *node);
1.118 +/* delete specified node from AVL tree */
1.119 +
1.120 +#define avl_delete_tree _glp_avl_delete_tree
1.121 +void avl_delete_tree(AVL *tree);
1.122 +/* delete AVL tree */
1.123 +
1.124 +#endif
1.125 +
1.126 +/* eof */