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


C++ HashTable::find方法代码示例

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


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

示例1: TestHashTable_Int

int TestHashTable_Int()
{
	HashTable<unsigned long, unsigned long> ht;

	const unsigned long                     max = 1000;
	unsigned long                           i;
	for (i = 0; i < max; i++) {
		ht.insert(i, max - i);
	}

	for (i = 0; i < max; i += 2) {
		TEST_ASSERT(ht.find(i) != 0);
	}

	for (i = 0; i < max; i += 2) {
		TEST_ASSERT(ht.erase(i));
	}

	for (i = 0; i < max; i += 2) {
		TEST_ASSERT(ht.find(i) == 0);
	}

	for (i = 1; i < max; i += 2) {
		TEST_ASSERT(ht.find(i) == max - i);
	}

	return 0;
}
开发者ID:skydevgit,项目名称:crisscross,代码行数:28,代码来源:hashtable.cpp

示例2: main

int main() {
    int value, result;
    bool found;
    
    HashTable A;
    
    value = 55;
    for (int i = 1; i < 21; i++) {      //Populates table with multiples of 55
        A.insert(value * i); 
    } 
        
    A.print();                          //Tests prints function
    
    value = A.size();
    cout << "Size is: " << value << endl;   //Tests size function
    
    //Code below tests that find works appropriately. Test values are reset
    //before each function call so as to ensure that values are being modified
    //appropriately.
    value = 165;
    result = 100;
    found = false;
    
    A.find(value, found, result);
    cout << "Value: " << value << endl;
    if (found) {
        cout << "Found: True" << endl;
    } else {
        cout << "Found: False" << endl;
    }
    cout << "Found at index: " << result << endl;
    
    value = 131;
    result = 100;
    found = false;
    
    A.find(value, found, result);
    cout << "Value: " << value << endl;
    if (found) {
        cout << "Found: True" << endl;
    } else {
        cout << "Found: False" << endl;
    }
    cout << "Found at index: " << result << endl;
    
    value = 1045;
    result = 100;
    found = false;
    
    A.find(value, found, result);
    cout << "Value: " << value << endl;
    if (found) {
        cout << "Found: True" << endl;
    } else {
        cout << "Found: False" << endl;
    }
    cout << "Found at index: " << result << endl;
    
    return 0;
}
开发者ID:thefridge111,项目名称:NUDataStruct,代码行数:60,代码来源:main.cpp

示例3: HashTable

TEST(hashtable_test, simple_condition)
{
    HashTable *hashtable = new HashTable(4);
    EXPECT_EQ(hashtable->find(1, 5), -1);
    hashtable->insert(1, 5, 7);
    EXPECT_EQ(hashtable->find(1, 5), 7);
    hashtable->insert(2, 4, 8);
    hashtable->remove(1, 5);
    EXPECT_EQ(hashtable->find(1, 5), -1);
    delete hashtable;
}
开发者ID:alogfans,项目名称:seaweed,代码行数:11,代码来源:hashtable_test.cpp

示例4: main

int main(){
  cout << "Hello World\n";
  HashTable<int>* HT = new HashTable<int>(0);
  HT->insert("taco", 3);
  HT->insert("banana", 4);
  HT->insert("taco", 5);
  cout << HT->find("taco") << "\n";
  cout << HT->find("banana") << "\n";
  HT->remove("banana");
  cout << HT->find("banana") << "\n";
  delete HT;
}
开发者ID:tsuk13,项目名称:csci333-proj4-HashTable,代码行数:12,代码来源:HTTest.cpp

示例5: LoadLibrary

void
CHooker::HookModule(TCHAR *name)
{
	HMODULE h = LoadLibrary(name);
	if (h == NULL)
		return;

	IMAGE_DOS_HEADER *dosHeader = (IMAGE_DOS_HEADER *) h;
	IMAGE_NT_HEADERS *peHeader = (IMAGE_NT_HEADERS *) ((char *) h + dosHeader->e_lfanew);
	IMAGE_EXPORT_DIRECTORY *expDir = (IMAGE_EXPORT_DIRECTORY *) ((char *) h + peHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);

	DWORD *names = (DWORD *) ((char *) h + expDir->AddressOfNames);
	WORD *ordinals = (WORD *) ((char *) h + expDir->AddressOfNameOrdinals);
	DWORD *functions = (DWORD *) ((char *) h + expDir->AddressOfFunctions);

	size_t hookCountBefore = m_hookedAddrToName.size();

	for (unsigned int i = 0; i < expDir->NumberOfNames; i++)
	{
		char *name = (char *) h + names[i];
		void *addr = (unsigned char *) h + functions[ordinals[i]];

		if (m_hookedAddrToName.find(addr) == m_hookedAddrToName.end())
			HookFunction(name, addr);
	}

	cout << "CHooker::HookModule: <" << name << "> hooked " << m_hookedAddrToName.size() - hookCountBefore << " functions" << endl;
}
开发者ID:JamalAbuDayyeh,项目名称:ospy,代码行数:28,代码来源:UniHook.cpp

