Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
o2scl::table< vec_t > Class Template Reference

Data table class. More...

#include <table.h>

Inheritance diagram for o2scl::table< vec_t >:
o2scl::table_units< vec_t >

Classes

class  col
 Column structure for table [protected]. More...
 

Public Member Functions

template<class vec2_t >
void insert_table (table< vec2_t > &source, std::string src_index, bool allow_extrap=true, std::string dest_index="")
 Insert columns from a source table into the new table by interpolation (or extrapolation)
 
Constructors, destructors
 table (size_t cmaxlines=0)
 Create a new table with space for nlines<=cmaxlines.
 
virtual ~table ()
 
 table (const table &t)
 Copy constructor.
 
tableoperator= (const table &t)
 Copy constructor.
 
Basic get and set methods
void set (std::string scol, size_t row, double val)
 Set row row of column named col to value val . $ {\cal O}(\log(C)) $. More...
 
void set (size_t icol, size_t row, double val)
 Set row row of column number icol to value val . $ {\cal O}(1) $.
 
template<class size_vec_t >
void set_row (size_t row, size_vec_t &v)
 Set an entire row of data. More...
 
double get (std::string scol, size_t row) const
 Get value from row row of column named col. $ {\cal O}(\log(C)) $.
 
double get (size_t icol, size_t row) const
 Get value from row row of column number icol. $ {\cal O}(1) $.
 
size_t get_ncolumns () const
 Return the number of columns.
 
Manipulate current and maximum number of rows
size_t get_nlines () const
 Return the number of lines.
 
void set_nlines (size_t il)
 Set the number of lines. More...
 
size_t get_maxlines ()
 Return the maximum number of lines before a reallocation is required.
 
template<class resize_vec_t >
void get_row (std::string scol, double val, resize_vec_t &row) const
 Returns a copy of the row with value val in column col. $ {\cal O}(R C) $. More...
 
template<class resize_vec_t >
void get_row (size_t irow, resize_vec_t &row) const
 Returns a copy of row number irow. $ {\cal O}(C) $. More...
 
void set_nlines_auto (size_t il)
 Set the number of lines, increasing the size more agressively. More...
 
void inc_maxlines (size_t llines)
 Manually increase the maximum number of lines.
 
Column manipulation
const vec_t & get_column (std::string scol) const
 Returns a reference to the column named col. $ {\cal O}(\log(C)) $.
 
const vec_t & operator[] (size_t icol) const
 Returns the column of index icol (const version). $ {\cal O}(1) $. More...
 
const vec_t & operator[] (std::string scol) const
 Returns the column named scol (const version). $ {\cal O}(\log(C)) $. More...
 
void new_column (std::string head)
 Add a new column owned by the table $ {\cal O}(\log(C)) $. More...
 
template<class vec2_t >
int new_column (std::string name, size_t sz, vec2_t &v)
 Add a new column by copying data from another vector. More...
 
std::string get_column_name (size_t icol) const
 Returns the name of column col $ {\cal O}(1) $. More...
 
virtual void swap_column_data (std::string scol, vec_t &v)
 Swap the data in column scol with that in vector v. More...
 
virtual void rename_column (std::string src, std::string dest)
 Rename column named src to dest $ {\cal O}(C) $.
 
virtual void delete_column (std::string scol)
 Delete column named scol $ {\cal O}(C) $. More...
 
std::string get_sorted_name (size_t icol) const
 Returns the name of column col in sorted order. $ {\cal O}(1) $.
 
void init_column (std::string scol, double val)
 Initialize all values of column named scol to val $ {\cal O}(R \log(C)) $. More...
 
bool is_column (std::string scol) const
 Return true if scol is a column in the current table. More...
 
size_t lookup_column (std::string lname) const
 Find the index for column named name $ {\cal O}(\log(C)) $. More...
 
virtual void copy_column (std::string src, std::string dest)
 Copy data from column named src to column named dest, creating a new column if necessary $ {\cal O}(R \log(C)) $.
 
