bool Keyword::contains(String const& query) const { if (find_i(keyword,query) != String::npos) return true; if (find_i(rules,query) != String::npos) return true; if (find_i(match,query) != String::npos) return true; if (find_i(reminder.get(),query) != String::npos) return true; return false; }
/* Checks state safety. Returns true if safe, else false. */ bool is_safe() { /* Work vector, length m. */ int work[RESOURCES]; /* Finish vector, length n. */ bool finish[CUSTOMERS]; /* Initialize work vector = available vector. */ copy_array(available, work); /* Set all elements in finish vector to false. */ set_all_false(finish); /* Find index i such that finish[i] == false && need[i] <= work. */ int i = find_i(work, finish); /* If no such i exists, check if all finish elements are true. */ if (i == -1) { //such I does not exist if (all_true(finish) == true) { /* The system is in a safe state! */ return true; } } else { /* work = work + allocation */ add_vectors(work, allocation[i]); finish[i] = true; /* Go to step 2. */ i = find_i(work, finish); } }
void problem024(char arr[], int size, int max) { char tmp_arr[size], swap; int i, k, j, tmpLen, num = 1; k = find_k(arr, size); while (k != -1) { if (num == max) { break; } i = find_i(arr, k, size); swap = arr[i]; arr[i] = arr[k]; arr[k] = swap; tmpLen = size - k - 1; memcpy(tmp_arr, arr + (k + 1), tmpLen); // reverse for (j=0; j < tmpLen / 2; j++) { swap = tmp_arr[j]; tmp_arr[j] = tmp_arr[tmpLen - j - 1]; tmp_arr[tmpLen - j - 1] = swap; } memcpy(arr + (k + 1), tmp_arr, tmpLen); k = find_k(arr, size); num++; } //return arr; }
static int exist(T *thiz, mkey_t *key, uint64_t ver) { int r; mkv_t tkv; r = find_i(thiz, key, NULL, &tkv); if (r == RC_NOT_FOUND) return 0; if (ver == 0 || tkv.seq <= ver) return RC_FOUND; return RC_NOT_FOUND; }
void for_wchar_next(wchar_t *str, size_t *res, int *fl, size_t len) { int pr; if (fl[5] > 0 && fl[3] == 0) { pr = fl[5] - (((fl[6] < (int)len) && fl[6] != 0) ? find_i(str, fl) : (int)len); fl[4] == 1 ? PSN(pr, res, '0') : PSN(pr, res, ' '); pr_symb(str, fl, res, 0); } else if ((fl[5] > (int)len && fl[3] == 1)) { pr_symb(str, fl, res, 0); pr = fl[5] - (((fl[6] < (int)len) && fl[6] != 0) ? find_i(str, fl) : (int)len); fl[4] == 1 ? pr_space_null(pr, res, '0') : pr_space_null(pr, res, ' '); } else pr_symb(str, fl, res, 1); }
// Get the instance using <name> for specific configuration repository. void * ACE_Dynamic_Service_Base::instance (const ACE_Service_Gestalt* repo, const ACE_TCHAR *name, bool no_global) { ACE_TRACE ("ACE_Dynamic_Service_Base::instance"); void *obj = 0; const ACE_Service_Type_Impl *type = 0; const ACE_Service_Gestalt* repo_found = repo; const ACE_Service_Type *svc_rec = find_i (repo_found, name, no_global); if (svc_rec != 0) { type = svc_rec->type (); if (type != 0) obj = type->object (); } if (ACE::debug ()) { ACE_Guard <ACE_Log_Msg> log_guard (*ACE_Log_Msg::instance ()); if (repo->repo_ != repo_found->repo_) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE (%P|%t) DSB::instance, repo=%@, name=%s") ACE_TEXT (" type=%@ => %@") ACE_TEXT (" [in repo=%@]\n"), repo->repo_, name, type, obj, repo_found->repo_)); } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE (%P|%t) DSB::instance, repo=%@, name=%s") ACE_TEXT (" type=%@ => %@\n"), repo->repo_, name, type, obj)); } } return obj; }
value_type Stokhos::Sparse3Tensor<ordinal_type, value_type>:: getValue(ordinal_type i, ordinal_type j, ordinal_type k) const { #ifdef STOKHOS_DEBUG TEUCHOS_TEST_FOR_EXCEPTION(fill_completed == false, std::logic_error, "You must call fillComplete() before calling getValue()!"); #endif k_iterator k_it = find_k(k); if (k_it == k_end()) return value_type(0); kj_iterator j_it = find_j(k_it, j); if (j_it == j_end(k_it)) return value_type(0); kji_iterator i_it = find_i(j_it, i); if (i_it == i_end(j_it)) return value_type(0); return i_it.value(); }
/// Insert the ACE_Service_Type SR into the repository. Note that /// services may be inserted either resumed or suspended. Using same /// name as in an existing service causes the delete () to be called /// for the old one, i.e. make sure @code sr is allocated on the heap! int ACE_Service_Repository::insert (const ACE_Service_Type *sr) { ACE_TRACE ("ACE_Service_Repository::insert"); size_t i = 0; int return_value = -1; ACE_Service_Type const *s = 0; // Establish scope for locking while manipulating the service // storage { // @TODO: Do we need a recursive mutex here? ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); return_value = find_i (sr->name (), i, &s, false); // Adding an entry. if (s != 0) { this->service_array_[i] = sr; } else { // New services are always added where current_size_ points, // because if any DLL relocation needs to happen, it will be // performed on services with indexes between some old // current_size_ and the new current_size_ value. See // ACE_Service_Type_Dynamic_Guard ctor and dtor for details. if (i < this->service_array_.size ()) i = this->service_array_.size (); this->service_array_[i] = sr; return_value = 0; } } #ifndef ACE_NLOGGING if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE (%P|%t) SR::insert - repo=%@ [%d],") ACE_TEXT (" name=%s (%C) (type=%@, object=%@, active=%d)\n"), this, i, sr->name(), (return_value == 0 ? ((s==0) ? "new" : "replacing") : "failed"), sr->type (), (sr->type () != 0) ? sr->type ()->object () : 0, sr->active ())); #endif // If necessary, delete but outside the lock. (s may be 0, but // that's okay, too) delete s; if (return_value == -1) ACE_OS::last_error (ENOSPC); return return_value; }
// Insert the ACE_Service_Type SR into the repository. Note that // services may be inserted either resumed or suspended. Using same // name as in an existing service causes the delete () to be called // for the old one, i.e. make sure @code sr is allocated on the heap! int ACE_Service_Repository::insert (const ACE_Service_Type *sr) { ACE_TRACE ("ACE_Service_Repository::insert"); size_t i = 0; int return_value = -1; ACE_Service_Type const *s = 0; // Establish scope for locking while manipulating the service // storage { // @TODO: Do we need a recursive mutex here? ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); return_value = find_i (sr->name (), i, &s, false); // Adding an entry. if (s != 0) { this->service_vector_[i] = sr; } else { // New services are always added where current_size_ points, // because if any DLL relocation needs to happen, it will be // performed on services with indexes between some old // current_size_ and the new current_size_ value. See // ACE_Service_Type_Dynamic_Guard ctor and dtor for details. if (i < this->current_size_) i = this->current_size_; if (i < this->total_size_) { this->service_vector_[i] = sr; this->current_size_++; return_value = 0; } else { return_value = -1; // no space left } // Since there may be "holes" left by removed services one // could consider wrapping current_size_ modulo // total_size_. This is going to impact // ACE_Service_Type_Dynamic_Guard, too and is tricky. Perhaps // a new directive, like "reload" would be better as it can // combine the removal and insertion in an atomic step and // avoid creating too many "holes". } } #ifndef ACE_NLOGGING if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE (%P|%t) SR::insert - repo=%@ [%d] (%d),") ACE_TEXT (" name=%s (%s) (type=%@, object=%@, active=%d)\n"), this, i, this->total_size_, sr->name(), (return_value == 0 ? ((s==0) ? "new" : "replacing") : "failed"), sr->type (), (sr->type () != 0) ? sr->type ()->object () : 0, sr->active ())); #endif // If necessary, delete but outside the lock. (s may be 0, but // that's okay, too) delete s; if (return_value == -1) ACE_OS::last_error (ENOSPC); return return_value; }
iterator find(const key_type & to_find) { bool h; iterator i = find_i(to_find,h); return h ? i : end(); }
static int find(T *thiz, mkey_t *key, mval_t *v) { mkv_t tkv; return find_i(thiz, key, v, &tkv); }