void Searches::tabSelected(QWidget* searchwidget) { if (mSearchTabWidget->currentIndex() <= 1) return; Search * uw = dynamic_cast<Search*>(searchwidget); if (uw) setSearchText(uw->query()); }
void TokenDatabase::findNext(Database::Search *rSearch, CssmDbRecordAttributeData *inAttributes, mach_msg_type_number_t inAttributesLength, CssmData *data, RefPointer<Key> &key, RefPointer<Database::Record> &rRecord, CssmDbRecordAttributeData * &outAttributes, mach_msg_type_number_t &outAttributesLength) { Access access(token()); RefPointer<Record> record = new Record(*this); Search *search = safe_cast<Search *>(rSearch); TRY KeyHandle hKey = noKey; validate(CSSM_ACL_AUTHORIZATION_DB_READ, openCreds()); GUARD record->tokenHandle() = access().Tokend::ClientSession::findNext( search->tokenHandle(), inAttributes, inAttributesLength, NULL, hKey, outAttributes, outAttributesLength); if (!record->tokenHandle()) { // no more matches releaseSearch(*search); // release search handle (consumed by EOD) rRecord = NULL; // return null record return; } if (data) { if (!hKey) record->validate(CSSM_ACL_AUTHORIZATION_DB_READ, openCreds()); CssmDbRecordAttributeData *noAttributes; mach_msg_type_number_t noAttributesLength; access().Tokend::ClientSession::findRecordHandle(record->tokenHandle(), NULL, 0, data, hKey, noAttributes, noAttributesLength); if (hKey) { // tokend returned a key reference & data CssmKey &keyForm = *data->interpretedAs<CssmKey>(CSSMERR_CSP_INVALID_KEY); key = new TokenKey(*this, hKey, keyForm.header()); } } rRecord = record->commit(); DONE }
void Searches::setToken(const QString& query, uint token) { int i; for(i = 2; i < mSearchTabWidget->count(); ++i) { Search* search = dynamic_cast<Search*>(mSearchTabWidget->widget(i)); if(search && search->query() == QString(query)) { search->setToken(token); return; } } // Create the tab if it's a wishlist result if ((i == mSearchTabWidget->count()) && museeq->isInWishlist(query)) { Search* s = new Search(query, mSearchTabWidget, false); mSearchTabWidget->addTab(s, query); // Highlight the search icon so that the user know that there are some new search results connect(s, SIGNAL(highlight(int, QWidget*)), SIGNAL(highlight(int))); // Highlight the tab where we have received new search results connect(s, SIGNAL(highlight(int, QWidget*)), mSearchTabWidget, SLOT(setHighlight(int, QWidget*))); mSearchTabWidget->setCurrentWidget(s); s->setToken(token); } }
void DoFoundChecks(Search& s, COORD& coordStartExpected, SHORT lineDelta) { COORD coordEndExpected = coordStartExpected; coordEndExpected.X += 1; VERIFY_IS_TRUE(s.FindNext()); VERIFY_ARE_EQUAL(coordStartExpected, s._coordSelStart); VERIFY_ARE_EQUAL(coordEndExpected, s._coordSelEnd); coordStartExpected.Y += lineDelta; coordEndExpected.Y += lineDelta; VERIFY_IS_TRUE(s.FindNext()); VERIFY_ARE_EQUAL(coordStartExpected, s._coordSelStart); VERIFY_ARE_EQUAL(coordEndExpected, s._coordSelEnd); coordStartExpected.Y += lineDelta; coordEndExpected.Y += lineDelta; VERIFY_IS_TRUE(s.FindNext()); VERIFY_ARE_EQUAL(coordStartExpected, s._coordSelStart); VERIFY_ARE_EQUAL(coordEndExpected, s._coordSelEnd); coordStartExpected.Y += lineDelta; coordEndExpected.Y += lineDelta; VERIFY_IS_TRUE(s.FindNext()); VERIFY_ARE_EQUAL(coordStartExpected, s._coordSelStart); VERIFY_ARE_EQUAL(coordEndExpected, s._coordSelEnd); VERIFY_IS_FALSE(s.FindNext()); }
int main (int argc, const char * argv[]) { srand(0); Megaminx * target = new Megaminx; target->setTarget(target); unsigned int maxInst = target->getPossibleInstructions(); Puzzle const * test = target; for (int i = 0; i < 14; ++i) { int inst = rand() % maxInst; cout << instToCStr(inst) << endl; test = test->getPuzzleRotatedBy(inst); } Search * search = new Search; cout << "******\n"; stack<int> * solution = search->aStarSearch(test); cout << search->getCreatedNodes() << " " << search->getElapsedTime() << endl; delete search; while (!solution->empty()) { cout << instToCStr(solution->top()) << endl; solution->pop(); } return 0; }
bool Query::set(int index, const Search& search) { if (!isValidIndex(index)) return false; int subindex = m_searchMap.indexOf(index); if (subindex >= 0) { delete m_search.at(subindex); m_search.replace(subindex, search.clone()); return true; } else { subindex = m_operatorMap.indexOf(index); if (subindex >= 0) { // Here the given index is a operator, so we have to remove the operator, // and add a search at that position m_operatorMap.removeAt(m_operatorMap.at(subindex)); m_operator.removeAt(m_operator.at(subindex)); m_search.append(search.clone()); m_searchMap.append(index); m_elementType[index] = SearchElement; return true; } else { // The index could not be found in the operator or search lists return false; } } }
class RAGS2{ public: RAGS2(){ //make graph //search graph //totalCost = 0; //totalCost = RAGS2(searchGraph, SGPaths[0]->GetVertex(), GSPaths[0]->GetVertex()); //allCosts.push_back(totalCost); }; private: } double RAGS2::Search(Graph * graph, Vertex * source, Vertex * goal){ // Initialize search double cost = 0.0; Search * testSearch = new Search(graph, curLoc, goal); pathOut pType = RAGS2; testSearch.PathSearch(pType); // To modify this into D* style search add loop...search after each step delete testSearch; return cost; }
int main(int argc, char** argv) { Node node("input.txt"); Search search; stringstream sstream; Node goal; bool success = search.bfs(&node, &goal); if (success) { sstream << goal.getLevel() << endl; sstream << goal.getPath() << endl; } else { sstream << -1 << endl << endl; } success = search.ucs(&node, &goal); if (success) { sstream << goal.getCost() << endl; sstream << goal.getPath() << endl; } else { sstream << -1 << endl; } IO io; io.stringToFile("output.txt", sstream.str()); return 0; }
int main() { Parser p; IndexReader in; in.genIndexFromFile(); Search s; string query; while (getline(cin,query)) { Query* q=p.parse(query); //cout<<"------"<<endl; //cout<<q->sign<<" "<<q->token<<endl; /*for(int i=0;i<q->size();i++) { Query* s=q->get(i); //cout<<s->sign<<" "<<s->token<<endl; for(int j=0;j<s->size();j++) { Query* p=s->get(j); // cout<<p->sign<<" "<<p->token<<endl; } }*/ vector<vector<string> > l; s.search(q,in,l); s.show(q,in,l); delete q; } }
std::vector<std::string> TextFinder::GetResults() { Search searchService; std::vector<std::string> results = searchService.StartTextSearch(_searchKeywords, _searchPath, _searchAll); return results; }
void SearchTabWidget::selected(QWidget* searchwidget) { if (currentIndex() <= 1) return; Search * uw = dynamic_cast<Search*>(searchwidget); if(uw && uw->highlighted() != 0) { uw->setHighlighted(0); setHighlight(uw->highlighted(), uw ); } }
void Searches::append(uint token, const QString& user, bool free, uint speed, uint files, const NFolder& r) { qDebug() << "Search results from " << user; for(int i = 2; i < mSearchTabWidget->count(); ++i) { Search* search = dynamic_cast<Search*>(mSearchTabWidget->widget(i)); if(search && search->hasToken(token)) { search->append(user, free, speed, files, r); return; } } }
void SearchDialog::newSearch() { QString phrase = QInputDialog::getText(pgView, "Search in notebook", "Search phrase:", QLineEdit::Normal, lastPhrase); lastPhrase = phrase; if (phrase.isEmpty()) return; QProgressDialog *progress = new QProgressDialog(pgView); progress->setLabelText("Searching..."); progress->setCancelButton(0); progress->setMinimumDuration(500); progress->setValue(0); Search *search = new Search(pgView->notebook()); QList<SearchResult> res = search->immediatelyFindPhrase(phrase); if (res.isEmpty()) { delete progress; QMessageBox::information(pgView, "Search - eln", QString::fromUtf8("Search phrase “%1” not found") .arg(phrase)); return; } SearchResultScene *scene = new SearchResultScene(phrase, QString::fromUtf8("Search results for “%1”") .arg(phrase), res, pgView->notebook()->bookData()); scene->populate(); connect(scene, SIGNAL(pageNumberClicked(int, Qt::KeyboardModifiers, QString, QString)), this, SLOT(gotoPage(int, Qt::KeyboardModifiers, QString, QString))); SearchView *view = new SearchView(scene); view->setAttribute(Qt::WA_DeleteOnClose, true); connect(parent(), SIGNAL(destroyed()), view, SLOT(close())); delete progress; view->resize(pgView->size()*.9); QString ttl = pgView->notebook()->bookData()->title(); view->setWindowTitle("Search in: " + ttl.replace(QRegExp("\\s\\s*"), " ") + " - eln"); view->show(); }
bool Query::internalCheck() { int i; Search::Operator op; Search *s = NULL; ElementTypeList::iterator elementIter; if (count() != (countOperands() + countOperators())) { return false; } for (elementIter = m_elementType.begin(), i = 0; elementIter != m_elementType.end(); ++elementIter, ++i) { switch (*elementIter) { case SearchElement : s = search(i); if (s == NULL) { return false; } switch (s->type()) { case Search::NullSearch : case Search::PositionSearch : case Search::EloSearch : break; default : // undefined search return false; } break; case OperatorElement : op = searchOperator(i); switch (op) { case Search::And : case Search::Or : case Search::Remove : case Search::Not : case Search::NullOperator : break; default : // Undefined operator return false; } break; default : // Undefined element return false; } } return true; }
dict count(char* content){ vec_str_count result=_search.count(content); dict k_c; for(vec_str_count::iterator i=result.begin();i!=result.end();++i) k_c.setdefault(i->first,i->second); return k_c; }
bool setupSearch(const Game *g, const int *needList, Search &search, SearchMap &searchData) { for (const int *entry = needList; *entry != -1; ++entry) { ExtractEntryList providers = getProvidersForId(*entry); if (providers.empty()) { fprintf(stderr, "ERROR: No provider for id %d/%s\n", *entry, getIdString(*entry)); return false; } else { for (ExtractEntryList::const_iterator i = providers.begin(); i != providers.end(); ++i) { // Only add generic or partly matching providers here. #ifndef DEBUG_EXTRACTION_TABLES if ((i->lang == UNK_LANG || i->lang == g->lang[0] || i->lang == g->lang[1] || i->lang == g->lang[2]) && (i->platform == kPlatformUnknown || (i->platform == g->platform))) { #endif search.addData(i->hint); searchData.insert(SearchMapEntry(*entry, *i)); #ifndef DEBUG_EXTRACTION_TABLES } #endif } } } return true; }
int main() { Search movSearch; char* epic = new char[80]; do { cin>>epic; queue<char*>wew = movSearch.SearchMovie(epic); for(int i = 0 ; i < wew.size();i++) { cout << wew.front() << endl; wew.pop(); } }while(epic[0] != '0'); system("pause<0"); return 0; }
void Searches::doSearch(const QString& q) { if(q.isEmpty()) return; QString user; if (mUser->isChecked ()) { if ( mUserEntry->currentText().isEmpty() ) return; else { user = mUserEntry->currentText(); } } mEntry->setCurrentIndex(0); int i; for(i = 2; i < mSearchTabWidget->count(); ++i) { Search* search = dynamic_cast<Search*>(mSearchTabWidget->widget(i)); if(search && search->query() == q) { mSearchTabWidget->setCurrentIndex(i); break; } } if(i == mSearchTabWidget->count()) { Search* s = new Search(q, mSearchTabWidget, false); mSearchTabWidget->addTab(s, q); // Highlight the search icon so that the user know that there are some new search results connect(s, SIGNAL(highlight(int, QWidget*)), SIGNAL(highlight(int))); // Highlight the tab where we have received new search results connect(s, SIGNAL(highlight(int, QWidget*)), mSearchTabWidget, SLOT(setHighlight(int, QWidget*))); mSearchTabWidget->setCurrentWidget(s); } if(mBuddies->isChecked()) museeq->buddySearch(q); else if (mRooms->isChecked ()) museeq->roomSearch (q); else if (mGlobal->isChecked ()) museeq->search(q); else if (mUser->isChecked ()) { if ( ! user.isEmpty() ) museeq->userSearch(user, q); } else if (mWishList->isChecked ()) museeq->wishListSearch(q); }
//Note it's probably cheaper to pass a CapturedCont than a Continuation Trampoline stream2(Search &s, CapturedVar<int> m, Trampoline c) { CapturedLambda(Search &, int) rest; UncountedLambda(Search &, int) rest_uncounted = rest; *rest = [=](Search &s, int n) { n += 1; if (n == 4) { return s.fail(); } else { s.alt(trampoline(rest_uncounted, s, n)); // cout << "m is " << *n * *n << endl; *m = n * n; return c; } }; return trampoline(rest, s, 0); }
STDMETHODIMP CTextSearch::GetResults(SAFEARRAY ** files) { // TODO: Add your implementation code here Search searchService; std::string path = searchService.ConvertBSTRToMBS(_searchPath); //std::string keyword = searchService.ConvertBSTRToMBS(_searchKeyword); std::vector<std::string> keywords; for (int i = 0; i < (int)_searchKeywords.GetCount(); ++i) keywords.push_back(searchService.ConvertBSTRToMBS(_searchKeywords[i].Copy())); std::vector<std::string> results = searchService.StartTextSearch(keywords, path, _searchAll); CComSafeArray<BSTR> temp; for (auto result : results) temp.Add(CComBSTR(result.c_str())); *files = temp.Detach(); return S_OK; }
//oops, the return value could be nixed by stack clean exception //but it worked when I made it always throw... {}{}{} WHY DOES IT WORK? //OH it works because it doesn't use the search until AFTER it returns the value Trampoline stream1(Search &s, CapturedVar<int> m, Trampoline c) { CapturedLambda(Search &, int) rest; UncountedLambda(Search &, int) rest_uncounted = rest; *rest = [=](Search &s, int n) { n = n + 1; if (n == 10) { return s.fail(); } else { s.alt(trampoline(rest_uncounted, s, n)); *m = n; // cout << "n is " << *n << endl; return c; } }; cout << rest.get()->use_count() << endl; return trampoline(rest, s, 0); }
int main() { //Get data Search dfs; dfs.populateMatrix("distanceMatrix.txt"); dfs.displayKey(); Dijkstra d; d.populateMatrix("distanceMatrix.txt"); // Get input cout << "Enter the start intersection number: "; int begin; cin >> begin; cout << "Enter the end intersection number: "; int end; cin >> end; //Perform DFS algorithm dfs.DFS(begin, end); cout << "-------------------------" << endl; cout << "DFS" << endl; dfs.displayList(); //Perform Dijkstra's algorithm d.dijkstra(begin, end); cout << "-------------------------" << endl; cout << "DIJKSTRA" << endl; d.displayList(); cout << "Press Enter to Exit" << endl; cin.ignore(10, '\n'); cin.get(); return 0; }
void SearchTabWidget::setHighlight(int highlight, QWidget* widget) { Search * uw = dynamic_cast<Search*>(widget); if (!uw) return; int pos = indexOf(uw); if(( currentIndex() != pos) && highlight > uw->highlighted() ) { uw->setHighlighted(highlight); if (uw->highlighted() > 0) { // Icon on tab tabBar()->setTabIcon(pos, QIcon(IMG("new-element"))); } if (uw->highlighted() > 1) { // Red tab tabBar()->setTabTextColor(pos, QColor(255, 0, 0)); } } else if (highlight == 0) { tabBar()->setTabTextColor(pos, tabBar()->palette().buttonText().color()); tabBar()->setTabIcon(pos, QIcon()); } }
vector<Move> calculate() { vector<Move> list_moves; Search* engine; if (method_flag == 0) { engine = new AB(2); } else if (method_flag == 1) { Board::init(); engine = new MCTS(); } else if (method_flag == 2) { AB * minimax = new AB(2); minimax->setPruning(false); engine = minimax; } else { vector<Move> moves = Board::available_moves(initial_board, Board::move_to_player(initial_move), initial_move, 0, 1); list_moves.push_back(moves[rand() % ((int)moves.size())]); moves = Board::available_moves(Board::make_move(initial_board, list_moves[0], Board::move_to_player(initial_move)), Board::move_to_player(initial_move + 1), initial_move + 1, 1, 0); list_moves.push_back(moves[rand() % ((int)moves.size())]); } if (method_flag != 3) { engine->solve(initial_board, initial_move); list_moves = engine->get_solution(); delete engine; } return list_moves; }
Trampoline unify_tests(Search &s) { LVar A, B, C, D, E, F, G; LVar hello("hello"), one(1), willBeHello, willBeOne, l1(L(A, "hello", B, L(one, C, hello), F)); CapturedCont c, d, e, f, g, h, i, j, k, l; *c = [=](Search &s) { cout << hello << "?=" << willBeHello << endl; return s.identical(1, one, trampoline(d, s)); }; *d = [=](Search &s) { cout << one << "?=" << willBeOne << endl; s.alt(f); return s.identical(hello, "hello", trampoline(e, s)); }; *e = [=](Search &s) { cout << "compare with string succeeded" << endl; s.alt(g); return s.identical(F, G, trampoline(h, s)); }; *f = [=](Search &s) { cout << "compare with string failed" << endl; return end_search; }; *g = [=](Search &s) { cout << "unlike compare with vars did the right thing" << endl; s.alt(i); return s.unify(l1, L("Say", D, "there", L(E, 2, "hello"), G), trampoline(j, s)); }; *h = [=](Search &s) { cout << "unlike compare with vars did the wrong thing" << endl; return end_search; }; *i = [=](Search &s) { cout << "list unify failed" << A << " " << D << " " << B << " " << E << " " << C << endl; return end_search; }; *j = [=](Search &s) { s.alt(l); return s.identical(F, G, trampoline(k, s));}; *k = [=](Search &s) { cout << "list unify: " << A << " " << D << " " << B << " " << E << " " << C << " " << F << " " << G << endl; return end_search; }; *l = [=](Search &s) { cout << "var unify failed" << endl; return end_search; }; return s.unify(hello, willBeHello, trampoline(c, s)); }
int main(int argc, char* argv[]) { switch (argc) { case 1: usage(); return 0; } string command(argv[1]); if (command.compare("essayomat") == 0) { if (argc < 4) { usage(); return 0; } int limit = 500; if (argc == 5) { limit = atoi(argv[4]); } string fname(argv[2]); string question_fname(argv[3]); Essayomat *essayomat = new Essayomat; essayomat->run(fname, question_fname, limit); delete essayomat; } else if (command.compare("search") == 0) { Search *search = new Search; search->run(); delete search; } else { cerr << "Unknown command." << endl; usage(); return -1; } return 0; }
int main(int argc, char** argv) { Graph graph; graph.InsertEdge("A", "B"); graph.InsertEdge("A", "C"); graph.InsertEdge("B", "D"); graph.Print(); Search search; search.Initialize(graph); search.Bfs(graph, "A"); for (unordered_map<string, string>::iterator item = search.parents_.begin(); item != search.parents_.end(); ++item) cout << item->first << ":" << item->second << endl; search.Initialize(graph); search.Dfs(graph, "A"); for (unordered_map<string, string>::iterator item = search.parents_.begin(); item != search.parents_.end(); ++item) cout << item->first << ":" << item->second << endl; return 0; }
int main(int argc, char const *argv[]) { Config *p = Config::get_instance(); string dict_path; string model_path; //读取需要的文件 p->get_file_name("dict_path", dict_path); p->get_file_name("model_path", model_path); //初始化切词工具 CppJieba::MixSegment segment(dict_path, model_path); cout << "Overload segment done !" << endl; Search query; vector<Document> result_vec; string word; cout << "input word:" << endl; while(cin >> word) { result_vec.clear(); query.search_result(word, result_vec, segment); } return 0; }
void NetSearch::searchFinished(void) { QMutexLocker locker(&m_lock); if (m_busyPopup) { m_busyPopup->Close(); m_busyPopup = NULL; } Search *item = new Search(); QByteArray data = m_reply->readAll(); item->SetData(data); item->process(); uint searchresults = item->numResults(); uint returned = item->numReturned(); uint firstitem = item->numIndex(); if (returned > 0) m_siteList->GetItemAt(m_currentGrabber)-> SetText(QString::number( searchresults), "count"); else return; if (firstitem + returned == searchresults) m_maxpage = m_pagenum; else { if (((float)searchresults/returned + 0.999) >= ((int)searchresults/returned + 1)) m_maxpage = (searchresults/returned + 1); else m_maxpage = (searchresults/returned); } if (m_pageText && m_maxpage > 0 && m_pagenum > 0 && returned > 0) m_pageText->SetText(QString("%1 / %2") .arg(QString::number(m_pagenum)) .arg(QString::number(m_maxpage))); ResultItem::resultList list = item->GetVideoList(); populateResultList(list); }
Trampoline AmbTest(Search &s) { CapturedVar<int> n, m; CapturedCont c1, c2, c3; UncountedCont c1_u = c1, c2_u = c2, c3_u = c3; combine_refs(c1, c2, c3); //note it can't safely use Search inside of functions that return a value *c1 = [=](Search &s) { return stream1(s, n, trampoline(c2_u, s)); }; *c2 = [=](Search &s) { return stream2(s, m, trampoline(c3_u, s)); }; *c3 = [=](Search &s) { if (*n != *m) return s.fail(); else { s.results.insert_or_assign("n", *n); s.results.insert_or_assign("m", *m); return end_search; } }; cout << c1.get()->use_count() << endl; cout << c2.get()->use_count() << endl; cout << c3.get()->use_count() << endl; return trampoline(c1, s); }