コード例 #1
0
ファイル: sparselib.c プロジェクト: bremond/siconos
void dswapVector3(sparseVector *sparse1, sparseVector *sparse2, int indexStart, int indexEnd)
{

  REAL *dense1, *dense2;

  if(indexStart<=0)
    indexStart = 1;
  if(indexEnd<=0)
    indexEnd = MAX(lastIndex(sparse1), lastIndex(sparse2));

  if(indexStart <= firstIndex(sparse1) && indexStart <= firstIndex(sparse2) && 
     indexEnd >= lastIndex(sparse1) && indexEnd >= lastIndex(sparse2)) {
    swapVector(sparse1, sparse2);
  }
  else {

    CALLOC(dense1, (indexEnd+1));
    CALLOC(dense2, (indexEnd+1));
    getVector(sparse1, dense1, indexStart, indexEnd, TRUE);
    getVector(sparse2, dense2, indexStart, indexEnd, TRUE);
    clearVector(sparse1, indexStart, indexEnd);
    clearVector(sparse2, indexStart, indexEnd);
    putVector(sparse1, dense2, indexStart, indexEnd);
    putVector(sparse2, dense1, indexStart, indexEnd);
    MEMFREE(dense1);
    MEMFREE(dense2);
  }
}
コード例 #2
0
void THtmlParser::parseCloseTag()
{
    ++pos;
    skipWhiteSpace();
    QString tag = parseWord();
    skipUpTo(">");
    
    // Finds corresponding open element
    int i = lastIndex();
    while (i > 0) {
        if (!tag.isEmpty() && at(i).tag.toLower() == tag.toLower() && !isElementClosed(i)) {
            break;
        }
        i = at(i).parent;
    }

    if (i > 0) {
        at(i).tagClosed = true;
    } else {
        // Can't find a corresponding open element
        last().text += QLatin1String("</");
        last().text += tag;
        last().text += QLatin1Char('>');
        return;
    }

    // Append a empty element for next entry
    int p = at(i).parent;
    appendNewElement(p);
}
コード例 #3
0
THtmlElement &THtmlParser::insertNewElement(int parent, int index)
{
    if (elementCount() > 1 && last().isEmpty()) {
        // Re-use element
        changeParent(lastIndex(), parent, index);
    } else {
        elements.resize(elements.size() + 1);
        last().parent = parent;
        if (index >= 0 && index < elements[parent].children.count()) {
            elements[parent].children.insert(index, lastIndex());
        } else {
            elements[parent].children.append(lastIndex());
        }
    }
    return last();
}
コード例 #4
0
ファイル: sparselib.c プロジェクト: bremond/siconos
void dswapVector1(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd)
{
  int i, d, n;
  REAL *x;

  if(indexStart <= 0)
    indexStart = 1;
  n = lastIndex(sparse);
  if(indexEnd <= 0) 
    indexEnd = n;
  CALLOC(x, (MAX(indexEnd,n)+1));

  getVector(sparse, x, indexStart, n, FALSE);
  d = getDiagonalIndex(sparse);
  clearVector(sparse, indexStart, n);
  for(i = indexStart; i<=indexEnd; i++) {
    if(dense[i] != 0)
      putItem(sparse, i, dense[i]);
  }
  for(i = indexEnd+1; i<=n; i++) {
    if(x[i] != 0)
      putItem(sparse, i, x[i]);
  }
  MEMCOPY(&dense[indexStart], &x[indexStart], (indexEnd-indexStart+1));

#ifdef DEBUG_SPARSELIB
  verifyVector(sparse);
#endif
  
  MEMFREE(x);
}
コード例 #5
0
ファイル: notehistory.cpp プロジェクト: Fabijenna/QOwnNotes
void NoteHistory::add(Note note, int cursorPosition) {
    if (!note.exists()) {
        return;
    }

    NoteHistoryItem item(&note, cursorPosition);

    if (noteHistory->contains(item)) {
        // decrease current index if we are going to remove an item before it
        if (noteHistory->indexOf(item) < currentIndex) {
            currentIndex--;
        }

        // remove found item
        noteHistory->removeAll(item);
    }

    noteHistory->prepend(item);

    if (currentIndex < lastIndex()) {
        // increase current index
        currentIndex++;
    }

    noteHistory->move(0, currentIndex);
    currentIndex = noteHistory->indexOf(item);

    qDebug() << " added to history: " << item;
}
コード例 #6
0
void THtmlParser::parseTag()
{
    // Close-tag
    if (txt.at(pos) == QLatin1Char('/')) {
        parseCloseTag();
        return;
    }

    // p : parent index
    int p = lastIndex();
    while (p > 0) {
        if (!at(p).tag.isEmpty() && !isElementClosed(p)) {
            break;
        }
        p = at(p).parent;
    }

    THtmlElement &he = appendNewElement(p);
    he.tag = parseWord();
    // Parses the attributes
    he.attributes.clear();
    if (pos < txt.length()) {
        he.attributes = parseAttributes();
    }

    // Tag closed?
    if (txt.at(pos) == QLatin1Char('/')) {
        const QRegExp rx("(\\s*/[^>]*)>");  // "/>" or "//-->"
        int idx = rx.indexIn(txt, pos - 1);
        if (idx == pos || idx == pos - 1) {
            he.selfCloseMark = rx.cap(1);
            pos = idx + rx.cap(1).length();
        }
    }

    if (txt.at(pos) == QLatin1Char('>')) {
        ++pos;
    } else {
        // coding error
        Q_ASSERT(0);
    }

    if (isElementClosed(lastIndex())) {
        appendNewElement(he.parent);
    }
}
コード例 #7
0
// ---------------------------------------------------------------------------
// CSmileyIconRecord::SmileyRange
// ---------------------------------------------------------------------------
//
void CSmileyIconRecord::SetSelection( TInt aStart, TInt aLength )
    {
    TInt firstIndex( FirstIndexIn( aStart, aLength ) );
    TInt lastIndex( LastIndexIn( aStart, aLength, firstIndex ) );
    for ( TInt i( firstIndex ); i != KErrNotFound && i <= lastIndex; i++ )
        {
        iIconArray[i]->EnableHighlight( ETrue );
        }
    }
