int TestSearchFunction(hash_table* hash_info) { int k, len; char buf[10]; char* ptrtmp; ptrtmp = SearchElement("Make_GCOV_happy!", hash_info); for ( k = 0; k < 100; k++ ) { len = sprintf(buf, "%d", k); ptrtmp = SearchElement(buf, hash_info); } ptrtmp = SearchElement("11111111", hash_info); free(ptrtmp); return 0; }
int SearchElement(BinaryTreeNode* root,int findMe) { if(root) { if(findMe == root->getData()) { return 1; } else { int temp = SearchElement(root->getLeft(),findMe); if(temp!=0) return temp; else return SearchElement(root->getRight(),findMe); } } else return 0; }
void SearchRand ( const JHashTable< JStrValue<int> >* const table, const JSize listLength, const JHashValue* const hashList, const JStrValue<int>* const valueList, const int* const countList ) { const JIndex el = gRand.UniformLong(0, listLength-1); SearchElement(el, table, listLength, hashList, valueList, countList); }
int main(int argc, char const *argv[]) { BinaryTree b; for (int i = 0; i < 10; ++i) { b.insert(i); } if(SearchElement(b.getRoot(),5)) cout<<"FOUND!!!"<<endl; else cout<<"NOT FOUND!!!"<<endl; return 0; }
HRESULT CConfigFindElement::FindElement(IHTMLDocument2* pDoc, CElementInfo* out_ElementInfo, CCondition* in_Condition) { HRESULT hRet = S_FALSE; HRESULT hr = S_FALSE; if (pDoc && out_ElementInfo && in_Condition) { CComQIPtr<IHTMLElement> pElement; CComQIPtr<IHTMLElement> pElementTemp; hr = pDoc->get_body(&pElement); if (!hr) { DWORD dwSize = in_Condition->vElementPos.size(); if (dwSize > 0) { std::vector<DWORD> vNewPos; for (int index = 0; index < dwSize; index++) { hr = SearchElement(pElement, in_Condition->vElementPos[index], pElementTemp); if (!hr) { if (!pElementTemp) { hRet = S_OK; break; } } vNewPos.push_back(in_Condition->vElementPos[index]); pElement = pElementTemp; } out_ElementInfo->vElementPos = vNewPos; out_ElementInfo->pElement = pElement; if (S_OK == hRet) hRet = S_FALSE; else hRet = S_OK; } } } return hRet; }
int main () { hash_table hash_array; hash_table* hash_info = &hash_array; hash_info->size = 256; CreateHash(hash_info); struct timespec start, stop; double worktime; // test AddElement unsigned long j; char tmp[LENGTH] = {0}; if (clock_gettime( CLOCK_REALTIME, &start) == -1) { perror ("clock gettime"); return -1; } for ( j = 0; j < 10000; ++j ) { AddElement(GenerateRandomString(tmp), hash_info); } if (clock_gettime( CLOCK_REALTIME, &stop) == -1) { perror ("clock gettime"); return -1; } worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000; printf ("%.10f sec for AddElement cycle \n", worktime); // test SearchElement if (clock_gettime( CLOCK_REALTIME, &start) == -1) { perror ("clock gettime"); return -1; } for ( j = 0; j < 10000; ++j ) { SearchElement(GenerateRandomString(tmp), hash_info); } if (clock_gettime( CLOCK_REALTIME, &stop) == -1) { perror( "clock gettime" ); return -1; } worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000; printf("%.10f sec for SearchElement cycle \n", worktime); // test Remove if (clock_gettime( CLOCK_REALTIME, &start) == -1) { perror( "clock gettime" ); return -1; } int k; for ( j = 0; j < 10000; ++j ) { k = Remove(GenerateRandomString(tmp), hash_info); } if (clock_gettime( CLOCK_REALTIME, &stop) == -1) { perror( "clock gettime" ); return -1; } worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000; printf ("%.10f sec for Remove cycle \n", worktime); // test CleanMemory if (clock_gettime( CLOCK_REALTIME, &start) == -1) { perror ("clock gettime"); return -1; } for ( j = 0; j < 10000; ++j ) { hash_table hash_array; hash_table* hash_info = &hash_array; hash_info->size = 256; CreateHash(hash_info); CleanMemory(hash_info); } if (clock_gettime( CLOCK_REALTIME, &stop) == -1) { perror( "clock gettime" ); return -1; } worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000; printf ("%.10f sec for CreateHash and CleanMemory cycle\n", worktime); return 0; }