string::iterator string::insert(iterator pos, const string &s, size_type b, size_type e)
{
    if ( e == b )
        return pos;
    
    if ( pos == end() )
        return append(s, b, e).end();
    
    __base::size_type bb = s.to_byte_size(b);
    __base::size_type be = s.to_byte_size(b, e);
    
    if ( bb == npos )
        throw std::range_error("Position to copy from inserted string out of range");
    
    auto first = s._base.begin()+bb;
    auto last = (be == npos ? s._base.end() : s._base.begin()+be);
    
#if CXX11_STRING_UNAVAILABLE
    _base.insert(pos.base(), first, last);
    return iterator(pos + utf32_distance(first, last));
#else
    __base::iterator inserted(_base.insert(pos.base(), first, last));
    return iterator(inserted, _base.begin(), _base.end());
#endif
}
Ejemplo n.º 2
0
void testOrdLst()
{
	OrdList<char> lst0;
	auto lst1 = lst0.inserted('m');
	print(lst1);
	auto lst2 = lst1.inserted('p');
	print(lst2);
	auto lst3 = lst2.inserted('c');
	auto lst4 = lst1.inserted('d');
	auto lst5 = lst1.inserted('e');
	std::cout << "Merging\n";
	print(lst3);
	print(lst5);
	auto lst = merged(lst3, lst5);
	print(lst);
}
Ejemplo n.º 3
0
void ViBufferStream::insert(qint64 position, const char *data, int length)
{
    QMutexLocker streamLocker(&mStreamMutex);
    mBuffer->insert(position, data, length);
    streamLocker.unlock();
    inserted(position, length);
}
Ejemplo n.º 4
0
void ViBufferStream::insert(qint64 position, const ViBufferChunk &chunk)
{
    QMutexLocker streamLocker(&mStreamMutex);
    mBuffer->insert(position, chunk);
    streamLocker.unlock();
    inserted(position, chunk.size());
}
string::iterator string::insert(iterator pos, size_type n, char16_t c)
{
    if ( n == 0 )
        return pos;
    if ( pos == end() )
        return append(n, c).end();
    
    auto utf8 = _Convert<char16_t>::toUTF8(c);
    if ( utf8.size() == 1 )
    {
#if CXX11_STRING_UNAVAILABLE
        _base.insert(pos.base(), n, utf8[0]);
        return iterator(pos + n);
#else
        __base::iterator inserted(_base.insert(pos.base(), n, utf8[0]));
        return iterator(inserted, _base.begin(), _base.end());
#endif
    }
    
    decltype(utf8) buf;
    buf.reserve(n*utf8.size());
    
    for ( size_type i = 0; i < n; i++ )
        buf.append(utf8);
#if CXX11_STRING_UNAVAILABLE
    _base.insert(pos.base(), buf.begin(), buf.end());
    return iterator(pos + n);
#else
    auto inserted = _base.insert(pos.base(), buf.begin(), buf.end());
    return iterator(inserted, _base.begin(), _base.end());
#endif
}
Ejemplo n.º 6
0
void matrixEnter::accept(){
    QString help;
    int count=0;

    matInfo = matInfo.number(lines);
    matInfo = matInfo.append(",");
    help = help.number(columns);
    matInfo = matInfo.append(help);

    resInfo = resInfo.number(lines);
    resInfo = resInfo.append(",1");

    QList<MaceLineEdit*>::iterator iter = edits.begin();
    while (iter != edits.end()){
        if (fctnCode == 143 && (count%(columns+1) == columns)){
            resInfo = resInfo.append(",");
            dit = *iter;
            resInfo = resInfo.append(dit->text());
        }
        else{
            matInfo = matInfo.append(",");
            dit = *iter;
            matInfo = matInfo.append(dit->text());
        }
        iter++;
        count++;
    }

    this->close();

    emit inserted();
}
Ejemplo n.º 7
0
int ViBuffer::insert(int start, const QByteArray &data)
{
	QMutexLocker locker(&mMutex);
	int newLength = mData->insert(start, data).size();
	locker.unlock();
	emit inserted(start, data.size());
	emit changed();
	return newLength;
}
Ejemplo n.º 8
0
void FctnDialog::agree(){
        ok = true;
        a = line1->text();
        b = line2->text();
        c = line3->text();
        d = line4->text();
        this->close();
        emit inserted();
}
Ejemplo n.º 9
0
int ViBuffer::insert(int start, const ViBufferChunk &data, int length)
{
	QMutexLocker locker(&mMutex);
	int newLength = mData->insert(start, data.constData(), length).size();
	locker.unlock();
	emit inserted(start, length);
	emit changed();
	return newLength;
}
Ejemplo n.º 10
0
bool PopupMenuEditor::qt_emit( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->signalOffset() ) {
    case 0: inserted((QAction*)static_QUType_ptr.get(_o+1)); break;
    case 1: removed((QAction*)static_QUType_ptr.get(_o+1)); break;
    default:
	return QWidget::qt_emit(_id,_o);
    }
    return TRUE;
}
Ejemplo n.º 11
0
int CutPointList::addCutPoint(const CutPoint& point)
{
	int idx = qLowerBound(m_list, point) - m_list.begin();
	
	emit aboutToInsert(idx);
	m_list.insert(idx, point);
	emit inserted(idx);
	
	return idx;
}
string::iterator string::insert(iterator pos, __base::iterator first, __base::iterator last)
{
    if ( first == last )
        return pos;
#if CXX11_STRING_UNAVAILABLE
    _base.insert(pos.base(), first, last);
    return iterator(pos + utf32_distance(first, last));
#else
    __base::iterator inserted(_base.insert(pos.base(), first, last));
    return iterator(inserted, _base.begin(), _base.end());
#endif
}
string::iterator string::insert(iterator pos, const_u4pointer s, size_type e)
{
    if ( e == 0 )
        return pos;
    auto utf8 = _Convert<value_type>::toUTF8(s, 0, e);
#if CXX11_STRING_UNAVAILABLE
    _base.insert(pos.base(), utf8.begin(), utf8.end());
    return iterator(pos + e);
#else
    __base::iterator inserted(_base.insert(pos.base(), utf8.begin(), utf8.end()));
    return iterator(inserted, _base.begin(), _base.end());
#endif
}
string::iterator string::insert(iterator pos, const char16_t* s, size_type e)
{
    if ( e == 0 )
        return pos;
    auto utf8 = _Convert<char16_t>::toUTF8(s, 0, e);
#if CXX11_STRING_UNAVAILABLE
    _base.insert(pos.base(), utf8.begin(), utf8.end());
    return iterator(pos + utf32_distance(utf8.begin(), utf8.end()));
#else
    __base::iterator inserted(_base.insert(pos.base(), utf8.begin(), utf8.end()));
    return iterator(inserted, _base.begin(), _base.end());
#endif
}
Ejemplo n.º 15
0
/*!
  Constructs a new QContactSimSyncer as a child of the given \a parent for SIM storage of the given \a type.
*/
QContactSimSyncer::QContactSimSyncer(const QString &type, QObject *parent)
    : QObject(parent), readState(Idle), mError(NoError), mSimType(type),
    SIMLabelLimit(20), SIMNumberLimit(60),
    SIMListStart(1), SIMListEnd(200), 
    addNameQuery("INSERT INTO contacts (recid, firstname, context) VALUES (:i, :fn, :c)"),
    addNumberQuery("INSERT INTO contactphonenumbers (recid, phone_type, phone_number) VALUES (:i, 1, :pn)"),
    updateNameQuery("UPDATE contacts SET firstname = :fn WHERE recid = :i"),
    updateNumberQuery("UPDATE contactphonenumbers SET phone_number = :pn WHERE recid = :i AND phone_type = 1"),
    removeNameQuery("DELETE FROM contacts WHERE recid = :i"),
    removeNumberQuery("DELETE FROM contactphonenumbers WHERE recid = :i"),
    selectNameQuery("SELECT firstname FROM contacts WHERE recid = :i"),
    selectNumberQuery("SELECT phone_number from contactphonenumbers where recid=:id and phone_type=1"),
    mPhoneBook(0), mSimInfo(0), simValueSpace(0), mReadyTimer(0)
{
    static QUuid u("b63abe6f-36bd-4bb8-9c27-ece5436a5130");
    // construct source for contact data.
    mSource.context = u;
    if (type == "SM")
        mSource.identity = "sim";
    else 
        mSource.identity = type;

    mAccess = new ContactSqlIO(this);

    mPhoneBook = new QPhoneBook( QString(), this );
    mSimInfo = new QSimInfo( QString(), this );

    connect(mPhoneBook, SIGNAL(entries(QString,QList<QPhoneBookEntry>)),
            this, SLOT(updatePhoneBook(QString,QList<QPhoneBookEntry>)));
    connect(mPhoneBook, SIGNAL(limits(QString,QPhoneBookLimits)),
            this, SLOT(updatePhoneBookLimits(QString,QPhoneBookLimits)));

    connect(mSimInfo, SIGNAL(inserted()), this, SLOT(updateSimIdentity()));
    connect(mSimInfo, SIGNAL(removed()), this, SLOT(updateSimIdentity()));

    readState = ReadingId | ReadingLimits | ReadingEntries;

    resetSqlState();

    if (mPhoneBook->storages().contains(mSimType))
        sync();
    else {
        qLog(SimPhoneBook) << mSimType << "start timeout timer and connect to phonebook ready";
        connect(mPhoneBook, SIGNAL(ready()), this, SLOT(sync()));
        mReadyTimer = new QTimer(this);
        mReadyTimer->setSingleShot(true);
        mReadyTimer->setInterval(30000); // 30 seconds
        connect(mReadyTimer, SIGNAL(timeout()), this, SLOT(simInfoTimeout()));
        mReadyTimer->start();
    }
}
Ejemplo n.º 16
0
void
test_CString()
{
    nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());

    // Create table with a single string column.
    (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
                                   "CREATE TABLE test (str STRING)"
                               ));

    // Create statements to INSERT and SELECT the string.
    nsCOMPtr<mozIStorageStatement> insert, select;
    (void)db->CreateStatement(NS_LITERAL_CSTRING(
                                  "INSERT INTO test (str) VALUES (?1)"
                              ), getter_AddRefs(insert));
    (void)db->CreateStatement(NS_LITERAL_CSTRING(
                                  "SELECT str FROM test"
                              ), getter_AddRefs(select));

    // Roundtrip a string through the table, and ensure it comes out as expected.
    static const char sCharArray[] =
        "I'm not a \xff\x00\xac\xde\xbb ASCII string!";
    nsCAutoString inserted(sCharArray, NS_ARRAY_LENGTH(sCharArray) - 1);
    do_check_true(inserted.Length() == NS_ARRAY_LENGTH(sCharArray) - 1);
    {
        mozStorageStatementScoper scoper(insert);
        bool hasResult;
        do_check_true(NS_SUCCEEDED(insert->BindUTF8StringByIndex(0, inserted)));
        do_check_true(NS_SUCCEEDED(insert->ExecuteStep(&hasResult)));
        do_check_false(hasResult);
    }

    {
        nsCAutoString result;

        mozStorageStatementScoper scoper(select);
        bool hasResult;
        do_check_true(NS_SUCCEEDED(select->ExecuteStep(&hasResult)));
        do_check_true(hasResult);
        do_check_true(NS_SUCCEEDED(select->GetUTF8String(0, result)));

        do_check_true(result == inserted);
    }

    (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DELETE FROM test"));
}
Ejemplo n.º 17
0
void
test_ASCIIString()
{
    nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());

    // Create table with a single string column.
    (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
                                   "CREATE TABLE test (str STRING)"
                               ));

    // Create statements to INSERT and SELECT the string.
    nsCOMPtr<mozIStorageStatement> insert, select;
    (void)db->CreateStatement(NS_LITERAL_CSTRING(
                                  "INSERT INTO test (str) VALUES (?1)"
                              ), getter_AddRefs(insert));
    (void)db->CreateStatement(NS_LITERAL_CSTRING(
                                  "SELECT str FROM test"
                              ), getter_AddRefs(select));

    // Roundtrip a string through the table, and ensure it comes out as expected.
    nsCAutoString inserted("I'm an ASCII string");
    {
        mozStorageStatementScoper scoper(insert);
        bool hasResult;
        do_check_true(NS_SUCCEEDED(insert->BindUTF8StringByIndex(0, inserted)));
        do_check_true(NS_SUCCEEDED(insert->ExecuteStep(&hasResult)));
        do_check_false(hasResult);
    }

    nsCAutoString result;
    {
        mozStorageStatementScoper scoper(select);
        bool hasResult;
        do_check_true(NS_SUCCEEDED(select->ExecuteStep(&hasResult)));
        do_check_true(hasResult);
        do_check_true(NS_SUCCEEDED(select->GetUTF8String(0, result)));
    }

    do_check_true(result == inserted);

    (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DELETE FROM test"));
}
Ejemplo n.º 18
0
void main()
{
	testInit();
	std::string init =  "a red black tree walks into a bar "
						"has johnny walker on the rocks "
						"and quickly rebalances itself."
						"A RED BLACK TREE WALKS INTO A BAR "
						"HAS JOHNNY WALKER ON THE ROCKS "
						"AND QUICKLY REBALANCES ITSELF.";
	auto t = inserted(RBTree<char>(), init.begin(), init.end());
	print(t);
	t.assert1();
	std::cout << "Black depth: " << t.countB() << std::endl;
	std::cout << "Member z: " << t.member('z') << std::endl;
	std::for_each(init.begin(), init.end(), [t](char c) 
	{
		if (!t.member(c))
			std::cout << "Error: " << c << " not found\n";
	});
}
Ejemplo n.º 19
0
void PopupMenuEditor::insert( PopupMenuEditorItem * item, int index )
{
    if ( !item )
	return;
    if ( index == -1 ) {
	itemList.append( item );
	if ( isVisible() )
	    currentIndex = itemList.count() - 1;
    } else {
	itemList.insert( index, item );
	if ( isVisible() )
	    currentIndex = index;
    }
    item->m = this;
    if (item->s)
        item->s->parentMenu = this;
    resizeToContents();
    if ( isVisible() && parentMenu )
	parentMenu->update(); // draw arrow in parent menu
    emit inserted( item->action() );
}
Ejemplo n.º 20
0
QString ChangePicture::getpicturepath(){
    QFileDialog* filedialog = new QFileDialog;
    filedialog->setNameFilter("Image files (*.png *.xpm *.jpg)");
    QString path;
    if(filedialog->exec() == QDialog::Accepted) {
        newpictureinsert = true;
        pictureinsert = true;
        path = filedialog->selectedFiles()[0];
        emit inserted();
     } else {
        newpictureinsert = false;
        QMessageBox msg(QMessageBox::Warning,"提示","你沒有選擇任何圖片");
        msg.layout()->setMargin(15);
        msg.layout()->setSpacing(10);
        QFont font;
        font.setPixelSize(15);
        font.setFamily("微軟正黑體");
        msg.setFont(font);
        msg.exec();
     }

    return path;
}
Ejemplo n.º 21
0
void EntitySystem::insertToSystem(Entity *e)
{
   mActives.add(e);
   e->getSystemBits().set(mType);
   inserted(e);
}
Ejemplo n.º 22
0
// get same delaunay triangulation for two facesand draw the triangles
void delaunay2Faces(Mat im0, Mat im1, vector<vector<Point2f> > &triangles0, vector<vector<Point2f> > &triangles1, vector<Point2f> &facepoints0, vector<Point2f> &facepoints1, string name0, string name1)
{
    Rect imFrame(0, 0, im0.cols, im0.rows);
    cout << "imFrame: " << im0.cols << ", " << im0.rows << endl;
    Subdiv2D subdiv2d(imFrame);
    
    // Want to do random insertion of points to be faster -- verify this?
    // So need to keep track of which points have be inserted since we have a fixed set of points to insert
    size_t numFacePoints = facepoints0.size();
    vector<bool> inserted(numFacePoints, false);
    size_t count = 0;
    while(count < numFacePoints)
    {
        size_t idx = count;//rand() % numFacePoints;
        
        // if inserted already, do not re-insert (search for other points)
        if (inserted[idx])
            continue;
        
        inserted[idx] = true;
        
        // else, we can add this point
        count++;
        
        Point2f curPt = facepoints0[idx];
        
        /// locate_point
        int edge0=0, vertex=0;
        subdiv2d.locate(curPt, edge0, vertex);
        
        if(edge0 > 0)
        {
            int edge = edge0;
            do
            {
                Point2f org, dst;
                if( subdiv2d.edgeOrg(edge, &org) > 0 && subdiv2d.edgeDst(edge, &dst) > 0 )
                    ;//line( delaunayIm, org, dst, RED, 1, 1, 0 );
                
                edge = subdiv2d.getEdge(edge, Subdiv2D::NEXT_AROUND_LEFT);
            }
            while(edge != edge0);
        }
        ///
        
        subdiv2d.insert(curPt);
        
        // else triangles will just draw on top of each other
        Mat delaunayIm0 = im0.clone();
        Mat delaunayIm1 = im1.clone();
        
        //drawDelaunayTriangles(im, subdiv2d, RED);
        vector<Vec6f> newTriangles0;
        subdiv2d.getTriangleList(newTriangles0);
        vector<Point2f> triVertices(3), triVertices2(3); // 1 triangle has 3 vertices
        Vec6f triangle;
        
        // clear triangle lists as we are re-populating them
        triangles0.clear();
        triangles1.clear();
        
        for (int k = 0; k < newTriangles0.size(); k++)
        {
            triangle = newTriangles0[k];
            
            // don't accept bad triangles (for some reason getTriangleList generates extra out-of-bound triangles)
            if (triangle[0] >= im0.cols || triangle[2] >= im0.cols || triangle[4] >= im0.cols || triangle[0] < 0 || triangle[2] < 0 || triangle[4] < 0 || triangle[5] < 0 || triangle[1] < 0 || triangle[3] < 0 || triangle[1] > im0.rows || triangle[3] > im0.rows || triangle[5] > im0.rows)
                continue;
            
            // populate vertices of one triangle
            triVertices[0].x = triangle[0];//cvRound(triangle[0]);
            triVertices[0].y = triangle[1];//cvRound(triangle[1]);
            triVertices[1].x = triangle[2];//cvRound(triangle[2]);
            triVertices[1].y = triangle[3];//cvRound(triangle[3]);
            triVertices[2].x = triangle[4];//cvRound(triangle[4]);
            triVertices[2].y = triangle[5];//cvRound(triangle[5]);
            
            // find corresponding vertices/ triangle
            int vert1idx = getFPindex(facepoints0, triangle[0], triangle[1]);
            int vert2idx = getFPindex(facepoints0, triangle[2], triangle[3]);
            int vert3idx = getFPindex(facepoints0, triangle[4], triangle[5]);
            triVertices2[0].x = facepoints1[vert1idx].x;
            triVertices2[0].y = facepoints1[vert1idx].y;
            triVertices2[1].x = facepoints1[vert2idx].x;
            triVertices2[1].y = facepoints1[vert2idx].y;
            triVertices2[2].x = facepoints1[vert3idx].x;
            triVertices2[2].y = facepoints1[vert3idx].y;
            
            // update trianglelists with acceptable triangles
            triangles0.push_back(triVertices);
            triangles1.push_back(triVertices2);
            
            // draw face0's triangles
            line(delaunayIm0, Point(triVertices[0].x, triVertices[0].y),
                 Point(triVertices[1].x, triVertices[1].y), GREEN);
            line(delaunayIm0, Point(triVertices[1].x, triVertices[1].y),
                 Point(triVertices[2].x, triVertices[2].y), GREEN);
            line(delaunayIm0, Point(triVertices[2].x, triVertices[2].y),
                 Point(triVertices[0].x, triVertices[0].y), GREEN);
            
            // draw face1's triangles
            line(delaunayIm1, Point(triVertices2[0].x, triVertices2[0].y),
                 Point(triVertices2[1].x, triVertices2[1].y), GREEN);
            line(delaunayIm1, Point(triVertices2[1].x, triVertices2[1].y),
                 Point(triVertices2[2].x, triVertices2[2].y), GREEN);
            line(delaunayIm1, Point(triVertices2[2].x, triVertices2[2].y),
                 Point(triVertices2[0].x, triVertices2[0].y), GREEN);
        }
        delaunayIm_0 = delaunayIm0.clone();
        delaunayIm_1 = delaunayIm1.clone();
    }
}
Ejemplo n.º 23
0
/*!
  \internal

  Construct a new CellModemManager with the appropriate \a parent.  Only one
  instance of CellModemManager may be constructed.
 */
