ccgl::utils_array Namespace Reference

Array related functions include vector and pointer array. More...

Classes

class  Array2D
 Rudimentary RAII class of 2D Array which occupy successive memory. More...
 

Functions

void Output1DArrayToTxtFile (int n, const float *data, const char *filename)
 Write 1D array to a file. More...
 
void Output2DArrayToTxtFile (int rows, int cols, const float **data, const char *filename)
 Write 2D array to a file. More...
 
template<typename T >
void Read1DArrayFromTxtFile (const char *filename, int &rows, T *&data)
 Read 1D array from file The input file should follow the format: a 1D array sized rows * 1. More...
 
template<typename T >
void Read2DArrayFromTxtFile (const char *filename, int &rows, T **&data)
 Read 2D array from file The input file should follow the format: a 2D array sized rows * rows. More...
 
template<typename T >
void Read2DArrayFromString (const char *s, int &rows, T **&data)
 Read 2D array from string The input string should follow the format: float value, total number is rows * rows. More...
 
template<typename T , typename INI_T >
bool Initialize1DArray (int row, T *&data, INI_T init_value)
 Initialize DT_Array1D data. More...
 
template<typename T , typename INI_T >
bool Initialize1DArray (int row, T *&data, INI_T *init_data)
 Initialize DT_Array1D data based on an existed array. More...
 
template<typename T , typename INI_T >
bool Initialize1DArray4ItpWeight (int row, T *&data, INI_T *init_data, int itp_weight_data_length)
 
template<typename T , typename INI_T >
bool Initialize2DArray (int row, int col, T **&data, INI_T init_value)
 Initialize DT_Array2D data. More...
 
template<typename T , typename INI_T >
bool Initialize2DArray (int row, int col, T **&data, INI_T **init_data)
 Initialize DT_Array2D data based on an existed array The usage of const T * const * is refers to http://blog.csdn.net/pmt123456/article/details/50813564. More...
 
template<typename T1 , typename T2 >
bool Initialize2DArray (T1 *init_data, int &rows, int &max_cols, T2 **&data)
 Initialize irregular DT_Array2D data based on an existed 1D array. More...
 
template<typename T >
void Release1DArray (T *&data)
 Release DT_Array1D data. More...
 
template<typename T >
void Release2DArray (T **&data)
 Release DT_Array2D data. More...
 
template<typename T >
void BatchRelease1DArray (T *&data,...)
 Batch release of 1D array Variable arguments with the end of nullptr. More...
 
template<typename T >
void BatchRelease2DArray (int nrows, T **&data,...)
 Batch release of 2D array,. More...
 
template<typename T >
bool ValueInVector (T val, const vector< T > &vec)
 If value in vector container. More...
 
template<typename T >
void RemoveValueInVector (T val, vector< T > &vec)
 Remove value in vector container. More...
 

Detailed Description

Array related functions include vector and pointer array.

Function Documentation

◆ BatchRelease1DArray()

template<typename T >
void ccgl::utils_array::BatchRelease1DArray ( T *&  data,
  ... 
)

Batch release of 1D array Variable arguments with the end of nullptr.

The input parameters are listed as data, data2, ... , dataN, and ended with nullptr.

Example:

BatchRelease1DArray(array1, array2, array3, nullptr);
void BatchRelease1DArray(T *&data,...)
Batch release of 1D array Variable arguments with the end of nullptr.
Definition: utils_array.h:478
Warning
After batch release, the variable will not be set to nullptr. So, do not use these variables any more. BTW, this function will not cause memory leak.

USE WITH ALL CAUTIONS CLEARLY AWARED.

◆ BatchRelease2DArray()

template<typename T >
void ccgl::utils_array::BatchRelease2DArray ( int  nrows,
T **&  data,
  ... 
)

Batch release of 2D array,.

See also
BatchRelease1DArray Variable arguments with the end of nullptr.

Example:

BatchRelease2DArray(rows, array1, array2, array3, nullptr);
void BatchRelease2DArray(int nrows, T **&data,...)
Batch release of 2D array,.
Definition: utils_array.h:491
Parameters
[in]nrowsRows
[in]dataThe input parameters are listed as data, data2, ... , dataN, and ended with nullptr.
Warning
USE WITH ALL CAUTIONS CLEARLY AWARED.

◆ Initialize1DArray() [1/2]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize1DArray ( int  row,
T *&  data,
INI_T *  init_data 
)

Initialize DT_Array1D data based on an existed array.

Parameters
[in]row
[in]data
[in]init_data
Returns
True if succeed, else false and the error message will print as well.

◆ Initialize1DArray() [2/2]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize1DArray ( int  row,
T *&  data,
INI_T  init_value 
)

