gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
avl.h
Go to the documentation of this file.
1 #ifndef AVL_H
2 #define AVL_H
3 
4 /*
5  * avl package
6  *
7  * Copyright (c) 1988-1993, The Regents of the University of California.
8  *
9  * Permission to use, copy, modify, and distribute this software and its
10  * documentation for any purpose and without fee is hereby granted, provided
11  * that the above copyright notice appear in all copies and that both that
12  * copyright notice and this permission notice appear in supporting
13  * documentation, and that the name of the University of California not
14  * be used in advertising or publicity pertaining to distribution of
15  * the software without specific, written prior permission. The University
16  * of California makes no representations about the suitability of this
17  * software for any purpose. It is provided "as is" without express or
18  * implied warranty.
19  *
20  * THE UNIVERSITY OF CALIFORNIA DISCLAIMS ALL WARRANTIES WITH REGARD TO
21  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
22  * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR
23  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
24  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
25  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27  */
28 
29 // Modified for Gmsh (C++, 64 bits, ...)
30 
31 typedef struct avl_node_struct avl_node;
34  void *key;
35  void *value;
36  int height;
37 };
38 
39 
40 typedef struct avl_tree_struct avl_tree;
43  int (*compar)(const void *key1, const void *key2);
45  int modified;
46 };
47 
48 
49 typedef struct avl_generator_struct avl_generator;
53  int count;
54 };
55 
56 
57 #define AVL_FORWARD 0
58 #define AVL_BACKWARD 1
59 
60 #define AVL_MOST_LEFT 0
61 #define AVL_MOST_RIGHT 1
62 
63 #define avl_is_member(tree, key) avl_lookup(tree, key, (void **) 0)
64 #define NIL(type) (type *) 0
65 
66 #define avl_foreach_item(table, gen, dir, key_p, value_p) \
67  for(gen = avl_init_gen(table, dir); \
68  avl_gen(gen, key_p, value_p) || (avl_free_gen(gen),0);)
69 
70 
71 inline void avl_walk_forward(avl_node *node, void (*func)(void *key, void *value))
72 {
73  if (node != NIL(avl_node)) {
74  avl_walk_forward(node->left, func);
75  (*func)(node->key, node->value);
76  avl_walk_forward(node->right, func);
77  }
78 }
79 
80 inline void avl_walk_backward(avl_node *node, void (*func)(void *key, void *value))
81 {
82  if (node != NIL(avl_node)) {
83  avl_walk_backward(node->right, func);
84  (*func)(node->key, node->value);
85  avl_walk_backward(node->left, func);
86  }
87 }
88 
89 inline void avl_foreach(avl_tree *tree, void (*func)(void *key, void *value), int direction)
90 {
91  if (direction == AVL_FORWARD) {
92  avl_walk_forward(tree->root, func);
93  } else {
94  avl_walk_backward(tree->root, func);
95  }
96 }
97 
98 avl_tree *avl_init_table(int (*compar)(const void *key1, const void *key2));
99 int avl_lookup(avl_tree *tree, void *key, void **value_p);
100 int avl_insert(avl_tree *tree, void *key, void *value);
101 int avl_delete(avl_tree *tree, void **key_p, void **value_p);
102 void avl_free_table(avl_tree *tree, void (*key_free)(void *key), void (*value_free)(void *value));
103 int avl_count(avl_tree *tree);
104 int avl_check_tree(avl_tree *tree);
105 int avl_extremum(avl_tree *tree, int side, void **value_p);
106 
107 avl_generator *avl_init_gen(avl_tree *tree, int dir);
108 int avl_gen(avl_generator *gen, void **key_p, void **value_p);
109 void avl_free_gen(avl_generator *gen);
110 
111 int avl_numcmp(const void *x, const void*y);
112 
113 #endif
AVL_FORWARD
#define AVL_FORWARD
Definition: avl.h:57
avl_walk_forward
void avl_walk_forward(avl_node *node, void(*func)(void *key, void *value))
Definition: avl.h:71
avl_gen
int avl_gen(avl_generator *gen, void **key_p, void **value_p)
Definition: avl.cpp:204
avl_tree_struct::num_entries
int num_entries
Definition: avl.h:44
avl_generator_struct
Definition: avl.h:50
avl_node_struct::height
int height
Definition: avl.h:36
avl_insert
int avl_insert(avl_tree *tree, void *key, void *value)
Definition: avl.cpp:96
avl_check_tree
int avl_check_tree(avl_tree *tree)
Definition: avl.cpp:367
avl_free_gen
void avl_free_gen(avl_generator *gen)
Definition: avl.cpp:218
avl_init_table
avl_tree * avl_init_table(int(*compar)(const void *key1, const void *key2))
Definition: avl.cpp:67
avl_delete
int avl_delete(avl_tree *tree, void **key_p, void **value_p)
Definition: avl.cpp:123
avl_generator_struct::nodelist
avl_node ** nodelist
Definition: avl.h:52
avl_tree_struct::compar
int(* compar)(const void *key1, const void *key2)
Definition: avl.h:43
avl_init_gen
avl_generator * avl_init_gen(avl_tree *tree, int dir)
Definition: avl.cpp:183
avl_foreach
void avl_foreach(avl_tree *tree, void(*func)(void *key, void *value), int direction)
Definition: avl.h:89
avl_node_struct::key
void * key
Definition: avl.h:34
avl_tree_struct::root
avl_node * root
Definition: avl.h:42
avl_lookup
int avl_lookup(avl_tree *tree, void *key, void **value_p)
Definition: avl.cpp:78
avl_tree_struct::modified
int modified
Definition: avl.h:45
avl_extremum
int avl_extremum(avl_tree *tree, int side, void **value_p)
Definition: avl.cpp:309
avl_count
int avl_count(avl_tree *tree)
Definition: avl.cpp:345
avl_generator_struct::tree
avl_tree * tree
Definition: avl.h:51
avl_node_struct
Definition: avl.h:32
avl_node_struct::right
avl_node * right
Definition: avl.h:33
avl_free_table
void avl_free_table(avl_tree *tree, void(*key_free)(void *key), void(*value_free)(void *value))
Definition: avl.cpp:339
NIL
#define NIL(type)
Definition: avl.h:64
avl_walk_backward
void avl_walk_backward(avl_node *node, void(*func)(void *key, void *value))
Definition: avl.h:80
avl_numcmp
int avl_numcmp(const void *x, const void *y)
Definition: avl.cpp:362
avl_generator_struct::count
int count
Definition: avl.h:53
direction
static void direction(Vertex *v1, Vertex *v2, double d[3])
Definition: Geo.cpp:218
avl_node_struct::value
void * value
Definition: avl.h:35
avl_node_struct::left
avl_node * left
Definition: avl.h:33
avl_tree_struct
Definition: avl.h:41