Beispiel #1
0
void HashTable::updateValue(MDDAGState& state, CAction *action, double td, CActionData * actionData)
{
    if (td != td) {
        assert(false);
    }
    
    int actionIndex = dynamic_cast<MultiBoost::CAdaBoostAction*>(action)->getMode();
    
    ValueKey key;
    getKey(state, key);
    
    AlphaReal value;
    bool entryExists = getTableValue(actionIndex, key, value);
    
    if (entryExists)
        _valueTable[key][actionIndex] += td; //* _learningRate;
    else
        addTableEntry(td, key, actionIndex);
};
void bufferManager::addRecord(CString table_name, char* head, int size)
{
	address add, dataAdd, nextAdd;
	findTableEntry(table_name, add);
	if(add.block_position == -1 && add.index_position == -1)
	{
		int i = addTableEntry(table_name,add);
		int j = storeData(head,size,dataAdd);
		buffer[i].setRecordFrontLink(add.index_position, dataAdd);
		buffer[i].setRecordNextLink(add.index_position, dataAdd);
		buffer[j].setRecordFrontLink(dataAdd.index_position, add);
		buffer[j].setRecordNextLink(dataAdd.index_position, add);
	}
	else
	{
		int i = readBlockFromDisk(add.block_position);
		buffer[i].getRecordNextLink(add.index_position, nextAdd);
		if(nextAdd.block_position != -1 && nextAdd.index_position != -1)
		{
			int j = storeData(head, size, dataAdd);
			buffer[i].getRecordNextLink(add.index_position, nextAdd);
			int m = readBlockFromDisk(nextAdd.block_position);

			buffer[j].setRecordFrontLink(dataAdd.index_position, add);
			buffer[j].setRecordNextLink(dataAdd.index_position, nextAdd);
			buffer[i].setRecordNextLink(add.index_position, dataAdd);
			buffer[m].setRecordFrontLink(nextAdd.index_position, dataAdd);
		}
		else
		{
			int j = storeData(head, size, dataAdd);
			buffer[j].setRecordFrontLink(dataAdd.index_position, add);
			buffer[j].setRecordNextLink(dataAdd.index_position, add);
			buffer[i].setRecordFrontLink(add.index_position, dataAdd);
			buffer[i].setRecordNextLink(add.index_position, dataAdd);
		}
	}
}
void QgsSpatiaLiteTableModel::setGeometryTypesForTable( const QString & table, const QString & attribute, const QString & type )
{
  bool typeIsEmpty = type.isEmpty();  //true means the table has no valid geometry entry and the item for this table should be removed
  QStringList typeList = type.split( ',' );

  //find schema item and table item
  QStandardItem *dbItem;
  QList < QStandardItem * >dbItems = findItems( mSqliteDb, Qt::MatchExactly, 0 );

  if ( dbItems.size() < 1 )
  {
    return;
  }
  dbItem = dbItems.at( 0 );
  int numChildren = dbItem->rowCount();

  QModelIndex currentChildIndex;
  QModelIndex currentTableIndex;
  QModelIndex currentTypeIndex;
  QModelIndex currentGeomColumnIndex;

  for ( int i = 0; i < numChildren; ++i )
  {
    currentChildIndex = indexFromItem( dbItem->child( i, 0 ) );
    if ( !currentChildIndex.isValid() )
    {
      continue;
    }
    currentTableIndex = currentChildIndex.sibling( i, 1 );
    currentTypeIndex = currentChildIndex.sibling( i, 2 );
    currentGeomColumnIndex = currentChildIndex.sibling( i, 3 );
    QString geomColText = itemFromIndex( currentGeomColumnIndex )->text();

    if ( !currentTypeIndex.isValid() || !currentTableIndex.isValid() || !currentGeomColumnIndex.isValid() )
    {
      continue;
    }

    if ( itemFromIndex( currentTableIndex )->text() == table &&
         ( geomColText == attribute || geomColText.startsWith( attribute + " AS " ) ) )
    {
      if ( typeIsEmpty )
      {
        removeRow( i, indexFromItem( dbItem ) );
        return;
      }

      QgsWkbTypes::Type wkbType = qgisTypeFromDbType( typeList.at( 0 ) );
      QIcon myIcon = iconForType( wkbType );
      itemFromIndex( currentTypeIndex )->setText( typeList.at( 0 ) ); //todo: add other rows
      itemFromIndex( currentTypeIndex )->setIcon( myIcon );
      if ( !geomColText.contains( " AS " ) )
      {
        itemFromIndex( currentGeomColumnIndex )->setText( geomColText + " AS " + typeList.at( 0 ) );
      }

      for ( int j = 1; j < typeList.size(); ++j )
      {
        //todo: add correct type
        addTableEntry( typeList.at( j ), table, geomColText + " AS " + typeList.at( j ), "" );
      }
    }
  }
}
Beispiel #4
0
void QgsDb2TableModel::setGeometryTypesForTable( QgsDb2LayerProperty layerProperty )
{
  QStringList typeList = layerProperty.type.split( ',', QString::SkipEmptyParts );
  QStringList sridList = layerProperty.srid.split( ',', QString::SkipEmptyParts );
  Q_ASSERT( typeList.size() == sridList.size() );

  //find schema item and table item
  QStandardItem *schemaItem = nullptr;
  QList<QStandardItem *> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, DbtmSchema );

  if ( schemaItems.empty() )
  {
    return;
  }

  schemaItem = schemaItems.at( 0 );

  int n = schemaItem->rowCount();
  for ( int i = 0; i < n; i++ )
  {
    QModelIndex currentChildIndex = indexFromItem( schemaItem->child( i, DbtmSchema ) );
    if ( !currentChildIndex.isValid() )
    {
      continue;
    }

    QList<QStandardItem *> row;

    row.reserve( DbtmColumns );
    for ( int j = 0; j < DbtmColumns; j++ )
    {
      row << itemFromIndex( currentChildIndex.sibling( i, j ) );
    }

    if ( row[ DbtmTable ]->text() == layerProperty.tableName && row[ DbtmGeomCol ]->text() == layerProperty.geometryColName )
    {
      row[ DbtmSrid ]->setText( layerProperty.srid );

      if ( typeList.isEmpty() )
      {
        row[ DbtmType ]->setText( tr( "Select…" ) );
        row[ DbtmType ]->setFlags( row[ DbtmType ]->flags() | Qt::ItemIsEditable );

        row[ DbtmSrid ]->setText( tr( "Enter…" ) );
        row[ DbtmSrid ]->setFlags( row[ DbtmSrid ]->flags() | Qt::ItemIsEditable );

        for ( QStandardItem *item : qgis::as_const( row ) )
        {
          item->setFlags( item->flags() | Qt::ItemIsEnabled );
        }
      }
      else
      {
        // update existing row
        QgsWkbTypes::Type wkbType = QgsDb2TableModel::wkbTypeFromDb2( typeList.at( 0 ) );

        row[ DbtmType ]->setIcon( iconForWkbType( wkbType ) );
        row[ DbtmType ]->setText( QgsWkbTypes::displayString( wkbType ) );
        row[ DbtmType ]->setData( false, Qt::UserRole + 1 );
        row[ DbtmType ]->setData( wkbType, Qt::UserRole + 2 );

        row[ DbtmSrid ]->setText( sridList.at( 0 ) );

        Qt::ItemFlags flags = Qt::ItemIsEnabled;
        if ( layerProperty.pkCols.size() < 2 )
          flags |= Qt::ItemIsSelectable;

        for ( QStandardItem *item : qgis::as_const( row ) )
        {
          item->setFlags( item->flags() | flags );
        }

        for ( int j = 1; j < typeList.size(); j++ )
        {
          layerProperty.type = typeList[j];
          layerProperty.srid = sridList[j];
          addTableEntry( layerProperty );
        }
      }
    }
  }
}