summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f4c3e68)
raw | patch | inline | side by side (parent: f4c3e68)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 15 Feb 2007 08:47:37 +0000 (09:47 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 15 Feb 2007 08:47:37 +0000 (09:47 +0100) |
The iterator-code has been disabled, because it's not very practical and
`utils_llist' should be used if order matters. `avl_node_{next,prev}' have been
made `static', because they're not exported.
`utils_llist' should be used if order matters. `avl_node_{next,prev}' have been
made `static', because they're not exported.
src/utils_avltree.c | patch | blob | history | |
src/utils_avltree.h | patch | blob | history |
diff --git a/src/utils_avltree.c b/src/utils_avltree.c
index 830b711f8f9713d45bfe5b898995b2ac5f85b7ae..b107b03dac09a59c1a25013241c62f9f999ea41d 100644 (file)
--- a/src/utils_avltree.c
+++ b/src/utils_avltree.c
} /* while (n != NULL) */
} /* void rebalance */
+#if 0
+/* This code disabled until a need arises. */
static avl_iterator_t *avl_create_iterator (avl_tree_t *t, avl_node_t *n)
{
avl_iterator_t *iter;
return (iter);
}
+#endif
-void *avl_node_next (avl_tree_t *t, avl_node_t *n)
+static void *avl_node_next (avl_tree_t *t, avl_node_t *n)
{
avl_node_t *r; /* return node */
return (r);
}
-void *avl_node_prev (avl_tree_t *t, avl_node_t *n)
+static void *avl_node_prev (avl_tree_t *t, avl_node_t *n)
{
avl_node_t *r; /* return node */
{
avl_tree_t *t;
+ if (compare == NULL)
+ return (NULL);
+
if ((t = (avl_tree_t *) malloc (sizeof (avl_tree_t))) == NULL)
return (NULL);
return (0);
}
-avl_iterator_t *avl_get_iterator (avl_tree_t *t)
-{
- avl_node_t *n;
-
- if (t == NULL)
- return (NULL);
-
- for (n = t->root; n != NULL; n = n->left)
- if (n->left == NULL)
- break;
-
- return (avl_create_iterator (t, n));
-} /* avl_iterator_t *avl_get_iterator */
-
int avl_pick (avl_tree_t *t, void **key, void **value)
{
avl_node_t *n;
avl_node_t *p;
- assert ((key != NULL) && (value != NULL));
+ if ((key == NULL) || (value == NULL))
+ return (-1);
if (t->root == NULL)
return (-1);
return (0);
} /* int avl_pick */
+#if 0
+/* This code disabled until a need arises. */
+avl_iterator_t *avl_get_iterator (avl_tree_t *t)
+{
+ avl_node_t *n;
+
+ if (t == NULL)
+ return (NULL);
+
+ for (n = t->root; n != NULL; n = n->left)
+ if (n->left == NULL)
+ break;
+
+ return (avl_create_iterator (t, n));
+} /* avl_iterator_t *avl_get_iterator */
+
void *avl_iterator_next (avl_iterator_t *iter)
{
avl_node_t *n;
{
free (iter);
}
+#endif /* 0 */
diff --git a/src/utils_avltree.h b/src/utils_avltree.h
index 7875e0b2674802df844901e1b5f42fed644ab437..37af5e482dc1cc700f74ffe03b7d865d95835960 100644 (file)
--- a/src/utils_avltree.h
+++ b/src/utils_avltree.h
+/**
+ * collectd - src/utils_avltree.h
+ * Copyright (C) 2006,2007 Florian octo Forster
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
#ifndef UTILS_AVLTREE_H
#define UTILS_AVLTREE_H 1
struct avl_iterator_s;
typedef struct avl_iterator_s avl_iterator_t;
-struct avl_keyval_s
-{
- void *key;
- void *value;
-};
-
+/*
+ * NAME
+ * avl_create
+ *
+ * DESCRIPTION
+ * Allocates a new AVL-tree.
+ *
+ * PARAMETERS
+ * `compare' The function-pointer `compare' is used to compare two keys. It
+ * has to return less than zero if it's first argument is smaller
+ * then the second argument, more than zero if the first argument
+ * is bigger than the second argument and zero if they are equal.
+ * If your keys are char-pointers, you can use the `strcmp'
+ * function from the libc here.
+ *
+ * RETURN VALUE
+ * A avl_tree_t-pointer upon success or NULL upon failure.
+ */
avl_tree_t *avl_create (int (*compare) (const void *, const void *));
+
+
+/*
+ * NAME
+ * 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);
+/*
+ * NAME
+ * avl_insert
+ *
+ * DESCRIPTION
+ * Stores the key-value-pair in the AVL-tree pointed to by `t'.
+ *
+ * PARAMETERS
+ * `t' AVL-tree to store the data in.
+ * `key' Key used to store the value under. This is used to get back to
+ * the value again.
+ * `value' Value to be stored.
+ *
+ * RETURN VALUE
+ * 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);
+
+/*
+ * NAME
+ * avl_remove
+ *
+ * DESCRIPTION
+ * Removes a key-value-pair from the tree t. The stored key and value may be
+ * returned in `rkey' and `rvalue'.
+ *
+ * PARAMETERS
+ * `t' AVL-tree to remove key-value-pair from.
+ * `key' Key to identify the entry.
+ * `rkey' Pointer to a pointer in which to store the key. May be NULL.
+ * `rvalue' Pointer to a pointer in which to store the value. May be NULL.
+ *
+ * RETURN VALUE
+ * Zero upon success or non-zero if the key isn't found in the tree.
+ */
int avl_remove (avl_tree_t *t, void *key, void **rkey, void **rvalue);
+/*
+ * NAME
+ * avl_get
+ *
+ * DESCRIPTION
+ * Retrieve the `value' belonging to `key'.
+ *
+ * PARAMETERS
+ * `t' AVL-tree to get the value from.
+ * `key' Key to identify the entry.
+ * `value' Pointer to a pointer in which to store the value. May be NULL.
+ *
+ * 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);
+/*
+ * NAME
+ * avl_pick
+ *
+ * DESCRIPTION
+ * Remove a (pseudo-)random element from the tree and return it's `key' and
+ * `value'. Entries are not returned in any particular order. This function
+ * is intended for cache-flushes that don't care about the order but simply
+ * want to remove all elements, one at a time.
+ *
+ * PARAMETERS
+ * `t' AVL-tree to get the value from.
+ * `key' Pointer to a pointer in which to store the key.
+ * `value' Pointer to a pointer in which to store the value.
+ *
+ * RETURN 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);
+
+#if 0
+/* This code disabled until a need arises. */
avl_iterator_t *avl_get_iterator (avl_tree_t *t);
void *avl_iterator_next (avl_iterator_t *iter);
void *avl_iterator_prev (avl_iterator_t *iter);
void avl_iterator_destroy (avl_iterator_t *iter);
+#endif
#endif /* UTILS_AVLTREE_H */