示例6: init

		/// <summary>
		/// 最初のシーンを初期化します。
		/// </summary>
		/// <param name="state">
		/// 最初のシーン
		/// </param>
		/// <returns>
		/// 初期化に成功した場合 true, それ以外の場合は false
		/// </returns>
		bool init(const State& state)
		{
			if (m_current)
			{
				return false;
			}

			auto it = m_factories.find(state);

			if (it == m_factories.end())
			{
				return false;
			}

			m_currentState = state;

			m_current = it->second();

			if (hasError())
			{
				return false;
			}

			m_transitionState = TransitionState::FadeIn;

			m_stopwatch.restart();

			return true;
		}
开发者ID:azaika,项目名称:OpenSiv3D,代码行数:38,代码来源:SceneManager.hpp

示例7: add

		SceneManager& add(const State& state)
		{
			typename Scene::InitData initData{ state, m_data, this };
			
			auto factory = [=](){
				return std::make_shared<Scene>(initData);
			};
		
			auto it = m_factories.find(state);
			
			if (it != m_factories.end())
			{
				it.value() = factory;
			}
			else
			{
				m_factories.emplace(state, factory);

				if (!m_first)
				{
					m_first = state;
				}
			}

			return *this;
		}
开发者ID:azaika,项目名称:OpenSiv3D,代码行数:26,代码来源:SceneManager.hpp

示例8: unweighted

void Graph::unweighted( const string & startName )
{
    clearAll( );

    const MapEntry & match = vertexMap.find( MapEntry( startName ) );
    if( match == ITEM_NOT_FOUND )
    {
        cout << startName << " is not a vertex in this graph" << endl;
        return;
    }

    Vertex *start = match.storedVertex;
    Queue<Vertex *> q( numVertices );
    q.enqueue( start ); start->dist = 0;

    while( !q.isEmpty( ) )
    {
        Vertex *v = q.dequeue( );

        ListItr<Vertex *> itr;
        for( itr = v->adj.first( ); !itr.isPastEnd( ); itr.advance( ) )
        {
            Vertex *w = itr.retrieve( );
            if( w->dist == INFINITY )
            {
                w->dist = v->dist + 1;
                w->path = v;
                q.enqueue( w );
            }
        }
    }
}
开发者ID:barathsriram,项目名称:practicecodes,代码行数:32,代码来源:Graph2.cpp

示例9:

void
Filtered_UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT>::
initialize(const Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > & ugi,
           const std::vector<GlobalOrdinalT> & filtered)
{ 
  typedef std::unordered_set<GlobalOrdinalT> HashTable;

  base_ = ugi;

  // ensure the localIDs match with the users 
  // this is essential for a class to be a decorator
  this->shareLocalIDs(*base_);

  // from base global indexer build the filtered owned indices
  std::vector<GlobalOrdinalT> baseOwned;
  base_->getOwnedIndices(baseOwned);

  // build a hash table for fast searching
  HashTable filteredHash;
  for(std::size_t i=0;i<filtered.size();i++)
    filteredHash.insert(filtered[i]);

  // search for indices in filtered array, add to owned_ if not found
  for(std::size_t i=0;i<baseOwned.size();i++) {
    typename HashTable::const_iterator itr = filteredHash.find(baseOwned[i]);    

    if(itr==filteredHash.end())
      owned_.push_back(baseOwned[i]);
  }
}
开发者ID:mhoemmen,项目名称:Trilinos,代码行数:30,代码来源:Panzer_Filtered_UniqueGlobalIndexer_impl.hpp

示例10: lookup

 // looks up an element.  Returns null if the element did not exist.
 // returns an empty string if the element exists but has a null value
 // otherwise returns the value
 const char * lookup(ParmStr key) const 
 {
   CIter_ i = lookup_.find(key);
   if (i == lookup_.end())
     return 0;
   else
     return i->second;
 }  
