本文整理汇总了C++中Hash::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ Hash::remove方法的具体用法?C++ Hash::remove怎么用?C++ Hash::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::remove方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
Hash<int>* h = new Hash<int>();
h->insert("one", 1);
std::cout << "inserted (\"one\", 1)\nresult: " << h->get("one") << std::endl;
h->insert("one", 2);
std::cout << "replaced 1 with 2\n" << h->get("one") << std::endl;
h->insert("noe", 3);
std::cout << "inserted (\"noe\", 3) (should create the same hash as \"one\", but with value of 3)\nresult: " << h->get("noe") << std::endl;
h->insert("ZZZZZZzZzZzZzzzZUHcuhu", 239);
h->insert("ZZZZZZzZzZZzzzzZUHcuhu", 13);
std::cout << "inserted (\"ZZZZZZzZzZzZzzzZUHcuhu\", 239)\n" << h->get("ZZZZZZzZzZzZzzzZUHcuhu") << std::endl;
h->remove("noe");
std::cout << "removed (\"noe\"\n" << std::endl;
h->print();
return 0;
}
示例2: main
int main()
{
Hash<int,string> h;
if(h.find(111)!=0)
cout<<*(h.find(111))<<endl;
else
cout<<111<<" Not exist"<<endl;
h.insert(111,"111");
h.insert(222,"222");
h.insert(333,"333");
if(h.find(111)!=0)
cout<<*(h.find(111))<<endl;
else
cout<<111<<"Not exist"<<endl;
if(h.find(222)!=0)
cout<<*(h.find(222))<<endl;
else
cout<<222<<"Not exist"<<endl;
h.remove(111);
cout<<"Remove 111 ..."<<endl;
if(h.find(111)!=0)
cout<<*(h.find(111))<<endl;
else
cout<<111<<" Not exist"<<endl;
}
示例3: testRemove
void testRemove() {
Hash<int, int> h;
for (vector<pair<int, int> >::const_iterator i = ints.begin(); i != ints.begin() + ints.size() / 2; ++i) {
h.put(i->first, i->second);
}
for (vector<pair<int, int> >::const_iterator i = ints.begin(); i != ints.begin() + ints.size() / 2; ++i) {
h.remove(i->first);
}
if (!h.isEmpty()) {
cout << "testRemove failed\n";
}
for (vector<pair<int, int> >::const_iterator i = ints.begin(); i != ints.end(); ++i) {
h.put(i->first, i->second);
}
for (map<int, int>::const_iterator i = uniqueInts.begin(); i != uniqueInts.end(); ++i) {
if (h.get(i->first)->value != i->second) {
cout << "Fail on remove test with number " << i->first << ". Expected: " << i->second << " Got: " << h.get(i->first)->value << endl;
}
}
}
示例4: main
int main()
{
cout << "Welcome to this awesome Phone Book\n" << endl;
Hash hash;
int choice;
string name;
string phone;
Node* entry;
do
{
menu();
cin >> choice;
switch (choice)
{
case 1:
getchar();
cout << "Name: ";
getline(cin, name);
cout << "Phone: ";
getline(cin, phone);
entry = new Node();
entry->name = name;
entry->phone = phone;
hash.add(entry);
break;
case 2:
getchar();
cout << "Enter full name: ";
getline(cin, name);
hash.search(name);
break;
case 3:
getchar();
cout << "Name: ";
getline(cin, name);
hash.remove(name);
break;
case 4:
hash.printAll();
break;
case 0:
hash.clearAll();
break;
default:
cout << "Invalid entry. Please try again" << endl;
break;
}
} while (choice != 0);
cout << "Have a good day!" << endl;
return 0;
}
示例5: main
int main(){
Hash<int>* tab = new Hash<int>(100);
tab->insert("chickin" , 5);
tab->insert("car" , 1);
tab->insert("asdf", 3);
cout << tab->find("chickin") << endl;
cout << tab->find("asdf") << endl;
tab->remove("car");
cout << tab->find("car");
delete tab;
return 0;
}
示例6: popMemOwner
void FW::popMemOwner(void)
{
#if FW_MEM_DEBUG
U32 threadID = Thread::getID();
Array<const char*>* stack = s_memOwnerStacks.search(threadID);
if (stack)
{
stack->removeLast();
if (!stack->getSize())
{
s_memOwnerStacks.remove(threadID);
if (!s_memOwnerStacks.getSize())
s_memOwnerStacks.reset();
}
}
#endif
}
示例7: setprecision
int
main ( ) {
Hash hashTable;
cout << setprecision ( 10 );
cout << "Test 1 - print empty table" << endl;
hashTable.print ( );
cout << "-------------------------------------------------------------"
<< endl;
cout << "Test 2 - processing input file" << endl;
hashTable.processFile ( "dict5.txt" );
hashTable.print ( );
cout << "-------------------------------------------------------------"
<< endl;
cout << "Test 3 - searching" << endl;
if ( hashTable.search ( "heath" ) )
cout << "Passed - searching for valid item" << endl;
else
cout << "FAILED - searching for valid item" << endl;
if ( hashTable.search ( "hello" ) )
cout << "Passed - searching for valid item" << endl;
else
cout << "FAILED - searching for valid item" << endl;
if ( hashTable.search ( "ttttt" ) )
cout << "Passed - searching for valid item" << endl;
else
cout << "FAILED - searching for valid item" << endl;
if ( hashTable.search ( "empty" ) )
cout << "FAILED - searching for invalid item" << endl;
else
cout << "Passed - searching for invalid item" << endl;
cout << "-------------------------------------------------------------"
<< endl;
cout << "Test 4 - testing remove" << endl;
hashTable.remove ( "happy" );
hashTable.print ( );
cout << endl;
hashTable.remove ( "hello" );
hashTable.remove ( "harps" );
hashTable.print ( );
cout << endl;
hashTable.remove ( "heath" );
hashTable.remove ( "heath" );
hashTable.remove ( "heath" );
hashTable.print ( );
cout << endl;
hashTable.remove ( "rrrrr" );
hashTable.remove ( "ooooo" );
hashTable.print ( );
cout << "-------------------------------------------------------------"
<< endl;
cout << "Test 5 - output to file" << endl;
hashTable.output ( "hash.out" );
cout << endl << endl;
cout << "-------------------------------------------------------------"
<< endl;
cout << "Test 6 - Stats" << endl;
hashTable.printStats ( );
cout << "-------------------------------------------------------------"
<< endl;
return 1;
}
示例8: QVERIFY
void tst_QHash::insert1()
{
const char *hello = "hello";
const char *world = "world";
const char *allo = "allo";
const char *monde = "monde";
{
typedef QHash<QString, QString> Hash;
Hash hash;
QString key;
for (int i = 0; i < 10; ++i) {
key[0] = i + '0';
for (int j = 0; j < 10; ++j) {
key[1] = j + '0';
hash.insert(key, "V" + key);
}
}
for (int i = 0; i < 10; ++i) {
key[0] = i + '0';
for (int j = 0; j < 10; ++j) {
key[1] = j + '0';
hash.remove(key);
}
}
}
{
typedef QHash<int, const char *> Hash;
Hash hash;
hash.insert(1, hello);
hash.insert(2, world);
QVERIFY(hash.size() == 2);
QVERIFY(!hash.isEmpty());
{
Hash hash2 = hash;
hash2 = hash;
hash = hash2;
hash2 = hash2;
hash = hash;
hash2.clear();
hash2 = hash2;
QVERIFY(hash2.size() == 0);
QVERIFY(hash2.isEmpty());
}
QVERIFY(hash.size() == 2);
{
Hash hash2 = hash;
hash2[1] = allo;
hash2[2] = monde;
QVERIFY(hash2[1] == allo);
QVERIFY(hash2[2] == monde);
QVERIFY(hash[1] == hello);
QVERIFY(hash[2] == world);
hash2[1] = hash[1];
hash2[2] = hash[2];
QVERIFY(hash2[1] == hello);
QVERIFY(hash2[2] == world);
hash[1] = hash[1];
QVERIFY(hash[1] == hello);
}
{
Hash hash2 = hash;
hash2.detach();
hash2.remove(1);
QVERIFY(hash2.size() == 1);
hash2.remove(1);
QVERIFY(hash2.size() == 1);
hash2.remove(0);
QVERIFY(hash2.size() == 1);
hash2.remove(2);
QVERIFY(hash2.size() == 0);
QVERIFY(hash.size() == 2);
}
hash.detach();
{
Hash::iterator it1 = hash.find(1);
QVERIFY(it1 != hash.end());
Hash::iterator it2 = hash.find(0);
QVERIFY(it2 != hash.begin());
QVERIFY(it2 == hash.end());
*it1 = monde;
QVERIFY(*it1 == monde);
QVERIFY(hash[1] == monde);
*it1 = hello;
QVERIFY(*it1 == hello);
QVERIFY(hash[1] == hello);
//.........这里部分代码省略.........
示例9: main
int main()
{
Hash<char> toTest (hasher, 10);
// isEmpty() test
cout << "\nisEmpty() Test" << endl;
cout << "isEmpty(): " << toTest.isEmpty() << endl;
cout << "isFull(): " << toTest.isFull() << endl;
toTest.showStructure();
// insert() test
cout << "\ninsert() Test" << endl;
for (char c = '0'; c <= 'z'; c++)
{
toTest.insert(c);
}
toTest.showStructure();
// isFull() test
cout << "\nisFull() Test" << endl;
cout << "isEmpty(): " << toTest.isEmpty() << endl;
cout << "isFull(): " << toTest.isFull() << endl;
// remove() and retrieve() test
cout << "\nremove() and retrieve() Test" << endl;
char rtest = ' ';
cout << "remove(3): " << toTest.remove(3) << endl;
bool rreturn = toTest.retrieve(3, rtest);
cout << "retrieve(3, rtest): " << rreturn << " | rtest = " << rtest << endl;
toTest.showStructure();
// clear() test
cout << "\nclear() Test" << endl;
toTest.clear();
toTest.showStructure();
// isEmpty() test
cout << "\nisEmpty() Test" << endl;
cout << "isEmpty(): " << toTest.isEmpty() << endl;
cout << "isFull(): " << toTest.isFull() << endl;
toTest.showStructure();
// Int test version
Hash<int> testTwo(hasher_two, 20);
cout << "\n\nTesting with ints:" << endl;
// insert() test
cout << "\ninsert() Test" << endl;
for (int i = 1; i <= 115; i++)
{
testTwo.insert(i);
}
testTwo.showStructure();
// isFull() test
cout << "\nisFull() Test" << endl;
cout << "isEmpty(): " << testTwo.isEmpty() << endl;
cout << "isFull(): " << testTwo.isFull() << endl;
// remove() and retrieve() test
cout << "\nremove() and retrieve() Test" << endl;
cout << "remove(3): " << testTwo.remove(3) << endl;
int itest;
bool ireturn = testTwo.retrieve(3, itest);
cout << "retrieve(3, rtest): " << ireturn << " | rtest = " << itest << endl;
testTwo.showStructure();
// clear() test
cout << "\nclear() Test" << endl;
testTwo.clear();
testTwo.showStructure();
system("pause");
}