template<class resize_vec_t >
void column_to_vector (std::string scol, resize_vec_t &v) const
 Copy a column to a generic vector object. More...
 
template<class vec2_t >
void copy_to_column (vec2_t &v, std::string scol)
 Copy to a column from a generic vector object. More...
 
template<class vec2_t >
void add_col_from_table (table< vec2_t > &source, std::string src_index, std::string src_col, std::string dest_index, std::string dest_col="")
 Insert a column from a separate table, interpolating it into a new column. More...
 
Row maninpulation and data input
void new_row (size_t n)
 Insert a row before row n. More...
 
void copy_row (size_t src, size_t dest)
 Copy the data in row src to row dest.
 
void delete_row (std::string scol, double val)
 Delete the row with the entry closest to the value val in column scol $ {\cal O}(R C) $.
 
void delete_row (size_t irow)
 Delete the row of index irow $ {\cal O}(R C) $.
 
void delete_rows (std::string func)
 Delete all rows where func evaluates to a number greater than 0.5 $ {\cal O}(R C) $. More...
 
template<class vec2_t >
void copy_rows (std::string func, table< vec2_t > &dest)
 Copy all rows matching a particular condition to a new table. More...
 
void delete_rows (size_t row_start, size_t row_end)
 Delete all rows between row_start and row_end $ {\cal O}(R C) $. More...
 
void line_of_names (std::string newheads)
 Read a new set of names from newheads. More...
 
template<class vec2_t >
void line_of_data (size_t nv, const vec2_t &v)
 Read a line of data from the first nv entries in a vector and store as a new row in the table. More...
 
template<class vec2_t >
void line_of_data (const vec2_t &v)
 Read a line of data and store in a new row of the table. More...
 
Lookup and search methods
size_t ordered_lookup (std::string scol, double val) const
 Look for a value in an ordered column $ {\cal O}(\log(C) \log(R)) $. More...
 
size_t lookup (std::string scol, double val) const
 Exhaustively search column col for the value val $ {\cal O}(R \log(C)) $.
 
double lookup_val (std::string scol, double val, std::string scol2) const
 Search column col for the value val and return value in col2.
 
size_t lookup (int icol, double val) const
 Exhaustively search column col for the value val $ {\cal O}(R \log(C)) $.
 
size_t mlookup (std::string scol, double val, std::vector< size_t > &results, double threshold=0.0) const
 Exhaustively search column col for many occurences of val $ {\cal O}(R \log(C)) $.
 
Interpolation, differentiation, integration, max, min
void set_interp_type (size_t interp_type)
 Set the base interpolation objects.
 
size_t get_interp_type () const
 Get the interpolation type.
 
double interp (std::string sx, double x0, std::string sy)
 Interpolate x0 from sx into sy. More...
 
double interp_const (std::string sx, double x0, std::string sy) const
 Interpolate x0 from sx into sy. More...
 
double interp (size_t ix, double x0, size_t iy)
 Interpolate x0 from ix into iy $ {\cal O}(\log(R)) $.
 
double interp_const (size_t ix, double x0, size_t iy) const
 Interpolate x0 from ix into iy $ {\cal O}(\log(R)) $.
 
void deriv (std::string x, std::string y, std::string yp)
 Make a new column yp which is the derivative $ y^{\prime}(x) $ . $ {\cal O}(R \log(C)) $.
 
double deriv (std::string sx, double x0, std::string sy)
 The first derivative of the function sy(sx) at sx=x0. More...
 
double deriv_const (std::string sx, double x0, std::string sy) const
 The first derivative of the function sy(sx) at sx=x0. More...
 
double deriv (size_t ix, double x0, size_t iy)
 The first derivative of the function iy(ix) at ix=x0. More...
 
double deriv_const (size_t ix, double x0, size_t iy) const
 The first derivative of the function iy(ix) at ix=x0. More...
 
