avl.h

Go to the documentation of this file.
00001 /* Produced by texiweb from libavl.w on 2002/02/09 at 01:45. */
00002 
00003 /* libavl - library for manipulation of binary trees.
00004    Copyright (C) 1998-2002 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU General Public License as
00008    published by the Free Software Foundation; either version 2 of the
00009    License, or (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful, but
00012    WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00014    See the GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019    02111-1307, USA.
00020 
00021    The author may be contacted at <blp@gnu.org> on the Internet, or
00022    as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA through more
00023    mundane means.
00024 */
00025 
00026 #ifndef AVL_H
00027 #define AVL_H 1
00028 
00029 #include <stddef.h>
00030 
00031 /* Function types. */
00032 typedef int avl_comparison_func (const void *avl_a, const void *avl_b,
00033                                  void *avl_param);
00034 typedef void avl_item_func (void *avl_item, void *avl_param);
00035 typedef void *avl_copy_func (void *avl_item, void *avl_param);
00036 
00037 #ifndef LIBAVL_ALLOCATOR
00038 #define LIBAVL_ALLOCATOR
00039 /* Memory allocator. */
00040 struct libavl_allocator
00041   {
00042     void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size);
00043     void (*libavl_free) (struct libavl_allocator *, void *libavl_block);
00044   };
00045 #endif
00046 
00047 /* Default memory allocator. */
00048 extern struct libavl_allocator avl_allocator_default;
00049 void *avl_malloc (struct libavl_allocator *, size_t);
00050 void avl_free (struct libavl_allocator *, void *);
00051 
00052 /* Maximum AVL height. */
00053 #ifndef AVL_MAX_HEIGHT
00054 #define AVL_MAX_HEIGHT 32
00055 #endif
00056 
00057 /* Tree data structure. */
00058 struct avl_table
00059   {
00060     struct avl_node *avl_root;          /* Tree's root. */
00061     avl_comparison_func *avl_compare;   /* Comparison function. */
00062     void *avl_param;                    /* Extra argument to |avl_compare|. */
00063     struct libavl_allocator *avl_alloc; /* Memory allocator. */
00064     size_t avl_count;                   /* Number of items in tree. */
00065     unsigned long avl_generation;       /* Generation number. */
00066   };
00067 
00068 /* An AVL tree node. */
00069 struct avl_node
00070   {
00071     struct avl_node *avl_link[2];  /* Subtrees. */
00072     void *avl_data;                /* Pointer to data. */
00073     signed char avl_balance;       /* Balance factor. */
00074   };
00075 
00076 /* AVL traverser structure. */
00077 struct avl_traverser
00078   {
00079     struct avl_table *avl_table;        /* Tree being traversed. */
00080     struct avl_node *avl_node;          /* Current node in tree. */
00081     struct avl_node *avl_stack[AVL_MAX_HEIGHT];
00082                                         /* All the nodes above |avl_node|. */
00083     size_t avl_height;                  /* Number of nodes in |avl_parent|. */
00084     unsigned long avl_generation;       /* Generation number. */
00085   };
00086 
00087 /* Table functions. */
00088 struct avl_table *avl_create (avl_comparison_func *, void *,
00089                               struct libavl_allocator *);
00090 struct avl_table *avl_copy (const struct avl_table *, avl_copy_func *,
00091                             avl_item_func *, struct libavl_allocator *);
00092 void avl_destroy (struct avl_table *, avl_item_func *);
00093 void **avl_probe (struct avl_table *, void *);
00094 void *avl_insert (struct avl_table *, void *);
00095 void *avl_replace (struct avl_table *, void *);
00096 void *avl_delete (struct avl_table *, const void *);
00097 void *avl_find (const struct avl_table *, const void *);
00098 void avl_assert_insert (struct avl_table *, void *);
00099 void *avl_assert_delete (struct avl_table *, void *);
00100 
00101 #define avl_count(table) ((size_t) (table)->avl_count)
00102 
00103 /* Table traverser functions. */
00104 void avl_t_init (struct avl_traverser *, struct avl_table *);
00105 void *avl_t_first (struct avl_traverser *, struct avl_table *);
00106 void *avl_t_last (struct avl_traverser *, struct avl_table *);
00107 void *avl_t_find (struct avl_traverser *, struct avl_table *, void *);
00108 void *avl_t_insert (struct avl_traverser *, struct avl_table *, void *);
00109 void *avl_t_copy (struct avl_traverser *, const struct avl_traverser *);
00110 void *avl_t_next (struct avl_traverser *);
00111 void *avl_t_prev (struct avl_traverser *);
00112 void *avl_t_cur (struct avl_traverser *);
00113 void *avl_t_replace (struct avl_traverser *, void *);
00114 
00115 #endif /* avl.h */

Generated on Sun Apr 6 17:32:44 2008 for GRASS by  doxygen 1.5.5