nds_bool UnicharQueue_pop(UnicharQueue* self, unichar * character) { if (character == NULL) return NDS_FALSE; if (self->tail < 0) return NDS_FALSE; /* queue is empty */ assert(UnicharQueue_length(self) > 0); *character = self->buffer[self->tail]; if (self->peek == self->tail) self->peek = nextIndex(self->peek); self->tail = nextIndex(self->tail); if (self->tail == self->head) self->tail = -1; /* mark as empty */ if (self->peek == self->head) self->peek = -1; return NDS_TRUE; }
int nextNonwhitespace(char* buffer, int bufferSize, int i) { i = nextIndex(buffer, bufferSize, i); while (buffer[i] == '\n') { i = nextIndex(buffer, bufferSize, i); } return i; }
P PointerTable<P, K, HF, KF>::insert(P p, Boolean replace) { size_t h; if (vec_.size() == 0) { vec_.assign(8, P(0)); usedLimit_ = 4; h = startIndex(KF::key(*p)); } else { for (h = startIndex(KF::key(*p)); vec_[h] != 0 ; h = nextIndex(h)) if (KF::key(*vec_[h]) == KF::key(*p)) { if (replace) { P tem(vec_[h]); vec_[h] = p; return tem; } else return vec_[h]; } if (used_ >= usedLimit_) { if (vec_.size() > size_t(-1)/2) { if (usedLimit_ == vec_.size() - 1) abort(); // FIXME throw an exception else usedLimit_ = vec_.size() - 1; } else { // rehash Vector<P> oldVec(vec_.size()*2, P(0)); vec_.swap(oldVec); usedLimit_ = vec_.size() / 2; for (size_t i = 0; i < oldVec.size(); i++) if (oldVec[i] != 0) { size_t j; for (j = startIndex(KF::key(*oldVec[i])); vec_[j] != 0; j = nextIndex(j)) ; vec_[j] = oldVec[i]; } for (h = startIndex(KF::key(*p)); vec_[h] != 0; h = nextIndex(h)) ; } } } used_++; vec_[h] = p; return 0; }
int queueFull (const tQueue* q) { /* ** Vrací nenulovou hodnotu, je-li fronra plná, jinak vrací hodnotu 0. ** Funkci implementujte jako jediný pøíkaz s vyu¾itím pomocné funkce nextIndex. */ return(nextIndex(q->b_index) == q->f_index); //fronta je plna konecny posunuty o jedno sa rovna zaciatocnemu }
void t4p::FinderActionClass::BackgroundWork() { if (!Finder.Prepare()) { return; } Code = t4p::CharToIcu(Utf8Buf); int32_t nextIndex(0); bool found = Finder.FindNext(Code, nextIndex); int32_t matchStart(0); int32_t matchLength(0); while (found) { if (Finder.GetLastMatch(matchStart, matchLength)) { // convert match back to UTF-8 ugh int utf8Start = t4p::CharToUtf8Pos(Utf8Buf, BufferLength, matchStart); int utf8End = t4p::CharToUtf8Pos(Utf8Buf, BufferLength, matchStart + matchLength); t4p::FinderHitEventClass hit(GetEventId(), utf8Start, utf8End - utf8Start); PostEvent(hit); nextIndex = matchStart + matchLength + 1; // prevent infinite find next's } else { break; } found = Finder.FindNext(Code, nextIndex); } delete[] Utf8Buf; }
int findVertex(const QVector3D &v) { end_ptr = vec_data->size() - 1; // last one not in QMap start_ptr = number_mapped; // first one not in QMap target = v; return nextIndex(); }
int getMaxRepetitions(string s1, int n1, string s2, int n2) { vector<int> repeatCount(n1 + 1, 0); vector<int> nextIndex(n1 + 1, 0); int j = 0, cnt = 0; for (int k = 1; k <= n1; ++k) { for (int i = 0; i < s1.size(); ++i) { if (s1[i] == s2[j]) { ++j; if (j == s2.size()) { j = 0; ++cnt; } } } repeatCount[k] = cnt; nextIndex[k] = j; for (int start = 0; start < k; ++start) { if (nextIndex[start] == j) { int prefixCount = repeatCount[start]; int patternCount = (n1 - start) / (k - start) * (repeatCount[k] - prefixCount); int suffixCount = repeatCount[start + (n1 - start) % (k - start)] - prefixCount; return (prefixCount + patternCount + suffixCount) / n2; } } } return repeatCount[n1] / n2; }
int queueFull (const tQueue* q) { /* ** Vrací nenulovou hodnotu, je-li fronra plná, jinak vrací hodnotu 0. ** Funkci implementujte jako jediný pøíkaz s vyu¾itím pomocné funkce nextIndex. */ return nextIndex(q->b_index) == q->f_index; /* Ak je index za b_index zhodný s f_index, fronta je plná - vracia 1. Inak 0 */ }
int queueFull (const tQueue* q) { /* ** Vrac nenulovou hodnotu, je-li fronra pln, jinak vrac hodnotu 0. ** Funkci implementujte jako jedin pkaz s vyuitm pomocn funkce nextIndex. */ return (nextIndex(q->b_index) == q->f_index); }
size_t GPRSClient::callback(byte *buf, size_t length, void *data) { size_t used = 0; GPRSClient *client = (GPRSClient *)data; if (client->_size_left == 0) { char *p = strstr_P((char *)buf, G("+IPD")); if (p) { p += 4; char *end = strchr(p, ':'); if (end) { *end = 0; client->_size_left = atoi(p); used = (byte *)end - buf + 1; } } } while (client->_size_left > 0 && used < length) { // Data will be discarded when buffer is full if (!client->isFull()) { client->_rx_buf[client->_rx_tail] = buf[used++]; client->_rx_tail = nextIndex(client->_rx_tail); } client->_size_left--; } return used + client->_size_left; }
int queueFull (const tQueue* q) { /* ** Vrací nenulovou hodnotu, je-li fronra plná, jinak vrací hodnotu 0. ** Funkci implementujte jako jediný pøíkaz s vyu¾itím pomocné funkce nextIndex. */ return (nextIndex(q->b_index) == q->f_index)? 1: 0; // Je-li index prvniho prvku o jeden index vetsi nez index prvni volne pozice, jedna se o plnou frontu }
void PlaylistModel::dataChangeNotice(int newidx, int newnum) { bool c = (newidx != img_index); int len = countShowImages(); for (int i = 0; i < len; ++i) { int idx = currentIndex(i); if (isValidIndex(idx)) { QModelIndex midx = index(idx, 0); dataChanged(midx, midx); } } img_index = newidx; img_num = newnum; if (newidx >= 0) { for (int i = 0; i < len; ++i) { int idx = currentIndex(i); if (isValidIndex(idx)) { QModelIndex midx = index(idx, 0); dataChanged(midx, midx); } } } if (c) { QVector<ImageFile> list; int num = std::min(files.count(), prft.getCacheSize()); for (int i = 1, n = 0; n < num; ++i) { list.append(*files.at(nextIndex(img_index, i))); n++; if (n+1 >= num) break; list.append(*files.at(nextIndex(img_index, -i))); n++; } prft.putRequest(list); list.clear(); } }
unsigned char* RingBuffer::getNextBufferToRead() { if( readIndex == writeIndex ){ return NULL; }else{ int nextReadIndex = nextIndex( readIndex ); return buffer[ nextReadIndex ]; } }
unsigned char* RingBuffer::getNextBufferToWrite() { int nextWriteIndex = nextIndex( writeIndex ); if( nextWriteIndex == readIndex ){ return NULL; }else{ return buffer[ nextWriteIndex ]; } }
/** * returns the next available port in the range, returns -1 if no ports are available * if reqport is not 0 then assigns the requested port */ int allocPort (PortAlloc *ptr, int reqport, dirxn d) { int port = -1; int count, index = 0; NETDEBUG(MFCE, NETLOG_DEBUG4, ("allocPort: request to allocate port %d for %s\n", reqport, dirxn2str(d))); if (!ptr->inited) { NETERROR(MFCE, ("allocPort: trying to allocate port before initialization\n")); return -1; } if (reqport) { index = (reqport - ptr->low)/2; } else { if ((index = nextIndex(ptr)) == -1) { NETERROR(MFCE, ("allocPort: cannot allocate port, no more ports available in the range %d - %d\n", ptr->low, ptr->high)); return -1; // no ports available in the port range } incrementIndex(ptr); /* get ready for the next request */ reqport = (index * 2) + ptr->low; } /* set the current port as used */ if (d == rx) { if (GET_RX_CNT(ptr->bArray[index])) { /* port is already allocated */ NETERROR(MFCE, ("allocPort: can not allocate rx port on %d.\n", reqport)); return port; } SET_RX_CNT(ptr->bArray[index], 1); } else if (d == tx) { count = GET_TX_CNT(ptr->bArray[index]); count++; if (count <= MAX_TX_CNT) { SET_TX_CNT(ptr->bArray[index], count); } else { NETERROR(MFCE, ("allocPort: can not allocate %d tx ports on %d.\n", count, reqport)); return port; // no ports available in the port range } } else { NETERROR(MFCE, ("allocPort: can not allocate port for %s(%d).\n", dirxn2str(d), d)); return port; } port = reqport; NETDEBUG(MFCE, NETLOG_DEBUG4, ("allocPort: allocating port %d for %s\n", port, dirxn2str(d))); return port; }
QModelIndex ThumbnailModel::nextThumbnail(QModelIndex s) const { QModelIndex i = s; while(true) { i = nextIndex(i); if(!i.isValid()) break; if(!i.data(IsDirRole).toBool()) return i; } return s; }
float PathAnimation::opacity() { unsigned int i = progressIndex(); unsigned int iNext = nextIndex(i); float iNextFactor = progressOverTheIndex() / progressPerSegment_; float iFactor = 1.0f - iNextFactor; return iFactor * points_[i].pointer()->opacity() + iNextFactor * points_[iNext].pointer()->opacity(); }
const P &PointerTable<P, K, HF, KF>::lookup(const K &k) const { if (used_ > 0) { for (size_t i = startIndex(k); vec_[i] != 0; i = nextIndex(i)) if (KF::key(*vec_[i]) == k) return vec_[i]; } return null_; }
int RingBuffer::read_char() { if(_iTail == _iHead) return -1; uint8_t value = _aucBuffer[_iTail]; _iTail = nextIndex(_iTail); return value; }
String Tokenizer::next() { StringIndex tmp; nextIndex(tmp); if(tmp.m_length >= m_stringBufferSize) { SAFEDELETEARRAY(m_stringBuffer); m_stringBuffer = new TCHAR[m_stringBufferSize = 2 * (tmp.m_length+1)]; TRACE_NEW(m_stringBuffer); } _tcsncpy(m_stringBuffer,(const TCHAR*)m_str+tmp.m_start, tmp.m_length); m_stringBuffer[tmp.m_length] = 0; return m_stringBuffer; }
Eigen::Vector3f PathAnimation::location() { unsigned int i = progressIndex(); unsigned int iNext = nextIndex(i); Eigen::Vector3f tmp = points_[iNext].pointer()->location() - points_[i].pointer()->location(); if(i == iNext && iNext > 0) // at the end { tmp = points_[iNext].pointer()->location() - points_[iNext - 1].pointer()->location(); } float iNextFactor = progressOverTheIndex() / progressPerSegment_; return points_[i].pointer()->location() + iNextFactor * tmp; }
int headerNext(HeaderIterator hi, rpmtd td) { indexEntry entry = nextIndex(hi); int rc = 0; rpmtdReset(td); if (entry) { td->tag = entry->info.tag; rc = copyTdEntry(entry, td, HEADERGET_DEFAULT); } return ((rc == 1) ? 1 : 0); }
PBYTE RingBuffer::getNextBufferToRead() { PBYTE nextBuffer = NULL; if( readIndex == writeIndex ){ nextBuffer = NULL; }else{ int nextReadIndex = nextIndex( readIndex ); nextBuffer = buffer[ nextReadIndex ]; } return nextBuffer; }
void queueRemove (tQueue* q) { /* ** Odstraní znak ze zaèátku fronty q. Pokud je fronta prázdná, o¹etøete ** vzniklou chybu voláním funkce queueError(QERR_REMOVE). ** Hodnotu na uvolnìné pozici ve frontì nijak neo¹etøujte (nepøepisujte). ** Pøi implementaci vyu¾ijte døíve definované funkce queueEmpty a nextIndex. */ if (queueEmpty(q)) { queueError(QERR_REMOVE); return; } q->f_index = nextIndex(q->f_index); /* Indexom prvého prvku sa stáva prvok za aktuálnym f_index */ }
void RingBuffer::store_char( uint8_t c ) { int i = nextIndex(_iHead); // if we should be storing the received character into the location // just before the tail (meaning that the head would advance to the // current location of the tail), we're about to overflow the buffer // and so we don't write the character or advance the head. if ( i != _iTail ) { _aucBuffer[_iHead] = c ; _iHead = i ; } }
void queueRemove (tQueue* q) { /* ** Odstraní znak ze zaèátku fronty q. Pokud je fronta prázdná, o¹etøete ** vzniklou chybu voláním funkce queueError(QERR_REMOVE). ** Hodnotu na uvolnìné pozici ve frontì nijak neo¹etøujte (nepøepisujte). ** Pøi implementaci vyu¾ijte døíve definované funkce queueEmpty a nextIndex. */ if(queueEmpty(q)){ // Zkontroluj, zda-li neni fronte prazdna queueError(QERR_REMOVE); // Vyhod chybovou hlasku return; // Ukonci } q->f_index = nextIndex(q->f_index); // Odstran znak ze zacatku fronty }
ulen MultiSemBase::try_take_locked() { ulen index=base; for(ulen cnt=counts.len; cnt ;cnt--,index=nextIndex(index)) { if( counts[index] ) { counts[index]--; base=nextIndex(base); index++; event(Task::GetCurrent(),MultiSemEvent_task::Take,index); Log("#;:#; is taken by #;",name,index,GetTaskName(CurTaskContext)); return index; } } return 0; }
P PointerTable<P, K, HF, KF>::remove(const K &k) { if (used_ > 0) { for (size_t i = startIndex(k); vec_[i] != 0; i = nextIndex(i)) if (KF::key(*vec_[i]) == k) { P p = vec_[i]; do { vec_[i] = P(0); size_t j = i; size_t r; do { i = nextIndex(i); if (vec_[i] == 0) break; r = startIndex(KF::key(*vec_[i])); } while ((i <= r && r < j) || (r < j && j < i) || (j < i && i <= r)); vec_[j] = vec_[i]; } while (vec_[i] != 0); --used_; return p; } } return 0; }
Eigen::Matrix4f PathAnimation::rotation() { unsigned int i = progressIndex(); unsigned int iNext = nextIndex(i); Eigen::Quaternionf qI(points_[i].pointer()->rotation()); if(iNext != i) { Eigen::Quaternionf qINext(points_[iNext].pointer()->rotation()); float factor = progressOverTheIndex() / progressPerSegment_; Eigen::Quaternionf tmp(qI.slerp(factor, qINext)); return Eigen::Affine3f(tmp).matrix(); } // exactly at end return Eigen::Affine3f(qI).matrix(); }
void queueRemove (tQueue* q) { /* ** Odstraní znak ze zaèátku fronty q. Pokud je fronta prázdná, o¹etøete ** vzniklou chybu voláním funkce queueError(QERR_REMOVE). ** Hodnotu na uvolnìné pozici ve frontì nijak neo¹etøujte (nepøepisujte). ** Pøi implementaci vyu¾ijte døíve definované funkce queueEmpty a nextIndex. */ if(queueEmpty(q) == 0) //fronta nie je prazdna { q->f_index = nextIndex(q->f_index); //posunieme sa } else //fronta je prazdna { queueError(QERR_REMOVE); } }