tavl.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 TAVL_H
00027 #define TAVL_H 1
00028 
00029 #include <stddef.h>
00030 
00031 /* Function types. */
00032 typedef int tavl_comparison_func (const void *tavl_a, const void *tavl_b,
00033                                  void *tavl_param);
00034 typedef void tavl_item_func (void *tavl_item, void *tavl_param);
00035 typedef void *tavl_copy_func (void *tavl_item, void *tavl_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 tavl_allocator_default;
00049 void *tavl_malloc (struct libavl_allocator *, size_t);
00050 void tavl_free (struct libavl_allocator *, void *);
00051 
00052 /* Maximum TAVL height. */
00053 #ifndef TAVL_MAX_HEIGHT
00054 #define TAVL_MAX_HEIGHT 32
00055 #endif
00056 
00057 /* Tree data structure. */
00058 struct tavl_table
00059   {
00060     struct tavl_node *tavl_root;        /* Tree's root. */
00061     tavl_comparison_func *tavl_compare; /* Comparison function. */
00062     void *tavl_param;                   /* Extra argument to |tavl_compare|. */
00063     struct libavl_allocator *tavl_alloc; /* Memory allocator. */
00064     size_t tavl_count;                  /* Number of items in tree. */
00065   };
00066 
00067 /* Characterizes a link as a child pointer or a thread. */
00068 enum tavl_tag
00069   {
00070     TAVL_CHILD,                     /* Child pointer. */
00071     TAVL_THREAD                     /* Thread. */
00072   };
00073 
00074 /* An TAVL tree node. */
00075 struct tavl_node
00076   {
00077     struct tavl_node *tavl_link[2]; /* Subtrees. */
00078     void *tavl_data;                /* Pointer to data. */
00079     unsigned char tavl_tag[2];      /* Tag fields. */
00080     signed char tavl_balance;       /* Balance factor. */
00081   };
00082 
00083 /* TAVL traverser structure. */
00084 struct tavl_traverser
00085   {
00086     struct tavl_table *tavl_table;        /* Tree being traversed. */
00087     struct tavl_node *tavl_node;          /* Current node in tree. */
00088   };
00089 
00090 /* Table functions. */
00091 struct tavl_table *tavl_create (tavl_comparison_func *, void *,
00092                               struct libavl_allocator *);
00093 struct tavl_table *tavl_copy (const struct tavl_table *, tavl_copy_func *,
00094                             tavl_item_func *, struct libavl_allocator *);
00095 void tavl_destroy (struct tavl_table *, tavl_item_func *);
00096 void **tavl_probe (struct tavl_table *, void *);
00097 void *tavl_insert (struct tavl_table *, void *);
00098 void *tavl_replace (struct tavl_table *, void *);
00099 void *tavl_delete (struct tavl_table *, const void *);
00100 void *tavl_find (const struct tavl_table *, const void *);
00101 void tavl_assert_insert (struct tavl_table *, void *);
00102 void *tavl_assert_delete (struct tavl_table *, void *);
00103 
00104 #define tavl_count(table) ((size_t) (table)->tavl_count)
00105 
00106 /* Table traverser functions. */
00107 void tavl_t_init (struct tavl_traverser *, struct tavl_table *);
00108 void *tavl_t_first (struct tavl_traverser *, struct tavl_table *);
00109 void *tavl_t_last (struct tavl_traverser *, struct tavl_table *);
00110 void *tavl_t_find (struct tavl_traverser *, struct tavl_table *, void *);
00111 void *tavl_t_insert (struct tavl_traverser *, struct tavl_table *, void *);
00112 void *tavl_t_copy (struct tavl_traverser *, const struct tavl_traverser *);
00113 void *tavl_t_next (struct tavl_traverser *);
00114 void *tavl_t_prev (struct tavl_traverser *);
00115 void *tavl_t_cur (struct tavl_traverser *);
00116 void *tavl_t_replace (struct tavl_traverser *, void *);
00117 
00118 #endif /* tavl.h */

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