bool Queue::enQueue( const Item& item ) { if(isFull()) return false; Node* add = new Node; add->item = item; add->next = NULL; items++; if(front == NULL) front = add; else rear->next = add; rear = add; return true; }
// Attention, the index of the heap starts from 1 // return the index the element inserted into the binary heap void insertHeap(ElementTypePtr value, BinaryHeap bh) { int i; if(isFull(bh)) { Error("failed insertion , for the BinaryHeap is full, from func insert!"); return ; } if(!isEmpty(bh)) for(i = ++bh->size; bh->elements[i/2]->weight > value->weight; i /= 2) *bh->elements[i] = *bh->elements[i/2]; else i = ++bh->size; *bh->elements[i] = *value; }
// 增加元素 int Add(Element *q, Element item) { // 使用循环队列 /* * 便于理解的传统写法 * if (rear == MAX_QUEUE_SIZE -1) rear = 0; * else rear ++ * */ rear = (rear + 1) % MAX_QUEUE_SIZE; if(!isFull()) { q[rear] = item; return 1; }else return 0; }
void freeIndex(NativeNaturalType index, PageRefType pageRef) { assert(getSize(index) > 0); if(isFull()) { assert(superPage->fullBlobBuckets.erase<Key>(pageRef)); assert(superPage->freeBlobBuckets[header.type].insert(pageRef)); } --header.count; if(isEmpty()) { assert(superPage->freeBlobBuckets[header.type].erase<Key>(pageRef)); releasePage(pageRef); } else { setSize(index, 0); setSymbol(index, header.freeIndex); header.freeIndex = index; } }
bool LCache::findInCache(vector<WClause*> CNF, LogDouble& val) { if(CNF.size() > MAXCNFSIZE || CNF.size() == 0) return false; //for(unsigned int i=0;i<currentIndex;i++) vector<LCacheEntry*> tempCache = cacheIndex[CNF.size() - 1]; //for(unsigned int i=0;i<cacheEntries.size();i++) for(unsigned int i=0;i<tempCache.size();i++) { if(tempCache[i]) { if(unifier->CNFUnify(tempCache[i]->CNF,CNF)) { val = tempCache[i]->wCount; tempCache[i]->hits++; successfulHits++; #ifdef __DEBUG_PRINT__ cout<<"Cache Hit "<<i<<endl; for(unsigned int j=0;j<tempCache[i]->CNF.size();j++) { if(tempCache[i]->CNF[j]->satisfied) cout<<"Satisfied V "; tempCache[i]->CNF[j]->print(); } cout<<"******************"<<endl; for(unsigned int j=0;j<CNF.size();j++) { if(CNF[j]->satisfied) cout<<"Satisfied V "; CNF[j]->print(); } cout<<"sucesssful hit end"<<endl; #endif hits++; return true; } } } misses++; if(isFull() && (double)misses/(double)(misses+hits) > 0.5) { cleanCache(0); hits = 0; misses = 0; } return false; }
// Pushes an element onto the top of the stack, if there's room. void push(Stack *s, int n) { if (s == NULL) return; if (isFull(s)) { printf("\n -> error: stack is full\n\n"); return; } s->elements[s->top++] = n; // Or, you could use this: //s->elements[s->top] = n; //++s->top; }
void push() { if(!isFull()) { int num; printf("\n Enter the data you want to push\n"); scanf("%d",&num); s.top = s.top + 1; s.stk[s.top] = num; } else { printf("\n The Stack is full mate\n"); } }
void insertPriorityQueue(pPriorityQueue heap, elemType elem) { if (NULL == heap || isFull(heap)) return; if (isEmpty(heap)) //no sentinel at 0; this is needed; { heap->element[0] = elem; (heap->size)++; return; } int i; for (i = heap->size; elem < heap->element[i / 2] && i!=0 ; i = i / 2) //没i!=0,如果0元素最小,或者最大,都可能死循环 { heap->element[i] = heap->element[i / 2]; // } heap->element[i] = elem; heap->size++; // }
bool FThreadPool::pushTask(FThreadTask *task) { bool ret = false; pthread_mutex_lock(&m_mutex); if (!isTaskFull()) { m_tasks.push_back(task); if (m_idle.empty() && !isFull()) { createThead(); } ret = true; } pthread_mutex_unlock(&m_mutex); pthread_cond_signal(&m_cond); return ret; }
int main(void) { printf("Hi, this program compiles"); Stack s = newStack(); printf("Empty? %d\n", isEmpty(&s)); char* s1 = "how are you\n"; push(&s,"String 1\n"); printf("%s", (char*)(s->val)); push(&s, s1); printf("%s", (char*)(s->val)); // pop(&s); // printf("%s", (char*)(s->val)); printf("Full? %d\n", isFull(&s)); printf("Empty? %d\n", isEmpty(&s)); int numElements = getNumElements(&s); printf("%d", numElements); destroy(&s); }
void push(struct Stack *s, int data) { //printf("push"); if(isFull(s)) { printf("stack full"); doubleStack(s); } //printf("push"); s->a[++s->top] = data; //printf("%d",s->a[s->top]); }
//----------------------------------------------------------- // This routine pushes data into the stack. //----------------------------------------------------------- void Stack::push(int number) { // Check for full stack if (isFull()) return; // Allocate space for data SNode *temp = new SNode; if (temp == NULL) return; // Insert data at head of list temp->number = number; temp->next = head; head = temp; length++; }
void list_add(list_t * self, int value, int index) { resetStatus(self); if(isFull(self)) { self->status = LIST_FULL; return; } if(index - 1 >= MAX_LIST_SIZE || index - 1 >= self->size - 1){ self->arr[(self->size)++] = value; return; } if(index - 1 < self->size - 1) shift_right(self, index); self->arr[index - 1] = value; (self->size)++; }
/********************************************************************** * * Method: add() * * Description: Add an item to the buffer. * * Notes: It is up to the caller to check isFull() first, since * there is no convenient way to indicate that error. * * Returns: None defined. * **********************************************************************/ void CircBuf::add(item i) { /* Si el Buffer esta lleno, no hay lugar en la cola para colocar los datos*/ if(isFull()){ printf("ERROR : BUFFER COMPLETO "); } /*Si el Buffer está vacío el elemento se coloca en la 1° posición de la cola * Y se incrementan count y tail */ else if (isEmpty()){ array[0]=i; count=1; head=0; //primer elemento no vacío tail=count; } /*Si la cola tiene más de dos espacios vacíos (a la derecha de la cola) *el elemento se coloca donde apunta tail y se incrementan tail y count */ else if (tail< size-1){ array[tail]=i; tail++; count++; /*Si la cola sólo tiene el último espacio libre a la derecha, el elemento se coloca en ese *último espacio. */ } else if(tail== size-1){ array[tail]=i; /*Si hay espacio al principio de la cola (a la izquierda del buffer), tail se pone a 0, y count * es igual al tamaño de la cola menos la cabecera head. */ if(head>0){ tail=0; count=size-head; } /*Si no hay espacio a la izquierda del buffer, tail se pone a 0 y count es igual al tamaño del buffer, o sea, el buffer está lleno */ if(head==0){tail=0; count=size; } } } /* add() */
int MPIRecvDataBuffer::transmit(int node, int tag, MPI_Datatype type, MPI_Comm &comm, int size) { // first check the size to receive. if (size < 0) return BAD_DATA; void *ldata = NULL; if (size == 0) { // size is zero, receive it and through it away (so the message is received. MPI_Recv(ldata, size, type, node, tag, comm, MPI_STATUS_IGNORE); return status; } if (isStopped()) return status; if (isFull()) return FULL; long long t1 = ::cci::common::event::timestampInUS(); // else size is greater than 1. ldata = malloc(size); memset(ldata, 0, size); if (non_blocking) { MPI_Request *req = (MPI_Request *)malloc(sizeof(MPI_Request)); MPI_Irecv(ldata, size, type, node, tag, comm, req); mpi_buffer[req] = std::make_pair(size, ldata); mpi_req_starttimes[req] = t1; } else { MPI_Status mstat; MPI_Recv(ldata, size, type, node, tag, comm, &mstat); buffer.push(std::make_pair(size, ldata)); long long t2 = ::cci::common::event::timestampInUS(); char len[21]; // max length of uint64 is 20 digits memset(len, 0, 21); sprintf(len, "%d", size); if (this->logsession != NULL) this->logsession->log(cci::common::event(0, std::string("MPI B RECV"), t1, t2, std::string(len), ::cci::common::event::NETWORK_IO)); } return status; }
unsigned short enQueue(Queue *queue, unsigned short* pointer) { if(isFull(queue)) { return 1; } else { *pointer = queue->tail; queue->tail++; if(queue->tail == queue->queue_size) { queue->tail = 0; } } return 0; }
void Hash::insert(int x){ //Not in the array. if( contains ( x ) == false && isFull() != true ){ int index = hash( x , 0 ) ; k = key ; if(index != -1 ){ myArray[ index ] = x ; } } }
void fillBox(int n){ int i, j, num; if (isFull(n)){ return; } while (true){ i = rand() % n; j = rand() % n; num = rand() % 2 == 0 ? 2 : 4; if (Array2048[i][j] == 0){ Array2048[i][j] = num; break; } } }
void Queue<T>::enqueue(const T& item) { // If queue is full, do nothing assert(!isFull()); // Create temporary node with passed in data Node<T> *temp = new Node<T>(item); if (front == 0) { front = temp; back = temp; } else { back->next = temp; back = temp; } ++length; }
Server::Server(QObject *parent) : QTcpServer(parent) { connect(this, SIGNAL(isFull()), SLOT(startGame())); numberOfPlayers = 2; for (int i = 0; i < numberOfPlayers; i++){ players[i] = new Player(); } playerTurn = 0; round = 0; hand = 0; cardsOfRoundOne = new int[numberOfPlayers]; cardsOfRoundTwo = new int[numberOfPlayers]; cardsOfRoundThree = new int[numberOfPlayers]; method[00] = &Server::setPlayerNick; method[01] = &Server::playedCard; }
bool FArrayList::insert(Object *e, int p) { if ( isFull() ) return false; if ( !((p >= 0) && (p <= size())) ) return false; if ( isEmpty() ) data[p] = e; else { if ( p == size() ) data[p] = e; else { for (int i = size() - 1; i >= p; i--) data[i + 1] = data[i]; data[p]=e; } } ssize++; return true; }
// 住队列中存入一个元素 int RingQueueOfInt::Push(void *element) { FUNCTION_TRACK(); // 函数轨迹跟踪 if( isFull() ) { // LOG_DEBUG("Queue full."); return ERR; } m_buf[ m_write ] = element; m_write++; if(m_max == m_write) { m_write = 0; } return OK; }
int push(const T &item, CThread *thr, unsigned int timeoutMsec) { std::chrono::duration<unsigned int, std::milli> duration(timeoutMsec); std::unique_lock<std::mutex> lock(m_mutex); while(isFull()) { m_condNotEmpty.wait_for(lock, duration); if (thr->isTerminated()) return -1; } if (thr->isTerminated()) return -1; m_rwmut.lock(); m_que.push(item); m_rwmut.unlock(); m_condNotFull.notify_all(); return 0; }
// This function checks for is full condition. The user of this function may // not just use isFull before calling this. Just check the return type, you will know. uint8_t write_packet(QueueType* queue, uint8_t* packet_ptr) { uint8_t is_full = isFull(queue); // Dont do anything if the queue is full if(!is_full) { // copy the value at the pointer provided in the queue. memcpy(&(queue->packets[queue->write]), packet_ptr, sizeof(ECGPacket)); if(FIFO_SIZE-1 == queue->write) { queue->write = 0; } else { queue->write ++; } }else { nrk_kprintf(PSTR("ERROR: TX FIFO FULL\n\r")); } return !is_full; }
void ExplorationSquad::computeActions() { if (!active) { if (isFull()) { active = true; } return; } //First, remove dead agents for(int i = 0; i < (int)agents.size(); i++) { if(!agents.at(i)->isAlive()) { agents.erase(agents.begin() + i); i--; } } //All units dead, go back to inactive if ((int)agents.size() == 0) { active = false; return; } if (active) { if (activePriority != priority) { priority = activePriority; } TilePosition nGoal = ExplorationManager::Instance().getNextToExplore(this); if (nGoal.x() >= 0) { this->goal = nGoal; setMemberGoals(goal); } } }
void Queue::push_front(SinhVien sv) { if(isFull()){ return; } else{ if(size == 0) { push_back(sv); return; } else{ front = (front+MAX)-1; this->sv[front] = sv; size += 1; } } }
void Add(Queue *Q,market val) { if (!isFull(*Q)) { if(isEmpty(*Q)) { (*Q).Head=(*Q).Tail=0; (*Q).happy[(*Q).Tail]=val; } else if((*Q).Tail==MAX-1) { (*Q).Tail=0; } else { (*Q).Tail++; (*Q).happy[(*Q).Tail]=val; } } }
void insert(int key, int val) { if (isFull()) return; int idx = hash1(key); if (m_hash[idx] == -1) { m_hash[idx] = val; } else { int idx2 = hash2(key); int i = 1; while (true) { int nidx = (idx + i * idx2) % m_hash.size(); if (m_hash[nidx] == -1) { m_hash[nidx] = val; break; } ++i; } } m_used++; }
void RoboMiner::mine() { if(!cell->mineralCount() || isFull()) return; int extract_quant = 5; int remain = getRemainingSpace(); if(remain < extract_quant) extract_quant = remain; MineralStore *output = cell->extract(extract_quant); // std::cout << "Mining (" << cell_y << "," << cell_x // << ") yields:" << std::endl; // std::cout << *output; process(*output); delete output; }
WolValueImplSptr WolRangeValueImpl::getNotValueInt() { DEBUG4_MSG << "RANGE " << this->getStringRep() << " NOT "; if (isFull()) { DEBUG4_MSG << "RESULT = " << this->getStringRep(); return shared_from_this(); } assert(checkConsistency()); int position = OptimalSplitPosition(); if (position == 0) position = _prec/2; auto rangeSplit = split(position); WolValueImplSptr retValue = rangeSplit->getNotValueInt(); DEBUG4_MSG << "RESULT = " << retValue->getStringRep(); return retValue; }