COIN-OR::LEMON - Graph Library

source: glpk-cmake/src/glpavl.h @ 1:c445c931472f

Last change on this file since 1:c445c931472f was 1:c445c931472f, checked in by Alpar Juttner <alpar@…>, 10 years ago

Import glpk-4.45

  • Generated files and doc/notes are removed
File size: 4.2 KB
Line 
1/* glpavl.h (binary search tree) */
2
3/***********************************************************************
4*  This code is part of GLPK (GNU Linear Programming Kit).
5*
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>.
10*
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.
15*
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.
20*
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***********************************************************************/
24
25#ifndef GLPAVL_H
26#define GLPAVL_H
27
28#include "glpdmp.h"
29
30typedef struct AVL AVL;
31typedef struct AVLNODE AVLNODE;
32
33struct AVL
34{     /* AVL tree (Adelson-Velsky & Landis binary search tree) */
35      DMP *pool;
36      /* memory pool for allocating nodes */
37      AVLNODE *root;
38      /* pointer to the root node */
39      int (*fcmp)(void *info, const void *key1, const void *key2);
40      /* application-defined key comparison routine */
41      void *info;
42      /* transit pointer passed to the routine fcmp */
43      int size;
44      /* the tree size (the total number of nodes) */
45      int height;
46      /* the tree height */
47};
48
49struct AVLNODE
50{     /* node of AVL tree */
51      const void *key;
52      /* pointer to the node key (data structure for representing keys
53         is supplied by the application) */
54      int rank;
55      /* node rank = relative position of the node in its own subtree =
56         the number of nodes in the left subtree plus one */
57      int type;
58      /* reserved for the application specific information */
59      void *link;
60      /* reserved for the application specific information */
61      AVLNODE *up;
62      /* pointer to the parent node */
63      short int flag;
64      /* node flag:
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 */
68      short int bal;
69      /* node balance = the difference between heights of the right and
70         left subtrees:
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 */
74      AVLNODE *left;
75      /* pointer to the root of the left subtree */
76      AVLNODE *right;
77      /* pointer to the root of the right subtree */
78};
79
80#define avl_create_tree _glp_avl_create_tree
81AVL *avl_create_tree(int (*fcmp)(void *info, const void *key1,
82      const void *key2), void *info);
83/* create AVL tree */
84
85#define avl_strcmp _glp_avl_strcmp
86int avl_strcmp(void *info, const void *key1, const void *key2);
87/* compare character string keys */
88
89#define avl_insert_node _glp_avl_insert_node
90AVLNODE *avl_insert_node(AVL *tree, const void *key);
91/* insert new node into AVL tree */
92
93#define avl_set_node_type _glp_avl_set_node_type
94void avl_set_node_type(AVLNODE *node, int type);
95/* assign the type field of specified node */
96
97#define avl_set_node_link _glp_avl_set_node_link
98void avl_set_node_link(AVLNODE *node, void *link);
99/* assign the link field of specified node */
100
101#define avl_find_node _glp_avl_find_node
102AVLNODE *avl_find_node(AVL *tree, const void *key);
103/* find node in AVL tree */
104
105#define avl_get_node_type _glp_avl_get_node_type
106int avl_get_node_type(AVLNODE *node);
107/* retrieve the type field of specified node */
108
109#define avl_get_node_link _glp_avl_get_node_link
110void *avl_get_node_link(AVLNODE *node);
111/* retrieve the link field of specified node */
112
113#define avl_delete_node _glp_avl_delete_node
114void avl_delete_node(AVL *tree, AVLNODE *node);
115/* delete specified node from AVL tree */
116
117#define avl_delete_tree _glp_avl_delete_tree
118void avl_delete_tree(AVL *tree);
119/* delete AVL tree */
120
121#endif
122
123/* eof */
Note: See TracBrowser for help on using the repository browser.