Exemplo n.º 1
0
//MML语句分析
int MML_Console_Command::parse_mml_cnd_string(const char *mml_string,
                                              MML_Console_Command::MML_STRING_PATTERN pattern)
{

    switch (pattern)
    {
        case MML_STRING_PATTERN_1:
            parse_mml_cnd_string1(mml_string);
            break;
        case MML_STRING_PATTERN_2:
            parse_mml_cnd_string2(mml_string);
            break;
        default:
            ZCE_ASSERT_ALL(false);
            return -1;
    }
    return 0;
}
Exemplo n.º 2
0
//使用随机数测试,测试equal的情况,AVL Tree
int test_mmap_avltree5(int /*argc*/, char * /*argv*/[])
{

    typedef ZCE_LIB::shm_avl_tree< int, int >  TEST_AVL_TREE;
    TEST_AVL_TREE* test_avl_tree;
    const size_t  SIZE_OF_TREE = 2000;
    TEST_AVL_TREE::iterator  tree_iter, tree_iter_end;
    size_t sz_malloc = TEST_AVL_TREE::getallocsize(SIZE_OF_TREE);

    char *pt_avl_tree = new char[sz_malloc];
    memset(pt_avl_tree, 0, sz_malloc);

    //初始化
    test_avl_tree = TEST_AVL_TREE::initialize(SIZE_OF_TREE, pt_avl_tree, false);
    if (NULL == test_avl_tree)
    {
        return 0;
    }

    //
    const uint32_t TEST_SEED = 1010123;
    ZCE_LIB::random_mt11213b  mt11231b_gen(TEST_SEED);
    int ins = 0;
    size_t ins_count = 0;
    //插入相同的数值
    for (ins_count = 0; ins_count < SIZE_OF_TREE;)
    {
        ins = mt11231b_gen.rand() % SIZE_OF_TREE;
        auto ins_iter = test_avl_tree->insert_equal(ins);
        if (ins_iter.second == true)
        {
            ++ins_count;
        }
        else
        {
            ZCE_ASSERT_ALL(false);
        }
    }

    auto f_iter = test_avl_tree->insert_unique(5);
    if (f_iter.second == true)
    {
        ZCE_ASSERT_ALL(false);
    }
    printf("%s", "\n==========================================================\n");
    printf("After insert:size=%u, capacity=%u, empty=%u, full=%u\n",
        test_avl_tree->size(),
        test_avl_tree->capacity(),
        test_avl_tree->empty(),
        test_avl_tree->full());

    tree_iter = test_avl_tree->begin();
    tree_iter_end = test_avl_tree->end();
    int a = 0, b = 0;
    for (; tree_iter != tree_iter_end;)
    {
        printf("%d ", (*tree_iter));

        bool ok = test_avl_tree->check_balanced(tree_iter.getserial());
        if (!ok)
        {
            printf("(No OK)");
        }

        a = (*tree_iter);
        ++tree_iter;
        if (tree_iter != tree_iter_end)
        {
            b = (*tree_iter);
            if (a > b)
            {
                ZCE_ASSERT_ALL(false);
            }
        }
    }

    //printf("%s", "\n-----------------------------------------------------\n");
    //for (size_t u = 0; u <= SIZE_OF_TREE; ++u)
    //{
    //    test_avl_tree->debug_note(u);
    //}
    //printf("%s", "\n-----------------------------------------------------\n");

    int del = 0;
    size_t erase_count = 0;
    size_t del_count = 0;
    for (erase_count = 0; erase_count < SIZE_OF_TREE;)
    {
        del = mt11231b_gen.rand() % SIZE_OF_TREE;
        del_count = test_avl_tree->erase_equal(del);
        if (del_count > 0)
        {
            erase_count += del_count;
            printf("del %d count.After del list:", del, del_count);
            tree_iter = test_avl_tree->begin();
            tree_iter_end = test_avl_tree->end();
            for (; tree_iter != tree_iter_end; ++tree_iter)
            {
                printf("%d ", (*tree_iter));

                bool ok = test_avl_tree->check_balanced(tree_iter.getserial());
                if (!ok)
                {
                    printf("(No OK)");
                }
            }
            printf("%s", "\n");

            a = (*tree_iter);
            ++tree_iter;
            if (tree_iter != tree_iter_end)
            {
                b = (*tree_iter);
                if (a >= b)
                {
                    ZCE_ASSERT_ALL(false);
                }
            }

            //printf("%s", "\n-----------------------------------------------------\n");
            //for (size_t u = 0; u <= SIZE_OF_TREE; ++u)
            //{
            //    test_avl_tree->debug_note(u);
            //}
            //printf("%s", "\n-----------------------------------------------------\n");

        }
    }
    printf("%s", "\n---------------------------------------------\n");
    printf("\nAfter erase :size=%u, capacity=%u, empty=%u, full=%u\n",
        test_avl_tree->size(),
        test_avl_tree->capacity(),
        test_avl_tree->empty(),
        test_avl_tree->full());

    delete[] pt_avl_tree;
    pt_avl_tree = NULL;

    return 0;
}
Exemplo n.º 3
0
//测试,AVL Tree
int test_mmap_avltree1(int /*argc*/, char * /*argv*/[])
{

    typedef ZCE_LIB::shm_avl_tree< int, int >  TEST_AVL_TREE;
    TEST_AVL_TREE* test_avl_tree;
    const size_t  SIZE_OF_TREE = 500;
    TEST_AVL_TREE::iterator  tree_iter, tree_iter_end;
    size_t sz_malloc = TEST_AVL_TREE::getallocsize(SIZE_OF_TREE);

    char *pt_avl_tree = new char[sz_malloc];
    memset(pt_avl_tree, 0, sz_malloc);

    //初始化
    test_avl_tree = TEST_AVL_TREE::initialize(SIZE_OF_TREE, pt_avl_tree, false);
    if (NULL == test_avl_tree)
    {
        return 0;
    }

    //
    const uint32_t TEST_SEED = 1010123;
    ZCE_LIB::random_mt11213b  mt11231b_gen(TEST_SEED);

    size_t ins_count = 0;
    for (ins_count = 0; ins_count < SIZE_OF_TREE;)
    {
        int ins = mt11231b_gen.rand() % SIZE_OF_TREE;
        auto iter = test_avl_tree->insert_unique(ins);
        if (iter.second == true)
        {
            ++ins_count;
        }
    }

    auto f_iter = test_avl_tree->insert_unique(1);
    if (f_iter.second == true)
    {
        ZCE_ASSERT_ALL(false);
    }

    printf("Before insert:size=%u, capacity=%u, empty=%u, full=%u\n",
        test_avl_tree->size(),
        test_avl_tree->capacity(),
        test_avl_tree->empty(),
        test_avl_tree->full());

    tree_iter = test_avl_tree->begin();
    tree_iter_end = test_avl_tree->end();
    int a = 0, b = 0;
    for (; tree_iter != tree_iter_end;)
    {
        printf("%d ", (*tree_iter));
        a = (*tree_iter);
        ++tree_iter;
        if (tree_iter != tree_iter_end)
        {
            b = (*tree_iter);
            if (a >= b)
            {
                ZCE_ASSERT_ALL(false);
            }
        }
    }


    delete[] pt_avl_tree;
    pt_avl_tree = NULL;

    return 0;
}