114 return(
new CSG_Table(File, Format, Encoding) );
122 return(
new CSG_Table(File, Format, Encoding) );
204 for(
int i=0; !bResult && i<Connections.
Get_Count(); i++)
206 if( !Connection.
Cmp(Connections[i].asString(0)) )
263 return(
Load(File, (
int)Format, Separator, Encoding) );
334 _Destroy_Selection();
483 if( Position < 0 || Position >
m_nFields )
522 if( del_Field < 0 || del_Field >=
m_nFields )
569 if( iField < 0 || iField >=
m_nFields || iField == Position )
575 if( Position > iField )
585 if( Position < iField )
590 #pragma omp parallel for
613 if( iField >= 0 && iField <
m_nFields && Name && *Name )
646 (*pValue) = *pRecord->
m_Values[iField];
682 if( Length < nBytes )
689 return( (
int)Length );
744 #define GET_GROW_SIZE(n) (n < 256 ? 1 : (n < 8192 ? 128 : 1024))
747 bool CSG_Table::_Inc_Array(
void)
756 if( pRecords == NULL )
761 m_Records = pRecords;
768 bool CSG_Table::_Dec_Array(
void)
777 if( pRecords == NULL )
782 m_Records = pRecords;
823 if( Selection[i] > iRecord )
832 m_Records[i] = m_Records[i - 1]; m_Records[i]->
m_Index = i;
838 m_Records[iRecord] = pRecord;
860 if( iRecord >= 0 && iRecord <
m_nRecords && pCopy )
862 return( m_Records[iRecord]->
Assign(pCopy) );
878 delete(m_Records[iRecord]);
884 m_Records[i] = m_Records[i + 1]; m_Records[i]->
m_Index = i;
914 delete(m_Records[iRecord]);
932 else if( nRecords >= 0 &&
m_nRecords > nRecords )
955 return( Value.
Cmp(m_Records[iRecord = 0]->
asString(iField)) == 0 );
968 if( Value.
Cmp(m_Records[iRecord]->
asString(iField)) == 0 )
978 #define GET_RECORD(i) Get_Record_byIndex(bAscending ? (iRecord = i) : m_nRecords - 1 - (iRecord = i))
982 if( (d = Value.
Cmp(
GET_RECORD(0 )->asString(iField))) < 0 ) {
return(
false ); }
else if( d == 0 ) {
return(
true ); }
983 if( (d = Value.
Cmp(
GET_RECORD(
m_nRecords - 1)->asString(iField))) > 0 ) {
return(
false ); }
else if( d == 0 ) {
return(
true ); }
987 d = Value.
Cmp(
GET_RECORD(a + (b - a) / 2)->asString(iField));
1017 if(
Find_Record(iRecord, iField, Value, bCreateIndex) )
1035 return( Value == m_Records[iRecord = 0]->asDouble(iField) );
1046 for(iRecord=0; iRecord<
m_nRecords; iRecord++)
1048 if( Value == m_Records[iRecord]->asDouble(iField) )
1058 #define GET_RECORD(i) Get_Record_byIndex(bAscending ? (iRecord = i) : m_nRecords - 1 - (iRecord = i))
1062 if( (d = Value -
GET_RECORD(0 )->asDouble(iField)) < 0. ) {
return(
false ); }
else if( d == 0. ) {
return(
true ); }
1063 if( (d = Value -
GET_RECORD(
m_nRecords - 1)->asDouble(iField)) > 0. ) {
return(
false ); }
else if( d == 0. ) {
return(
true ); }
1067 d = Value -
GET_RECORD(a + (b - a) / 2)->asDouble(iField);
1097 if(
Find_Record(iRecord, iField, Value, bCreateIndex) )
1119 if( bModified ==
false )
1121 #pragma omp parallel for
1137 return( pRecord && pRecord->
Set_Value(iField, Value) );
1150 return( pRecord && pRecord->
Set_Value(iField, Value) );
1202 for(
int iField=0; iField<
m_nFields; iField++)
1242 for(
double i=0; i<(double)
Get_Count(); i+=d)
1248 Statistics += pRecord->
asDouble(iField);
1264 Statistics += pRecord->
asDouble(iField);
1376 CSG_Table_Record_Compare_Field(
const CSG_Table *pTable,
int Field,
bool Ascending)
1380 m_Ascending = Ascending;
1382 if( !m_pTable || m_Field < 0 || m_Field >= m_pTable->Get_Field_Count() )
1388 bool is_Okay (
void)
const {
return( m_pTable != NULL ); }
1392 sLong a = m_Ascending ? _a : _b;
1393 sLong b = m_Ascending ? _b : _a;
1395 switch( m_pTable->Get_Field_Type(m_Field) )
1399 m_pTable->Get_Record(a)->asDouble(m_Field) -
1400 m_pTable->Get_Record(b)->asDouble(m_Field);
1402 return( d < 0. ? -1 : d > 0. ? 1 : 0 );
1408 m_pTable->Get_Record(a)->asString(m_Field),
1409 m_pTable->Get_Record(b)->asString(m_Field))
1428 CSG_Table_Record_Compare_Field Compare(
this, Field, bAscending);
1442 CSG_Table_Record_Compare_Fields(
const CSG_Table *pTable,
int Fields[],
int nFields,
bool Ascending)
1443 : m_pTable(pTable), m_Fields(Fields), m_nFields(nFields)
1445 m_Ascending.Create(nFields);
1447 for(
int i=0; m_pTable && i<m_nFields; i++)
1449 if( m_Fields[i] >= m_pTable->Get_Field_Count() )
1454 m_Ascending[i] = Ascending ? 1 : 0;
1458 CSG_Table_Record_Compare_Fields(
const CSG_Table *pTable,
int Fields[],
int nFields,
int Ascending[])
1459 : m_pTable(pTable), m_Fields(Fields), m_nFields(nFields)
1461 m_Ascending.Create(nFields);
1463 for(
int i=0; m_pTable && i<m_nFields; i++)
1465 if( m_Fields[i] >= m_pTable->Get_Field_Count() )
1470 m_Ascending[i] = Ascending[i] > 0 ? 1 : 0;
1474 bool is_Okay (
void)
const {
return( m_pTable != NULL ); }
1480 for(
int i=0; !Difference && i<m_nFields; i++)
1482 int Field = m_Fields[i];
1484 sLong a = m_Ascending[i] ? _a : _b;
1485 sLong b = m_Ascending[i] ? _b : _a;
1487 switch( m_pTable->Get_Field_Type(Field) )
1490 double d = m_pTable->Get_Record(a)->asDouble(Field);
1491 d -= m_pTable->Get_Record(b)->asDouble(Field);
1492 Difference = d < 0. ? -1 : d > 0. ? 1 : 0;
1497 CSG_String s (m_pTable->Get_Record(a)->asString(Field));
1498 Difference = s.Cmp(m_pTable->Get_Record(b)->asString(Field));
1503 return( Difference );
1509 int *m_Fields, m_nFields;
1520 CSG_Table_Record_Compare_Fields Compare(
this, Fields, nFields, bAscending);
1532 void CSG_Table::_Index_Update(
void)
1534 if( m_Index_Fields.
Get_Size() < 1 )
1543 Fields += abs(m_Index_Fields[i]) - 1;
1544 Ascending += m_Index_Fields[i] > 0 ? 1 : 0;