Пример #1
0
void WgTablePanel::InsertRowSorted( WgTableRow* pRow )
{
	if( m_nRows == 0 )
		_connectRow( pRow, 0 );
	else
	{
		WgTableRow * pFirst = m_rows.First();
		WgTableRow * pLast = m_rows.Last();

		int diffFirst = CompareRows( pRow, pFirst );
		int diffLast = CompareRows( pRow, pLast );

		if( !m_bSortAscend )
		{
			diffFirst = -diffFirst;
			diffLast = -diffLast;
		}

		if( diffFirst < 0 )
			_connectRow( pRow, pFirst );
		else if( diffLast >= 0 )
			_connectRow( pRow, 0 );		// If inserted row is equal to last row it should be placed last.
		else
			_connectRow( pRow, _findRowInsertSpot( pFirst, pLast, pRow, m_nRows ) );
	}
}
Пример #2
0
static
void BasicArray(){
  ndbout << "Testing basic array operations" << endl;
  
  // Basic insert
  DBA_ArrayInsertRows(EmpB, EMP_TABLE_DATA, Rows-2, insertCallback);
  NdbSleep_SecSleep(1);
  DBA_ArrayReadRows(EmpB, EMP_TABLE_DATA_READ, Rows-2, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
  
  // Basic update
  AlterRows(EMP_TABLE_DATA, Rows-2);
  DBA_ArrayUpdateRows(EmpB, EMP_TABLE_DATA, Rows-2, updateCallback);
  NdbSleep_SecSleep(1);
  DBA_ArrayReadRows(EmpB, EMP_TABLE_DATA_READ, Rows-2, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
  
  // Basic write
  AlterRows(EMP_TABLE_DATA, Rows);
  DBA_ArrayWriteRows(EmpB, EMP_TABLE_DATA, Rows, writeCallback);
  NdbSleep_SecSleep(1);
  DBA_ArrayReadRows(EmpB, EMP_TABLE_DATA_READ, Rows, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
  
  // Basic delete
  DBA_ArrayDeleteRows(EmpB, EMP_TABLE_DATA, Rows, deleteCallback);
  NdbSleep_SecSleep(1);
}
Пример #3
0
static
void BasicPtr(){
  ndbout << "Testing array of pointer operations" << endl;
  Employee_t * EmpData[Rows];
  Employee_t * EmpDataRead[Rows];
  for(int i = 0; i<Rows; i++){
    EmpData[i]     = &EMP_TABLE_DATA[i];
    EmpDataRead[i] = &EMP_TABLE_DATA_READ[i];
  }
    
  void * const * EMP_TABLE_DATA2      = (void * const *)EmpData;
  void * const * EMP_TABLE_DATA_READ2 = (void * const *)EmpDataRead;
    
  // Basic insert
  DBA_InsertRows(EmpB, EMP_TABLE_DATA2, Rows-2, insertCallback);
  NdbSleep_SecSleep(1);
  DBA_ReadRows  (EmpB, EMP_TABLE_DATA_READ2, Rows-2, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
    
  // Basic update
  AlterRows(EMP_TABLE_DATA, Rows-2);
  DBA_UpdateRows(EmpB, EMP_TABLE_DATA2, Rows-2, updateCallback);
  NdbSleep_SecSleep(1);
  DBA_ReadRows  (EmpB, EMP_TABLE_DATA_READ2, Rows-2, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
    
    // Basic write
  AlterRows  (EMP_TABLE_DATA, Rows);
  DBA_WriteRows(EmpB, EMP_TABLE_DATA2, Rows, writeCallback);
  NdbSleep_SecSleep(1);
  DBA_ReadRows (EmpB, EMP_TABLE_DATA_READ2, Rows, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
    
    // Basic delete
  DBA_DeleteRows(EmpB, EMP_TABLE_DATA2, Rows, deleteCallback);
  NdbSleep_SecSleep(1);
}
Пример #4
0
static
void Multi(){
  ndbout << "Testing multi operations" << endl;

  DBA_ArrayInsertRows(EmpB, EMP_TABLE_DATA, Rows-2, insertCallback);
  DBA_ArrayInsertRows(AddB, ADD_TABLE_DATA, Rows-2, insertCallback);
  NdbSleep_SecSleep(1);
  
  const int R2 = Rows + Rows;
  
  DBA_Binding_t * Bindings[2];
  DBA_BulkReadResultSet_t DataRead[R2];
  
  Bindings[0] = EmpB;
  Bindings[1] = AddB;
  
  for(int i = 0; i<Rows; i++)
    DataRead[i].DataPtr = &EMP_TABLE_DATA_READ[i];
  
  for(int i = 0; i<Rows; i++)
    DataRead[i+Rows].DataPtr = &ADD_TABLE_DATA_READ[i];
  
  NdbSleep_SecSleep(1);

  DBA_BulkMultiReadRows(Bindings, DataRead, 2, Rows, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
  CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
  
  require(CountRows(DataRead, R2) == (R2-4));

  // Basic delete
  DBA_ArrayDeleteRows(EmpB, EMP_TABLE_DATA, Rows-2, deleteCallback);
  DBA_ArrayDeleteRows(AddB, ADD_TABLE_DATA, Rows-2, deleteCallback);
  NdbSleep_SecSleep(1);
}
void BinaryMatrix::SortRowsAsc() {
	int itemsLen = _row;
	bool swapped = true;
	int n = 0;
	while (swapped) {
		swapped = false;
		int loopCount = itemsLen - n - 1;
		for (int i = 0; i < loopCount; i++) {
			int j = i + 1;
			if (CompareRows(i, j) > 0) {
				SwapRows(i, j);
				swapped = true;
			}
		}
		n++;
	}
};
Пример #6
0
static
void Multi(){
  ndbout << "Testing multi operations" << endl;
  
  const int R2 = Rows + Rows;

  DBA_Binding_t * Bindings[R2];
  void * DATA[R2];
  void * DATA_READ[R2];
  for(int i = 0; i<Rows; i++){
    Bindings[2*i]   = EmpB;
    Bindings[2*i+1] = AddB;
    
    DATA[2*i]   = &EMP_TABLE_DATA[i];
    DATA[2*i+1] = &ADD_TABLE_DATA[i];

    DATA_READ[2*i]   = &EMP_TABLE_DATA_READ[i];
    DATA_READ[2*i+1] = &ADD_TABLE_DATA_READ[i];
  }
  
  // Basic insert
  DBA_MultiInsertRow(Bindings, DATA, R2-4, insertCallback);
  NdbSleep_SecSleep(1);
  DBA_MultiReadRow  (Bindings, DATA_READ, R2-4, readCallback);
  NdbSleep_SecSleep(1);

  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
  CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
  
  // Basic update
  AlterRows(EMP_TABLE_DATA, Rows-2);
  AlterRows(ADD_TABLE_DATA, Rows-2);
  DBA_MultiUpdateRow(Bindings, DATA, R2-4, updateCallback);
  NdbSleep_SecSleep(1);
  DBA_MultiReadRow  (Bindings, DATA_READ, R2-4, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
  CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
  
  // Basic write
  AlterRows(EMP_TABLE_DATA, Rows);
  AlterRows(ADD_TABLE_DATA, Rows);
  DBA_MultiWriteRow(Bindings, DATA, R2, writeCallback);
  NdbSleep_SecSleep(1);
  DBA_MultiReadRow (Bindings, DATA_READ, R2, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
  CompareRows(ADD_TABLE_DATA, Rows, ADD_TABLE_DATA_READ);
  
  // Basic delete
  DBA_MultiDeleteRow(Bindings, DATA, R2, deleteCallback);
  NdbSleep_SecSleep(1);
}
Пример #7
0
static
void BasicPtr(){
  ndbout << "Testing array of pointer operations" << endl;
  
  // Basic insert
  DBA_ArrayInsertRows(EmpB, EMP_TABLE_DATA, Rows-2, insertCallback);
  NdbSleep_SecSleep(1);

  DBA_BulkReadResultSet_t EmpDataRead[Rows];
  for(int i = 0; i<Rows; i++){
    EmpDataRead[i].DataPtr = &EMP_TABLE_DATA_READ[i];
  }
  
  DBA_BulkReadRows(EmpB, EmpDataRead, Rows, readCallback);
  NdbSleep_SecSleep(1);
  CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
  require(CountRows(EmpDataRead, Rows) == (Rows-2));
  
  // Basic delete
  DBA_ArrayDeleteRows(EmpB, EMP_TABLE_DATA, Rows-2, deleteCallback);
  NdbSleep_SecSleep(1);
}
Пример #8
0
WgTableRow* WgTablePanel::_findRowInsertSpot( WgTableRow* pFirst, WgTableRow* pLast, WgTableRow* pRow, Uint32 nRows )
{
	assert( nRows >= 2 && pFirst != pLast );

	if( nRows <= 2 )				// Should never be less than two but we handle it as a failsafe
									// in case we screw up some calling code in the future...
	{								// Only two items means that we have found our position for insertion.
		return pLast;
	}
	else
	{
		// Step to middle item

		WgTableRow* pMiddle = pFirst;
		int steps = nRows/2;
		for( int i = 0 ; i < steps ; i++ )
			pMiddle = pMiddle->Next();

		// Compare against middle item

		bool bUp = false;
		if( CompareRows( pRow, pMiddle ) < 0 )
			bUp = true;

		if( !m_bSortAscend )
			bUp = !bUp;

		// subdivide and recurse

		if ( bUp )
			return _findRowInsertSpot( pFirst, pMiddle, pRow, steps+1);
		else
			return _findRowInsertSpot( pMiddle, pLast, pRow, nRows-steps);
	}

}
Пример #9
0
bool WgTablePanel::SortRows( int column, bool bAscend, int prio )
{
	if( column >= m_nColumns || prio > c_nSortColumns )
		return false;


	int i = 0;
	while( i < c_nSortColumns-1 )
	{
		if( m_sortStack[i].column == column )
			break;
		i++;
	}

	while( i > prio )
	{
		m_sortStack[i] = m_sortStack[i-1];
		i--;
	}

	m_sortStack[i].column			= column;
	m_sortStack[i].bAscend			= bAscend;

	if( prio == m_clickSortPrio )
	{
		m_lastSortColumn				= column;
		m_lastSortColumnAscendStatus	= bAscend;
	}

	// From old SortItems()...

	WgTableRow * pRow = m_rows.First();
	int nRows = 1;

	while( pRow )
	{
		WgTableRow * pNext = pRow->Next();

		if( nRows >= 2 )
		{
			WgTableRow* pFirst = m_rows.First();
			WgTableRow* pLast = pRow;

			bool bFirst = false;
			if( CompareRows( pRow, pFirst ) < 0 )
				bFirst = true;

			if( !m_bSortAscend )
				bFirst = !bFirst;

			if( bFirst )
				m_rows.PushFront( pRow );
			else
				pRow->_moveBefore(_findRowInsertSpot( pFirst, pLast, pRow, m_nRows ));
		}

		nRows++;
		pRow = pNext;
	}

	_requestRender();
	return true;
}