コード例 #8
0
ファイル: notehistory.cpp プロジェクト: Fabijenna/QOwnNotes
bool NoteHistory::forward() {
    if ((currentIndex < 0) || (currentIndex > lastIndex()) || isEmpty()) {
        return false;
    } else if (currentIndex == lastIndex()) {
        currentIndex = 0;
    } else {
        currentIndex++;
    }

    currentHistoryItem = noteHistory->at(currentIndex);

    // check if note still exists, remove item if not
    if (!currentHistoryItem.isNoteValid()) {
        noteHistory->removeAll(currentHistoryItem);
        return forward();
    }

    return true;
}
コード例 #9
0
ファイル: Util.hpp プロジェクト: ghostonline/quaketrace
 inline int findItemInArray(const ArrayView<T>& array, const T& item)
 {
     for (int ii = lastIndex(array); ii >= 0; --ii)
     {
         if (array[ii] == item)
         {
             return ii;
         }
     }
     return -1;
 }
コード例 #10
0
ファイル: sparselib.c プロジェクト: bremond/siconos
int redimensionVector(sparseVector *sparse, int newDim)
{
  int olddim, i;

  olddim = sparse->limit;
  sparse->limit = newDim;
  if(lastIndex(sparse)>newDim) {
    i = sparse->count;
    while(i>0 && sparse->index[i]>newDim) i--;
    sparse->count = i;
    resizeVector(sparse, sparse->count);
  }
  return(olddim);
}
コード例 #11
0
// -----------------------------------------------------------------------------
// CNATTraversalNotIntegrated::FreeResources
// -----------------------------------------------------------------------------
//
void CNATTraversalNotIntegrated::FreeResources( TUint32 aIapId )
    {
    TInt lastIndex( iAsyncRequests.Count() - 1 );
    for ( TInt i = lastIndex; i >= 0; i-- )
	    {
	    TPendingAsyncRequest& request = iAsyncRequests[ i ];
	    if ( request.MatchIapId( aIapId ) )
	        {
    	    iAsyncCompletionTimer->Remove( request.iTimerEntry );
    	    iAsyncRequests.Remove( i );
    	    iAsyncRequests.Compress();
	        }
	    }
    }
コード例 #12
0
void THtmlParser::prepend(int parent, const THtmlParser &parser)
{
    if (parser.elementCount() <= 1)
        return;

    THtmlElement &e = insertNewElement(parent, 0);
    e.tag = parser.at(1).tag;
    e.attributes = parser.at(1).attributes;
    e.text = parser.at(1).text;
    e.selfCloseMark = parser.at(1).selfCloseMark;
    e.tagClosed = parser.at(1).tagClosed;
    int idx = lastIndex();
    for (int i = 0; i < parser.at(1).children.count(); ++i) {
        prepend(idx, parser.mid(parser.at(1).children[i]));
    }
}
コード例 #13
0
    int nthSuperUglyNumber(int n, vector<int>& primes) {
      if(n == 1)
        return 1;
      int size = primes.size();
      vector<int> lastIndex(size, 0);
      vector<int> uglyNumber(n+1, INFINITY);

      uglyNumber[0] = 1;

      for(int i = 1; i < n; i++){ // for kth Ugly Number
        for(int j = 0; j < size; j++)
          uglyNumber[i] = min(uglyNumber[i], uglyNumber[lastIndex[j]] * primes[j]);

        for(int j = 0; j < size; j++)
          if(uglyNumber[i] == uglyNumber[lastIndex[j]] * primes[j])
            lastIndex[j]++;
      }

      return uglyNumber[n-1];
    }
