예제 #1
0
  void Pmr_resource::do_deallocate(void* ptr, std::size_t s, std::size_t a) {
    Expects(s != 0); // POSIX malloc will allow size 0, but return nullptr.
    bool trigger_non_full = UNLIKELY(full() and non_full != nullptr);
    bool trigger_avail_thresh = UNLIKELY(allocatable() < avail_thresh
                                         and allocatable() + s >= avail_thresh
                                         and avail != nullptr);

    pool_->deallocate(ptr,s,a);
    deallocs++;
    used -= s;

    if (UNLIKELY(trigger_avail_thresh)) {
      Ensures(allocatable() >= avail_thresh);
      Ensures(avail != nullptr);
      avail(*this);
    }

    if (UNLIKELY(trigger_non_full)) {
      Ensures(!full());
      Ensures(non_full != nullptr);
      non_full(*this);
    }
  }
예제 #2
0
void QUProfileController::setData(
        quint64 total,
        const std::vector<double> & dataQ,
        const std::vector<double> & dataU)
{
    //    std::vector<double> dataQ = { 1,2,3 };
    //    std::vector<double> dataU= { 3,2,1 };
    //    total = 3;

    // make us a copy of the data
    m_total = total;
    m_dataQ = dataQ;
    m_dataU = dataU;

    // figure out data bounds & calculate means
    m_qmin = m_qmax = m_umin = m_umax = NAN;
    m_meanQ = m_meanU = 0;
    int count = 0;
    for( auto i = 0u ; i < avail() ; i ++) {
        double q = m_dataQ[i];
        if( ! std::isfinite(q)) continue;
        double u = m_dataU[i];
        if( ! std::isfinite(u)) continue;
        if( m_qmin > q || isnan( m_qmin)) m_qmin = q;
        if( m_umin > u || isnan( m_umin)) m_umin = u;
        if( m_qmax < q || isnan( m_qmax)) m_qmax = q;
        if( m_umax < u || isnan( m_umax)) m_umax = u;
        m_meanQ += q;
        m_meanU += u;
        count ++;
    }
    m_meanQ /= count;
    m_meanU /= count;

    // repaint everything
    markDirty();
}
예제 #3
0
/// recalculate and redraw everything that needs it, based on dirty flags
void QUProfileController::redrawAllNow()
{
    dbg(1) << "Redrawing quprofile #" << m_myId
           << " " << m_buffer.width() << "x" << m_buffer.height();

    double dotSize = m_vars.dotSize-> get();

//    bool updateDc = false;

    // helper function to format a double to a string
    auto fmtDouble = [](double x)->QString {
        if( std::isnan(x)) return "nan";
        if( std::isinf(x)) return "inf";
        return QString::number( x, 'g', 6);
    };

    int labelFontHeight = m_labelFontMetrics-> height();

    // apply autozoom
    if( m_autoZoom) {
        m_zoomX1 = m_qmin;
        m_zoomX2 = m_qmax;
        m_zoomY1 = m_umax; // max is at the top
        m_zoomY2 = m_umin;

        // make sure we are displaying something (cannot have x1==x2)
        if( m_zoomX2 - m_zoomX1 < 1e-9) {
            m_zoomX1 -= 1;
            m_zoomX2 += 1;
        }
        if( m_zoomY1 - m_zoomY2 < 1e-9) {
            m_zoomY2 -= 1;
            m_zoomY1 += 1;
        }
    }

    // if we are showing grid, make a first (bad) estimate for margins
    // so that we can adjust vertical zoom
    if( m_vars.showGrid-> get() && m_autoZoom) {
        m_x1 = 5; m_x2 = m_buffer.width() - measureLabelX( "0.0000001");
        m_y1 = 5; m_y2 = m_buffer.height() - labelFontHeight;
        double dw = std::fabs(m_zoomX2 - m_zoomX1);
        double dh = std::fabs(m_zoomY1 - m_zoomY2);
        double ww = std::fabs(m_x1 - m_x2);
        double wh = std::fabs(m_y1 - m_y2);
        // dw/dh = ww/wh
        if( std::fabs( dw/dh - ww/wh) > 1e-6) {
            if( dw/dh > ww/wh) {
                // a1 is wider, so make it taller
                double s = dw * wh / ww - dh;
                m_zoomY1 += s/2;
                m_zoomY2 -= s/2;
            } else {
                double s = ww * dh / wh - dw;
                m_zoomX1 -= s/2;
                m_zoomX2 += s/2;
            }
        }
    }



    // setup margins (m_x* and m_y*) & labels
    // note: this must happen simultaneously because the sizes of the
    // vertical axis labels will influence the drawing area...
    // ================================================================

    // start with vertical margins, they only depend on the font height, which does not change
    if( m_vars.showGrid-> get()) {
        m_y1 = 5;
        m_y2 = m_buffer.height() - labelFontHeight; // make room for bottom labels

        // update tty - it won't change anymore
        m_ty1 = LinearMap1D( m_zoomY1, m_zoomY2, m_y1+dotSize, m_y2-dotSize);

        // now calculate vertical labels
        // dont forget y1 = top, y2 = bottom
        m_vertLabeler-> setZoom( tty1inv( m_y2), tty1inv( m_y1));
        m_vertLabeler-> setPixels( m_y2 - m_y1 + 1);
        m_vertLabels = m_vertLabeler-> compute(
                    std::bind(& QUProfileController::measureLabelY, this,
                              std::placeholders::_1));

        // calculate the maximum width of all vertical labels
        double maxw = measureLabelX( "0");
        for( auto label : m_vertLabels) {
            maxw = std::max( maxw, measureLabelX( label.txt1));
        }
        maxw += measureLabelX( "0");

        // now we can set the horizontal margins
        m_x1 = 5;
        m_x2 = m_buffer.width() - maxw;
    }
    else {
        m_x1 = 1; m_x2 = m_buffer.width()-2;
        m_y1 = 1; m_y2 = m_buffer.height()-2;
        // update tty
        m_ty1 = LinearMap1D( m_zoomY1, m_zoomY2, m_y1+dotSize, m_y2-dotSize);
    }

    // fix aspect ratio by adjusting zoom x1,x2
    double dw = std::fabs(m_zoomX2 - m_zoomX1);
    double dh = std::fabs(m_zoomY1 - m_zoomY2);
    double ww = std::fabs(m_x1 - m_x2);
    double wh = std::fabs(m_y1 - m_y2);
    // dw/dh = ww/wh
    if( std::fabs( dw/dh - ww/wh) > 1e-6) {
        if( m_vars.showGrid-> get()) {
            // note: do not change y-zoom as we already used it to calculate vertical labels
            double s = ww * dh / wh - dw;
            m_zoomX1 -= s/2;
            m_zoomX2 += s/2;
        }
        else {
            // if we are not showing grid, we can decide if we adjust x or y zoom
            if( dw/dh > ww/wh) {
                // a1 is wider, so make it taller
                double s = dw * wh / ww - dh;
                m_zoomY1 += s/2;
                m_zoomY2 -= s/2;
                // re-update tty
                m_ty1 = LinearMap1D( m_zoomY1, m_zoomY2, m_y1+dotSize, m_y2-dotSize);
            } else {
                double s = ww * dh / wh - dw;
                m_zoomX1 -= s/2;
                m_zoomX2 += s/2;
            }
        }
    }

    // at this point margins are set, so update ttx*() functions
    m_tx1 = LinearMap1D( m_zoomX1, m_zoomX2, m_x1+dotSize, m_x2-dotSize);

    // calculate labels for the horizontal axis
    if( m_vars.showGrid-> get()) {
        m_horizLabeler-> setZoom( ttx1inv( m_x1), ttx1inv(m_x2));
        m_horizLabeler-> setPixels( m_x2 - m_x1 + 1);
        m_horizLabels = m_horizLabeler-> compute(
                    std::bind(& QUProfileController::measureLabelX, this,
                              std::placeholders::_1));
    }

    // do the drawing
    if( m_dirtyFlags.graph) {
        m_buffer.fill( 0xffffff);
        QPainter p( & m_buffer);
        p.setRenderHint( p.Antialiasing, true);
        p.setRenderHint( p.TextAntialiasing, true);
        p.setRenderHint( p.SmoothPixmapTransform, true);

        // set up clipping to only draw within the main plot area
        p.setClipRect( QRectF( QPointF(m_x1, m_y1), QPointF(m_x2, m_y2)));
        p.setClipping( true);

        // draw the grid
        drawGrid(p);

        // draw the plot
        drawPlot(p);

        // draw mean
        if( m_vars.showMean-> get()) {
            if( std::isfinite(m_meanQ) && std::isfinite(m_meanU)) {
                double x = ttx1( m_meanQ);
                double y = tty1( m_meanU);
                double s = 5;
                p.setPen( QPen( QColor(255,255,255,200), 5));
                p.drawLine( QPointF( x - s, y), QPointF( x + s, y));
                p.drawLine( QPointF( x , y - s), QPointF( x, y + s));
                s -= 1;
                if( m_vars.showSunbow-> get())
                    p.setPen( QPen( QColor(255,0,0), 3));
                else
                    p.setPen( QPen( QColor(0,0,128), 3));
                p.drawLine( QPointF( x - s, y), QPointF( x + s, y));
                p.drawLine( QPointF( x , y - s), QPointF( x, y + s));
            }
        }

        // draw cursor
//        if( m_showCursor && m_cursorIndex >= 0 && m_cursorIndex < avail()) {
        if( getShowCursor() && m_cursorIndex >= 0 && m_cursorIndex < avail()) {
            double x = m_dataQ[ m_cursorIndex];
            double y = m_dataU[ m_cursorIndex];
            x = ttx1(x);
            y = tty1(y);
            if( std::isfinite(x) && std::isfinite(y)) {
                p.setPen( QPen(QColor( 0,255,0), 2));
                p.setBrush( Qt::NoBrush);
                p.drawEllipse( QPointF(x,y), 6, 6);
            }
        }

        // if data is not complete yet, show a text
        p.setClipping( false);

        // let the clients know the mean
        m_vars.qMean-> set( fmtDouble( m_meanQ));
        m_vars.uMean-> set( fmtDouble( m_meanU));
//        updateDc = true;
    }

    // draw loading message if appropriate
    QPainter p( & m_buffer);
    drawLoadingMessage(p);

    // tell clients about the cursor
    if( m_dirtyFlags.cursor1) {
        if( m_cursorIndex >= 0 && m_cursorIndex < avail()) {
            m_vars.qVal-> set( fmtDouble( m_dataQ[ m_cursorIndex]));
            m_vars.uVal-> set( fmtDouble( m_dataU[ m_cursorIndex]));
        }
        else {
            m_vars.qVal-> set( "");
            m_vars.uVal-> set( "");
        }
        if( m_cursorIndex >= 0) {
            m_vars.frame-> set( QString::number( m_cursorIndex + 1));
        }
        else {
            m_vars.frame-> set( "");
        }
    }

//    // send additional info to render by the client
//    if( updateDc ){
//        pwsetdc( m_pwPrefix + "dc", qrand());
//    }

    //    dbg(1) << "... RedrawAllNow() done in " << debugTimer.elapsed() / 1000.0 << "s\n";
}
예제 #4
0
  // Color graph given by two arrays. API may change. Expert users only!
  void colorCrsGraph(
    const size_t nVtx,
    ArrayView<const gno_t> edgeIds,
    ArrayView<const lno_t> offsets,
    ArrayRCP<int> colors
  )
  {
    HELLO;
  
    // Find max degree, since (max degree)+1 is an upper bound.
    lno_t maxDegree = 0; 
    for (size_t i=0; i<nVtx; i++){
      if (offsets[i+1]-offsets[i] > maxDegree)
        maxDegree = offsets[i+1]-offsets[i];
    }

    // Greedy coloring.
    // Use natural order for now. 
    // TODO: Support better orderings (e.g., Smallest-Last)
    int maxColor = 0;
 
    // array of size #colors: forbidden[i]=v means color[v]=i so i is forbidden
    Teuchos::Array<int> forbidden(maxDegree+2, 0);
      
    // LeastUsed: need array of size #colors
    Teuchos::Array<lno_t> numVerticesWithColor(maxDegree+2, 0);

    // Get colorChoice from parameter list.
    Teuchos::ParameterList &pl = env_->getParametersNonConst();
    std::string colorChoice = pl.get<std::string>("color_choice", "FirstFit");

    for (size_t i=0; i<nVtx; i++){
      //std::cout << "Debug: i= " << i << std::endl;
      lno_t v=i; // TODO: Use ordering here.
      for (lno_t j=offsets[v]; j<offsets[v+1]; j++){
        gno_t nbor = edgeIds[j];
        //std::cout << "Debug: nbor= " << nbor << ", color= " << colors[nbor] << std::endl;
        if (colors[nbor] > 0){
          // Neighbors' colors are forbidden
          forbidden[colors[nbor]] = v;
        }
      }

      // Pick color for v

      // Keep colors[v] if possible, otherwise find valid color.
      if ((colors[v]==0) || ((colors[v]>0) && forbidden[colors[v]] == v)){

        if (colorChoice.compare("FirstFit")){
          // Pick first (smallest) available color > 0
          for (int c=1; c <= maxColor+1; c++){
            if (forbidden[c] != v){ 
              colors[v] = c;
              break;
            }
          }
        }
        else if (colorChoice.compare("Random")){
          // Pick random available color.
          // Truely random is slow, please consider RandomFast instead.
          int numAvail = 0;
          Teuchos::Array<int> avail(maxColor+1);
          for (int c=1; c < maxColor+1; c++){
            if (forbidden[c] != v){ 
              avail[numAvail++] = c;
            }
          }
          if (numAvail==0)
            colors[v] = maxColor+1;
          else
            colors[v] = avail[rand()%numAvail];
        }
        else if (colorChoice.compare("RandomFast")){
          // Pick random color, then find first available color after that.
          bool foundColor = false;
          int r = (rand() % maxColor) +1;
          for (int c=r; c <= maxColor; c++){
            if (forbidden[c] != v){ 
              colors[v] = c;
              foundColor = true;
              break;
            }
          }
          if (!foundColor){ // Look for colors in [1, r)
            for (int c=1; c < r; c++){
              if (forbidden[c] != v){ 
                colors[v] = c;
                foundColor = true;
                break;
              }
            }
          }
          if (!foundColor) colors[v] = maxColor+1;
        }
        else if (colorChoice.compare("LeastUsed")){
          // Pick least used available color.
          // Simple linear algorithm; could maintain a priority queue but not sure any faster?
          int leastUsedColor = 1;
          lno_t leastUsedNumber = numVerticesWithColor[1];
          for (int c=1; c <= maxColor; c++){
            if (forbidden[c] != v){
              if (numVerticesWithColor[c] < leastUsedColor){
                leastUsedColor = c;
                leastUsedNumber = numVerticesWithColor[c];
              }
            }
          }
          colors[v] = leastUsedColor;

          // Update color counts
          numVerticesWithColor[colors[v]]++;
        }
  
        if ((v==0) && colors[v]==0) colors[v]=1; // Corner case for first vertex
        
        // If we used a new color, increase maxColor.
        if (colors[v] > maxColor){
          maxColor = colors[v];
        }
      }
    }
  
    return;
  }
