// Calculate the union of two reference lists.
void MdamRefList::unionx(const MdamRefList & refList0Ref,
                         const MdamRefList & refList1Ref,
			 FixedSizeHeapManager & mdamRefListEntryHeap)
{
  // Delete all the entries from the target list.
  deleteEntries(mdamRefListEntryHeap);

  // Obtain the first disjunct number from each source list.
  Int32 disjunctNum0 = disjunctNumInitialValue;
  Int32 disjunctNum1 = disjunctNumInitialValue;
  MdamRefListIterator iterator0(&refList0Ref);
  MdamRefListIterator iterator1(&refList1Ref); 
  NABoolean more0 = iterator0(disjunctNum0);
  NABoolean more1 = iterator1(disjunctNum1);
  
  // Loop through both lists until either one is empty.
  while (more0 && more1)
    {
      if (disjunctNum0 == disjunctNum1)
        {
          // Disjunct numbers are equal.  Keep one copy.
          insert(disjunctNum0, mdamRefListEntryHeap);
          // Advance both lists.
          more0 = iterator0(disjunctNum0);
          more1 = iterator1(disjunctNum1);
        }
      else if (disjunctNum0 < disjunctNum1)
        {
          // Disjunct number from list 0 is less.
          // Insert it into the result and advance list 0. 
          insert(disjunctNum0, mdamRefListEntryHeap);
          more0 = iterator0(disjunctNum0);
        }
      else
        {
          // Disjunct number from list 1 is less.
          // Insert it into the result and advance list 1.  
          insert(disjunctNum1, mdamRefListEntryHeap);
          more1 = iterator1(disjunctNum1);
        }
    }

  // Copy any remaining disjunct numbers from refList0Ref.
  while (more0)
    {
      insert(disjunctNum0, mdamRefListEntryHeap);
      more0 = iterator0(disjunctNum0);
    }

  // Copy any remaining disjunct numbers from refList1Ref.
  while (more1)
    {
      insert(disjunctNum1, mdamRefListEntryHeap);
      more1 = iterator1(disjunctNum1);
    }
} 
// Calculate the intersection of two reference lists.
void MdamRefList::intersect(const MdamRefList & refList0Ref,
                            const MdamRefList & refList1Ref,
			    FixedSizeHeapManager & mdamRefListEntryHeap)
{
  // Delete all the entries from this list.
  deleteEntries(mdamRefListEntryHeap);

  // Obtain the first disjunct number from each list.
  Int32 disjunctNum0 = disjunctNumInitialValue;
  Int32 disjunctNum1 = disjunctNumInitialValue;
  MdamRefListIterator iterator0(&refList0Ref);
  MdamRefListIterator iterator1(&refList1Ref); 
  NABoolean more0 = iterator0(disjunctNum0);
  NABoolean more1 = iterator1(disjunctNum1);
  
  // Iterate finding disjunct numbers common to both lists.
  // Stop when either list is exhausted.
  while (more0 && more1)
    {
      if (disjunctNum0 == disjunctNum1)
        {
          // Disjunct numbers are equal.  Insert into result list.
          insert(disjunctNum0, mdamRefListEntryHeap);
          // Advance both lists.
          more0 = iterator0(disjunctNum0);
          more1 = iterator1(disjunctNum1);
        }
      else if (disjunctNum0 < disjunctNum1)
        {
          // Disjunct number from list 0 is less.
          // Advance list 0. 
          more0 = iterator0(disjunctNum0);
        }
      else
        {
          // Disjunct number from list 1 is less.
          // Advance list 1. 
          more1 = iterator1(disjunctNum1);
        }
    }
}
Beispiel #3
0
bool NestLoopExecutor::p_execute(const NValueArray &params, ReadWriteTracker *tracker) {
    VOLT_DEBUG("executing NestLoop...");

    NestLoopPlanNode* node = dynamic_cast<NestLoopPlanNode*>(abstract_node);
    assert(node);
    assert(node->getInputTables().size() == 2);

    Table* output_table_ptr = node->getOutputTable();
    assert(output_table_ptr);

    // output table must be a temp table
    TempTable* output_table = dynamic_cast<TempTable*>(output_table_ptr);
    assert(output_table);

    Table* outer_table = node->getInputTables()[0];
    assert(outer_table);

    Table* inner_table = node->getInputTables()[1];
    assert(inner_table);

    VOLT_TRACE ("input table left:\n %s", outer_table->debug().c_str());
    VOLT_TRACE ("input table right:\n %s", inner_table->debug().c_str());

    //
    // Join Expression
    //
    AbstractExpression *predicate = node->getPredicate();
    if (predicate) {
        predicate->substitute(params);
        VOLT_TRACE ("predicate: %s", predicate == NULL ?
                    "NULL" : predicate->debug(true).c_str());
    }

    int outer_cols = outer_table->columnCount();
    int inner_cols = inner_table->columnCount();
    TableTuple outer_tuple(node->getInputTables()[0]->schema());
    TableTuple inner_tuple(node->getInputTables()[1]->schema());
    TableTuple &joined = output_table->tempTuple();

    TableIterator iterator0(outer_table);
    while (iterator0.next(outer_tuple)) {

        // populate output table's temp tuple with outer table's values
        // probably have to do this at least once - avoid doing it many
        // times per outer tuple
        for (int col_ctr = 0; col_ctr < outer_cols; col_ctr++) {
            joined.setNValue(col_ctr, outer_tuple.getNValue(col_ctr));
        }

        TableIterator iterator1(inner_table);
        while (iterator1.next(inner_tuple)) {
            if (predicate == NULL || predicate->eval(&outer_tuple, &inner_tuple).isTrue()) {
                // Matched! Complete the joined tuple with the inner column values.
                for (int col_ctr = 0; col_ctr < inner_cols; col_ctr++) {
                    joined.setNValue(col_ctr + outer_cols, inner_tuple.getNValue(col_ctr));
                }
                output_table->insertTupleNonVirtual(joined);
            }
        }
    }

    return (true);
}
// Determine if the intersection of three reference lists is empty.
// - this (which we will refer as refList0), refList1 and reflist2.
NABoolean MdamRefList::intersectEmpty(const MdamRefList & refList1,
				    const MdamRefList & refList2)
{

  // For readability purpose, let's refer to this pointer as reflist0.
  MdamRefList *refList0 = this;

  // Obtain the first disjunct number from each list.
  Int32 disjunctNum0 = disjunctNumInitialValue;
  Int32 disjunctNum1 = disjunctNumInitialValue;
  Int32 disjunctNum2 = disjunctNumInitialValue;

  MdamRefListIterator iterator0(refList0);
  MdamRefListIterator iterator1(&refList1); 
  MdamRefListIterator iterator2(&refList2); 

  NABoolean more0 = iterator0(disjunctNum0);
  NABoolean more1 = iterator1(disjunctNum1);
  NABoolean more2 = iterator2(disjunctNum2);
  
  // Iterate finding disjunct numbers common to all three lists.
  // Stop when one is found or when one of the refLists is exhausted.
  while (more0 && more1 && more2)
    {
      if (disjunctNum0 == disjunctNum1)
        {
	  if (disjunctNum0 == disjunctNum2)
	    return FALSE; // Found a match in refList0 refList1 and refList2!
	                  // intersection is non-empty.
  	  else if (disjunctNum0 < disjunctNum2)
	    {
	      // We already know disjunctNum0=disjunctNum1. 
	      // Advance both refList0 and refList1.
	      more0 = iterator0(disjunctNum0);
	      more1 = iterator1(disjunctNum1);
	    }
	  else 
	    {
	      // Must be disjunctNum2<disjunctNum0 and 
	      // disjunctNum2<disjunctNum1
	      more2 = iterator2(disjunctNum2);
	    }
	} 
      else if (disjunctNum0 < disjunctNum1)
	{
	  if (disjunctNum0 < disjunctNum2)
	    {
	      // Disjunct number from list 0 is less than 1 and 2.
	      // Advance list 0. 
	      more0 = iterator0(disjunctNum0);
	    }
	  else
	    {
	      // We know disjunctNum2 <= disjunctNum0 < disjunctNum1
	      more0 = iterator0(disjunctNum0);
	      more2 = iterator2(disjunctNum2);
	    }
	}
      else // (disjunctNum1 < disjunctNum0)
        {
	  if (disjunctNum1 < disjunctNum2)
	    {
	      // Disjunct number from list 1 is less than from 0 and 2.
	      // Advance list 1. 
	      more1 = iterator1(disjunctNum1);
	    }
	  else
	    {
	      // We know that disjunctNum2 <= disjunctNum1 < disjunctNum0 
	      more1 = iterator1(disjunctNum1);
	      more2 = iterator2(disjunctNum2);
	    }
        }
      
    }//While
  
  return TRUE; // Return true because the intersection is empty.
}
Beispiel #5
0
void Graph::drawCurves(QPainter *painter)
{
    QRect rect(Margin, Margin,
               width() - 2 * Margin, height() - 2 * Margin);
    if(!rect.isValid())
        return;

    painter->setClipRect(rect.adjusted(+1, +1, -1, -1));

    QPolygon polyline0, polyline1;

    QVectorIterator<QPoint> iterator0(pointStorage_0);
    while(iterator0.hasNext()){
        
        QPoint point = iterator0.next();
        
        int x = rect.left() + point.x();
        int y = rect.bottom() - point.y();
        
        polyline0 << QPoint(x, y);
    }
    
    QVectorIterator<QPoint> iterator1(pointStorage_1);
    while(iterator1.hasNext()){
        
        QPoint point = iterator1.next();
        
        int x = rect.left() + point.x();
        int y = rect.bottom() - point.y();
        
        polyline1 << QPoint(x, y);
    }
    
    
    QPen light = palette().light().color();
    QPen bright(Qt::green, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    
    int static xyz =  0;

    int value0, value1;
    if(!polyline0.isEmpty()){
        value0 = polyline0.last().y();
    }

    if(!polyline1.isEmpty()){
        value1 = polyline1.last().y();
    }

    painter->setPen(light);
    painter->drawPolyline(polyline0);
    painter->drawText(rect, Qt::AlignCenter, QString::number(value0));

    painter->setPen(bright);
    painter->drawPolyline(polyline1);
    painter->drawText(rect, Qt::AlignVCenter, QString::number(value1));

    painter->setPen(light);
    painter->drawLine(rect.left() + xyz, rect.left() + 50, rect.left() + xyz, rect.left() + 15);
    painter->drawRect(rect.adjusted(0, 0, -1, -1));

    xyz++;

}