From e686e07b9c1ffcb3a9be3483a39b069ac5795867 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 12 Oct 2007 10:13:11 +0200 Subject: [PATCH] src/utils_avltree.[ch]: Rename all types and functions to use the prefix `c_avl_'. The prefix `avl_' clashed with an AVL implementation on Solaris 10.. --- src/network.c | 28 ++++----- src/rrdtool.c | 32 +++++------ src/utils_avltree.c | 136 ++++++++++++++++++++++---------------------- src/utils_avltree.h | 42 +++++++------- 4 files changed, 119 insertions(+), 119 deletions(-) diff --git a/src/network.c b/src/network.c index 21b96940..a426214d 100644 --- a/src/network.c +++ b/src/network.c @@ -166,7 +166,7 @@ static value_list_t send_buffer_vl = VALUE_LIST_STATIC; static char send_buffer_type[DATA_MAX_NAME_LEN]; static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER; -static avl_tree_t *cache_tree = NULL; +static c_avl_tree_t *cache_tree = NULL; static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER; static time_t cache_flush_last; static int cache_flush_interval = 1800; @@ -184,12 +184,12 @@ static int cache_flush (void) char *key; time_t *value; - avl_iterator_t *iter; + c_avl_iterator_t *iter; time_t curtime = time (NULL); - iter = avl_get_iterator (cache_tree); - while (avl_iterator_next (iter, (void *) &key, (void *) &value) == 0) + iter = c_avl_get_iterator (cache_tree); + while (c_avl_iterator_next (iter, (void *) &key, (void *) &value) == 0) { if ((curtime - *value) <= cache_flush_interval) continue; @@ -198,7 +198,7 @@ static int cache_flush (void) if (tmp == NULL) { sfree (keys); - avl_iterator_destroy (iter); + c_avl_iterator_destroy (iter); ERROR ("network plugin: cache_flush: realloc" " failed."); return (-1); @@ -206,15 +206,15 @@ static int cache_flush (void) keys = tmp; keys[keys_num] = key; keys_num++; - } /* while (avl_iterator_next) */ - avl_iterator_destroy (iter); + } /* while (c_avl_iterator_next) */ + c_avl_iterator_destroy (iter); for (i = 0; i < keys_num; i++) { - if (avl_remove (cache_tree, keys[i], (void *) &key, + if (c_avl_remove (cache_tree, keys[i], (void *) &key, (void *) &value) != 0) { - WARNING ("network plugin: cache_flush: avl_remove" + WARNING ("network plugin: cache_flush: c_avl_remove" " (%s) failed.", keys[i]); continue; } @@ -246,7 +246,7 @@ static int cache_check (const char *type, const value_list_t *vl) pthread_mutex_lock (&cache_lock); - if (avl_get (cache_tree, key, (void *) &value) == 0) + if (c_avl_get (cache_tree, key, (void *) &value) == 0) { if (*value < vl->time) { @@ -267,7 +267,7 @@ static int cache_check (const char *type, const value_list_t *vl) if ((key_copy != NULL) && (value != NULL)) { *value = vl->time; - avl_insert (cache_tree, key_copy, value); + c_avl_insert (cache_tree, key_copy, value); retval = 0; } else @@ -1299,12 +1299,12 @@ static int network_shutdown (void) void *key; void *value; - while (avl_pick (cache_tree, &key, &value) == 0) + while (c_avl_pick (cache_tree, &key, &value) == 0) { sfree (key); sfree (value); } - avl_destroy (cache_tree); + c_avl_destroy (cache_tree); cache_tree = NULL; } @@ -1327,7 +1327,7 @@ static int network_init (void) memset (&send_buffer_vl, '\0', sizeof (send_buffer_vl)); memset (send_buffer_type, '\0', sizeof (send_buffer_type)); - cache_tree = avl_create ((int (*) (const void *, const void *)) strcmp); + cache_tree = c_avl_create ((int (*) (const void *, const void *)) strcmp); cache_flush_last = time (NULL); /* setup socket(s) and so on */ diff --git a/src/rrdtool.c b/src/rrdtool.c index d274ba02..fbd83602 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -105,7 +105,7 @@ static double xff = 0.1; static int cache_timeout = 0; static int cache_flush_timeout = 0; static time_t cache_flush_last; -static avl_tree_t *cache = NULL; +static c_avl_tree_t *cache = NULL; static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER; static rrd_queue_t *queue_head = NULL; @@ -641,7 +641,7 @@ static void *rrd_queue_thread (void *data) * we make a copy of it's values */ pthread_mutex_lock (&cache_lock); - avl_get (cache, queue_entry->filename, (void *) &cache_entry); + c_avl_get (cache, queue_entry->filename, (void *) &cache_entry); values = cache_entry->values; values_num = cache_entry->values_num; @@ -665,7 +665,7 @@ static void *rrd_queue_thread (void *data) } /* while (42) */ pthread_mutex_lock (&cache_lock); - avl_destroy (cache); + c_avl_destroy (cache); cache = NULL; pthread_mutex_unlock (&cache_lock); @@ -713,7 +713,7 @@ static void rrd_cache_flush (int timeout) int keys_num = 0; char *key; - avl_iterator_t *iter; + c_avl_iterator_t *iter; int i; DEBUG ("rrdtool plugin: Flushing cache, timeout = %i", timeout); @@ -721,8 +721,8 @@ static void rrd_cache_flush (int timeout) now = time (NULL); /* Build a list of entries to be flushed */ - iter = avl_get_iterator (cache); - while (avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0) + iter = c_avl_get_iterator (cache); + while (c_avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0) { if (rc->flags == FLAG_QUEUED) continue; @@ -744,20 +744,20 @@ static void rrd_cache_flush (int timeout) "realloc failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); - avl_iterator_destroy (iter); + c_avl_iterator_destroy (iter); return; } keys[keys_num] = key; keys_num++; } - } /* while (avl_iterator_next) */ - avl_iterator_destroy (iter); + } /* while (c_avl_iterator_next) */ + c_avl_iterator_destroy (iter); for (i = 0; i < keys_num; i++) { - if (avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0) + if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0) { - DEBUG ("rrdtool plugin: avl_remove (%s) failed.", keys[i]); + DEBUG ("rrdtool plugin: c_avl_remove (%s) failed.", keys[i]); continue; } @@ -783,7 +783,7 @@ static int rrd_cache_insert (const char *filename, pthread_mutex_lock (&cache_lock); - avl_get (cache, filename, (void *) &rc); + c_avl_get (cache, filename, (void *) &rc); if (rc == NULL) { @@ -816,7 +816,7 @@ static int rrd_cache_insert (const char *filename, sstrerror (errno, errbuf, sizeof (errbuf)); - avl_remove (cache, filename, &cache_key, NULL); + c_avl_remove (cache, filename, &cache_key, NULL); pthread_mutex_unlock (&cache_lock); ERROR ("rrdtool plugin: realloc failed: %s", errbuf); @@ -856,7 +856,7 @@ static int rrd_cache_insert (const char *filename, return (-1); } - avl_insert (cache, cache_key, rc); + c_avl_insert (cache, cache_key, rc); } DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; " @@ -1095,10 +1095,10 @@ static int rrd_init (void) /* Set the cache up */ pthread_mutex_lock (&cache_lock); - cache = avl_create ((int (*) (const void *, const void *)) strcmp); + cache = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (cache == NULL) { - ERROR ("rrdtool plugin: avl_create failed."); + ERROR ("rrdtool plugin: c_avl_create failed."); return (-1); } diff --git a/src/utils_avltree.c b/src/utils_avltree.c index 09cf2e6f..e4609593 100644 --- a/src/utils_avltree.c +++ b/src/utils_avltree.c @@ -35,35 +35,35 @@ /* * private data types */ -struct avl_node_s +struct c_avl_node_s { void *key; void *value; int height; - struct avl_node_s *left; - struct avl_node_s *right; - struct avl_node_s *parent; + struct c_avl_node_s *left; + struct c_avl_node_s *right; + struct c_avl_node_s *parent; }; -typedef struct avl_node_s avl_node_t; +typedef struct c_avl_node_s c_avl_node_t; -struct avl_tree_s +struct c_avl_tree_s { - avl_node_t *root; + c_avl_node_t *root; int (*compare) (const void *, const void *); }; -struct avl_iterator_s +struct c_avl_iterator_s { - avl_tree_t *tree; - avl_node_t *node; + c_avl_tree_t *tree; + c_avl_node_t *node; }; /* * private functions */ #if 0 -static void verify_tree (avl_node_t *n) +static void verify_tree (c_avl_node_t *n) { if (n == NULL) return; @@ -78,7 +78,7 @@ static void verify_tree (avl_node_t *n) # define verify_tree(n) /**/ #endif -static void free_node (avl_node_t *n) +static void free_node (c_avl_node_t *n) { if (n == NULL) return; @@ -91,7 +91,7 @@ static void free_node (avl_node_t *n) free (n); } -static int calc_height (avl_node_t *n) +static int calc_height (c_avl_node_t *n) { int height_left; int height_right; @@ -107,9 +107,9 @@ static int calc_height (avl_node_t *n) : height_right) + 1); } /* int calc_height */ -static avl_node_t *search (avl_tree_t *t, const void *key) +static c_avl_node_t *search (c_avl_tree_t *t, const void *key) { - avl_node_t *n; + c_avl_node_t *n; int cmp; n = t->root; @@ -135,11 +135,11 @@ static avl_node_t *search (avl_tree_t *t, const void *key) * / a\ /_b\ /_b\ /_c\ * /____\ */ -static avl_node_t *rotate_right (avl_tree_t *t, avl_node_t *x) +static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x) { - avl_node_t *p; - avl_node_t *y; - avl_node_t *b; + c_avl_node_t *p; + c_avl_node_t *y; + c_avl_node_t *b; p = x->parent; y = x->left; @@ -176,11 +176,11 @@ static avl_node_t *rotate_right (avl_tree_t *t, avl_node_t *x) * /_b\ / c\ /_a\ /_b\ * /____\ */ -static avl_node_t *rotate_left (avl_tree_t *t, avl_node_t *x) +static c_avl_node_t *rotate_left (c_avl_tree_t *t, c_avl_node_t *x) { - avl_node_t *p; - avl_node_t *y; - avl_node_t *b; + c_avl_node_t *p; + c_avl_node_t *y; + c_avl_node_t *b; p = x->parent; y = x->right; @@ -208,19 +208,19 @@ static avl_node_t *rotate_left (avl_tree_t *t, avl_node_t *x) return (y); } /* void rotate_left */ -static avl_node_t *rotate_left_right (avl_tree_t *t, avl_node_t *x) +static c_avl_node_t *rotate_left_right (c_avl_tree_t *t, c_avl_node_t *x) { rotate_left (t, x->left); return (rotate_right (t, x)); } /* void rotate_left_right */ -static avl_node_t *rotate_right_left (avl_tree_t *t, avl_node_t *x) +static c_avl_node_t *rotate_right_left (c_avl_tree_t *t, c_avl_node_t *x) { rotate_right (t, x->right); return (rotate_left (t, x)); } /* void rotate_right_left */ -static void rebalance (avl_tree_t *t, avl_node_t *n) +static void rebalance (c_avl_tree_t *t, c_avl_node_t *n) { int b_top; int b_bottom; @@ -264,9 +264,9 @@ static void rebalance (avl_tree_t *t, avl_node_t *n) } /* while (n != NULL) */ } /* void rebalance */ -static avl_node_t *avl_node_next (avl_tree_t *t, avl_node_t *n) +static c_avl_node_t *c_avl_node_next (c_avl_tree_t *t, c_avl_node_t *n) { - avl_node_t *r; /* return node */ + c_avl_node_t *r; /* return node */ if (n == NULL) { @@ -307,11 +307,11 @@ static avl_node_t *avl_node_next (avl_tree_t *t, avl_node_t *n) } return (r); -} /* avl_node_t *avl_node_next */ +} /* c_avl_node_t *c_avl_node_next */ -static avl_node_t *avl_node_prev (avl_tree_t *t, avl_node_t *n) +static c_avl_node_t *c_avl_node_prev (c_avl_tree_t *t, c_avl_node_t *n) { - avl_node_t *r; /* return node */ + c_avl_node_t *r; /* return node */ if (n == NULL) { @@ -352,25 +352,25 @@ static avl_node_t *avl_node_prev (avl_tree_t *t, avl_node_t *n) } return (r); -} /* avl_node_t *avl_node_prev */ +} /* c_avl_node_t *c_avl_node_prev */ -static int _remove (avl_tree_t *t, avl_node_t *n) +static int _remove (c_avl_tree_t *t, c_avl_node_t *n) { assert ((t != NULL) && (n != NULL)); if ((n->left != NULL) && (n->right != NULL)) { - avl_node_t *r; /* replacement node */ + c_avl_node_t *r; /* replacement node */ if (BALANCE (n) > 0) /* left subtree is higher */ { assert (n->left != NULL); - r = avl_node_prev (t, n); + r = c_avl_node_prev (t, n); } else /* right subtree is higher */ { assert (n->right != NULL); - r = avl_node_next (t, n); + r = c_avl_node_next (t, n); } assert ((r->left == NULL) || (r->right == NULL)); @@ -467,14 +467,14 @@ static int _remove (avl_tree_t *t, avl_node_t *n) /* * public functions */ -avl_tree_t *avl_create (int (*compare) (const void *, const void *)) +c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *)) { - avl_tree_t *t; + c_avl_tree_t *t; if (compare == NULL) return (NULL); - if ((t = (avl_tree_t *) malloc (sizeof (avl_tree_t))) == NULL) + if ((t = (c_avl_tree_t *) malloc (sizeof (c_avl_tree_t))) == NULL) return (NULL); t->root = NULL; @@ -483,19 +483,19 @@ avl_tree_t *avl_create (int (*compare) (const void *, const void *)) return (t); } -void avl_destroy (avl_tree_t *t) +void c_avl_destroy (c_avl_tree_t *t) { free_node (t->root); free (t); } -int avl_insert (avl_tree_t *t, void *key, void *value) +int c_avl_insert (c_avl_tree_t *t, void *key, void *value) { - avl_node_t *new; - avl_node_t *nptr; + c_avl_node_t *new; + c_avl_node_t *nptr; int cmp; - if ((new = (avl_node_t *) malloc (sizeof (avl_node_t))) == NULL) + if ((new = (c_avl_node_t *) malloc (sizeof (c_avl_node_t))) == NULL) return (-1); new->key = key; @@ -554,11 +554,11 @@ int avl_insert (avl_tree_t *t, void *key, void *value) verify_tree (t->root); return (0); -} /* int avl_insert */ +} /* int c_avl_insert */ -int avl_remove (avl_tree_t *t, const void *key, void **rkey, void **rvalue) +int c_avl_remove (c_avl_tree_t *t, const void *key, void **rkey, void **rvalue) { - avl_node_t *n; + c_avl_node_t *n; int status; assert (t != NULL); @@ -575,11 +575,11 @@ int avl_remove (avl_tree_t *t, const void *key, void **rkey, void **rvalue) status = _remove (t, n); verify_tree (t->root); return (status); -} /* void *avl_remove */ +} /* void *c_avl_remove */ -int avl_get (avl_tree_t *t, const void *key, void **value) +int c_avl_get (c_avl_tree_t *t, const void *key, void **value) { - avl_node_t *n; + c_avl_node_t *n; assert (value != NULL); @@ -592,10 +592,10 @@ int avl_get (avl_tree_t *t, const void *key, void **value) return (0); } -int avl_pick (avl_tree_t *t, void **key, void **value) +int c_avl_pick (c_avl_tree_t *t, void **key, void **value) { - avl_node_t *n; - avl_node_t *p; + c_avl_node_t *n; + c_avl_node_t *p; if ((key == NULL) || (value == NULL)) return (-1); @@ -629,27 +629,27 @@ int avl_pick (avl_tree_t *t, void **key, void **value) rebalance (t, p); return (0); -} /* int avl_pick */ +} /* int c_avl_pick */ -avl_iterator_t *avl_get_iterator (avl_tree_t *t) +c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t) { - avl_iterator_t *iter; + c_avl_iterator_t *iter; if (t == NULL) return (NULL); - iter = (avl_iterator_t *) malloc (sizeof (avl_iterator_t)); + iter = (c_avl_iterator_t *) malloc (sizeof (c_avl_iterator_t)); if (iter == NULL) return (NULL); - memset (iter, '\0', sizeof (avl_iterator_t)); + memset (iter, '\0', sizeof (c_avl_iterator_t)); iter->tree = t; return (iter); -} /* avl_iterator_t *avl_get_iterator */ +} /* c_avl_iterator_t *c_avl_get_iterator */ -int avl_iterator_next (avl_iterator_t *iter, void **key, void **value) +int c_avl_iterator_next (c_avl_iterator_t *iter, void **key, void **value) { - avl_node_t *n; + c_avl_node_t *n; if ((iter == NULL) || (key == NULL) || (value == NULL)) return (-1); @@ -663,7 +663,7 @@ int avl_iterator_next (avl_iterator_t *iter, void **key, void **value) } else { - n = avl_node_next (iter->tree, iter->node); + n = c_avl_node_next (iter->tree, iter->node); } if (n == NULL) @@ -674,11 +674,11 @@ int avl_iterator_next (avl_iterator_t *iter, void **key, void **value) *value = n->value; return (0); -} /* int avl_iterator_next */ +} /* int c_avl_iterator_next */ -int avl_iterator_prev (avl_iterator_t *iter, void **key, void **value) +int c_avl_iterator_prev (c_avl_iterator_t *iter, void **key, void **value) { - avl_node_t *n; + c_avl_node_t *n; if ((iter == NULL) || (key == NULL) || (value == NULL)) return (-1); @@ -692,7 +692,7 @@ int avl_iterator_prev (avl_iterator_t *iter, void **key, void **value) } else { - n = avl_node_prev (iter->tree, iter->node); + n = c_avl_node_prev (iter->tree, iter->node); } if (n == NULL) @@ -703,9 +703,9 @@ int avl_iterator_prev (avl_iterator_t *iter, void **key, void **value) *value = n->value; return (0); -} /* int avl_iterator_prev */ +} /* int c_avl_iterator_prev */ -void avl_iterator_destroy (avl_iterator_t *iter) +void c_avl_iterator_destroy (c_avl_iterator_t *iter) { free (iter); } diff --git a/src/utils_avltree.h b/src/utils_avltree.h index 0ac6087e..5d35af11 100644 --- a/src/utils_avltree.h +++ b/src/utils_avltree.h @@ -23,15 +23,15 @@ #ifndef UTILS_AVLTREE_H #define UTILS_AVLTREE_H 1 -struct avl_tree_s; -typedef struct avl_tree_s avl_tree_t; +struct c_avl_tree_s; +typedef struct c_avl_tree_s c_avl_tree_t; -struct avl_iterator_s; -typedef struct avl_iterator_s avl_iterator_t; +struct c_avl_iterator_s; +typedef struct c_avl_iterator_s c_avl_iterator_t; /* * NAME - * avl_create + * c_avl_create * * DESCRIPTION * Allocates a new AVL-tree. @@ -45,24 +45,24 @@ typedef struct avl_iterator_s avl_iterator_t; * function from the libc here. * * RETURN VALUE - * A avl_tree_t-pointer upon success or NULL upon failure. + * A c_avl_tree_t-pointer upon success or NULL upon failure. */ -avl_tree_t *avl_create (int (*compare) (const void *, const void *)); +c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *)); /* * NAME - * avl_destroy + * c_avl_destroy * * DESCRIPTION * Deallocates an AVL-tree. Stored value- and key-pointer are lost, but of * course not freed. */ -void avl_destroy (avl_tree_t *t); +void c_avl_destroy (c_avl_tree_t *t); /* * NAME - * avl_insert + * c_avl_insert * * DESCRIPTION * Stores the key-value-pair in the AVL-tree pointed to by `t'. @@ -77,11 +77,11 @@ void avl_destroy (avl_tree_t *t); * Zero upon success and non-zero upon failure and if the key is already * stored in the tree. */ -int avl_insert (avl_tree_t *t, void *key, void *value); +int c_avl_insert (c_avl_tree_t *t, void *key, void *value); /* * NAME - * avl_remove + * c_avl_remove * * DESCRIPTION * Removes a key-value-pair from the tree t. The stored key and value may be @@ -96,11 +96,11 @@ int avl_insert (avl_tree_t *t, void *key, void *value); * RETURN VALUE * Zero upon success or non-zero if the key isn't found in the tree. */ -int avl_remove (avl_tree_t *t, const void *key, void **rkey, void **rvalue); +int c_avl_remove (c_avl_tree_t *t, const void *key, void **rkey, void **rvalue); /* * NAME - * avl_get + * c_avl_get * * DESCRIPTION * Retrieve the `value' belonging to `key'. @@ -113,11 +113,11 @@ int avl_remove (avl_tree_t *t, const void *key, void **rkey, void **rvalue); * RETURN VALUE * Zero upon success or non-zero if the key isn't found in the tree. */ -int avl_get (avl_tree_t *t, const void *key, void **value); +int c_avl_get (c_avl_tree_t *t, const void *key, void **value); /* * NAME - * avl_pick + * c_avl_pick * * DESCRIPTION * Remove a (pseudo-)random element from the tree and return it's `key' and @@ -134,11 +134,11 @@ int avl_get (avl_tree_t *t, const void *key, void **value); * Zero upon success or non-zero if the tree is empty or key or value is * NULL. */ -int avl_pick (avl_tree_t *t, void **key, void **value); +int c_avl_pick (c_avl_tree_t *t, void **key, void **value); -avl_iterator_t *avl_get_iterator (avl_tree_t *t); -int avl_iterator_next (avl_iterator_t *iter, void **key, void **value); -int avl_iterator_prev (avl_iterator_t *iter, void **key, void **value); -void avl_iterator_destroy (avl_iterator_t *iter); +c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t); +int c_avl_iterator_next (c_avl_iterator_t *iter, void **key, void **value); +int c_avl_iterator_prev (c_avl_iterator_t *iter, void **key, void **value); +void c_avl_iterator_destroy (c_avl_iterator_t *iter); #endif /* UTILS_AVLTREE_H */ -- 2.30.2