コード例 #14
0
ファイル: zip.cpp プロジェクト: roman313/Doomsday-Engine
void Zip::unlockLump(int lumpIdx)
{
    LOG_AS("Zip::unlockLump");
    LOG_TRACE("\"%s:%s\"") << de::NativePath(composePath()).pretty() << lump(lumpIdx).composePath();

    if(isValidIndex(lumpIdx))
    {
        if(d->lumpCache)
        {
            d->lumpCache->unlock(lumpIdx);
        }
        else
        {
            LOG_DEBUG("LumpCache not in use, ignoring.");
        }
    }
    else
    {
        QString msg = invalidIndexMessage(lumpIdx, lastIndex());
        LOG_DEBUG(msg + ", ignoring.");
    }
}
コード例 #15
0
ファイル: zip.cpp プロジェクト: roman313/Doomsday-Engine
void Zip::clearCachedLump(int lumpIdx, bool* retCleared)
{
    LOG_AS("Zip::clearCachedLump");

    if(retCleared) *retCleared = false;

    if(isValidIndex(lumpIdx))
    {
        if(d->lumpCache)
        {
            d->lumpCache->remove(lumpIdx, retCleared);
        }
        else
        {
            LOG_DEBUG("LumpCache not in use, ignoring.");
        }
    }
    else
    {
        QString msg = invalidIndexMessage(lumpIdx, lastIndex());
        LOG_DEBUG(msg + ", ignoring.");
    }
}
コード例 #16
0
ファイル: textundostack.cpp プロジェクト: letmefly/edbee-lib
/// Returns last textchange on the undo stack
/// @param controller the controller
/// @return the last change (with optional the controller context) 0 if no last change
Change* TextUndoStack::last(TextEditorController* controller)
{
    int idx = lastIndex(controller);
    if( idx < 0 ) { return  0; }
    return at(idx);
}
コード例 #17
0
ファイル: zip.cpp プロジェクト: roman313/Doomsday-Engine
PathTree::Node& Zip::lumpDirectoryNode(int lumpIdx) const
{
    if(!isValidIndex(lumpIdx)) throw NotFoundError("Zip::lumpDirectoryNode", invalidIndexMessage(lumpIdx, lastIndex()));
    d->buildLumpNodeLut();
    return *((*d->lumpNodeLut)[lumpIdx]);
}
コード例 #18
0
ファイル: zip.cpp プロジェクト: roman313/Doomsday-Engine
File1& Zip::lump(int lumpIdx)
{
    LOG_AS("Zip");
    if(!isValidIndex(lumpIdx)) throw NotFoundError("Zip::lump", invalidIndexMessage(lumpIdx, lastIndex()));
    d->buildLumpNodeLut();
    return *reinterpret_cast<ZipFile*>((*d->lumpNodeLut)[lumpIdx]->userPointer());
}
コード例 #19
0
ファイル: zip.cpp プロジェクト: roman313/Doomsday-Engine
uint8_t const* Zip::cacheLump(int lumpIdx)
{
    LOG_AS("Zip::cacheLump");

    if(!isValidIndex(lumpIdx)) throw NotFoundError("Zip::cacheLump", invalidIndexMessage(lumpIdx, lastIndex()));

    ZipFile& file = reinterpret_cast<ZipFile&>(lump(lumpIdx));
    LOG_TRACE("\"%s:%s\" (%u bytes%s)")
            << de::NativePath(composePath()).pretty()
            << de::NativePath(file.composePath()).pretty()
            << (unsigned long) file.info().size
            << (file.info().isCompressed()? ", compressed" : "");

    // Time to create the cache?
    if(!d->lumpCache)
    {
        d->lumpCache = new LumpCache(lumpCount());
    }

    uint8_t const* data = d->lumpCache->data(lumpIdx);
    if(data) return data;

    uint8_t* region = (uint8_t*) Z_Malloc(file.info().size, PU_APPSTATIC, 0);
    if(!region) throw Error("Zip::cacheLump", QString("Failed on allocation of %1 bytes for cache copy of lump #%2").arg(file.info().size).arg(lumpIdx));

    readLump(lumpIdx, region, false);
    d->lumpCache->insert(lumpIdx, region);

    return region;
}