void deriv2 (std::string x, std::string y, std::string yp)
 Make a new column yp which is $ y^{\prime \prime}(x) $ - O(log(C)*R).
 
double deriv2 (std::string sx, double x0, std::string sy)
 The second derivative of the function sy(sx) at sx=x0. More...
 
double deriv2_const (std::string sx, double x0, std::string sy) const
 The second derivative of the function sy(sx) at sx=x0. More...
 
double deriv2 (size_t ix, double x0, size_t iy)
 The second derivative of the function iy(ix) at ix=x0. More...
 
double deriv2_const (size_t ix, double x0, size_t iy) const
 The second derivative of the function iy(ix) at ix=x0. More...
 
double integ (std::string sx, double x1, double x2, std::string sy)
 The integral of the function sy(sx) from sx=x1 to sx=x2. More...
 
double integ_const (std::string sx, double x1, double x2, std::string sy) const
 The integral of the function sy(sx) from sx=x1 to sx=x2. More...
 
double integ (size_t ix, double x1, double x2, size_t iy)
 The integral of the function iy(ix) from ix=x1 to ix=x2. More...
 
double integ_const (size_t ix, double x1, double x2, size_t iy) const
 The integral of the function iy(ix) from ix=x1 to ix=x2. More...
 
void integ (std::string x, std::string y, std::string ynew)
 The integral of the function iy(ix) More...
 
double max (std::string scol) const
 Return column maximum. Makes no assumptions about ordering $ {\cal O}(R) $.
 
double min (std::string scol) const
 Return column minimum. Makes no assumptions about ordering $ {\cal O}(R) $.
 
Subtable method
void subtable (std::string list, size_t top, size_t bottom, table< vec_t > &tnew) const
 Make a subtable. More...
 
Clear methods
void zero_table ()
 Zero the data entries but keep the column names and nlines fixed.
 
void clear ()
 Clear everything.
 
void clear_table ()
 Clear the table and the column names (but leave constants)
 
void clear_data ()
 Remove all of the data by setting the number of lines to zero. More...
 
void clear_constants ()
 CLear all constants.
 
Sorting methods
void sort_table (std::string scol)
 Sort the entire table by the column scol. More...
 
void sort_column (std::string scol)
 Individually sort the column scol.
 
Summary method
virtual void summary (std::ostream *out, size_t ncol=79) const
 Output a summary of the information stored. More...
 
Constant manipulation
virtual void add_constant (std::string name, double val)
 Add a constant, or if the constant already exists, change its value.
 
virtual int set_constant (std::string name, double val, bool err_on_notfound=true)
 Set a constant equal to a value, but don't add it if not already present. More...
 
virtual bool is_constant (std::string name) const
 Test if name is a constant.
 
virtual double get_constant (std::string name) const
 Get a constant.
 
virtual size_t get_nconsts () const
 Get the number of constants.
 
virtual void get_constant (size_t ix, std::string &name, double &val) const
 Get a constant by index.
 
virtual void remove_constant (std::string name)
 Remove a constant.
 
Miscellaneous methods
virtual int read_generic (std::istream &fin, int verbose=0)
 Clear the current table and read from a generic data file.
 
void check_synchro () const
 Return 0 if the tree and list are properly synchronized.
 
virtual const char * type ()
 Return the type, "table".
 
Parsing mathematical functions specified as strings
void functions_columns (std::string list)
 Create new columns or recompute from a list of functions. More...
 
void function_column (std::string function, std::string scol)
 Make a column from the function specified in function and add it to the table. More...
 
template<class resize_vec_t >
int function_vector (std::string function, resize_vec_t &vec, bool throw_on_err=true)
 Compute a column from a function specified in a string. More...
 
double row_function (std::string function, size_t row) const
 Compute a value by applying a function to a row.
 
size_t function_find_row (std::string function) const
 Find a row which maximizes a function.
 

Protected Types