Initialize DT_Array1D data.

Parameters
[in]row
[in]data
[in]init_value
Returns
True if succeed, else false and the error message will print as well.

◆ Initialize2DArray() [1/3]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize2DArray ( int  row,
int  col,
T **&  data,
INI_T **  init_data 
)

Initialize DT_Array2D data based on an existed array The usage of const T * const * is refers to http://blog.csdn.net/pmt123456/article/details/50813564.

Parameters
[in]row
[in]col
[in]data
[in]init_datadimension MUST BE (row, col)
Returns
True if succeed, else false and the error message will print as well.

◆ Initialize2DArray() [2/3]

template<typename T , typename INI_T >
bool ccgl::utils_array::Initialize2DArray ( int  row,
int  col,
T **&  data,
INI_T  init_value 
)

Initialize DT_Array2D data.

The 2D array are created in a successive memory.

  1. Create a 1D array of row data pointers with the length of row
  2. Create a 1D array of data pool with the length of row * col
  3. Iteratively point row pointers to appropriate positions in data pool

Refers to https://stackoverflow.com/a/21944048/4837280

Parameters
[in]row
[in]col
[in]data
[in]init_value
Returns
True if succeed, else false and the error message will print as well.

◆ Initialize2DArray() [3/3]

template<typename T1 , typename T2 >
bool ccgl::utils_array::Initialize2DArray ( T1 *  init_data,
int &  rows,
int &  max_cols,
T2 **&  data 
)

Initialize irregular DT_Array2D data based on an existed 1D array.

Parameters
[in]init_dataInitial 1D array
[out]rowsRows count
[out]max_colsMaximum cols count
[out]dataIrregular 2D array
Returns
True if succeed, else false and the error message will print as well.

◆ Output1DArrayToTxtFile()

void ccgl::utils_array::Output1DArrayToTxtFile ( int  n,
const float *  data,
const char *  filename 
)

Write 1D array to a file.

See also
Read1DArrayFromTxtFile(), Read2DArrayFromTxtFile(), Output2DArrayToTxtFile()
Parameters
[in]n,data,filename

◆ Output2DArrayToTxtFile()

void ccgl::utils_array::Output2DArrayToTxtFile ( int  rows,
int  cols,
const float **  data,
const char *  filename 
)

Write 2D array to a file.

See also
Read1DArrayFromTxtFile(), Read2DArrayFromTxtFile(), Output1DArrayToTxtFile()
Parameters
[in]rows,cols,data,filename

◆ Read1DArrayFromTxtFile()

template<typename T >
void ccgl::utils_array::Read1DArrayFromTxtFile ( const char *  filename,
int &  rows,
T *&  data 
)

Read 1D array from file The input file should follow the format: a 1D array sized rows * 1.

The size of data is rows

See also
Read2DArrayFromTxtFile(), Output1DArrayToTxtFile(), Output2DArrayToTxtFile()
Parameters
[in]filename
[out]rows,data

◆ Read2DArrayFromString()

template<typename T >
void ccgl::utils_array::Read2DArrayFromString ( const char *  s,
int &  rows,
T **&  data 
)

Read 2D array from string The input string should follow the format: float value, total number is rows * rows.

The size of data is rows * (rows + 1), the first element of each row is the rows.

Parameters
[in]s
[out]rows,data

◆ Read2DArrayFromTxtFile()

template<typename T >
void ccgl::utils_array::Read2DArrayFromTxtFile ( const char *  filename,
int &  rows,
T **&  data 
)

Read 2D array from file The input file should follow the format: a 2D array sized rows * rows.

The size of data is rows * (rows + 1), the first element of each row is the rows

See also
Read1DArrayFromTxtFile(), Output1DArrayToTxtFile(), Output2DArrayToTxtFile()
Parameters
[in]filename
[out]rows,data

◆ Release1DArray()

template<typename T >
void ccgl::utils_array::Release1DArray ( T *&  data)

Release DT_Array1D data.

Parameters
[in]data

◆ Release2DArray()

template<typename T >
void ccgl::utils_array::Release2DArray ( T **&  data)

Release DT_Array2D data.

Parameters
[in]data

◆ RemoveValueInVector()

template<typename T >
void ccgl::utils_array::RemoveValueInVector ( val,
vector< T > &  vec 
)

Remove value in vector container.

Parameters
[in]valValue to be removed, e.g., a int, or float
[in]vecVector container, data type is consistent with val

◆ ValueInVector()

template<typename T >
bool ccgl::utils_array::ValueInVector ( val,
const vector< T > &  vec 
)

If value in vector container.

Parameters
[in]valValue, e.g., a int, or float
[in]vecVector container, data type is consistent with val
Returns
True if val is in vec, otherwise False