예제 #5
0
void ask_pos(int type)
{int i,c_no,c_nox,c_noy;

 settextstyle(1,0,3);
 take:
 outtextxy(5,400,"STATUS-");

 if(type==0)
 {setcolor(0);outtextxy(100,400,pl2_name);
  setcolor(WHITE);outtextxy(100,400,pl1_name);}
  else
  {setcolor(0);outtextxy(100,400,pl1_name);
   setcolor(WHITE);outtextxy(100,400,pl2_name);}
   outtextxy(5,420,"ENTER POSITION(X,Y):");

   setcolor(0);
  for(i=0;i<300;i++)
   outtextxy(290+i,420,"[1,1]");
   setcolor(WHITE);
   c_nox=bioskey(0);
   c_noy=bioskey(0);

switch(type)
{case 0:{switch(c_nox)
      {case 561:  {c_nox=1;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235-100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235-100);    break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235-100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235-100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235-100);    break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235-100);break;}
			default:{goto take;}
			}break;}
       case 818:  {c_nox=2;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235);break;}
			default:{goto take;}
			}break;}
       case 1075: {c_nox=3;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235+100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235+100);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235+100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235+100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235+100);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235+100);break;}
			default:{goto take;}
			}break;}
       case 20273:  {c_nox=1;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235-100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235-100);    break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235-100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235-100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235-100);    break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235-100);break;}
			default:{goto take;}
			}break;}
       case 20530:  {c_nox=2;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235);break;}
			default:{goto take;}
			}break;}
       case 20787: {c_nox=3;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235+100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235+100);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235+100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315-160,235+100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315,235+100);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_circle(315+160,235+100);break;}
			default:{goto take;}
			}break;}
       case 283:{closegraph();break;}
		}
  break;}

 case 1:{switch(c_nox)
      {case 561:  {c_nox=1;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235-100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235-100);    break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235-100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235-100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235-100);    break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235-100);break;}
			default:{goto take;}
			}break;}
       case 818:  {c_nox=2;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235);break;}
			default:{goto take;}
			}break;}
       case 1075: {c_nox=3;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235+100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235+100);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235+100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235+100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235+100);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235+100);break;}
			default:{goto take;}
			}break;}
       case 20273:  {c_nox=1;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235-100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235-100);    break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235-100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[1,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235-100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[1,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235-100);    break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[1,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235-100);break;}
			default:{goto take;}
			}break;}
       case 20530:  {c_nox=2;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[2,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[2,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[2,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235);break;}
			default:{goto take;}
			}break;}
       case 20787: {c_nox=3;switch(c_noy)
		       {case 561:
{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235+100);break;}
			case 818:
{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235+100);break;}
			case 1075:
{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235+100);break;}

			case