Iterator types
typedef std::map< std::string, col, std::greater< std::string > >::iterator aiter
 Map iterator type.
 
typedef std::map< std::string, col, std::greater< std::string > >::const_iterator aciter
 Const map iterator type.
 
typedef std::vector< aiter >::iterator aviter
 Vector iterator type.
 

Protected Member Functions

void reset_list ()
 Set the elements of alist with the appropriate iterators from atree. $ {\cal O}(C) $. More...
 
void make_fp_varname (std::string &s)
 Ensure a variable name does not match a function or contain non-alphanumeric characters.
 
void make_unique_name (std::string &colx, std::vector< std::string > &cnames)
 Make sure a name is unique.
 
Column manipulation methods
aiter get_iterator (std::string lname)
 Return the iterator for a column.
 
colget_col_struct (std::string lname)
 Return the column structure for a column.
 
aiter begin ()
 Return the beginning of the column tree.
 
aiter end ()
 Return the end of the column tree.
 

Protected Attributes

std::map< std::string, double > constants
 The list of constants.
 
vec_t empty_col
 An empty vector for get_column()
 
Actual data
size_t maxlines
 The size of allocated memory.
 
size_t nlines
 The size of presently used memory.
 
std::map< std::string, col, std::greater< std::string > > atree
 The tree of columns.
 
std::vector< aiteralist
 The list of tree iterators.
 
Interpolation
bool intp_set
 True if the interpolation object is up-to-date.
 
size_t itype
 Current interpolation type.
 
interp_vec< vec_t > * si
 Interpolation object.
 
std::string intp_colx
 The last x-column interpolated.
 
std::string intp_coly
 The last y-column interpolated.
 

Friends

void o2scl_hdf::hdf_output (o2scl_hdf::hdf_file &hf, table<> &t, std::string name)
 
template<class vecf_t >
void o2scl_hdf::hdf_input (o2scl_hdf::hdf_file &hf, table< vecf_t > &t, std::string name)
 
void o2scl_hdf::hdf_output_data (o2scl_hdf::hdf_file &hf, table<> &t)
 
template<class vecf_t >
void o2scl_hdf::hdf_input_data (o2scl_hdf::hdf_file &hf, table< vecf_t > &t)
 

Detailed Description

template<class vec_t = std::vector<double>>
class o2scl::table< vec_t >

Summary

A class to contain and manipulate several equally-sized columns of data. The purpose of this class is to provide a structure which allows one to refer to the columns using a name represented by a string. Thus for a table object named t with 3 columns (named "colx", "coly" and "colz") and three rows, one could do the following:

// Set the 1st row of column "colx" to 1.0
t.set("colx",0,1.0);
// Set the 2nd row of column "colz" to 2.0
t.set("colz",1,2.0);
// Set the 3rd row of column "coly" to 4.0
t.set("coly",2,4.0);
// This will print out 2.0
cout << t.get("colz",1) << endl;

Note that the rows are numbered starting with 0 instead of starting with 1. To output all the rows of entire column, one can use

for(size_t i=0;i<t.get_nlines();i++) {
cout << i << " " << t.get("colx",i) << endl;
}

To output all the columns of an entire row (in the following example it is the second row), labeled by their column name, one can use:

for(size_t i=0;i<t.get_ncolumns();i++) {
cout << t.get_column_name(i) << " ";
}
cout << endl;
for(size_t i=0;i<t.get_ncolumns();i++) {
cout << t.get(i,1) << " ";
}
cout << endl;

Methods are provided for interpolating columns, sorting columns, finding data points, and several other manipulations of the data.

Column size

The columns grow automatically (similar to the STL <vector>) in reponse to an attempt to call set() for a row that does not presently exist or in a call to line_of_data() when the table is already full. However, this forces memory rearrangments that are expensive, O(R*C). If the user has a good estimate of the number of rows beforehand, it is best to either specify this in the constructor, or in an explicit call to inc_maxlines().

