本文整理汇总了C++中HashTable::Find方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::Find方法的具体用法?C++ HashTable::Find怎么用?C++ HashTable::Find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::Find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Get
inline Tsegment& Get(Key& key, bool *found)
{
Tsegment *item = m_map.Find(key);
if (item == NULL) {
*found = false;
item = new (m_heap.Append()) Tsegment(key);
m_map.Push(*item);
} else {
*found = true;
}
return *item;
}
示例2: main
int main(int argc, const char * argv[])
{
HashTable * ht = iHashTable.Create(64, sizeof(int));
const char test_key0[] = "test_key0";
const char test_key1[] = "test_key1";
const char test_key2[] = "test_key2";
const char invalid_key[] = "invalid_key";
int a = 1;
int b = 2;
int c = 3;
// Test Insert & Retrieve
printf ("Test Insert & Retrieve...\n");
ht->Insert(ht, (void*)test_key0, strlen(test_key0), &a);
ht->Insert(ht, (void*)test_key1, strlen(test_key1), &b);
ht->Insert(ht, (void*)test_key2, strlen(test_key2), &c);
assert(ht->cnt == 3);
int data;
ht->Retrieve(ht, (void*)test_key0, strlen(test_key0), &data);
assert(data == a);
ht->Retrieve(ht, (void*)test_key1, strlen(test_key1), &data);
assert(data == b);
ht->Retrieve(ht, (void*)test_key2, strlen(test_key2), &data);
assert(data == c);
int ret = ht->Retrieve(ht, (void*)invalid_key, strlen(invalid_key), &data);
assert(ret == E_NOT_FOUND);
assert(ht->cnt == 3);
// Test replacement
printf ("Test Replace...\n");
ht->Insert(ht, (void*)test_key0, strlen(test_key0), &b);
assert(ht->cnt == 3);
ht->Retrieve(ht, (void*)test_key0, strlen(test_key0), &data);
assert(data == b);
// Test Continas, Find & Erase
printf ("Test Contains, Find, Erase...\n");
void *key_ret = NULL;
size_t key_len;
assert(ht->Contains(ht, &c) == RET_OK);
ht->Find(ht, &c, &key_ret, &key_len);
assert(key_ret != NULL && key_len != 0);
ht->Erase(ht, key_ret, key_len);
free (key_ret);
assert(ht->cnt == 2);
assert(ht->Contains(ht, &c) == E_NOT_FOUND);
ret = ht->Retrieve(ht, (void*)test_key2, strlen(test_key2), &data);
assert(ret == E_NOT_FOUND);
// Test destroy
printf ("Test Destroy...\n");
ht->Destroy(ht);
printf("All tests passed\n");
}