bool process_string(const char * src,pfc::string_base & out)//returns if changed { if (check_string(src)) {out=src;return false;} unsigned idx=0; while(src[idx]==' ') idx++; while(src[idx]) { if (is_alphanumeric(src[idx]) && !is_used(src[idx])) { insert(src,idx,out); return true; } while(src[idx] && src[idx]!=' ' && src[idx]!='\t') idx++; if (src[idx]=='\t') break; while(src[idx]==' ') idx++; } //no success picking first letter of one of words idx=0; while(src[idx]) { if (src[idx]=='\t') break; if (is_alphanumeric(src[idx]) && !is_used(src[idx])) { insert(src,idx,out); return true; } idx++; } //giving up out = src; return false; }
struct pvdrm_slot* pvdrm_slot_alloc(struct pvdrm_device* pvdrm, int32_t file_handle) { int i; struct pvdrm_slots* slots; struct pvdrm_slot* slot; struct pvdrm_mapped* mapped; unsigned long flags; slots = pvdrm->slots; mapped = slots->mapped; down(&slots->sema); spin_lock_irqsave(&slots->lock, flags); for (i = 0; i < PVDRM_SLOT_NR; ++i) { if (!is_used(&mapped->slot[i])) { slot = &mapped->slot[i]; slot->code = PVDRM_HELD; slot->file = file_handle; break; } } BUG_ON(i == PVDRM_SLOT_NR); spin_unlock_irqrestore(&slots->lock, flags); pvdrm_fence_emit(&slot->__fence, 0); slot->ret = 0; return slot; }
std::string IOComponent::info() { char buffer[512] = { 0 }; snprintf(buffer, sizeof(buffer) - 1, "id:%lu type:%d state:%d used:%d fd:%d addr:%s peer:%s " "last_use_time %lu", getid(), get_type(), get_state(), is_used(), _socket->get_fd(), _socket->get_addr().c_str(), _socket->get_peer_addr().c_str(), get_last_use_time()); return buffer; }
static void clear_lost_client(int sindex) { int cli ; for (cli = 0; cli < RH_MAX_CLIENTS; cli++) { if (!is_used(sindex, cli) && is_sock(sindex, cli)) { close(get_sock(sindex, cli)); set_sock(sindex, cli, INVALID_SOCKET); } } }
static int privServer_get_nullPos(int sindex) { int cli ; for (cli = 0; cli < RH_MAX_CLIENTS; cli++) { if (!is_used(sindex, cli)) { return cli; } } return -1; }
void pvdrm_slot_request_async(struct pvdrm_device* pvdrm, struct pvdrm_slot* slot) { struct pvdrm_slots* slots; uint32_t pos; struct pvdrm_mapped* mapped; slots = pvdrm->slots; mapped = slots->mapped; BUG_ON(!is_used(slot)); /* Request slot, increment counter. */ pos = ((uint32_t)atomic_add_return(1, &slots->put)) % PVDRM_SLOT_NR; mapped->ring[pos] = pvdrm_slot_id(mapped, slot); wmb(); atomic_inc(&mapped->count); }
void pvdrm_slot_free(struct pvdrm_device* pvdrm, struct pvdrm_slot* slot) { struct pvdrm_slots* slots; unsigned long flags; struct pvdrm_mapped* mapped; slots = pvdrm->slots; mapped = slots->mapped; spin_lock_irqsave(&slots->lock, flags); BUG_ON(!is_used(slot)); slot->code = PVDRM_UNUSED; spin_unlock_irqrestore(&slots->lock, flags); up(&slots->sema); }
void stream_send_dataToClient(int sindex, int nLen, unsigned char * pData, Stream_Head_t* fh) { int nRet = -1; int cnt = 0; int sendsocket = -1; int fh_len = sizeof(Stream_Head_t); int data_len = nLen; int send_len = 0; for (cnt = 0; cnt < RH_MAX_CLIENTS; cnt++) { if (is_used(sindex, cnt)) { sendsocket = get_sock(sindex, cnt); if (sendsocket > 0) { send_len = fh_len; nRet = socket_tcp_sendNonBlock(sendsocket, (char *)fh, &send_len, 300); if (nRet < 0 || send_len != fh_len) { close(sendsocket); set_client_used(sindex, cnt, FALSE); set_sock(sindex, cnt, INVALID_SOCKET); printf("xxx Error: SOCK = %d count =%d errno=%d<%s> ret = %d\n", sendsocket, cnt, errno,strerror(errno), nRet); continue; } send_len = data_len; nRet = socket_tcp_sendNonBlock(sendsocket, (char *)pData, &send_len, 300); if (nRet < 0 || send_len != data_len) { close(sendsocket); set_client_used(sindex, cnt, FALSE); set_sock(sindex, cnt, INVALID_SOCKET); printf("Error: SOCK = %d count = %d errno = %d ret = %d\n", sendsocket, cnt, errno, nRet); continue; } } } } }
bool check_string(const char * src) {//check for existing mnemonics const char * ptr = src; while(ptr = strchr(ptr,'&')) { if (ptr[1]=='&') ptr+=2; else { unsigned c = 0; if (pfc::utf8_decode_char(ptr+1,c)>0) { if (!is_used(c)) used.add_char(uCharLower(c)); } return true; } } return false; }
int tm_min_left_overall (struct timeval *min_result) { int i; int nexp; struct timeval left; nexp = 0; tv_set (min_result, HUGE_TV_SEC, 0); for (i = 0; i < table_used_; i++) if (is_used (table_, i)) { if (!tmout_left (i, &left)) nexp++; tv_min (min_result, min_result, &left); } return nexp; }
Tree(InputMatrix<Categ,Scalar>& inMx,InfoType inf_measure) : root { new Node<Categ,Scalar>(nullptr,{})}, information_measure {inf_measure} { std::vector<bool> is_used (inMx[0].features.size(),false); //is_used[j] will record if feature j was already tested for InternalMatrix internal_mx; //vector of pointers to be the internal representation //used in elaborating the tree for(int i = 0; i < inMx.size(); i++) { internal_mx.push_back(&inMx[i]); } generate_recursive(internal_mx,&(*root),is_used); //&*root is there because we want to pass a Node*, //not a std::unique_ptr<Node> }
// Used to calculate random generation of points vector<int> Assignment2::randomGenerate(int N, int M)//Flyodd Algo { vector<unsigned char> is_used(N, 0); /* flags */ int in, im; vector<int> vektor(M); im = 0; for (in = N - M; in < N && im < M; ++in) { int r = rand() % (in + 1); /* generate a random number 'r' */ if (is_used[r]) /* we already have 'r' */ r = in; /* use 'in' instead of the generated number */ assert(!is_used[r]); vektor[im++] = r + 1; /* +1 since your range begins from 1 */ is_used[r] = 1; } assert(im == M); return vektor; }
bool Model_Payee::remove(int id) { if (is_used(id)) return false; return this->remove(id, db_); }
bool Model_Payee::is_used(const Data& record) { return is_used(&record); }
bool Model_Payee::is_used(const Data* record) { return is_used(record->PAYEEID); }