gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
|
Go to the documentation of this file.
28 #include "GmshConfig.h"
29 #if !defined(HAVE_NO_STDINT_H)
31 #elif defined(HAVE_NO_INTPTR_T)
32 typedef unsigned long intptr_t;
38 #define ALLOC(type, number) (type *) Malloc((unsigned) sizeof(type) * number)
39 #define FREE(item) (void) Free(item)
40 #define XRNMAX(a,b) ((a) > (b) ? (a) : (b))
41 #define HEIGHT(node) (node == NIL(avl_node) ? -1 : (node)->height)
42 #define BALANCE(node) (HEIGHT((node)->right) - HEIGHT((node)->left))
44 #define compute_height(node) { \
45 int x=HEIGHT(node->left), y=HEIGHT(node->right); \
46 (node)->height = XRNMAX(x,y) + 1; \
49 #define COMPARE(key, nodekey, compare) \
50 ((compare == avl_numcmp) ? \
51 (intptr_t) key - (intptr_t) nodekey : \
52 (*compare)(key, nodekey))
61 void (*value_free)(
void *value));
81 int (*
compare)(
const void*,
const void *) = tree->
compar, diff;
88 if (value_p !=
NIL(
void *)) *value_p = node->
value;
91 node = (diff < 0) ? node->
left : node->
right;
104 node_p = &tree->
root;
109 stack_nodep[stack_n++] = node_p;
111 if (diff == 0) status = 1;
112 node_p = (diff < 0) ? &node->
left : &node->
right;
125 avl_node **node_p, *node, *rightmost;
128 int (*
compare)(
const void*,
const void*) = tree->
compar, diff;
131 node_p = &tree->
root;
136 if (diff == 0)
goto delete_item;
137 stack_nodep[stack_n++] = node_p;
138 node_p = (diff < 0) ? &node->
left : &node->
right;
145 if (value_p !=
nullptr) *value_p = node->
value;
147 *node_p = node->
right;
154 stack_nodep[stack_n++] = node_p;
212 if (key_p !=
NIL(
void *)) *key_p = node->
key;
213 if (value_p !=
NIL(
void *)) *value_p = node->
value;
232 stack_nodep[stack_n++] = node_p;
233 node_p = &node->
right;
236 *node_p = node->
left;
249 while (--stack_n >= 0) {
250 node_p = stack_nodep[stack_n];
254 if ((hr - hl) < -1) {
256 }
else if ((hr - hl) > 1) {
259 height =
XRNMAX(hl, hr) + 1;
260 if (height == node->
height)
break;
268 avl_node *old_root = *node_p, *new_root, *new_right;
271 *node_p = new_root = old_root->
right;
273 new_root->
left = old_root;
275 new_right = old_root->
right;
276 *node_p = new_root = new_right->
left;
279 new_root->
right = new_right;
280 new_root->
left = old_root;
289 avl_node *old_root = *node_p, *new_root, *new_left;
292 *node_p = new_root = old_root->
left;
294 new_root->
right = old_root;
296 new_left = old_root->
left;
297 *node_p = new_root = new_left->
right;
300 new_root->
left = new_left;
301 new_root->
right = old_root;
321 if (value_p !=
NIL(
void *)) {
322 *value_p = node->
value;
333 if (key_free !=
nullptr) (*key_free)(node->
key);
334 if (value_free !=
nullptr) (*value_free)(node->
value);
364 return (intptr_t) x - (intptr_t) y;
375 int (*compar)(
const void *key1,
const void *key2),
int *error)
377 int l_height, r_height, comp_height, bal;
386 comp_height =
XRNMAX(l_height, r_height) + 1;
387 bal = r_height - l_height;
389 if (comp_height != node->
height) {
390 (void) printf(
"Bad height for %p: computed=%d stored=%d\n",
391 (
void*)node, comp_height, node->
height);
395 if (bal > 1 || bal < -1) {
396 (void) printf(
"Out of balance at node %p, balance = %d\n",
403 (void) printf(
"Bad ordering between %p and %p",
404 (
void*)node, (
void*)node->
left);
410 (void) printf(
"Bad ordering between %p and %p",
411 (
void*)node, (
void*)node->
right);
static void free_entry(avl_node *node, void(*key_free)(void *key), void(*value_free)(void *value))
static avl_node * find_rightmost(avl_node **node_p)
#define COMPARE(key, nodekey, compare)
static avl_node * new_node(void *key, void *value)
static void avl_record_gen_forward(avl_node *node, avl_generator *gen)
int avl_count(avl_tree *tree)
avl_tree * avl_init_table(int(*compar)(const void *key1, const void *key2))
avl_generator * avl_init_gen(avl_tree *tree, int dir)
static int do_check_tree(avl_node *node, int(*compar)(const void *key1, const void *key2), int *error)
static void rotate_left(avl_node **node_p)
int avl_gen(avl_generator *gen, void **key_p, void **value_p)
int(* compar)(const void *key1, const void *key2)
int avl_extremum(avl_tree *tree, int side, void **value_p)
void avl_free_table(avl_tree *tree, void(*key_free)(void *key), void(*value_free)(void *value))
int avl_check_tree(avl_tree *tree)
static void do_rebalance(avl_node ***stack_nodep, int stack_n)
#define compute_height(node)
static void rotate_right(avl_node **node_p)
int avl_numcmp(const void *x, const void *y)
int avl_insert(avl_tree *tree, void *key, void *value)
int avl_lookup(avl_tree *tree, void *key, void **value_p)
int avl_delete(avl_tree *tree, void **key_p, void **value_p)
static void avl_record_gen_backward(avl_node *node, avl_generator *gen)
void avl_free_gen(avl_generator *gen)
bool compare(const MVertex *const v0, const MVertex *const v1)
#define ALLOC(type, number)