CellModemManager::CellModemManager(QObject *parent)
: QAbstractCallPolicyManager(parent), d(new CellModemManagerPrivate)
{
    Q_ASSERT(!cellModemManagerInstance);
    cellModemManagerInstance = true;

    d->m_status = new QValueSpaceObject("/Telephony/Status", this);
    d->m_status->setAttribute("ModemStatus", "Initializing");

    QValueSpaceItem *simToolkitAvailable;
    simToolkitAvailable = new QValueSpaceItem
            ("/Telephony/Status/SimToolkit/Available", this);
    connect(simToolkitAvailable, SIGNAL(contentsChanged()),
            this, SLOT(simToolkitAvailableChange()));

    // Check for modem
    QServiceChecker checker("modem");
    if(!checker.isValid()) {
        d->m_aerialOn = false;
        d->m_state = NoCellModem;
        updateStatus();
        return;
    }

    d->m_netReg = new QNetworkRegistration("modem", this);
    d->m_regState = d->m_netReg->registrationState();
    d->m_operator = d->m_netReg->currentOperatorName();

    QObject::connect(d->m_netReg, SIGNAL(registrationStateChanged()),
                     this, SLOT(registrationStateChanged()));
    QObject::connect(d->m_netReg, SIGNAL(currentOperatorChanged()),
                     this, SLOT(currentOperatorChanged()));

    // Rename signal for QAbstractCallPolicyManager.
    QObject::connect(this, SIGNAL(registrationStateChanged(QTelephony::RegistrationState)),
                     this, SIGNAL(registrationChanged(QTelephony::RegistrationState)));

    d->m_pinManager = new QPinManager("modem", this);
    QObject::connect(d->m_pinManager,
                     SIGNAL(pinStatus(QString,QPinManager::Status,QPinOptions)),
                     this,
                     SLOT(pinStatus(QString,QPinManager::Status,QPinOptions)) );

    d->m_rfFunc = new QPhoneRfFunctionality("modem", this);
    QObject::connect(d->m_rfFunc,
                     SIGNAL(levelChanged()), this, SLOT(rfLevelChanged()));

    d->m_callForwarding = new QCallForwarding("modem", this);
    QObject::connect(d->m_callForwarding,
                     SIGNAL(forwardingStatus(QCallForwarding::Reason,QList<QCallForwarding::Status>)),
                     this,
                     SLOT(forwardingStatus(QCallForwarding::Reason,QList<QCallForwarding::Status>)));

    QSimInfo *simInfo = new QSimInfo( "modem", this );
    connect( simInfo, SIGNAL(removed()), this, SLOT(simRemoved()) );
    connect( simInfo, SIGNAL(inserted()), this, SLOT(simInserted()) );

    if(::profilesControlModem) {
        d->m_profiles = new QPhoneProfileManager(this);
        d->m_aerialOn = !d->m_profiles->planeMode();
        QObject::connect(d->m_profiles, SIGNAL(planeModeChanged(bool)),
                         this, SLOT(planeModeChanged(bool)));
    }

    // If plane mode isn't an option, then we have to fully initialize the modem
    // each time
    if(!planeModeSupported())
        d->m_aerialOn = true;

    setAerialEnabled(d->m_aerialOn);
    updateStatus();

    doInitialize();
}
Ejemplo n.º 24
0
int acceleratet::accelerate_loop(goto_programt::targett &loop_header)
{
  pathst loop_paths, exit_paths;
  goto_programt::targett back_jump=find_back_jump(loop_header);
  int num_accelerated=0;
  std::list<path_acceleratort> accelerators;
  natural_loops_mutablet::natural_loopt &loop =
    natural_loops.loop_map[loop_header];

  if(contains_nested_loops(loop_header))
  {
    // For now, only accelerate innermost loops.
#ifdef DEBUG
    std::cout << "Not accelerating an outer loop\n";
#endif
    return 0;
  }

  goto_programt::targett overflow_loc;
  make_overflow_loc(loop_header, back_jump, overflow_loc);
  program.update();

#if 1
  enumerating_loop_accelerationt
    acceleration(
      symbol_table,
      goto_functions,
      program,
      loop,
      loop_header,
      accelerate_limit);
#else
  disjunctive_polynomial_accelerationt
    acceleration(symbol_table, goto_functions, program, loop, loop_header);
#endif

  path_acceleratort accelerator;

  while(acceleration.accelerate(accelerator) &&
        (accelerate_limit < 0 ||
         num_accelerated < accelerate_limit))
  {
    // set_dirty_vars(accelerator);

    if(is_underapproximate(accelerator))
    {
      // We have some underapproximated variables -- just punt for now.
#ifdef DEBUG
      std::cout << "Not inserting accelerator because of underapproximation\n";
#endif

      continue;
    }

    accelerators.push_back(accelerator);
    num_accelerated++;

#ifdef DEBUG
    std::cout << "Accelerated path:\n";
    output_path(accelerator.path, program, ns, std::cout);

    std::cout << "Accelerator has "
              << accelerator.pure_accelerator.instructions.size()
              << " instructions\n";
#endif
  }

  goto_programt::instructiont skip(SKIP);
  program.insert_before_swap(loop_header, skip);

  goto_programt::targett new_inst=loop_header;
  ++new_inst;

  loop.insert(new_inst);


  std::cout << "Overflow loc is " << overflow_loc->location_number << '\n';
  std::cout << "Back jump is " << back_jump->location_number << '\n';

  for(std::list<path_acceleratort>::iterator it=accelerators.begin();
      it!=accelerators.end();
      ++it)
  {
    subsumed_patht inserted(it->path);

    insert_accelerator(loop_header, back_jump, *it, inserted);
    subsumed.push_back(inserted);
    num_accelerated++;
  }

  return num_accelerated;
}
Ejemplo n.º 25
0
void SCardReader::run()
{
    SCARDCONTEXT context;
    SCARDHANDLE cardHandle;
    DWORD activeProtocol;
    DWORD oldEventState;
    LONG erv;

    erv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &context);
    if (SCARD_S_SUCCESS == erv)
    {
        LONG crv;

        crv = SCardConnect(context, (LPCSTR) m_name, SCARD_SHARE_SHARED,
                          SCARD_PROTOCOL_T0, &cardHandle, &activeProtocol);
        do
        {
            if (SCARD_S_SUCCESS == crv)
            {
                SCARD_IO_REQUEST ioRecvPci;
                BYTE recvBuffer[32];
                BYTE sendBuffer[] = {0xFF, 0xCA, 0x00, 0x00, 0x00};
                DWORD recvLength = sizeof(recvBuffer);
                LONG trv;

                trv = SCardTransmit(cardHandle, SCARD_PCI_T0, sendBuffer, sizeof(sendBuffer),&ioRecvPci, recvBuffer, &recvLength);
                if (SCARD_S_SUCCESS == trv)
                {
                    if (recvLength == 6 && recvBuffer[4] == 0x90 && recvBuffer[5] == 0x00)
                        m_cardid = (int)recvBuffer[0] | (int)recvBuffer[1] << 8 | (int)recvBuffer[2] << 16 | (int)recvBuffer[3] << 24;

                    std::cout <<  m_cardid  <<  " card inserted." << std::endl;

                    if (m_mode == TallyMode) // m_mode(DriverMode)  初始化为DriverMode
                    {
                        //load authentication key
                        recvLength = sizeof(recvBuffer);
                        BYTE loadKey[] = {0xFF, 0x82, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
                        trv = SCardTransmit(cardHandle, SCARD_PCI_T0, loadKey, sizeof(loadKey), &ioRecvPci, recvBuffer, &recvLength);
                        if (SCARD_S_SUCCESS == trv && recvLength == 2 && recvBuffer[0] == 0x90 && recvBuffer[1] == 0x00)
                        {
                            //authentication key
                            recvLength = sizeof(recvBuffer);
                            BYTE authentication[] = {0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, 0x08, 0x60, 0x00};
                            trv = SCardTransmit(cardHandle, SCARD_PCI_T0, authentication, sizeof(authentication), &ioRecvPci, recvBuffer, &recvLength);
                            if (SCARD_S_SUCCESS == trv && recvLength == 2 && recvBuffer[0] == 0x90 && recvBuffer[1] == 0x00)
                            {
                                //read binary
                                recvLength = sizeof(recvBuffer);
                                BYTE read[] = {0xFF, 0xB0, 0x00, 0x08, 0x10};
                                trv = SCardTransmit(cardHandle, SCARD_PCI_T0, read, sizeof(read), &ioRecvPci, recvBuffer, &recvLength);
                                if (SCARD_S_SUCCESS == trv && recvLength == 18 && recvBuffer[16] == 0x90 && recvBuffer[17] == 0x00)
                                {
                                    QByteArray array((const char *)recvBuffer, 16);
                                    emit dataReady(QString::number(m_cardid), array);
                                }
                                else
                                    std::cerr << m_name << " : " << pcsc_stringify_error(trv) << std::endl;
                            }
                            else
                                std::cerr << m_name << " : " << pcsc_stringify_error(trv) << std::endl;
                        }
                        else
                            std::cerr << m_name << " : " << pcsc_stringify_error(trv) << std::endl;
                    }
                    else
                        emit inserted(QString::number(m_cardid));
                }
                else if (SCARD_E_NO_SMARTCARD == trv)
                    std::cerr << m_name << " : " << pcsc_stringify_error(trv) << std::endl;
                else
                {
                    std::cerr << m_name << " : " << pcsc_stringify_error(trv) << std::endl;
                    break;
                }

                (void) SCardDisconnect(cardHandle, SCARD_RESET_CARD);
            }

            if (SCARD_S_SUCCESS == crv || SCARD_E_NO_SMARTCARD == crv)
            {
                SCARD_READERSTATE readerStates;
                LONG grv;

                readerStates.szReader = m_name;
                readerStates.dwCurrentState = SCARD_STATE_UNAWARE;
                grv = SCardGetStatusChange(context, INFINITE, &readerStates, 1);
                oldEventState = readerStates.dwEventState;

                do
                {
                    if (SCARD_S_SUCCESS == grv)
                    {
                        if (readerStates.dwEventState != oldEventState)
                        {
                            //card inserted
                            if  ((SCARD_STATE_CHANGED & readerStates.dwEventState) && (SCARD_STATE_PRESENT & readerStates.dwEventState))
                                break;

                            //card removed
                            if ((SCARD_STATE_CHANGED & readerStates.dwEventState) && (SCARD_STATE_EMPTY & readerStates.dwEventState))
                            {
                                removed(QString::number(m_cardid));
                                std::cout << m_cardid <<  " card removed." << std::endl;
                            }
                        }
                        else
                            QThread::usleep(500);
                    }
                    else if (SCARD_E_TIMEOUT == grv)
                        QThread::sleep(1);
                    else
                        break;

                    oldEventState = readerStates.dwEventState;

                    readerStates.szReader = m_name;
                    readerStates.dwCurrentState = SCARD_STATE_UNAWARE;

                    grv = SCardGetStatusChange(context, INFINITE, &readerStates, 1);

                } while (true);

                //quit if fatal error occurs
                if (SCARD_S_SUCCESS != grv)
                    break;
            }
            else
            {
                std::cerr << m_name << " : " << pcsc_stringify_error(crv) << std::endl;
                break;
            }

            crv = SCardConnect(context, (LPCSTR) m_name, SCARD_SHARE_SHARED,
                              SCARD_PROTOCOL_T0, &cardHandle, &activeProtocol);

        } while(true);
    }
    else
        std::cerr << m_name << " : " << pcsc_stringify_error(erv) << std::endl;

    std::cout << m_name << " deamon thread has exit." << std::endl;
}
Ejemplo n.º 26
0
void EntitySystem::insertToSystem(Entity *par_entity)
{
    m_entitys.set(par_entity->m_id, par_entity);
    inserted(par_entity);
}
Ejemplo n.º 27
0
// -------------------------------------------------------------------------- //
void gradLimiting2D(
    int                        nSimplex,
    std::vector<std::array<double,3>>                 &Vertex,
    std::vector<std::vector<int>>                 &Simplex,
    std::vector<std::vector<int>>                 &Adjacency,
    std::vector<double>                 &val,
    double                     g
) {

// ========================================================================== //
// void gradLimiting2D(                                        //
//     int                        nSimplex,                                   //
//     dvector2D                 &Vertex,                                     //
//     std::vector<std::vector<int>>                 &Simplex,                                    //
//     std::vector<std::vector<int>>                 &Adjacency,                                  //
//     std::vector<double>                 &val,                                        //
//     double                     g)                                          //
//                                                                            //
// Solve the 2D grad-limiting equation, using a fast marching method over     //
// a 2D domain.                                                               //
// ========================================================================== //
// INPUT                                                                      //
// ========================================================================== //
// - nSimplex       : int, number of simplicies in volume tasselation         //
// - Vertex         : dvector2D, vertex coordinate list. Vertex[i][0],        //
//                    Vertex[i][1], ... are the x, y, ... coordinates of the  //
//                    cell center of the i-th simplex                         //
// - Simplex        : std::vector<std::vector<int>>, simplex-vertex connectivity                  //
// - Adjacency      : std::vector<std::vector<int>>, simplex-simplex adjacency                    //
// - val            : std::vector<double>, field to be smoothed                         //
// - g              : double, max gradient.                                   //
// ========================================================================== //
// OUTPUT                                                                     //
// ========================================================================== //
// - none                                                                     //
// ========================================================================== //

// ========================================================================== //
// VARIABLES DECLARATION                                                      //
// ========================================================================== //

// Local variables
int                                 idummy;
double                              ddummy;
std::vector<bool>                   inserted(nSimplex, false);
std::vector< std::array<int,2> >    map(nSimplex), *map_ = &map;
bitpit::MinPQueue<double, int>      heap(nSimplex, true, map_);

// Counters
int                                 j, k;
int                                 T, A;
int                                 m;

for (T = 0; T < nSimplex; T++) {
        map[T].fill(0.) ;
};

// ========================================================================== //
// BUILD MIN HEAP                                                             //
// ========================================================================== //

// Initialize data structure for min heap ----------------------------------- //
k = 0;
for (T = 0; T < nSimplex; T++) {
    if (!inserted[T]) {

        // Update mapper
        map[k][0] = T;
        map[T][1] = k;

        // Insert vertex into min-heap
        idummy = T;
        heap.insert(val[T], idummy);

        // Update flag & counters
        k++;
        inserted[T] = true;
    }
} //next T

// ========================================================================== //
// FAST GRADIENT LIMITING                                                     //
// ========================================================================== //
while (heap.heap_size > 0) {

    // Extract root from min heap
    heap.extract(ddummy, idummy);

    // Update value for extracted item
    T = idummy;
    inserted[T] = false;

    // Update value for neighboring vertices
    m = Adjacency[T].size();
    for (j = 0; j < m; ++j) {
        A = Adjacency[T][j];
        if (inserted[A]) {
            val[A] = grad2DUpdate(nSimplex, Vertex, Simplex, Adjacency, val, A, g, inserted);
            idummy = A;
            heap.modify(map[A][1], val[A], idummy);
        };
    } //next j
} //next item

}
Ejemplo n.º 28
0
// -------------------------------------------------------------------------- //
void gradLimiting2D(
    int                        nSimplex,
    std::vector<std::array<double,3>>                 &Vertex,
    std::vector<std::vector<int>>                 &Simplex,
    std::vector<double>                 &val,
    double                     g
) {

// ========================================================================== //
// void gradLimiting2D(                                        //
//     int                        nSimplex,                                   //
//     dvector2D                 &Vertex,                                     //
//     std::vector<std::vector<int>>                 &Simplex,                                    //
//     std::vector<double>                 &val,                                        //
//     double                     g)                                          //
//                                                                            //
// Solve the 2D grad-limiting equation, using a fast marching method over     //
// a 2D manifold immersed in a 3D Euclidean space.                            //
// ========================================================================== //
// INPUT                                                                      //
// ========================================================================== //
// - nSimplex       : int, number of simplicies in surface tasselation        //
// - Vertex         : dvector2D, vertex coordinate list. Vertex[i][0],        //
//                    Vertex[i][1], ... are the x, y, ... coordinates of the  //
//                    i-th vertex                                             //
// - Simplex        : std::vector<std::vector<int>>, simplex-vertex connectivity                  //
// - val            : std::vector<double>, field to be smoothed                         //
// - g              : double, max gradient.                                   //
// ========================================================================== //
// OUTPUT                                                                     //
// ========================================================================== //
// - none                                                                     //
// ========================================================================== //

// ========================================================================== //
// VARIABLES DECLARATION                                                      //
// ========================================================================== //

// // Local variables
int                                 nVertex = Vertex.size();
double                              ddummy;
std::vector<bool>                   inserted(nVertex, false);
std::vector<int>                           idummy1D(2, -1);
std::vector<std::vector<std::vector<int>>>  Ring1(nVertex);
std::vector< std::array<int,2> >            map(nVertex), *map_ = &map;
bitpit::MinPQueue<double, std::vector<int>>        heap(nVertex, true, map_);

// // Counters
size_t                              j;
int                                 i, k;
int                                 T, V, A, W;
int                                 m;

for (V = 0; V < nVertex; V++) {
        map[V].fill(0.) ;
};

// ========================================================================== //
// BUILD 1-RING OF VERTICES                                                   //
// ========================================================================== //
for (T = 0; T < nSimplex; T++) {
    m = Simplex[T].size();
    for (i = 0; i < m; ++i) {
        V = Simplex[T][i];
        idummy1D[0] = T;
        idummy1D[1] = i;
        Ring1[V].push_back(idummy1D);
    } //next i
} //next T

// ========================================================================== //
// BUILD MIN HEAP                                                             //
// ========================================================================== //

// Initialize data structure for min heap ----------------------------------- //
k = 0;
for (T = 0; T < nSimplex; T++) {
    m = Simplex[T].size();
    for (i = 0; i < m; i++) {
        V = Simplex[T][i];
        if (!inserted[V]) {

            // Update mapper
            map[k][0] = V;
            map[V][1] = k;

            // Insert vertex into min-heap
            idummy1D[0] = T;
            idummy1D[1] = i;
            heap.insert(val[V], idummy1D);

            // Update flag & counters
            k++;
            inserted[V] = true;
        }
    } //next i
} //next T

// ========================================================================== //
// FAST GRADIENT LIMITING                                                     //
// ========================================================================== //
while (heap.heap_size > 0) {

    // Extract root from min heap
    heap.extract(ddummy, idummy1D);

    // Update value for extracted item
    T = idummy1D[0];
    i = idummy1D[1];
    V = Simplex[T][i];
    inserted[V] = false;

    // Update value for neighboring vertices
    for (j = 0; j < Ring1[V].size(); ++j) {
        A = Ring1[V][j][0];
        k = Ring1[V][j][1];
        m = (k - 1 + Simplex[A].size()) % Simplex[A].size();
        W = Simplex[A][m];
        if (inserted[W]) {
            val[W] = grad2DUpdate(nSimplex, Vertex, Simplex, Ring1, val, A, m, g, inserted);
            idummy1D[0] = A;
            idummy1D[1] = m;
            heap.modify(map[W][1], val[W], idummy1D);
        };
        m = (k + 1) % Simplex[A].size();
        W = Simplex[A][m];
        if (inserted[W]) {
            val[W] = grad2DUpdate(nSimplex, Vertex, Simplex, Ring1, val, A, m, g, inserted);
            idummy1D[0] = A;
            idummy1D[1] = m;
            heap.modify(map[W][1], val[W], idummy1D);
        }
    } //next j
} //next item

}
Ejemplo n.º 29
0
// -------------------------------------------------------------------------- //
void gradLimiting1D(
    int                        nSimplex,
    std::vector<std::array<double,3>>                 &Vertex,
    std::vector<std::vector<int>>                 &Simplex,
    std::vector<std::vector<std::vector<int>>>                 &Adjacency,
    std::vector<double>                 &val,
    double                     g
) {

// ========================================================================== //
// void gradLimiting1D(                                        //
//     int                        nSimplex,                                   //
//     dvector2D                 &Vertex,                                     //
//     std::vector<std::vector<int>>                 &Simplex,                                    //
//     std::vector<std::vector<std::vector<int>>>                 &Adjacency,                                  //
//     std::vector<double>                 &val,                                        //
//     double                     g)                                          //
//                                                                            //
// Solve the 1D gradient limiting equation onto a 1D manifold in a 2D ,       //
// Euclidean space, using fast marching method.                               //
// ========================================================================== //
// INPUT                                                                      //
// ========================================================================== //
// - nSimplex  : int, number of simplicies                                    //
// - Vertex    : std::vector<double>, vertex coordinate list. Vertex[i][0],             //
//               Vertex[i][1] are the x, y, coordinates of the i-th vertex    //
// - Simplex   : std::vector<std::vector<int>>, simplex-vertex connectivity. Simplex[i][0] and    //
//               Simplex[i][1] are the global indices of vertices of the i-th //
//               segment.                                                     //
// - Adjacency : std::vector<std::vector<std::vector<int>>>, simplex-simplex adjacency. Adjacency[i][j] stores //
//               the global indices of all simplicies adjacenct to the i-th   //
//               simplex at vertex Simplex[i][j].                             //
// - val       : std::vector<double>, with scalar field to be limited.                  //
// - g         : double, max slope value.                                     //
// ========================================================================== //
// OUTPUT                                                                     //
// ========================================================================== //
// - none                                                                     //
// ========================================================================== //

// ========================================================================== //
// VARIABLES DECLARATION                                                      //
// ========================================================================== //

// Local variables
int                                   nVertex = Vertex.size();
double                                ddummy;
std::vector<bool>                     inserted(nVertex, false);
std::vector<int>                             idummy1D(2, -1);
// array<int,2>                          idummy1D;
// std::vector<std::vector<int>>         map(nVertex, std::vector<int>(2, -1)), *map_ = &map;
std::vector< std::array<int,2> >      map(nVertex), *map_ = &map;
bitpit::MinPQueue<double, std::vector<int>>  heap(nVertex, true, map_);

// Counters
int                                 i, j, k;
int                                 T, V, A, W;
int                                 m;

for (V = 0; V < nVertex; V++) {
    map[V].fill(0.) ;
};

// ========================================================================== //
// BUILD MIN HEAP                                                             //
// ========================================================================== //

// Initialize data structure for min heap ----------------------------------- //
k = 0;
for (T = 0; T < nSimplex; T++) {
    m = Simplex[T].size();
    for (i = 0; i < m; i++) {
        V = Simplex[T][i];
        if (!inserted[V]) {

            // Update mapper
            map[k][0] = V;
            map[V][1] = k;

            // Insert vertex into min-heap
            idummy1D[0] = T;
            idummy1D[1] = i;
            heap.insert(val[V], idummy1D);

            // Update flag & counters
            k++;
            inserted[V] = true;
        }
    } //next i
} //next T

// ========================================================================== //
// FAST GRADIENT LIMITING                                                     //
// ========================================================================== //
while (heap.heap_size > 0) {

    // Extract root from min heap
    heap.extract(ddummy, idummy1D);

    // Update value for extracted item
    T = idummy1D[0];
    i = idummy1D[1];
    V = Simplex[T][i];
    inserted[V] = false;

    // Update value for neighbors
    j = (i + 1) % Simplex[T].size();
    W = Simplex[T][j];
    if (inserted[W]) {
        val[W] = grad1DUpdate(nSimplex, Vertex, Simplex, Adjacency, val, T, j, g, inserted);
        idummy1D[0] = T;
        idummy1D[1] = j;
    }
    if (Adjacency[T][i][0] >= 0) {
        m = Adjacency[T][i].size();
        for (k = 0; k < m; k++) {
            A = Adjacency[T][i][k];
            j = 0;
            if (Simplex[A][0] == V) { j = 1; }
            W = Simplex[A][j];
            if (inserted[W]) {
                val[W] = grad1DUpdate(nSimplex, Vertex, Simplex, Adjacency, val, A, j, g, inserted);
                idummy1D[0] = A;
                idummy1D[1] = j;
                heap.modify(map[W][1], val[W], idummy1D);
            }
        } //next k
    }
} //next item

}
Ejemplo n.º 30
0
    pair<vector<unsigned long>,vector<unsigned long>> SeqGraphAlignment::alignStringToGraphFast() {
        //if (typeid(sequence).name() != "string") {
        //    cerr << "Invalid Type" << endl;
        //    return;
        //}

        unsigned long l1 = graph->numberOfNodes;
        unsigned long l2 = sequence.length();

        unordered_map<unsigned long, unsigned long> nodeIDtoIndex;
        unordered_map<unsigned long, unsigned long> nodeIndexToID;
        nodeIndexToID[-1] = (unsigned long) -1;

        auto nodes = graph->nodes;
        unsigned long index = 0;
        for (auto nodeID : graph->nodeOrder) {
            nodeIDtoIndex[nodeID] = index;
            nodeIndexToID[index] = nodeID;
            index++;
        }
//        for (map<int, Node *>::iterator it = nodes.begin(); it != nodes.end(); it++) {
//            nodeIDtoIndex[it->second->ID] = it->first;
//            nodeIndexToID[it->first] = it->second->ID;
//        }

        vector<vector<long>> scores(l1 + 1, vector<long>(l2 + 1));

        if (globalAlign) {
            for (int i = 1; i < l2 + 1; i++) {
                scores[0][i] = openGapValue + (i - 1) * extendGapValue;
            }

            nodes = graph->nodes;

            index = 0;
            for (auto nodeID : graph->nodeOrder) {
                auto mIter = graph->nodes[nodeID];
                auto prevIndexs = prevIndices(mIter, nodeIDtoIndex);

                scores[0][0] = openGapValue - extendGapValue;
                long best = scores[prevIndexs.front() + 1][0];

                for (auto lIter = prevIndexs.begin(); lIter != prevIndexs.end(); lIter++) {
                    best = max(best, scores[*lIter + 1][0]);
                }

                scores[index + 1][0] = best + extendGapValue;
                scores[0][0] = 0;
                index++;
            }
        }

        vector<vector<unsigned long>> backStrIdx(l1 + 1, vector<unsigned long>(l2 + 1));
        vector<vector<unsigned long>> backGrphIdx(l1 + 1, vector<unsigned long>(l2 + 1));

        vector<char> seqvec;
        copy(sequence.begin(), sequence.end(), back_inserter(seqvec));

        vector<vector<long>> insertCost(l1 + 1, vector<long>(l2 + 1, this->openGapValue));
//        memset(*insertCost, this->openGapValue, sizeof (int) * (l1+1) * (l2+1));
        vector<vector<long>> deleteCost(l1 + 1, vector<long>(l2 + 1, this->openGapValue));
//        memset(deleteCost, this->openGapValue, sizeof (int) * (l1+1) * (l2+1));
//        fill(&insertCost[0][0], &insertCost[l1][l2], this->openGapValue);
//        fill(&deleteCost[0][0], &deleteCost[l1][l2], this->openGapValue);
        vector<bool> inserted(l2 + 1, false);
        vector<long> insertScore(l2 + 2, 0);

        char gbase;
        vector<unsigned long> predecessors;
        vector<long> matchPoints, deleteScore(l2), matchScore(l2);
        vector<unsigned long> bestDelete(l2), bestMatch(l2);
        vector<bool> deleted;

        index = 0;
        for (auto nodeID : graph->nodeOrder) {
            auto it = nodes[nodeID];
            gbase = it->base;
            predecessors = prevIndices(it, nodeIDtoIndex);
            matchPoints = matchScoreVec(gbase, seqvec);

            deleteScore.clear();
            for (int j = 1; j < l2 + 1; j++) {
                deleteScore.push_back(scores[predecessors.front() + 1][j] + deleteCost[predecessors.front() + 1][j]);
                matchScore[j - 1] = scores[predecessors.front() + 1][j - 1] + matchPoints[j - 1];
            }
            auto fill_value = predecessors.front() + 1;
            fill(bestDelete.begin(), bestDelete.end(), fill_value);
            fill(bestMatch.begin(), bestMatch.end(), fill_value);

            for (auto it2 = next(predecessors.begin()); it2 != predecessors.end(); it2++) {

                vector<long> newDeleteScore;
                vector<long> newMatchScore;
                for (int j = 1; j < l2 + 1; j++) {
                    newDeleteScore.push_back(scores[*it2 + 1][j] + deleteCost[*it2 + 1][j]);
                    newMatchScore.push_back(scores[*it2 + 1][j - 1] + matchPoints[j - 1]);
                }
                for (int i = 0; i < l2; i++) {
                    bestDelete[i] = newDeleteScore[i] > deleteScore[i] ? *it2 + 1 : bestDelete[i];
                    bestMatch[i] = newMatchScore[i] > matchScore[i] ? *it2 + 1 : bestMatch[i];
                }

                for (int i = 0; i < l2; i++) {
                    deleteScore[i] = max(newDeleteScore[i], deleteScore[i]);
                    matchScore[i] = max(newMatchScore[i], matchScore[i]);
                }
            }

            deleted.clear();
            for (unsigned long i = 0; i < l2; i++) {
                deleted.push_back(deleteScore[i] > matchScore[i]);
            }

            for (unsigned long j = 1; j < l2 + 1; j++) {
                scores[index + 1][j] =
                        deleteScore[j - 1] >= matchScore[j - 1] ? deleteScore[j - 1] : matchScore[j - 1];
                backGrphIdx[index + 1][j] = deleted[j - 1] ? bestDelete[j - 1] : bestMatch[j - 1];
                backStrIdx[index + 1][j] = deleted[j - 1] ? j : j - 1;
                deleteCost[index + 1][j] = deleted[j - 1] ? extendGapValue : deleteCost[index + 1][j];
            }

            //insertions
            fill(inserted.begin(), inserted.end(), false);
            for (int j = 0; j < l2 + 1; j++) {
                insertScore[j] = scores[index + 1][j] + insertCost[index + 1][j];
            }

            for (unsigned long j = 0; j < l2; j++) {
                if (insertScore[j] > scores[index + 1][j + 1]) {
                    scores[index + 1][j + 1] = insertScore[j];
                    insertCost[index + 1][j + 1] = extendGapValue;
                    backStrIdx[index + 1][j + 1] = j;
                    inserted[j + 1] = true;
                    insertScore[j + 1] = scores[index + 1][j + 1] + insertCost[index + 1][j + 1];
                }
            }

            for (int j = 1; j < l2 + 1; j++) {
                if (inserted[j]) {
                    insertCost[index + 1][j] = extendGapValue;
                    deleteCost[index + 1][j] = openGapValue;
                    backGrphIdx[index + 1][j] = index + 1;
                }
            }

            if (!globalAlign) {
                for (int j = 0; j < l2; j++) {
                    backGrphIdx[nodeID + 1][j] = scores[nodeID + 1][j] > 0 ? backGrphIdx[nodeID + 1][j] : (unsigned long) -1;
                    backStrIdx[nodeID + 1][j] = scores[nodeID + 1][j] > 0 ? backStrIdx[nodeID + 1][j] : (unsigned long) -1;
                    scores[nodeID + 1][j] = max(scores[nodeID + 1][j], 0L);
                }
            }
            index++;
        }
        return backTrack(l1, l2, scores, backStrIdx, backGrphIdx, nodeIndexToID);
    }