Lookup, differentiation, integration, and interpolation
Lookup, differentiation, integration, and interpolation are automatically implemented using splines from the class interp_vec. A caching mechanism is implemented so that successive interpolations, derivative evaluations or integrations over the same two columns are fast.

Sorting
The columns are automatically sorted by name for speed, the results can be accessed from get_sorted_name(). Individual columns can be sorted (sort_column() ), or the entire table can be sorted by one column (sort_table() ).

Data representation
Each individual column is just a vector object. The columns can be referred to in one of two ways:

The columns are organized in a both a <map> and a <vector> structure so that finding a column by its index, using either of

std::string table::get_column_name(size_t index);
ubvector &table::operator[](size_t index);

takes only constant time, and finding a column by its name using either of

size_t lookup_column(std::string name) const;
const ubvector &get_column(std::string col) const;

is O(log(C)). Insertion of a column ( new_column() ) is O(log(C)), but deletion ( delete_column() ) is O(C). Adding a row of data can be either O(1) or O(C), but row insertion and deletion is slow, since the all of the rows must be shifted accordingly.

Because of the structure, this class is not suitable for the matrix manipulation.

Vector types
The type vec_t can be any vector type with operator[], size() and resize() methods. HDF5 I/O with vector types other than std::vector<double> requires a copy. See the the discussion in the sections Tensors and I/O and contiguous storage of the user's guide for more details.

Thread-safety
Generally, the member functions are only thread-safe if they are const .

I/O and command-line manipulation
When data from an object of type table is output to a file through the hdf_output() function in o2scl_hdf, the table can be manipulated on the command-line through the acol utility (see The 'acol' Command-line Utility).

There is an example for the usage of this class given in examples/ex_table.cpp.

Idea for Future:
  • Create a sort_column_names() or a function to arbitrarily rearrange the columns
  • The present structure, std::map<std::string,col,string_comp> atree and std::vector<aiter> alist; could be replaced with std::vector<col> list and std::map<std::string,int> tree where the map just stores the index of the the column in the list.
  • Rewrite check_synchro into a full is_valid()-like sanity check

Definition at line 49 of file table.h.

Member Function Documentation

◆ add_col_from_table()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::add_col_from_table ( table< vec2_t > &  source,
std::string  src_index,
std::string  src_col,
std::string  dest_index,
std::string  dest_col = "" 
)
inline

Given a pair of columns ( src_index, src_col ) in a separate table (source), this creates a new column in the present table named src_col which interpolates loc_index into src_index. The interpolation objects from the source table will be used. If there is already a column in the present table named src_col, then this will fail.

Definition at line 984 of file table.h.

◆ clear_data()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::clear_data ( )
inline

This leaves the column names intact and does not remove the constants.

Definition at line 2008 of file table.h.

◆ column_to_vector()

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
void o2scl::table< vec_t >::column_to_vector ( std::string  scol,
resize_vec_t &  v 
) const
inline
Note
It is assumed that the vector type is one that can be resized with resize().

Definition at line 952 of file table.h.

◆ copy_rows()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::copy_rows ( std::string  func,
table< vec2_t > &  dest 
)
inline

This function begins by ensuring that all columns in the current table are present in dest, creating new columns in dest if necessary. It then copies all rows where func evaluates to a number greater than 0.5 to table dest by adding rows at the end of the table.

Definition at line 1153 of file table.h.

◆ copy_to_column()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::copy_to_column ( vec2_t &  v,
std::string  scol 
)
inline

The type vec2_t can be any type with an operator[] method.

Definition at line 966 of file table.h.

◆ delete_column()

template<class vec_t = std::vector<double>>
virtual void o2scl::table< vec_t >::delete_column ( std::string  scol)
inlinevirtual

This is slow because the iterators in alist are mangled and we have to call reset_list() to get them back.

Reimplemented in o2scl::table_units< vec_t >.

Definition at line 816 of file table.h.

◆ delete_rows() [1/2]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::delete_rows ( std::string  func)
inline

