当前位置: 首页>>代码示例>>C++>>正文


C++ Test::Get方法代码示例

本文整理汇总了C++中Test::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ Test::Get方法的具体用法?C++ Test::Get怎么用?C++ Test::Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Test的用法示例。


在下文中一共展示了Test::Get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestHashTrie

void TestHashTrie ()
{
    // uint32 to uint32 key/vaue pair example
    struct Test : THashKey32<uint32>
    {
        Test(uint32 key) : THashKey32<uint32>(key) { }
        uint32 value{ 0 };
    };

    // string to uint32 key/vaue pair example
    struct TestStr : CHashKeyStrAnsiChar
    {
        TestStr(const char key[]) : CHashKeyStrAnsiChar(key) { }
        uint32 value{ 0 };
    };

    //
    // int test
    //
    HASH_TRIE(Test, THashKey32<uint32>) test_uint32;

    printf("32 bit integer test...\n");
    printf("1) Add %d entries:    ", MAX_TEST_ENTRIES);
    u64 t0 = GetMicroTime();
    for (int i = 0; i < MAX_TEST_ENTRIES; i++)
    {
        auto test = new Test(i);
        test_uint32.Add(test);
    }
    printf("   %10u usec\n", int(GetMicroTime() - t0));

    printf("2) Find %d entries:   ", MAX_TEST_ENTRIES);
    t0 = GetMicroTime();
    for (uint32 i = 0; i < MAX_TEST_ENTRIES; i++) {
        auto find = test_uint32.Find(THashKey32<uint32>(i));
        volatile uint32 value = find->Get();
        assert(value == i);
    }
    printf("   %10u usec\n", int(GetMicroTime() - t0));

    printf("3) Remove %d entries: ", MAX_TEST_ENTRIES);
    t0 = GetMicroTime();
    for (uint32 i = 0; i < MAX_TEST_ENTRIES; i++)
    {
        Test *removed = test_uint32.Remove(THashKey32<uint32>(i));
        assert(removed != 0);
        assert(removed->Get() == i);
        delete removed;
    }
    printf("   %10u usec\n\n", int(GetMicroTime() - t0));

    // THashTrieInt test
    THashTrieInt<int32> test_hashTrieInt;

    printf("32 bit integer test using THashTrieInt...\n");
    printf("1) Add %d entries:    ", MAX_TEST_ENTRIES);
    t0 = GetMicroTime();
    for (int32 i = 0; i < MAX_TEST_ENTRIES; i++)
    {
        auto added = test_hashTrieInt.Add(i);
        added->value = i;
    }
    printf("   %10u usec\n", int(GetMicroTime() - t0));

    printf("2) Find %d entries:   ", MAX_TEST_ENTRIES);
    t0 = GetMicroTime();
    for (int32 i = 0; i < MAX_TEST_ENTRIES; i++)
    {
        volatile auto * find = test_hashTrieInt.Find(i);
        assert(find->value == i);
    }
    printf("   %10u usec\n", int(GetMicroTime() - t0));

    printf("3) Remove %d entries: ", MAX_TEST_ENTRIES);
    t0 = GetMicroTime();
    for (int32 i = 0; i < MAX_TEST_ENTRIES; i++)
    {
        bool removed = test_hashTrieInt.Remove(i);
        assert(removed);
    }
    printf("   %10u usec\n\n", int(GetMicroTime() - t0));

    //
    // String hash test
    //
    HASH_TRIE(TestStr, CHashKeyStrAnsiChar)    test_str;

    printf("ANSI string test...\n");
    printf("1) Add %d entries:    ", MAX_TEST_ENTRIES);
    t0 = GetMicroTime();
    for (uint32 i = 0; i < MAX_TEST_ENTRIES; i++)
    {
        char buffer[16];
        sprintf_s(buffer, "%d", i);
        TestStr *test = new TestStr(buffer);
        test_str.Add(test);
    }
    printf("   %10u usec\n", int(GetMicroTime() - t0));

    printf("2) Find %d entries:   ", MAX_TEST_ENTRIES);
//.........这里部分代码省略.........
开发者ID:chaelim,项目名称:HAMT,代码行数:101,代码来源:main.cpp


注:本文中的Test::Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。