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


C++ StringHash::insert方法代码示例

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

示例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;
    }
//.........这里部分代码省略.........
开发者ID:gatgui,项目名称:fbpg,代码行数:101,代码来源:hash.cpp


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