If no rows match the delete condition, this function silently performs no changes to the table.

Definition at line 1118 of file table.h.

◆ delete_rows() [2/2]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::delete_rows ( size_t  row_start,
size_t  row_end 
)
inline

If row_start is less or equal to row_end, then all rows beginnning with row_start and ending with row_end are deleted (inclusive). If row_start is greater than row_end, then rows from the start of the table until row_end are deleted, as well as all rows from row_start through the end of the table.

If either row_start or row_end are beyond the end of the table (greater than or equal to the value given by get_nlines() ), an exception is thrown.

Definition at line 1194 of file table.h.

◆ deriv() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv ( std::string  sx,
double  x0,
std::string  sy 
)
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1551 of file table.h.

◆ deriv() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv ( size_t  ix,
double  x0,
size_t  iy 
)
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1609 of file table.h.

◆ deriv2() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2 ( std::string  sx,
double  x0,
std::string  sy 
)
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1652 of file table.h.

◆ deriv2() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2 ( size_t  ix,
double  x0,
size_t  iy 
)
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1710 of file table.h.

◆ deriv2_const() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2_const ( std::string  sx,
double  x0,
std::string  sy 
) const
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1686 of file table.h.

◆ deriv2_const() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2_const ( size_t  ix,
double  x0,
size_t  iy 
) const
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1719 of file table.h.

◆ deriv_const() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv_const ( std::string  sx,
double  x0,
std::string  sy 
) const
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1585 of file table.h.

◆ deriv_const() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv_const ( size_t  ix,
double  x0,
size_t  iy 
) const
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1618 of file table.h.

◆ function_column()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::function_column ( std::string  function,
std::string  scol 
)
inline

If a column named scol already exists, the data already present is overwritten with the result. Otherwise, a new column is created and filled with the result.

Definition at line 2445 of file table.h.

◆ function_vector()

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
int o2scl::table< vec_t >::function_vector ( std::string  function,
resize_vec_t &  vec,
bool  throw_on_err = true 
)
inline

The type resize_vec_t must have resize() and size() methods. If vec does not have enough space to hold the number of entries given by get_nlines(), it is resized.

Definition at line 2479 of file table.h.

◆ functions_columns()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::functions_columns ( std::string  list)
inline

The list should be a space-delimited list of entries of the form name=function where name is the column name and function the function specifing the values for the column. If a column named name is already present, it is overwritten. Otherwise, a new column is created.

Definition at line 2381 of file table.h.

◆ get_column_name()

template<class vec_t = std::vector<double>>
std::string o2scl::table< vec_t >::get_column_name ( size_t  icol) const
inline

This will throw if icol is larger than or equal to the number of columns.

Definition at line 758 of file table.h.

◆ get_row() [1/2]

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
void o2scl::table< vec_t >::get_row ( std::string  scol,
double  val,
resize_vec_t &  row 
) const
inline

This function searches the entire table for the row which has the entry in column col which is closest to the value val, and copies that row to the vector row.

If the object row previously contains any data, it will be lost.

The type resize_vec_t must be a type which has size() and resize() methods.

Definition at line 505 of file table.h.

◆ get_row() [2/2]

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
void o2scl::table< vec_t >::get_row ( size_t  irow,
resize_vec_t &  row 
) const
inline

This function returns a copy of row with index irow, where irow ranges from 0 to get_nlines()-1, inclusive.

If the object row previously contains any data, it will be lost.

The type resize_vec_t must be a type which has size() and resize() methods.

Definition at line 531 of file table.h.

◆ init_column()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::init_column ( std::string  scol,
double  val 
)
inline

Note that this does not initialize elements beyond nlines so that if the number of rows is increased afterwards, the new rows will have uninitialized values.

Definition at line 870 of file table.h.

