/* Hash table tests */
-#include "silcincludes.h"
+#include "silc.h"
typedef struct entry_struct {
char name[8];
int val;
} *entry;
-bool dump = FALSE;
-bool auto_rehash = TRUE;
+SilcBool dump = FALSE;
+SilcBool auto_rehash = TRUE;
int count = 2000;
SilcHashTable t = NULL;
return e->val + silc_hash_string(e->name, NULL);
}
-bool hash_compare(void *key1, void *key2, void *user_context)
+SilcBool hash_compare(void *key1, void *key2, void *user_context)
{
entry e = key1;
entry e2 = key2;
silc_free(e);
}
-bool add_entries()
+SilcBool add_entries()
{
entry e;
int i;
e = silc_calloc(1, sizeof(*e));
if (!e)
return FALSE;
- snprintf(e->name, sizeof(e->name), "%d", i);
+ silc_snprintf(e->name, sizeof(e->name), "%d", i);
e->val = i;
silc_hash_table_add(t, (void *)e, (void *)e->name);
return TRUE;
}
-bool del_entries_with_list()
+SilcBool del_entries_with_list()
{
SilcHashTableList htl;
entry e;
silc_hash_table_del(t, key);
}
-bool del_n_entries_foreach()
+SilcBool del_n_entries_foreach()
{
struct entry_struct f;
int i;
for (i = 0; i < count; i++) {
memset(&f, 0, sizeof(f));
- snprintf(f.name, sizeof(f.name), "%d", i);
+ silc_snprintf(f.name, sizeof(f.name), "%d", i);
f.val = i;
silc_hash_table_find_foreach(t, &f, del_foreach, NULL);
return TRUE;
}
-bool del_entries_foreach()
+SilcBool del_entries_foreach()
{
SILC_LOG_DEBUG(("Deleting all entries with foreach"));
silc_hash_table_foreach(t, del_foreach, NULL);
return TRUE;
}
-bool alloc_table()
+SilcBool alloc_table()
{
SILC_LOG_DEBUG(("Allocating hash table with %d entries (%s)",
count, auto_rehash ? "auto rehash" : "no auto rehash"));
- t = silc_hash_table_alloc(0, hash_entry, NULL,
+ t = silc_hash_table_alloc(NULL, 0, hash_entry, NULL,
hash_compare, NULL,
hash_destructor, NULL, auto_rehash);
return TRUE;
}
-bool delete_table_with_list()
+SilcBool delete_table_with_list()
{
SILC_LOG_DEBUG(("Deleting entries with SilcHashTableList"));
return TRUE;
}
-bool find_entries()
+SilcBool find_entries()
{
struct entry_struct f;
entry e;
for (i = 0; i < count; i++) {
memset(&f, 0, sizeof(f));
- snprintf(f.name, sizeof(f.name), "%d", i);
+ silc_snprintf(f.name, sizeof(f.name), "%d", i);
f.val = i;
/* Find */
return TRUE;
}
-bool dump_table()
+SilcBool dump_table()
{
SilcHashTableList htl;
entry e;
char *name;
- bool dumpped = FALSE;
+ SilcBool dumpped = FALSE;
SILC_LOG_DEBUG(("Dumping hash table entries"));
int main(int argc, char **argv)
{
- bool success = FALSE;
+ SilcBool success = FALSE;
+ SilcGetOptStruct op = SILC_GETOPT_INIT;
+ int opt;
int i;
- if (argc > 1 && !strcmp(argv[1], "-d")) {
- silc_debug = 1;
- silc_debug_hexdump = 1;
- silc_log_set_debug_string("*table*");
- }
-
- if (argc > 1 && !strcmp(argv[1], "-D")) {
- silc_debug = 1;
- dump = TRUE;
- silc_log_set_debug_string("*table*");
+ while ((opt = silc_getopt(argc, argv, "de::D", &op)) != -1) {
+ switch (opt) {
+ case 'd':
+ silc_log_debug(TRUE);
+ silc_log_debug_hexdump(TRUE);
+ silc_log_quick(TRUE);
+ silc_log_set_debug_string("*table*,*errno*");
+ break;
+
+ case 'D':
+ silc_log_debug(TRUE);
+ dump = TRUE;
+ silc_log_set_debug_string("*table*,*errno*");
+ break;
+
+ case 'e':
+ silc_log_debug(TRUE);
+ fprintf(stderr, "%s\n", op.opt_arg);
+ if (op.opt_arg) {
+ dump = TRUE;
+ silc_log_set_debug_string(op.opt_arg);
+ }
+ break;
+
+ default:
+ exit(1);
+ break;
+ }
}
if (!alloc_table())
auto_rehash = TRUE;
if (!alloc_table())
goto err;
- count = 3999;
+ count = 17999;
if (!add_entries())
goto err;
SILC_LOG_DEBUG(("rehash"));