Exemplo n.º 1
0
static void
test_autogrow(void)
{
    {
        bighash_table_t *table = bighash_table_create(BIGHASH_AUTOGROW);
        biglist_t *entries = NULL;
        insert__(table, 63, &entries);
        AIM_ASSERT(table->bucket_count == 128);
        test_table_data__(table, &entries);
        bighash_table_destroy(table, NULL);
    }

    {
        bighash_table_t *table = bighash_table_create(BIGHASH_AUTOGROW);
        biglist_t *entries = NULL;
        insert__(table, 64, &entries);
        AIM_ASSERT(table->bucket_count == 256);
        test_table_data__(table, &entries);
        bighash_table_destroy(table, NULL);
    }
}
void
router_ip_table_finish()
{
    indigo_core_gentable_unregister(router_ip_table);
    bighash_table_destroy(router_ip_entries, NULL);
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    biglist_t *entries = NULL;

    /** Basic Hashing -- statically allocated table */
    bighash_table_init_static(&static_table);
    insert__(&static_table, 10000, &entries);
    test_table_data__(&static_table, &entries);
    bighash_table_destroy(&static_table, NULL);

    /** Basic hashing -- dynamically allocated table */
    {
        bighash_table_t *dtable;
        dtable = bighash_table_create(64);
        insert__(dtable, 10000, &entries);
        test_table_data__(dtable, &entries);
        bighash_table_destroy(dtable, NULL);
    }

    /** Count and removal while iterating */
    {
        bighash_table_t *table;
        bighash_iter_t iter;
        bighash_entry_t *e;
        test_entry_t *te;
        int ecount=100;
        int count = 0;
        table = bighash_table_create(64);
        insert__(table, ecount, NULL);
        if(bighash_entry_count(table) != ecount) {
            AIM_DIE("Entry count mismatch: expected %d, got %d",
                    ecount, bighash_entry_count(table));
        }
        /* Iterate once, just counting */
        for(te = (test_entry_t*)bighash_iter_start(table, &iter);
            te; te = (test_entry_t*)bighash_iter_next(&iter)) {
            count++;
        }
        if(count != ecount) {
            AIM_DIE("Iteration count incorrect (%d)", count);
        }
        /* Iterate again, removing elements. Tests both iteration restart
         * and remove-while-iterating.
         */
        for(e = bighash_iter_start(table, &iter); e; e = bighash_iter_next(&iter)) {
            test_entry_t *te = container_of(e, hash_entry, test_entry_t);
            bighash_remove(table, &te->hash_entry);
            /* Clear the list links on this element to make sure the
             * removal was done properly. */
            memset(te, 0, sizeof(*te));
            aim_free(te);
        }
        if(bighash_entry_count(table) != 0) {
            AIM_DIE("Count is not zero after iterated removal (count=%d)",
                    bighash_entry_count(table));
        }
        bighash_table_destroy(table, NULL);
    }

    /** Migrating between tables */
    {
        bighash_table_t *src;
        bighash_table_t *dst;
        src = bighash_table_create(64);
        dst = bighash_table_create(128);
        insert__(src, 1000, &entries);
        bighash_entries_move(dst, src);
        if(bighash_entry_count(src) != 0) {
            AIM_DIE("Source table is not empty.");
        }
        bighash_table_destroy(src, NULL);
        test_table_data__(dst, &entries);
        bighash_table_destroy(dst, NULL);
    }

    /** Check utilization and automatic element destruction */
    bighash_table_init_static(&static_table);
    insert__(&static_table, 100000, 0);
    bighash_table_utilization_show(&static_table, &aim_pvs_stdout);
    bighash_table_destroy(&static_table, free_test_entry);

    test_template();

    return 0;
}