◆ integ() [1/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ ( std::string  sx,
double  x1,
double  x2,
std::string  sy 
)
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1728 of file table.h.

◆ integ() [2/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ ( size_t  ix,
double  x1,
double  x2,
size_t  iy 
)
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1788 of file table.h.

◆ integ() [3/3]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::integ ( std::string  x,
std::string  y,
std::string  ynew 
)
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1808 of file table.h.

◆ integ_const() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ_const ( std::string  sx,
double  x1,
double  x2,
std::string  sy 
) const
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1763 of file table.h.

◆ integ_const() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ_const ( size_t  ix,
double  x1,
double  x2,
size_t  iy 
) const
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1798 of file table.h.

◆ interp()

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::interp ( std::string  sx,
double  x0,
std::string  sy 
)
inline

This function is $ {\cal O}(\log(R) \log(C)) $ but can be as bad as $ {\cal O}(C \log(R) $ if the relevant columns are not well ordered.

Definition at line 1453 of file table.h.

◆ interp_const()

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::interp_const ( std::string  sx,
double  x0,
std::string  sy 
) const
inline

This function is $ {\cal O}(\log(R) \log(C)) $ but can be as bad as $ {\cal O}(C \log(R) $ if the relevant columns are not well ordered.

Definition at line 1487 of file table.h.

◆ is_column()

template<class vec_t = std::vector<double>>
bool o2scl::table< vec_t >::is_column ( std::string  scol) const
inline

This function does not call the error handler if the column is not found, but just silently returns false.

Definition at line 899 of file table.h.

◆ line_of_data() [1/2]

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::line_of_data ( size_t  nv,
const vec2_t &  v 
)
inline

The type vec2_t can be any type with an operator[] method.

Definition at line 1254 of file table.h.

◆ line_of_data() [2/2]

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::line_of_data ( const vec2_t &  v)
inline

The type vec2_t can be any type with an operator[] method.

Definition at line 1283 of file table.h.

◆ line_of_names()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::line_of_names ( std::string  newheads)
inline

This function reads a set of white-space delimited column names from the string newheads, and creates a new column for each name which is specified.

For example

t.line_of_names("position velocity acceleration");

will create three new columns with the names "position", "velocity", and "acceleration".

Definition at line 1231 of file table.h.

◆ lookup_column()

template<class vec_t = std::vector<double>>
size_t o2scl::table< vec_t >::lookup_column ( std::string  lname) const
inline

If the column is not present, this function calls the error handler.

Definition at line 911 of file table.h.

◆ new_column() [1/2]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::new_column ( std::string  head)
inline
Note
This function does not set all the column entries to zero in the case that a new column is added to a table which already contains data.

Definition at line 690 of file table.h.

◆ new_column() [2/2]

template<class vec_t = std::vector<double>>
template<class vec2_t >
int o2scl::table< vec_t >::new_column ( std::string  name,
size_t  sz,
vec2_t &  v 
)
inline

This function copies sz elements of vector v into the table in a new column named name. If sz is larger than the current number of lines (as given, e.g. in get_nlines() ), then only the first part of the vector v is copied, up to the current number of lines.

This function calls the error handler if sz is zero.

The type vec2_t can be any type with an operator[] method.

Definition at line 730 of file table.h.

◆ new_row()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::new_row ( size_t  n)
inline

Acceptable values for n are between 0 and get_nlines() inclusive, with the maximum value denoting the addition of a row after the last row presently in the table.

Definition at line 1055 of file table.h.

◆ operator[]() [1/2]

template<class vec_t = std::vector<double>>
const vec_t& o2scl::table< vec_t >::operator[] ( size_t  icol) const
inline

Note that several of the methods require reallocation of memory and refereces previously returned by this function will be incorrect.

Unlike set(), this function will not automatically result in an increase in the size of the table if the user attempts to set an element beyond the current column range.

This function will throw an exception if icol is out of range unless O2SCL_NO_RANGE_CHECK is defined.

Definition at line 644 of file table.h.

◆ operator[]() [2/2]

template<class vec_t = std::vector<double>>
const vec_t& o2scl::table< vec_t >::operator[] ( std::string  scol) const
inline

Note that several of the methods require reallocation of memory and refereces previously returned by this function will be incorrect.

Unlike set(), this function will not automatically result in an increase in the size of the table if the user attempts to set an element beyond the current column range.

This function will throw an exception if icol is out of range unless O2SCL_NO_RANGE_CHECK is defined.

Definition at line 672 of file table.h.

◆ ordered_lookup()

template<class vec_t = std::vector<double>>
size_t o2scl::table< vec_t >::ordered_lookup ( std::string  scol,
double  val 
) const
inline

This uses the function search_vec::ordered_lookup(), which offers caching and assumes the vector is monotonic. If you don't have monotonic data, you can still use the table::lookup() function, which is more general.

Definition at line 1301 of file table.h.

◆ reset_list()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::reset_list ( )
inlineprotected

Generally, the end-user shouldn't need this method. It is only used in delete_column() to rearrange the list when a column is deleted from the tree.

Definition at line 2594 of file table.h.

◆ set()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::set ( std::string  scol,
size_t  row,
double  val 
)
inline

This function adds the column col if it does not already exist and adds rows using inc_maxlines() and set_nlines() to create at least row+1 rows if they do not already exist.

Definition at line 327 of file table.h.

◆ set_constant()

template<class vec_t = std::vector<double>>
virtual int o2scl::table< vec_t >::set_constant ( std::string  name,
double  val,
bool  err_on_notfound = true 
)
inlinevirtual

If err_on_notfound is true (the default), then this function throws an exception if a constant with name name is not found. If err_on_notfound is false, then if a constant with name name is not found this function just silently returns o2scl::exc_enotfound.

Definition at line 2170 of file table.h.

◆ set_nlines()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::set_nlines ( size_t  il)
inline

This function is stingy about increasing the table memory space and will only increase it enough to fit il lines. Using it in succession to slowly increase the number of lines in the table is likely to be inefficient compared to set_nlines_auto() in this case.

Definition at line 467 of file table.h.

◆ set_nlines_auto()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::set_nlines_auto ( size_t  il)
inline

This function is like set_nlines(), but doubles the maximum column size if an increase in the maximum size is required instead of simply making enough room for the current number of lines. This function is used internally by set() to ensure that the cost of setting lines in sequence is linear and not quadratic.

Definition at line 559 of file table.h.

◆ set_row()

template<class vec_t = std::vector<double>>
template<class size_vec_t >
void o2scl::table< vec_t >::set_row ( size_t  row,
size_vec_t &  v 
)
inline

The type size_vec_t must be a type which has a size() method.

Definition at line 401 of file table.h.

◆ sort_table()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::sort_table ( std::string  scol)
inline
Note
This function works by allocating space for an entirely new chunk of memory for the data in the table.

Definition at line 2033 of file table.h.

◆ subtable()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::subtable ( std::string  list,
size_t  top,
size_t  bottom,
table< vec_t > &  tnew 
) const
inline

Uses the columns specified in list from the row top to the row of index bottom to generate a new table which is a copy of part of the original.

Definition at line 1904 of file table.h.

◆ summary()

template<class vec_t = std::vector<double>>
virtual void o2scl::table< vec_t >::summary ( std::ostream *  out,
size_t  ncol = 79 
) const
inlinevirtual

Outputs the number of constants, the number of columns, a list of the column names, and the number of lines of data.

Reimplemented in o2scl::table_units< vec_t >.

Definition at line 2095 of file table.h.

◆ swap_column_data()

template<class vec_t = std::vector<double>>
virtual void o2scl::table< vec_t >::swap_column_data ( std::string  scol,
vec_t &  v 
)
inlinevirtual

This requires that the column v must have the correct size, that returned by get_maxlines().

This function is useful, in part, because if objects of type vec_t have std::move defined, then the swap doesn't require a full copy.

Definition at line 777 of file table.h.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).