📄 hash_string.cpp
字号:
// hash_string.cpp : Definiert den Einsprungpunkt f黵 die Konsolenanwendung.
//
#include <stdio.h>
#include <stdlib.h>
#define STL_USING_STRING
#include "stl.h"
#include "hash_table.h"
/* my hash table is of type <std::string> */
typedef CHashTable<std::string> CStdStringHashT;
int main(int argc, char* argv[])
{
CStdStringHashT MyHashTable;
/* some names and locations */
std::string names[4] = {"Peter Mueller", "Li Chen", "Juan Cortez", "Sergej Petrov"};
std::string locations[4] = {"Berlin", "Peking", "Madrid", "Moscow"};
/* put entries into hash */
for(int entry = 0; entry < 4; entry++)
{
MyHashTable.AddKey(names[entry], &locations[entry]);
}
/* show all entries with iterator */
printf("SHOW ALL ENTRIES:\n\n");
CStdStringHashT::iterator iter = MyHashTable.begin();
while(iter != MyHashTable.end())
{
std::string name = *iter;
std::string* pLoc = MyHashTable.GetMember(name);
if(pLoc) printf(" %s lives in %s.\n", name.c_str(), pLoc->c_str());
iter++;
}
printf("\n\n");
/* single access */
printf("SINGLE ACCESS:\n\n");
std::string* pLoc = MyHashTable.GetMember(names[3]);
printf("Mr. %s lives in %s.\n", names[3].c_str(), pLoc->c_str());
printf("\n\n");
/* clean up table and do not free memory because entries not dynamic allocated */
MyHashTable.RemoveAllKey(false);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -