src/glpavl.h
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 06 Dec 2010 13:09:21 +0100
changeset 1 c445c931472f
permissions -rw-r--r--
Import glpk-4.45

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