20273:{c_noy=1;outtextxy(290,420,"[3,1]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315-160,235+100);break;}
			case
20530:{c_noy=2;outtextxy(290,420,"[3,2]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315,235+100);break;}
			case
20787:{c_noy=3;outtextxy(290,420,"[3,3]");if(avail(c_nox,c_noy)==0){goto
take;}mark_cross(315+160,235+100);break;}
			default:{goto take;}
			}break;}
	 case 283:{closegraph();break;}
   }
  }
 }
if(type==0)
{rec_0[c_0][0]=c_nox;
 rec_0[c_0][1]=c_noy;c_0++;
//printf("
%d %d",rec_0[c_0-1][0],rec_0[c_0-1][1]);
예제 #6
0
bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std::vector<std::string> &dns_urls)
{
  // Prevent infinite recursion when distributing
  if (dns_urls.empty()) return false;

  std::vector<std::vector<std::string> > records;
  records.resize(dns_urls.size());

  std::random_device rd;
  std::mt19937 gen(rd());
  std::uniform_int_distribution<int> dis(0, dns_urls.size() - 1);
  size_t first_index = dis(gen);

  // send all requests in parallel
  std::vector<boost::thread> threads(dns_urls.size());
  std::deque<bool> avail(dns_urls.size(), false), valid(dns_urls.size(), false);
  for (size_t n = 0; n < dns_urls.size(); ++n)
  {
    threads[n] = boost::thread([n, dns_urls, &records, &avail, &valid](){
      records[n] = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n], valid[n]); 
    });
  }
  for (size_t n = 0; n < dns_urls.size(); ++n)
    threads[n].join();

  size_t cur_index = first_index;
  do
  {
    const std::string &url = dns_urls[cur_index];
    if (!avail[cur_index])
    {
      records[cur_index].clear();
      LOG_PRINT_L2("DNSSEC not available for checkpoint update at URL: " << url << ", skipping.");
    }
    if (!valid[cur_index])
    {
      records[cur_index].clear();
      LOG_PRINT_L2("DNSSEC validation failed for checkpoint update at URL: " << url << ", skipping.");
    }

    cur_index++;
    if (cur_index == dns_urls.size())
    {
      cur_index = 0;
    }
  } while (cur_index != first_index);

  size_t num_valid_records = 0;

  for( const auto& record_set : records)
  {
    if (record_set.size() != 0)
    {
      num_valid_records++;
    }
  }

  if (num_valid_records < 2)
  {
    LOG_PRINT_L0("WARNING: no two valid MoneroPulse DNS checkpoint records were received");
    return false;
  }

  int good_records_index = -1;
  for (size_t i = 0; i < records.size() - 1; ++i)
  {
    if (records[i].size() == 0) continue;

    for (size_t j = i + 1; j < records.size(); ++j)
    {
      if (dns_records_match(records[i], records[j]))
      {
        good_records_index = i;
        break;
      }
    }
    if (good_records_index >= 0) break;
  }

  if (good_records_index < 0)
  {
    LOG_PRINT_L0("WARNING: no two MoneroPulse DNS checkpoint records matched");
    return false;
  }

  good_records = records[good_records_index];
  return true;
}
예제 #7
0
static treeptr insert_root(treeptr p, float diff)
{
   treeptr newp, prev, q, t;
   float dist, prevdist,td;

   newp = avail();

   t = p->parent;
   prevdist = t->dist;

   p->parent = newp;

   dist = p->dist;

   p->dist = diff / 2;
   if (p->dist < 0.0) p->dist = 0.0;
   if (p->dist > dist) p->dist = dist;

   t->dist = dist - p->dist; 

   newp->left = t;
   newp->right = p;
   newp->parent = NULL;
   newp->dist = 0.0;
   newp->leaf = NODE;

   if (t->left == p) t->left = t->parent;
   else t->right = t->parent;

   prev = t;
   q = t->parent;

   t->parent = newp;

   while (q != NULL)
     {
        if (q->left == prev)
           {
              q->left = q->parent;
              q->parent = prev;
              td = q->dist;
              q->dist = prevdist;
              prevdist = td;
              prev = q;
              q = q->left;
           }
        else
           {
              q->right = q->parent;
              q->parent = prev;
              td = q->dist;
              q->dist = prevdist;
              prevdist = td;
              prev = q;
              q = q->right;
           }
    }

/*
   remove the old root node
*/
   q = prev;
   if (q->left == NULL)
      {
         dist = q->dist;
         q = q->right;
         q->dist += dist;
         q->parent = prev->parent;
         if (prev->parent->left == prev)
            prev->parent->left = q;
         else
            prev->parent->right = q;
         prev->right = NULL;
      }
   else
      {
         dist = q->dist;
         q = q->left;
         q->dist += dist;
         q->parent = prev->parent;
         if (prev->parent->left == prev)
            prev->parent->left = q;
         else
            prev->parent->right = q;
         prev->left = NULL;
      }

   return(newp);
}
예제 #8
0
sint read_tree(char *treefile, sint first_seq, sint last_seq)
{

  char c;
  char name1[MAXNAMES+1], name2[MAXNAMES+1];
  sint i, j, k;
  Boolean found;

  numseq = 0;
  nnodes = 0;
  ntotal = 0;
  rooted_tree = TRUE;

#ifdef VMS
  if ((fd = fopen(treefile,"r","rat=cr","rfm=var")) == NULL)
#else
  if ((fd = fopen(treefile, "r")) == NULL)
#endif
    {
      error("cannot open %s", treefile);
      return((sint)0);
    }

  skip_space(fd);
  ch = (char)getc(fd);
  if (ch != '(')
    {
      error("Wrong format in tree file %s", treefile);
      return((sint)0);
    }
  rewind(fd);

  distance_tree = TRUE;

/*
  Allocate memory for tree
*/
  nptr = (treeptr *)ckalloc(3*(last_seq-first_seq+1) * sizeof(treeptr));
  ptrs = (treeptr *)ckalloc(3*(last_seq-first_seq+1) * sizeof(treeptr));
  lptr = (treeptr *)ckalloc((last_seq-first_seq+1) * sizeof(treeptr));
  olptr = (treeptr *)ckalloc((last_seq+1) * sizeof(treeptr));
  
  seq_tree = avail();
  set_info(seq_tree, NULL, 0, "", 0.0);

  create_tree(seq_tree,NULL);
  fclose(fd);


  if (numseq != last_seq-first_seq)
     {
         error("tree not compatible with alignment\n(%d sequences in alignment and %d in tree", (pint)last_seq-first_seq,(pint)numseq);
         return((sint)0);
     }

/*
  If the tree is unrooted, reroot the tree - ie. minimise the difference
  between the mean root->leaf distances for the left and right branches of
  the tree.
*/

  if (distance_tree == FALSE)
     {
  	if (rooted_tree == FALSE)
          {
       	     error("input tree is unrooted and has no distances.\nCannot align sequences");
             return((sint)0);
          }
     }

  if (rooted_tree == FALSE)
     {
        root = reroot(seq_tree, last_seq-first_seq+1);
     }
  else
     {
        root = seq_tree;
     }

/*
  calculate the 'order' of each node.
*/
  order_nodes();

  if (numseq >= 2)
     {
/*
  If there are more than three sequences....
*/
/*
  assign the sequence nodes (in the same order as in the alignment file)
*/
      for (i=first_seq; i<last_seq; i++)
       {
         if (strlen(names[i+1]) > MAXNAMES)
             warning("name %s is too long for PHYLIP tree format (max %d chars)", names[i+1],MAXNAMES);

         for (k=0; k< strlen(names[i+1]) && k<MAXNAMES ; k++)
           {
             c = names[i+1][k];
             if ((c>0x40) && (c<0x5b)) c=c | 0x20;
             if (c == ' ') c = '_';
             name2[k] = c;
           }
         name2[k]='\0';
         found = FALSE;
         for (j=0; j<numseq; j++)
           {
            for (k=0; k< strlen(lptr[j]->name) && k<MAXNAMES ; k++)
              {
                c = lptr[j]->name[k];
                if ((c>0x40) && (c<0x5b)) c=c | 0x20;
                name1[k] = c;
              }
            name1[k]='\0';
            if (strcmp(name1, name2) == 0)
              {
                olptr[i] = lptr[j];
                found = TRUE;
              }
           }
         if (found == FALSE)
           {
             error("tree not compatible with alignment:\n%s not found", name2);
             return((sint)0);
           }
       }

     }
   return((sint)1);
}
예제 #9
0
	void append(const char* buf, size_t len) {
		if (static_cast<size_t>(avail()) > len) {
			::memcpy(cur_, buf, len);
			cur_ += len;
		}
	}