/*
- * charybdis: an advanced ircd
+ * Solanum: a slightly advanced ircd
* rb_dictionary.c: Dictionary-based information storage.
*
* Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
rb_dictionary_element *elem;
lrb_assert(dict != NULL);
- lrb_assert(key != NULL);
elem = rb_dictionary_find(dict, key);
if (elem == NULL)
* Side Effects:
* - a node is linked to the dictionary tree
*/
-static void
+static rb_dictionary_element *
rb_dictionary_link(rb_dictionary *dict,
rb_dictionary_element *delem)
{
dict->count--;
rb_free(delem);
+ delem = dict->root;
}
}
+
+ return delem;
}
/*
* Side Effects:
* - none
*/
-void *rb_dictionary_foreach_cur(rb_dictionary *dtree,
+void *rb_dictionary_foreach_cur(rb_dictionary *dtree __attribute__((unused)),
rb_dictionary_iter *state)
{
lrb_assert(dtree != NULL);
rb_dictionary_element *rb_dictionary_find(rb_dictionary *dict, const void *key)
{
lrb_assert(dict != NULL);
- lrb_assert(key != NULL);
/* retune for key, key will be the tree's root if it's available */
rb_dictionary_retune(dict, key);
rb_dictionary_element *delem;
lrb_assert(dict != NULL);
- lrb_assert(key != NULL);
lrb_assert(data != NULL);
lrb_assert(rb_dictionary_find(dict, key) == NULL);
delem->key = key;
delem->data = data;
- rb_dictionary_link(dict, delem);
-
- return delem;
+ return rb_dictionary_link(dict, delem);
}
/*
* - name of DTree node to delete
*
* Outputs:
- * - on success, the remaining data that needs to be mowgli_freed
+ * - on success, the remaining data that needs to be rb_freed
* - on failure, NULL
*
* Side Effects:
* - data is removed from the DTree.
*
* Notes:
- * - the returned data needs to be mowgli_freed/released manually!
+ * - the returned data needs to be rb_freed/released manually!
*/
void *rb_dictionary_delete(rb_dictionary *dtree, const void *key)
{
{
maxdepth = 0;
sum = stats_recurse(dict->root, 0, &maxdepth);
- snprintf(str, sizeof str, "%-30s %-15s %-10d %-10d %-10d %-10d", dict->id, "DICT", dict->count, sum, sum / dict->count, maxdepth);
+ snprintf(str, sizeof str, "%-30s %-15s %-10u %-10d %-10d %-10d", dict->id, "DICT", dict->count, sum, sum / dict->count, maxdepth);
}
else
{