/*
* irc_dictionary_get_linear_index(struct Dictionary *dict,
- * const char *key)
+ * const void *key)
*
* Gets a linear index number for key.
*
* - rebuilds the linear index if the tree is marked as dirty.
*/
int
-irc_dictionary_get_linear_index(struct Dictionary *dict, const char *key)
+irc_dictionary_get_linear_index(struct Dictionary *dict, const void *key)
{
struct DictionaryElement *elem;
}
/*
- * irc_dictionary_retune(struct Dictionary *dict, const char *key)
+ * irc_dictionary_retune(struct Dictionary *dict, const void *key)
*
* Retunes the tree, self-optimizing for the element which belongs to key.
*
* - a new root node is nominated.
*/
static void
-irc_dictionary_retune(struct Dictionary *dict, const char *key)
+irc_dictionary_retune(struct Dictionary *dict, const void *key)
{
struct DictionaryElement n, *tn, *left, *right, *node;
int ret;
}
/*
- * irc_dictionary_find(struct Dictionary *dtree, const char *key)
+ * irc_dictionary_find(struct Dictionary *dtree, const void *key)
*
* Looks up a DTree node by name.
*
* Side Effects:
* - none
*/
-struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const char *key)
+struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const void *key)
{
s_assert(dict != NULL);
s_assert(key != NULL);
}
/*
- * irc_dictionary_add(struct Dictionary *dtree, const char *key, void *data)
+ * irc_dictionary_add(struct Dictionary *dtree, const void *key, void *data)
*
* Creates a new DTree node and binds data to it.
*
* Side Effects:
* - data is inserted into the DTree.
*/
-struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const char *key, void *data)
+struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const void *key, void *data)
{
struct DictionaryElement *delem;
delem->key = key;
delem->data = data;
- /* TBD: is this needed? --nenolod */
- if (delem->key == NULL)
- {
- rb_free(delem);
- return NULL;
- }
-
irc_dictionary_link(dict, delem);
return delem;
}
/*
- * irc_dictionary_delete(struct Dictionary *dtree, const char *key)
+ * irc_dictionary_delete(struct Dictionary *dtree, const void *key)
*
* Deletes data from a dictionary tree.
*
* Notes:
* - the returned data needs to be mowgli_freed/released manually!
*/
-void *irc_dictionary_delete(struct Dictionary *dtree, const char *key)
+void *irc_dictionary_delete(struct Dictionary *dtree, const void *key)
{
struct DictionaryElement *delem = irc_dictionary_find(dtree, key);
void *data;
}
/*
- * irc_dictionary_retrieve(struct Dictionary *dtree, const char *key)
+ * irc_dictionary_retrieve(struct Dictionary *dtree, const void *key)
*
* Retrieves data from a dictionary.
*
* Side Effects:
* - none
*/
-void *irc_dictionary_retrieve(struct Dictionary *dtree, const char *key)
+void *irc_dictionary_retrieve(struct Dictionary *dtree, const void *key)
{
struct DictionaryElement *delem = irc_dictionary_find(dtree, key);
if (depth > *pmaxdepth)
*pmaxdepth = depth;
result = depth;
- if (delem->left)
+ if (delem && delem->left)
result += stats_recurse(delem->left, depth + 1, pmaxdepth);
- if (delem->right)
+ if (delem && delem->right)
result += stats_recurse(delem->right, depth + 1, pmaxdepth);
return result;
}
s_assert(dict != NULL);
- cb(str, privdata);
- maxdepth = 0;
- sum = stats_recurse(dict->root, 0, &maxdepth);
- rb_snprintf(str, sizeof str, "%s: Objects: %d, Depth sum: %d, Avg depth: %d, Max depth: %d.", dict->id, dict->count, sum, sum / dict->count, maxdepth);
+ if (dict->count)
+ {
+ 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);
+ }
+ else
+ {
+ snprintf(str, sizeof str, "%-30s %-15s %-10s %-10s %-10s %-10s", dict->id, "DICT", "0", "0", "0", "0");
+ }
+
cb(str, privdata);
}