开发者ID:Distrotech,项目名称:aspell,代码行数:11,代码来源:string_map.hpp

示例11: TestHashTable_CString

int TestHashTable_CString()
{
	HashTable<const char *, const char *> ht;

	char                                  buffer1[32];
	char                                  buffer2[32];
	const unsigned long                   max = 1000;
	unsigned long                         i;

	for (i = 0; i < max; i++) {
		sprintf(buffer1, "%lu", i);
		sprintf(buffer2, "%lu", max - i);
		ht.insert(buffer1, (const char *)cc_strdup(buffer2));
	}

	for (i = 0; i < max; i += 2) {
		sprintf(buffer1, "%lu", i);
		TEST_ASSERT(ht.find(buffer1) != 0);
	}

	for (i = 0; i < max; i += 2) {
		sprintf(buffer1, "%lu", i);
		free((void *)ht.find(buffer1));
		TEST_ASSERT(ht.erase(buffer1));
	}

	for (i = 0; i < max; i += 2) {
		sprintf(buffer1, "%lu", i);
		TEST_ASSERT(ht.find(buffer1) == 0);
	}

	for (i = 1; i < max; i += 2) {
		sprintf(buffer1, "%lu", i);
		sprintf(buffer2, "%lu", max - i);
		TEST_ASSERT(strcmp(ht.find(buffer1), buffer2) == 0);
	}

	/* Rest of the cleanup */
	for (i = 1; i < max; i += 2) {
		sprintf(buffer1, "%lu", i);
		free((void *)ht.find(buffer1));
		TEST_ASSERT(ht.erase(buffer1));
	}

	return 0;
}
开发者ID:skydevgit,项目名称:crisscross,代码行数:46,代码来源:hashtable.cpp

示例12: main

int main() {

    HashTable<int>* h = new HashTable<int>(47);

    h->insert("sylvan",10);
    h->insert("lora",5);
    h->insert("jake",15);
    h->insert("kiran",20);
    h->insert("theo",16);
    h->insert("sylvan",41);
    h->insert("lora",39);
    h->insert("jake",6);
    h->insert("kiran",3);
    h->insert("theo",1);

    h->insert("will",10);
    h->insert("kelly",5);
    h->insert("nadine",15);
    h->insert("nick",20);
    h->insert("zoe",16);
    h->print();

    if (h->find("sylvan")!=0)
        cout << *(h->find("sylvan")) << endl;

    h->remove("sylvan");
    h->remove("lora");
    h->remove("will");
    h->print();

    h->insert("sylvan",30);
    h->insert("lora",28);
    h->insert("aili",0);
    h->insert("richard",70);
    h->insert("robert",70);
    h->insert("sandie",73);
    h->print();

    delete h;

}
开发者ID:skavanaugh,项目名称:HashTable,代码行数:41,代码来源:hash_test.cpp

示例13: UnionHash

void UnionHash(HashTable & h1, HashTable & h2)
{
  HashIterator iter(h2);
  iter.first();
  while (iter.isValid())
  {
    IMapping & cur = iter.query();
    IMapping * matched = h1.find(cur.getKey());
    if (!matched)
      h1.add(cur);
    iter.next();
  }
}
开发者ID:Josh-Googler,项目名称:HPCC-Platform,代码行数:13,代码来源:jhash.cpp

示例14: SubtractHash

void SubtractHash(HashTable & main, HashTable & sub)
{
  HashIterator iter(sub);
  iter.first();
  while (iter.isValid())
  {
    IMapping & cur = iter.query();
    IMapping * matched = main.find(cur.getKey());
    iter.next();
    if (matched)
      main.removeExact(&cur);
  }
}
开发者ID:Josh-Googler,项目名称:HPCC-Platform,代码行数:13,代码来源:jhash.cpp

示例15: IntersectHash

void IntersectHash(HashTable & h1, HashTable & h2)
{
  HashIterator iter(h1);
  iter.first();
  while (iter.isValid())
  {
    IMapping & cur = iter.query();
    IMapping * matched = h2.find(cur.getKey());
    iter.next();
    if (!matched)
      h1.removeExact(&cur);
  }
}
开发者ID:Josh-Googler,项目名称:HPCC-Platform,代码行数:13,代码来源:jhash.cpp


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