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


C++ HashTable::erase方法代码示例

本文整理汇总了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;
}
开发者ID:skydevgit,项目名称:crisscross,代码行数:28,代码来源:hashtable.cpp

示例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;
}
开发者ID:skydevgit,项目名称:crisscross,代码行数:46,代码来源:hashtable.cpp

示例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;
}
开发者ID:skydevgit,项目名称:crisscross,代码行数:46,代码来源:hashtable.cpp

示例4: remove

 // removes an element.  Returns true if the element existed.
 PosibErr<bool> remove(ParmStr key) {return lookup_.erase(key);}
开发者ID:Distrotech,项目名称:aspell,代码行数:2,代码来源:string_map.hpp


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