本文整理汇总了C++中HashTable::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::erase方法的具体用法?C++ HashTable::erase怎么用?C++ HashTable::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::erase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestHashTable_Int
int TestHashTable_Int()
{
HashTable<unsigned long, unsigned long> ht;
const unsigned long max = 1000;
unsigned long i;
for (i = 0; i < max; i++) {
ht.insert(i, max - i);
}
for (i = 0; i < max; i += 2) {
TEST_ASSERT(ht.find(i) != 0);
}
for (i = 0; i < max; i += 2) {
TEST_ASSERT(ht.erase(i));
}
for (i = 0; i < max; i += 2) {
TEST_ASSERT(ht.find(i) == 0);
}
for (i = 1; i < max; i += 2) {
TEST_ASSERT(ht.find(i) == max - i);
}
return 0;
}
示例2: TestHashTable_String
int TestHashTable_String()
{
HashTable<std::string, std::string> ht;
char buffer1[32];
char buffer2[32];
const unsigned long max = 1000;
unsigned long i;
for (i = 0; i < max; i++) {
sprintf(buffer1, "%lu", i);
sprintf(buffer2, "%lu", max - i);
ht.insert(std::string(buffer1), std::string(buffer2));
}
for (i = 0; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
TEST_ASSERT(ht.exists(std::string(buffer1)));
}
for (i = 0; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
TEST_ASSERT(ht.erase(std::string(buffer1)));
}
for (i = 0; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
TEST_ASSERT(!ht.exists(std::string(buffer1)));
}
std::string rec;
for (i = 1; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
sprintf(buffer2, "%lu", max - i);
TEST_ASSERT(ht.find(std::string(buffer1), rec));
TEST_ASSERT(std::string(rec) == std::string(buffer2));
}
/* Rest of the cleanup */
for (i = 1; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
TEST_ASSERT(ht.erase(std::string(buffer1)));
}
return 0;
}
示例3: TestHashTable_CString
int TestHashTable_CString()
{
HashTable<const char *, const char *> ht;
char buffer1[32];
char buffer2[32];
const unsigned long max = 1000;
unsigned long i;
for (i = 0; i < max; i++) {
sprintf(buffer1, "%lu", i);
sprintf(buffer2, "%lu", max - i);
ht.insert(buffer1, (const char *)cc_strdup(buffer2));
}
for (i = 0; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
TEST_ASSERT(ht.find(buffer1) != 0);
}
for (i = 0; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
free((void *)ht.find(buffer1));
TEST_ASSERT(ht.erase(buffer1));
}
for (i = 0; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
TEST_ASSERT(ht.find(buffer1) == 0);
}
for (i = 1; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
sprintf(buffer2, "%lu", max - i);
TEST_ASSERT(strcmp(ht.find(buffer1), buffer2) == 0);
}
/* Rest of the cleanup */
for (i = 1; i < max; i += 2) {
sprintf(buffer1, "%lu", i);
free((void *)ht.find(buffer1));
TEST_ASSERT(ht.erase(buffer1));
}
return 0;
}
示例4: remove
// removes an element. Returns true if the element existed.
PosibErr<bool> remove(ParmStr key) {return lookup_.erase(key);}