-/* Produced by texiweb from libavl.w on 2004/01/08 at 23:19. */
+/* src/toolbox/avl.h - AVL tree implementation
-/* libavl - library for manipulation of binary trees.
- Copyright (C) 1998-2002 Free Software Foundation, Inc.
+ Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- The author may be contacted at <blp@gnu.org> on the Internet, or
- write to Ben Pfaff, Stanford University, Computer Science Dept., 353
- Serra Mall, Stanford CA 94305, USA.
*/
-#ifndef AVL_H
-#define AVL_H 1
-
-#include <stddef.h>
-
-/* Function types. */
-typedef int avl_comparison_func (const void *avl_a, const void *avl_b,
- void *avl_param);
-typedef void avl_item_func (void *avl_item, void *avl_param);
-typedef void *avl_copy_func (void *avl_item, void *avl_param);
-
-#ifndef LIBAVL_ALLOCATOR
-#define LIBAVL_ALLOCATOR
-/* Memory allocator. */
-struct libavl_allocator
- {
- void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size);
- void (*libavl_free) (struct libavl_allocator *, void *libavl_block);
- };
+
+#ifndef _AVL_H
+#define _AVL_H
+
+#include "config.h"
+
+#include "vm/types.h"
+
+#include "vm/global.h"
+
+
+/* define direction in an AVL node ********************************************/
+
+#define AVL_LEFT 0
+#define AVL_RIGHT 1
+
+
+/* tree comparator prototype **************************************************/
+
+typedef s4 avl_comparator(const void *treenode, const void *node);
+
+
+/* forward typedefs ***********************************************************/
+
+typedef struct avl_tree_t avl_tree_t;
+typedef struct avl_node_t avl_node_t;
+
+
+/* avl_tree_t *****************************************************************/
+
+struct avl_tree_t {
+#if defined(ENABLE_THREADS)
+ java_object_t *lock; /* threads lock object */
#endif
+ avl_node_t *root; /* pointer to root node */
+ avl_comparator *comparator; /* pointer to comparison function */
+ s4 entries; /* contains number of entries */
+};
+
+
+/* avl_node_t *****************************************************************/
+
+struct avl_node_t {
+ void *data; /* pointer to data structure */
+ s4 balance; /* the range of the field is -2...2 */
+ avl_node_t *childs[2]; /* pointers to the child nodes */
+};
+
+
+/* function prototypes ********************************************************/
-/* Default memory allocator. */
-extern struct libavl_allocator avl_allocator_default;
-void *avl_malloc (struct libavl_allocator *, size_t);
-void avl_free (struct libavl_allocator *, void *);
+avl_tree_t *avl_create(avl_comparator *comparator);
+bool avl_insert(avl_tree_t *tree, void *data);
+void *avl_find(avl_tree_t *tree, void *data);
-/* Maximum AVL height. */
-#ifndef AVL_MAX_HEIGHT
-#define AVL_MAX_HEIGHT 32
+#if !defined(NDEBUG)
+void avl_dump(avl_node_t* node, s4 indent);
#endif
-/* Tree data structure. */
-struct avl_table
- {
- struct avl_node *avl_root; /* Tree's root. */
- avl_comparison_func *avl_compare; /* Comparison function. */
- void *avl_param; /* Extra argument to |avl_compare|. */
- struct libavl_allocator *avl_alloc; /* Memory allocator. */
- size_t avl_count; /* Number of items in tree. */
- unsigned long avl_generation; /* Generation number. */
- };
-
-/* An AVL tree node. */
-struct avl_node
- {
- struct avl_node *avl_link[2]; /* Subtrees. */
- void *avl_data; /* Pointer to data. */
- signed char avl_balance; /* Balance factor. */
- };
-
-/* AVL traverser structure. */
-struct avl_traverser
- {
- struct avl_table *avl_table; /* Tree being traversed. */
- struct avl_node *avl_node; /* Current node in tree. */
- struct avl_node *avl_stack[AVL_MAX_HEIGHT];
- /* All the nodes above |avl_node|. */
- size_t avl_height; /* Number of nodes in |avl_parent|. */
- unsigned long avl_generation; /* Generation number. */
- };
-
-/* Table functions. */
-struct avl_table *avl_create (avl_comparison_func *, void *,
- struct libavl_allocator *);
-struct avl_table *avl_copy (const struct avl_table *, avl_copy_func *,
- avl_item_func *, struct libavl_allocator *);
-void avl_destroy (struct avl_table *, avl_item_func *);
-void **avl_probe (struct avl_table *, void *);
-void *avl_insert (struct avl_table *, void *);
-void *avl_replace (struct avl_table *, void *);
-void *avl_delete (struct avl_table *, const void *);
-void *avl_find (const struct avl_table *, const void *);
-void avl_assert_insert (struct avl_table *, void *);
-void *avl_assert_delete (struct avl_table *, void *);
-
-#define avl_count(table) ((size_t) (table)->avl_count)
-
-/* Table traverser functions. */
-void avl_t_init (struct avl_traverser *, struct avl_table *);
-void *avl_t_first (struct avl_traverser *, struct avl_table *);
-void *avl_t_last (struct avl_traverser *, struct avl_table *);
-void *avl_t_find (struct avl_traverser *, struct avl_table *, void *);
-void *avl_t_insert (struct avl_traverser *, struct avl_table *, void *);
-void *avl_t_copy (struct avl_traverser *, const struct avl_traverser *);
-void *avl_t_next (struct avl_traverser *);
-void *avl_t_prev (struct avl_traverser *);
-void *avl_t_cur (struct avl_traverser *);
-void *avl_t_replace (struct avl_traverser *, void *);
-
-#endif /* avl.h */
+#endif /* _AVL_H */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */