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


C++ Hash::get方法代码示例

本文整理汇总了C++中Hash::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Hash::get方法的具体用法?C++ Hash::get怎么用?C++ Hash::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hash的用法示例。


在下文中一共展示了Hash::get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, const char *argv[])
{
    Node first(10, 20);
    Node second(30, 40);
    Node third(100, 50);
    Node forth(100, 33);
    first.setNext(&second);
    second.setNext(&third);
    std::cout << first.getTail()->getValue() << std::endl;
    std::cout << second.getTail()->getValue() << std::endl;
    std::cout << third.getTail()->getValue() << std::endl;

    Hash h;
    h.put(10,20);
    h.put(30,40);
    h.put(10,30);
    h.put(30,50);
    std::cout << h.get(10,20) << std::endl;
    std::cout << h.get(11,20) << std::endl;
    std::cout << h.get(10,30) << std::endl;
    std::cout << h.get(31,100) << std::endl;
    std::cout << h.get(30,40) << std::endl;
    std::cout << h.get(30,50) << std::endl;

    return 0;
}
开发者ID:marsanatta,项目名称:infinite,代码行数:26,代码来源:hash.cpp

示例2: 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;
}
开发者ID:thaithco,项目名称:csci333-hash,代码行数:27,代码来源:Hash_test.cpp

示例3: main

int main( int argc, char *argv[] ){

  for( unsigned char index=10; index > 0; index-- ){
    assert( hsh.set( int_to_str(index), index ) == index );
    assert( hsh.get(int_to_str(index)) == index );
  }

  for( unsigned char index=10; index; index-- ){
    assert( hsh.get( int_to_str(index) ) == index );
  }

  return 0x0000;  // EXIT_SUCCESS;
}
开发者ID:slackjockey,项目名称:slavadores_programmadores,代码行数:13,代码来源:hash_hpp.cpp

示例4: 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;
		}
	}
}
开发者ID:zstoychev,项目名称:data-structures,代码行数:25,代码来源:correctnesstest.cpp

示例5: testAdd

void testAdd() {
	Hash<int, int> h;

	h.put(42, 11);

	if (h.get(42) == h.end()) {
		cout << "testAdd failed\n";
	}
}
开发者ID:zstoychev,项目名称:data-structures,代码行数:9,代码来源:correctnesstest.cpp

示例6: bfs

int bfs(int x){
	//x is goal money
	queue<int> Q;
	Hash m;//money -> step
    m.put(0,0);
	Q.push(0);
	while(!Q.empty()){
		int h = Q.front();
		Q.pop();
		if(h==x) return m.get(x);
		for(int i=0;i<6;i++)
			for(int j=-1;j<=1;j+=2){
				int y = h+j*d[i];
				if(m.get(y)!=-1) continue;
				m.put(y,m.get(h)+1);
				Q.push(y);
			}
	}
	return -1;
}
开发者ID:AlbertSean,项目名称:POJ,代码行数:20,代码来源:1252EuroEfficiency.cpp

示例7: testManyStrings

void testManyStrings() {
	Hash<string, string> h;

	for (vector<pair<string, string> >::const_iterator i = strings.begin(); i != strings.end(); ++i) {
		h.put(i->first, i->second);
	}

	for (vector<pair<string, string> >::const_iterator i = strings.begin(); i != strings.end(); ++i) {
		if (h.get(i->first)->value != i->second) {
			cout << "Fail on string test with string " << i->first << ". Expected: " << i->second << " Got: " << h.get(i->first)->value << endl;
		}
	}
}
开发者ID:zstoychev,项目名称:data-structures,代码行数:13,代码来源:correctnesstest.cpp

示例8: testManyInts

void testManyInts() {
	Hash<int, int> h;

	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 int test with number " << i->first << ". Expected: " << i->second << " Got: " << h.get(i->first)->value << endl;
		}
	}
}
开发者ID:zstoychev,项目名称:data-structures,代码行数:13,代码来源:correctnesstest.cpp

示例9: testReplace

void testReplace() {
	Hash<int, int> h;

	h.put(42, 11);
	h.put(32, 10);
	h.put(90, 3);
	h.put(42, 9);
	h.put(50, 3);

	if (h.get(42)->value != 9) {
		cout << "testReplace failed\n";
	}
}
开发者ID:zstoychev,项目名称:data-structures,代码行数:13,代码来源:correctnesstest.cpp

示例10: downscaleTextures

void App::downscaleTextures(MeshBase* mesh)
{
    FW_ASSERT(mesh);
    Hash<const Image*, Texture> hash;
    for (int submeshIdx = 0; submeshIdx < mesh->numSubmeshes(); submeshIdx++)
    for (int textureIdx = 0; textureIdx < MeshBase::TextureType_Max; textureIdx++)
    {
        Texture& tex = mesh->material(submeshIdx).textures[textureIdx];
        if (tex.exists())
        {
            const Image* orig = tex.getImage();
            if (!hash.contains(orig))
            {
                Image* scaled = orig->downscale2x();
                hash.add(orig, (scaled) ? Texture(scaled, tex.getID()) : tex);
            }
            tex = hash.get(orig);
        }
    }
}
开发者ID:Zerphed,项目名称:advanced-computer-graphics-course,代码行数:20,代码来源:App.cpp

示例11: ngx_restfull_redis_handler

static ngx_int_t ngx_restfull_redis_handler(ngx_http_request_t *r)
{
  
  //TODO: deal with allocation problem - return 500
  ngx_chain_t   out;
  out.buf = create_response_buffer(r);;
  out.next = NULL;

  dd("command => %s", command(r));

  char* redis_command = command(r);
  define_content_type(r, "application/json; charset=utf-8");

  redisContext *c = redisConnect("127.0.0.1", 6379);

  if (c->err) {
    dd("Error: %s\n", c->errstr);
    write_to_buffer(out.buf, (u_char*) "Can't connect to redis", strlen("Can't connect to redis"));
  }

  Hash* params = get_params(r);
  
  redisReply *reply;

  if(!strcmp(redis_command, "get"))
  {
    reply = redisCommand(c,"GET %s", params->get(params, "key"));

    dd("Redis reply status: %d", reply->type);
    if(key_not_found(reply))
    {
      not_found(r, out.buf, (u_char*)"not found");
      return ngx_http_output_filter(r, &out);
    }
    dd("reply: %s", reply->str);

    u_char * result = copy(r->pool, reply->str, reply->len);
    write_to_buffer(out.buf, result, reply->len);
    write_header(r, NGX_HTTP_OK, reply->len);

  } else if (!strcmp(redis_command, "set"))
  {
    reply = redisCommand(c,"SET %s %s", params->get(params, "key"), params->get(params, "value"));

    dd("Redis reply status: %d", reply->type);
    if(key_not_found(reply))
    {
      not_found(r, out.buf, (u_char*)"not found");
      return ngx_http_output_filter(r, &out);
    }

    dd("Reply set %s -- %d", reply->str, reply->len);
    write_to_buffer(out.buf, (u_char*) reply->str, reply->len);
    write_header(r, NGX_HTTP_OK, reply->len);
  } else if(!strcmp(redis_command, "incr"))
  {
    reply = redisCommand(c,"INCR %s", params->get(params, "key"));

    dd("Redis reply status: %d", reply->type);

    int len = number_of_digits(reply->integer);

    dd("Reply INCR -- %d - len %d", (int)reply->integer, len);
    u_char* result = ngx_pcalloc(r->pool, sizeof(char)*len);
    sprintf((char*)result,"%d",(int)reply->integer);
    write_to_buffer(out.buf, result, len);
    write_header(r, NGX_HTTP_OK, len);
  }

  freeReplyObject(reply);
  redisFree(c);
  ngx_free(params);
    
  return ngx_http_output_filter(r, &out);
}
开发者ID:lrgalego,项目名称:http-redis,代码行数:75,代码来源:ngx_restfull_redis_module.c

示例12: main

int main(int argc, char* argv[])
{
   LogWrapperType logwrapper(new btg::core::logger::logWrapper);

   commandLineArgumentHandler* cla = new commandLineArgumentHandler(GPD->sDEFAULT_DAEMON_CONFIG());
   cla->setup();
   if (!cla->parse(argc, argv))
      {
         delete cla;
         cla = 0;

         return BTG_ERROR_EXIT;
      }

   bool verboseFlag = cla->beVerbose();

   std::string configFile = GPD->sDEFAULT_DAEMON_CONFIG();
   if (cla->configFileSet())
      {
         configFile = cla->configFile();
      }
#if BTG_AUTH_DEBUG
   BTG_NOTICE(logwrapper, "Config: '" << configFile << "'");
#endif //BTG_AUTH_DEBUG

   std::string errorString;
   if (!btg::core::os::fileOperation::check(configFile, errorString, false))
      {
         BTG_FATAL_ERROR(logwrapper, "btgpasswd", "Unable to open config file '" << configFile << "': " << errorString);

         delete cla;
         cla = 0;

         return BTG_ERROR_EXIT;
      }

   btg::daemon::daemonConfiguration* config  = new btg::daemon::daemonConfiguration(logwrapper,
                                                                                    configFile);

   if (!config->read())
      {
         BTG_FATAL_ERROR(logwrapper, "btgpasswd", "Could not open configuration file '" << configFile << "'");

         delete config;
         config = 0;
         delete cla;
         cla = 0;

         return BTG_ERROR_EXIT;
      }

#if BTG_AUTH_DEBUG
   BTG_NOTICE(logwrapper, "Config read from '" << configFile << "'.");
#endif // BTG_AUTH_DEBUG

   // Open the passwd file, filename from the config file.

   std::string auth_file = config->getAuthFile();

   bool newfile = cla->createNewFile();

   if (newfile)
      {
         if (cla->getOperation() != commandLineArgumentHandler::OP_ADD)
            {
               // Only allow creating new file when an user is being added.
               newfile = false;
            }
      }

   // resolve relative paths etc.
   if (!btg::core::os::fileOperation::resolvePath(auth_file))
      {
         BTG_NOTICE(logwrapper, "Unable to resolve path '" << auth_file << "'");
      }

   if (!newfile)
      {
         if (!btg::core::os::fileOperation::check(auth_file, errorString, false))
            {
               BTG_FATAL_ERROR(logwrapper, "btgpasswd", "Could not open passwd file '" << auth_file << "': " << errorString);

               delete config;
               config = 0;
               delete cla;
               cla = 0;

               return BTG_ERROR_EXIT;
            }
      }

   passwordAuth* auth = new passwordAuth(logwrapper, auth_file, newfile);

   if (!auth->initialized())
      {
         BTG_FATAL_ERROR(logwrapper, "btgpasswd", "Unable to load passwd file '" << auth_file << "'.");

         delete auth;
         auth = 0;
         delete config;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:btg-svn,代码行数:101,代码来源:btgpasswd.cpp

示例13: GetHash

		gnutls_digest_algorithm_t GetHash() const { return hash.get(); }
开发者ID:NikosPapakonstantinou,项目名称:inspircd,代码行数:1,代码来源:m_ssl_gnutls.cpp


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