本文整理汇总了C++中StringHash::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ StringHash::insert方法的具体用法?C++ StringHash::insert怎么用?C++ StringHash::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringHash
的用法示例。
在下文中一共展示了StringHash::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: splitStyle
StringHash Tools::splitStyle(const QString &style)
{
StringHash hash;
if (style.isEmpty())
return hash;
QStringList list = removeEdgeSpaces(style).split(";", QString::SkipEmptyParts);
for (int i = 0; i < list.count(); ++i) {
QString attr = list.at(i);
int pos = attr.indexOf(QLatin1Char(':'));
if (pos != -1)
hash.insert(removeEdgeSpaces(attr.mid(0, pos)), removeEdgeSpaces(attr.mid(pos+1)));
}
return hash;
}
示例2: main
int main(int argc, char **argv) {
#ifdef _MEMMGR
HeapManager heap;
#endif
clock_t from, to;
double diff;
LongHash lhash;
LongMap lmap;
StringHash shash;
StringMap smap;
srand(clock());
int nelems = 10;
int naccess = 100;
if (argc >= 2) {
sscanf(argv[1], "%d", &nelems);
}
if (argc >= 3) {
sscanf(argv[2], "%d", &naccess);
}
const char *strpool[] = {
"hello",
"_",
"world",
"012",
"before",
"after",
"if",
"then",
"else",
"for",
"while",
"do",
"@",
"~",
"+",
"-",
"function",
"class"
};
size_t nstrings = sizeof(strpool) / sizeof(const char*);
// fill elements
std::vector<std::string> skeys(nelems);
std::vector<long> lkeys(nelems);
std::cout << "Buid hash and map with " << nelems << " elements" << std::endl;
for (int i=0; i<nelems; ++i) {
long k = rand();
lkeys[i] = k;
int p = rand() % nstrings;
int s = rand() % nstrings;
skeys[i] = strpool[p];
skeys[i] += strpool[s];
}
from = clock();
for (int i=0; i<nelems; ++i) {
lhash.insert(lkeys[i], rand());
}
to = clock();
diff = double(to - from) / CLOCKS_PER_SEC;
std::cout << "LongHash fill " << nelems << " values: " << diff << " (s)" << std::endl;
from = clock();
for (int i=0; i<nelems; ++i) {
lmap[lkeys[i]] = rand();
}
to = clock();
diff = double(to - from) / CLOCKS_PER_SEC;
std::cout << "LongMap fill " << nelems << " values: " << diff << " (s)" << std::endl;
from = clock();
for (int i=0; i<nelems; ++i) {
shash.insert(skeys[i], rand());
}
to = clock();
diff = double(to - from) / CLOCKS_PER_SEC;
std::cout << "StringHash fill " << nelems << " values: " << diff << " (s)" << std::endl;
from = clock();
for (int i=0; i<nelems; ++i) {
smap[skeys[i]] = rand();
}
to = clock();
diff = double(to - from) / CLOCKS_PER_SEC;
std::cout << "StringMap fill " << nelems << " values: " << diff << " (s)" << std::endl;
// check datas
/*
std::cout << "Check data" << std::endl;
for (int k=0; k<nelems; ++k) {
long v0 = lhash.getValue(lkeys[k]);
long v1 = lmap[lkeys[k]];
if (v0 != v1) {
std::cout << "Data mismatch at long key \"" << lkeys[k] << "\"" << std::endl;
}
//.........这里部分代码省略.........