本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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 );
}
}
}
}
示例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]);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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);
}
}