// ------------------ _search ---------------------- void CBrunchAndBound::_search(int ind) { // это лист if (ind == NumItem) { copybool(cur, best, false); BestProfit = CurProfit; BestCost = CurCost; return; } // есть ли смысл расматривать поддерево, включающее [ind] if ((CurCost + invest[ind].cost) <= MaxCost) { cur[ind] = true; CurCost += invest[ind].cost; CurProfit += invest[ind].profit; NoUsedProfit -= invest[ind].profit; _search(ind+1); cur[ind] = false; CurCost -= invest[ind].cost; CurProfit -= invest[ind].profit; NoUsedProfit += invest[ind].profit; } // а если я выкину [ind], то будет ли его правое поддерево подходить по условию? NoUsedProfit -= invest[ind].profit; if ((CurProfit + NoUsedProfit) > BestProfit) _search(ind+1); NoUsedProfit += invest[ind].profit; }
typename BSTree<KeyType, ValueType>::BSTreeNode* BSTree<KeyType, ValueType>::_search(typename BSTree<KeyType, ValueType>::BSTreeNode *root, KeyType key) { if(root==0) return 0; else if(root->key == key) return root; else if(key < root->key) return _search(root->lchild, key); else return _search(root->rchild, key); }
// Returns if the word is in the data structure. A word could // contain the dot character '.' to represent any one letter. bool _search(Trie* p, string word, int idx){ if(p == NULL) return false; if(idx == word.length()) return p->wholeWord; if(word[idx] == '.'){ for(Trie* child : p->children){ if(_search(child, word, idx+1)) return true; } }else{ return _search(p->children[word[idx] - 'a'], word, idx+1); } return false; }
// // shelves[], isbns[]からエントリをさがす // static int _search(char *a[], char *s, int start, int end){ if(end-start <= 1){ return strcmp(s,a[start]) == 0 ? start : -1; } else { int m = (start + end) / 2; int cmp = strcmp(s,a[m]); if(cmp == 0) return m; else if(cmp > 0) return _search(a,s,m,end); else return _search(a,s,start,m); } }
/** * If a key was stroke within a short time, add that key to the current search * otherwise, initiate an other instajump. */ void ij_keyEvent(signed char key) { unsigned long time; int len; UWORD oldPageNumber, oldSelectorPos; UWORD res; len = strlen(_searchString); time = get_hz200(); if ( (time - _lastTime) < (IJ_TIMEOUT / 5) ) { } else { // init a new search len = 0; #ifdef IJ_DEBUG debug_line = 6; #endif } if ( (len < IJ_MAXLEN)) { _searchString[len++] = tolower(key); // lower case _searchString[len] = '\000'; } oldPageNumber = gfl_cachedPageNumber; oldSelectorPos = gfl_selectorPos; res = _search(oldPageNumber, oldSelectorPos); if (!res && len>1) { // remove the last character and restart the search at the next file _searchString[len-1] = '\000'; if (oldSelectorPos+1 >= NUMBER_OF_FILE_ON_DISPLAY) { res = _search(oldPageNumber+1, 0); } else { res = _search(oldPageNumber, oldSelectorPos+1); } } if (!res) { // still not found #ifdef IJ_DEBUG hxc_printf(0, 0, 8*(debug_line++), "Not found"); get_char(); #endif gfl_setCachedPage(oldPageNumber); // gfl_selectorPos = oldSelectorPos; // not needed: search only update the gfl_selectorpos when found } // reset the last with the time at the end of the search _lastTime = get_hz200(); }
Node* _search(char* key,Node* node){ fprintf(stderr, "searching %s in %s\n",key, node->key); if(node->is_leaf){ return node; } Node** data = node->data; unsigned int len = node->length; for(unsigned int i = 0; i < len; i++){ if(strcmp(key, data[i]->key) <= 0){ return _search(key, data[i]); } } return _search(key, data[len-1]); }
bstnode<type>* bst<type>::_search(np cur, const type& x) { if (cur == NULL) { return NULL; } if (cur->_data == x) { return cur; } else if (x > cur->_data) { return _search(cur->right, x); } else { return _search(cur->left, x); } }
Node* AVLTree::_search(string& data, AVLNode*& node) { if (node == nullptr) return nullptr; else if (node->data->getWord() == data) { return node->data; } else { if (data > node->data->getWord()) return _search(data, node->right); else return _search(data, node->left); } }
bool FindReplaceBar::search_next() { uint32_t flags = 0; String text = get_search_text(); if (is_whole_words()) flags |= TextEdit::SEARCH_WHOLE_WORDS; if (is_case_sensitive()) flags |= TextEdit::SEARCH_MATCH_CASE; int line, col; _get_search_from(line, col); if (line == result_line && col == result_col) { col += text.length(); if (col > text_edit->get_line(line).length()) { line += 1; if (line >= text_edit->get_line_count()) line = 0; col = 0; } } return _search(flags, line, col); }
int search(const char *string, size_t strlen, int32_t *ip4_address) { struct trie_node *found; //int rv; int result; // Skip strings of length 0 if (strlen == 0) return 0; pthread_cleanup_push(cleanup_handler,&lock); // obtain the lock //rv = pthread_mutex_lock(&lock); // assert(rv == 0); found = _search(root, string, strlen); if (found && ip4_address) *ip4_address = found->ip4_address; result = (found != NULL); // Return the lock /**** NEW ***/ pthread_cleanup_pop(1); //rv = pthread_mutex_unlock(&lock); //assert(rv == 0); return result; }
bool FindReplaceBar::search_prev() { uint32_t flags = 0; String text = get_search_text(); if (is_whole_words()) flags |= TextEdit::SEARCH_WHOLE_WORDS; if (is_case_sensitive()) flags |= TextEdit::SEARCH_MATCH_CASE; flags |= TextEdit::SEARCH_BACKWARDS; int line, col; _get_search_from(line, col); col -= text.length(); if (col < 0) { line -= 1; if (line < 0) line = text_edit->get_line_count() - 1; col = text_edit->get_line(line).length(); } return _search(flags, line, col); }
static node * _search(node *root, int key) { if (root->key == key) return root; if (root->key > key) if (root->left) return _search(root->left, key); else return NULL; if (root->key <= key) if (root->right) return _search(root->right, key); else return NULL; }
int _search(char *source_path, INPUT *keyword) { int ret = 0; struct stat statbuf; struct dirent *dir = NULL; DIR *file; char *fullpath; if ((file=opendir(source_path))==NULL) return 0; fullpath = (char*) __ax_malloc(MAX_FILE_PATH * sizeof(char)); while ((dir=readdir(file))) { if((strlen(source_path) + strlen(dir->d_name) + 2) > MAX_FILE_PATH) { FCGI_LOG("%s", "Error: path size too large"); continue; } sprintf(fullpath, "%s/%s", source_path, dir->d_name); fullpath[strlen(fullpath)] = '\0'; if (lstat(fullpath, &statbuf)<0) { ret = -1; break; } if (S_ISDIR(statbuf.st_mode)==0) { // file or link if (is_match(dir->d_name, keyword)) { total_file++; file_list = (char (*)[MAX_FILE_PATH]) __ax_realloc((void*)file_list, total_file * MAX_FILE_PATH * sizeof(char)); strcpy(file_list[total_file - 1], fullpath); } if (S_ISLNK(statbuf.st_mode)) { // do nothing continue; } else { } } else { // dir //do not include "." and ".." and ".@__thumb" if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..") || !strcmp(dir->d_name, ".@__thumb")) continue; if (is_match(dir->d_name, keyword)) { //print_file_xml(fullpath); //sort_by_type(fullpath, &list); total_folder++; folder_list = (char (*)[MAX_FILE_PATH]) __ax_realloc((void*)folder_list, total_folder * MAX_FILE_PATH * sizeof(char)); strcpy(folder_list[total_folder - 1], fullpath); } _search(fullpath, keyword); } } closedir(file); if (fullpath) __ax_free(fullpath); return ret; }
void FindReplaceDialog::_search_text_entered(const String &p_text) { if (replace_text->is_visible_in_tree()) return; emit_signal("search"); _search(); }
int heim_dict_add_value(heim_dict_t dict, heim_object_t key, heim_object_t value) { struct hashentry **tabptr, *h; h = _search(dict, key); if (h) { heim_release(h->value); h->value = heim_retain(value); } else { unsigned long v; h = malloc(sizeof(*h)); if (h == NULL) return ENOMEM; h->key = heim_retain(key); h->value = heim_retain(value); v = heim_get_hash(key); tabptr = &dict->tab[v % dict->size]; h->next = *tabptr; *tabptr = h; h->prev = tabptr; if (h->next) h->next->prev = &h->next; } return 0; }
void FindReplaceDialog::_search_callback() { if (is_replace_mode()) _replace(); else _search(); }
void ScenesDock::_search(EditorFileSystemDirectory *p_path,List<FileInfo>* matches,int p_max_items) { if (matches->size()>p_max_items) return; for(int i=0;i<p_path->get_subdir_count();i++) { _search(p_path->get_subdir(i),matches,p_max_items); } String match = search_box->get_text(); for(int i=0;i<p_path->get_file_count();i++) { String file = p_path->get_file(i); if (file.find(match)!=-1) { FileInfo fi; fi.name=file; fi.type=p_path->get_file_type(i); fi.path=p_path->get_file_path(i); matches->push_back(fi); if (matches->size()>p_max_items) return; } } }
vector<Document> AVLTree::search(string term) { if (root == NULL) { vector<Document> blank; return blank; } else { if (term == root->data->getWord()) { return root->data->getDocuments(); } else if (term < root->data->getWord()) { return _search(term, root->left); } else if (term > root->data->getWord()) { return _search(term, root->right); } else { cout << "THIS SHOULD NEVER HAPPEN in AVLTree::search(std::string term)" << endl; } } };
void * search(node *root, int key) { node *result = _search(root, key); if (result) return result->value; else return NULL; }
Node* AVLTree::search(string& data) { if (root == nullptr) { return nullptr; } else if (root->data->getWord() == data) return root->data; else { if (data > root->data->getWord()) { return _search(data, root->right); } else { return _search(data, root->left); } } }
bool bst<type>::remove(const type& x) { np cur = _search(_root, x); if (cur == NULL) { return false; } _remove(cur); _setheight(_root); return true; }
bool removeNode(LIST* pList, void* keyPtr) { bool found; LIST_NODE *pPre, *pLoc; found = _search(pList, &pPre, &pLoc, keyPtr); if (found) _delete(pList, pPre, pLoc); return found; }
heim_object_t heim_dict_copy_value(heim_dict_t dict, heim_object_t key) { struct hashentry *p; p = _search(dict, key); if (p == NULL) return NULL; return heim_retain(p->value); }
// helper function for recursive search facility. static struct trie_node * _search (struct trie_node *node, const char *string, size_t strlen) { // immediate exit on no-node. if (node == NULL) return NULL; // See if this key is a substring of the string passed in size_t keylen; int cmp = compare_keys(node->key, node->strlen, string, strlen, &keylen); if (cmp == 0) { // partial match, if the node keylen is longer than the // input key, we cannot have a match, and cannot have // sibling or child match, so return NULL. if (node->strlen > strlen) node = NULL; // else if there are still chars left in the input key // to consume, recurse into children. else if (strlen > keylen) node = _search(node->children, string, strlen - keylen); // else i we have a winner, but only if there is an ip address // if there isn't (0), then this must be considered an just an // intermediate note and should not be returned as the "find" else if (node->ip4_address == 0) node = NULL; } // if the node's key is "less" than look to the siblings // of the current node. else if (cmp < 0) node = _search(node->next, string, strlen); // else it is greater, and there can be no possible match else node = NULL; // final return value. return node; }
int search(Board b, int maxDepth, int m, int n) { searchNode* head = new searchNode(b); nodeCounter = 0; std::cout << "\n** R.Reti Endgame Board **\n"; head->printBoardImage(); int topHeurisic = _search(head,maxDepth,0,UNSET); printTree(head,m,n); printBest(head); return topHeurisic; }
bool removeNode (LIST* pList, void* keyPtr, void** dataOutPtr) { bool found; NODE* pPre; NODE* pLoc; found = _search (pList, &pPre, &pLoc, keyPtr); if (found) _delete (pList, pPre, pLoc, dataOutPtr); return found; }
static int _search (vpnode *node, Obj obj, Tdist r, bool show) { int rep = 0; if (node->hoja) { rep += searchbucket (node->u.hoja.bucket,node->u.hoja.size,obj,r,show); } else { Tdist dist; dist = distance (obj, node->u.interno.query); if (dist <= r) { rep++; if (show) printobj(node->u.interno.query); } if (dist-r < node->u.interno.dist) rep += _search(node->u.interno.child1,obj,r,show); if (dist+r >= node->u.interno.dist) rep += _search(node->u.interno.child2,obj,r,show); } return rep; }
vector<Document> AVLTree::_search(string term, AVLNode*& Node) { if (Node == NULL) { vector<Document> blank; return blank; } else { if (term == Node->data->getWord()) { vector<Document> temp; temp = Node->data->getDocuments(); cout << "~~~~~~" <<temp[0].getAuthor()<< endl; return Node->data->getDocuments(); } else if (term < Node->data->getWord()) { return _search(term, Node->left); } else if (term > Node->data->getWord()) { return _search(term, Node->right); } else { cout << "THIS SHOULD NEVER HAPPEN in AVLTree::_search(std::string term)" << endl; } } }
//[i, j) int _search(int* n, int i, int j, int t) { int m = 0, a = -1; j --; if (i > j) return -1; if (n[j] < n[i]) { m = i + (j - i) / 2; if (n[m] == t) return m; if (n[m] > n[i]) { a = _s(n, i, m, t); if (a != -1) return a; a = _search(n, m + 1, j, t); } else { a = _s(n, m + 1, j, t); if (a != -1) return a; a = _search(n, i, m, t); } return a; } else { return _s(n, i, j + 1, t); } }
//Special non lock function for squatting int squat_search(const char *string, size_t strlen, int32_t *ip4_address) { struct trie_node *found; int result = 0; // Skip strings of length 0 if (strlen == 0) return result; found = _search(root, string, strlen); if (found && ip4_address) *ip4_address = found->ip4_address; result = (found != NULL); return result; }