Class table (o2scl)¶

template<class vec_t = std::vector<double>>
class table¶ Data class.
Summary
A class to contain and manipulate several equallysized 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: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// 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;
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_nlines();i++) { cout << i << " " << t.get("colx",i) << endl; }
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.
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:
A numerical index from 0 to C1 (where C is the number of columns). For example, data can be accessed through table::get() and table::set(size_t c, size_t r,double val), or the overloaded [] operator,
table[c][r]
.A name of the column which is a string. For example, data can be accessed with table::get(string cname,
int r) and table::set(string cname, int r, double val).
The columns are organized in a both a <map> and a <vector> structure so that finding a column by its index, using either of
takes only constant time, and finding a column by its name using either ofstd::string table::get_column_name(size_t index); ubvector &table::operator[](size_t index);
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.size_t lookup_column(std::string name) const; const ubvector &get_column(std::string col) const;
Because of the structure, this class is not suitable for the matrix manipulation.
Vector types The type
vec_t
can be any vector type withoperator[]
,size()
andresize()
methods. HDF5 I/O with vector types other thanstd::vector<double>
requires a copy.See the the discussion in the sections Vector and matrix introduction and I/O and contiguous storage of the User’s Guide for more details.
Threadsafety Generally, the member functions are only threadsafe if they are
const
.I/O and commandline 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 commandline through theacol
utilitySee The acol Command Line Utility for more details on acol.
There is an example for the usage of this class given in
examples/ex_table.cpp
.Todo
In class table:
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 c std::vector<aiter> alist; could be replaced with c std::vector<col> list and c std::map<std::string,int> tree where the map just stores the index of the the column in the list.
Iterator types
Parsing mathematical functions specified as strings

std::map<std::string, double> constants¶
The list of constants.

inline void functions_columns(std::string list)¶
Create new columns or recompute from a list of functions.
The list should be a spacedelimited list of entries of the form
name=function
wherename
is the column name andfunction
the function specifing the values for the column. If a column namedname
is already present, it is overwritten. Otherwise, a new column is created.

inline void function_column(std::string function, std::string scol)¶
Make a column from the function specified in
function
and add it to the table.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.

template<class resize_vec_t>
inline 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.
The type
resize_vec_t
must haveresize()
andsize()
methods. Ifvec
does not have enough space to hold the number of entries given by get_nlines(), it is resized.Todo
In table::function_vector(): FIXME: there may be a problem with the OpenMP code if an exception is thrown in the calculator class and there is not a unique error handler for each thread.

inline double row_function(std::string function, size_t row) const¶
Compute a value by applying a function to a row.

inline size_t function_find_row(std::string function) const¶
Find a row which maximizes a function.

inline vec_t &get_column_no_const(std::string scol)¶
Returns a nonconst reference to the column named
col
. \( {\cal O}(\log(C)) \).

inline void reset_list()¶
Set the elements of alist with the appropriate iterators from atree. \( {\cal O}(C) \).
Generally, the enduser shouldn’t need this method. It is only used in delete_column() to rearrange the list when a column is deleted from the tree.

inline void make_fp_varname(std::string &s)¶
Ensure a variable name does not match a function or contain nonalphanumeric characters.

inline void make_unique_name(std::string &colx, std::vector<std::string> &cnames)¶
Make sure a name is unique.
Actual data

size_t maxlines¶
The size of allocated memory.

size_t nlines¶
The size of presently used memory.
Column manipulation methods

vec_t empty_col¶
An empty vector for get_column()
Interpolation

bool intp_set¶
True if the interpolation object is uptodate.

size_t itype¶
Current interpolation type.

interp_vec<vec_t> *si¶
Interpolation object.

std::string intp_colx¶
The last xcolumn interpolated.

std::string intp_coly¶
The last ycolumn interpolated.
Constructors, destructors

inline table(size_t cmaxlines = 0)¶
Create a new table with space for nlines<=cmaxlines.

inline virtual ~table()¶
Table destructor.
Basic get and set methods

inline void set(std::string scol, size_t row, double val)¶
Set row
row
of column namedcol
to valueval
. \( {\cal O}(\log(C)) \).This function calls the error handler if the row is beyond the end of the table or if the specified column is not found.

inline void set(size_t icol, size_t row, double val)¶
Set row
row
of column numbericol
to valueval
. \( {\cal O}(1) \).

template<class size_vec_t>
inline void set_row(size_t row, size_vec_t &v)¶ Set an entire row of data.
This function goes through
v
copying data until it runs out of columns in the table or it runs out of entries inv
, whichever comes first.The type
size_vec_t
must be a type which has asize()
method.

inline double get(std::string scol, size_t row) const¶
Get value from row
row
of column namedcol
. \( {\cal O}(\log(C)) \).

inline double get(size_t icol, size_t row) const¶
Get value from row
row
of column numbericol
. \( {\cal O}(1) \).

inline size_t get_ncolumns() const¶
Return the number of columns.
Manipulate current and maximum number of rows

inline size_t get_nlines() const¶
Return the number of lines.

inline void set_nlines(size_t il)¶
Set the number of lines.
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.

inline size_t get_maxlines()¶
Return the maximum number of lines before a reallocation is required.

template<class resize_vec_t>
inline void get_row(std::string scol, double val, resize_vec_t &row) const¶ Returns a copy of the row with value
val
in columncol
. \( {\cal O}(R C) \).This function searches the entire table for the row which has the entry in column
col
which is closest to the valueval
, and copies that row to the vectorrow
.If the object
row
previously contains any data, it will be lost.The type
resize_vec_t
must be a type which hassize()
andresize()
methods.

template<class resize_vec_t>
inline void get_row(size_t irow, resize_vec_t &row) const¶ Returns a copy of row number
irow
. \( {\cal O}(C) \).This function returns a copy of row with index
irow
, whereirow
ranges from 0 toget_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 hassize()
andresize()
methods.

inline void set_nlines_auto(size_t il)¶
Set the number of lines, increasing the size more agressively.
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.

inline void inc_maxlines(size_t llines)¶
Manually increase the maximum number of lines.

inline void set_maxlines(size_t llines)¶
Manually set the maximum number of lines.
Note
This function will call the error handler if the argument
llines
is smaller than the current number of lines in the table.
Column manipulation

inline const vec_t &get_column(std::string scol) const¶
Returns a reference to the column named
col
. \( {\cal O}(\log(C)) \).Note also that the vector object returned by this function may be larger than the number of rows in the table, as the table resizes these vectors automatically to make room for more data. To get the number of valid data entries in the object, use get_nlines() instead of
get_column().size()
.

inline const vec_t &operator[](size_t icol) const¶
Returns the column of index
icol
(const version). \( {\cal O}(1) \).Note that several of the methods require reallocation of memory and refereces previously returned by this function will be incorrect.
Note also that the vector object returned by this function may be larger than the number of rows in the table, as the table resizes these vectors automatically to make room for more data. To get the number of valid data entries in the object, use get_nlines() instead of
operator[].size()
.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 unlessO2SCL_NO_RANGE_CHECK
is defined.

inline const vec_t &operator[](std::string scol) const¶
Returns the column named
scol
(const version). \( {\cal O}(\log(C)) \).Note that several of the methods require reallocation of memory and refereces previously returned by this function will be incorrect.
Note also that the vector object returned by this function may be larger than the number of rows in the table, as the table resizes these vectors automatically to make room for more data. To get the number of valid data entries in the object, use get_nlines() instead of
operator[].size()
.This function will throw an exception if
icol
is out of range unlessO2SCL_NO_RANGE_CHECK
is defined.

inline void new_column(std::string head)¶
Add a new column owned by the \( {\cal O}(\log(C)) \).
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.

template<class vec2_t>
inline int new_column(std::string name, size_t sz, vec2_t &v)¶ Add a new column by copying data from another vector.
This function copies
sz
elements of vectorv
into the table in a new column namedname
. Ifsz
is larger than the current number of lines (as given, e.g. in get_nlines() ), then only the first part of the vectorv
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 anoperator[]
method.

inline std::string get_column_name(size_t icol) const¶
Returns the name of column
col
\( {\cal O}(1) \).This will throw if
icol
is larger than or equal to the number of columns.

inline virtual void swap_column_data(std::string scol, vec_t &v)¶
Swap the data in column
scol
with that in vectorv
.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
havestd::move
defined, then the swap doesn’t require a full copy.

inline virtual void rename_column(std::string src, std::string dest)¶
Rename column named
src
todest
\( {\cal O}(C) \).

inline virtual void delete_column(std::string scol)¶
Delete column named
scol
\( {\cal O}(C) \).This is slow because the iterators in alist are mangled and we have to call reset_list() to get them back.

inline std::string get_sorted_name(size_t icol) const¶
Returns the name of column
col
in sorted order. \( {\cal O}(1) \).

inline void init_column(std::string scol, double val)¶
Initialize all values of column named
scol
toval
\( {\cal O}(R \log(C)) \).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.

inline bool is_column(std::string scol) const¶
Return true if
scol
is a column in the current .This function does not call the error handler if the column is not found, but just silently returns false.

inline size_t lookup_column(std::string lname) const¶
Find the index for column named
name
\( {\cal O}(\log(C)) \).If the column is not present, this function calls the error handler.

inline virtual void copy_column(std::string src, std::string dest)¶
Copy data from column named
src
to column nameddest
, creating a new column if necessary \( {\cal O}(R \log(C)) \).

template<class resize_vec_t>
inline void column_to_vector(std::string scol, resize_vec_t &v) const¶ Copy a column to a generic vector object.
Note
It is assumed that the vector type is one that can be resized with
resize()
.

template<class vec2_t>
inline void copy_to_column(vec2_t &v, std::string scol)¶ Copy to a column from a generic vector object.
The type
vec2_t
can be any type with anoperator[]
method.

template<class vec2_t>
inline 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.
Given a pair of columns (
src_index
,src_col
) in a separate table (source
), this creates a new column in the present table namedsrc_col
which interpolatesloc_index
intosrc_index
. The interpolation objects from thesource
table will be used. If there is already a column in the present table namedsrc_col
, then this will fail.

template<class vec2_t>
inline 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)
This takes all of the columns in
source
, and adds them into the current table using interpolation, using the columnssrc_index
anddest_index
as the independent variable. The column namedsrc_index
is the column of the independent variable insource
and the column nameddest_index
is the column of the independent variable in the current table. Ifdest_index
is empty (the default) then the names in the two tables are taken to be the same.If necessary, columns are created in the current table for the dependent variable columns in
source
. Columns in the current table which do not correspond to dependent variable columns insource
are left unchanged.If
allow_extrap
is false, then extrapolation is not allowed, and rows in the current table which have values of the independent variable which are outside the source table are unmodified.If a column for a dependent variable in
source
has the same name asdest_index
, then it is ignored and not inserted into the current table.If the column named
src_index
cannot be found insource
or the column namesdest_index
cannot be found in the current table, then the error handler is called.If the
allow_extrap
is false and either the minimum or maximum values of the column namedsrc_index
in thesource
table are not finite, then the error handler is called.
Row maninpulation and data input

inline void new_row(size_t n)¶
Insert a row before row
n
.Acceptable values for
n
are between 0 andget_nlines()
inclusive, with the maximum value denoting the addition of a row after the last row presently in the table.

inline void copy_row(size_t src, size_t dest)¶
Copy the data in row
src
to rowdest
.

inline void delete_row(std::string scol, double val)¶
Delete the row with the entry closest to the value
val
in columnscol
\( {\cal O}(R C) \).

inline void delete_row(size_t irow)¶
Delete the row of index
irow
\( {\cal O}(R C) \).

inline void delete_rows_func(std::string func)¶
Delete all rows where
func
evaluates to a number greater than 0.5 \( {\cal O}(R C) \).If no rows match the delete condition, this function silently performs no changes to the table.

template<class vec2_t>
inline void copy_row(table<vec2_t> &src, size_t ix)¶ Copy row
ix
from tablesrc
to the end of the current table.

template<class vec2_t>
inline void copy_rows(std::string func, table<vec2_t> &dest)¶ Copy all rows matching a particular condition to a new table.
This function begins by ensuring that all columns in the current table are present in
dest
, creating new columns indest
if necessary. It then copies all rows wherefunc
evaluates to a number greater than 0.5 to tabledest
by adding rows at the end of the table.

inline void delete_rows_ends(size_t row_start, size_t row_end)¶
Delete all rows between
row_start
androw_end
\( {\cal O}(R C) \).If
row_start
is less or equal torow_end
, then all rows beginnning withrow_start
and ending withrow_end
are deleted (inclusive). Ifrow_start
is greater thanrow_end
, then rows from the start of the table untilrow_end
are deleted, as well as all rows fromrow_start
through the end of the table.If either
row_start
orrow_end
are beyond the end of the table (greater than or equal to the value given by get_nlines() ), an exception is thrown.

template<class vec_size_t>
inline void delete_rows_list(vec_size_t &row_list)¶ Delete all rows in a specified list.
Given a list of rows in
row_list
, this function deletes all of the specified rows. If a row beyond the end of the table is in the list, the error handler is called.Note
This function will proceed normally if a row is specified more than once in
row_list
.

inline size_t delete_rows_tolerance(double tol_rel = 1.0e12, double tol_abs = 1.0e20, int verbose = 0)¶
Exaustively search for groups of rows which match within a specified tolerance and remove all but one of each group.
This function returns the number of rows deleted.

inline void delete_idadj_rows()¶
Delete all rows which are identical to adjacent rows.
This function does silently does nothing if there are less than 2 rows in the table.

inline void line_of_names(std::string newheads)¶
Read a new set of names from
newheads
.This function reads a set of whitespace delimited column names from the string
newheads
, and creates a new column for each name which is specified.For example
will create three new columns with the names “position”, “velocity”, and “acceleration”.table t; t.line_of_names("position velocity acceleration");

template<class vec2_t>
inline 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.The type
vec2_t
can be any type with anoperator[]
method. Note that this function does not verify thatnv
is equal to the number of columns, so some of the columns may be uninitialized in the new row which is created.Similar to
std::vector
’spush_back()
method, this function now internally increases the maximum table size geometrically to help avoid excessive memory rearrangements.

template<class vec2_t>
inline void line_of_data(const vec2_t &v)¶ Read a line of data and store in a new row of the table.
The type
vec2_t
can be any type with anoperator[]
method. Note that this function does not verify that the vector size is equal to the number of columns, so some of the columns may be uninitialized in the new row which is created.
Lookup and search methods

inline size_t ordered_lookup(std::string scol, double val) const¶
Look for a value in an ordered column \( {\cal O}(\log(C) \log(R)) \).
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.

inline size_t lookup(std::string scol, double val) const¶
Exhaustively search column
col
for the valueval
\( {\cal O}(R \log(C)) \).

inline double lookup_val(std::string scol, double val, std::string scol2) const¶
Search column
col
for the valueval
and return value incol2
.

inline size_t lookup(int icol, double val) const¶
Exhaustively search column
col
for the valueval
\( {\cal O}(R \log(C)) \).

inline 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 ofval
\( {\cal O}(R \log(C)) \).
Interpolation, differentiation, integration, max, min

inline void set_interp_type(size_t interp_type)¶
Set the base interpolation objects.

inline size_t get_interp_type() const¶
Get the interpolation type.

inline double interp(std::string sx, double x0, std::string sy)¶
Interpolate value
x0
from column namedsx
into column namedsy
.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.

inline double interp_const(std::string sx, double x0, std::string sy) const¶
Interpolate value
x0
from column namedsx
into column namedsy
(const version)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.

inline double interp(size_t ix, double x0, size_t iy)¶
Interpolate value
x0
from column with indexix
into column with indexiy
\( {\cal O}(\log(R)) \).

inline double interp_const(size_t ix, double x0, size_t iy) const¶
Interpolate value
x0
from column with indexix
into column with indexiy
\( {\cal O}(\log(R)) \).

inline void deriv(std::string x, std::string y, std::string yp)¶
Make a new column named
yp
which is the derivative \( y^{\prime}(x) \) formed from columns namedx
andy
\( {\cal O}(R \log(C)) \).If the column
yp
is not already in the table it is automatically created.

inline double deriv(std::string sx, double x0, std::string sy)¶
Compute the first derivative of the function defined by xvalues stored in column named
sx
and yvalues stored in column namedsy
at the valuex0
.This function is O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

inline double deriv_const(std::string sx, double x0, std::string sy) const¶
Compute the first derivative of the function defined by xvalues stored in column named
sx
and yvalues stored in column namedsy
at the valuex0
(const version)O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

inline double deriv(size_t ix, double x0, size_t iy)¶
Compute the first derivative of the function defined by xvalues stored in column with index
ix
and yvalues stored in column with indexiy
at the valuex0
.O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

inline double deriv_const(size_t ix, double x0, size_t iy) const¶
Compute the first derivative of the function defined by xvalues stored in column with index
ix
and yvalues stored in column with indexiy
at the valuex0
(const version)O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

inline void deriv2(std::string x, std::string y, std::string yp)¶
Create a new column named
yp
which is equal to the second derivative of the function defined by xvalues stored in column namedx
and yvalues stored in column namedy
, i.e. \( y^{\prime \prime}(x) \)  O(log(C)*R).If the column
yp
is not already in the table it is automatically created.

inline double deriv2(std::string sx, double x0, std::string sy)¶
Compute the second derivative of the function defined by xvalues stored in column named
sx
and yvalues stored in column namedsy
at the valuex0
.O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

inline double deriv2_const(std::string sx, double x0, std::string sy) const¶
The Compute the second derivative of the function defined by xvalues stored in column named
sx
and yvalues stored in column namedsy
at the valuex0
(const version)O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

inline double deriv2(size_t ix, double x0, size_t iy)¶
Compute the second derivative of the function defined by xvalues stored in column with index
ix
and yvalues stored in column with indexiy
at the valuex0
.O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

inline double deriv2_const(size_t ix, double x0, size_t iy) const¶
Compute the second derivative of the function defined by xvalues stored in column with index
ix
and yvalues stored in column with indexiy
at the valuex0
(const version)O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

inline double integ(std::string sx, double x1, double x2, std::string sy)¶
Compute the integral of the function defined by xvalues stored in column named
sx
and yvalues stored in column namedsy
between the valuesx1
andx2
.O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

inline double integ_const(std::string sx, double x1, double x2, std::string sy) const¶
Compute the integral of the function defined by xvalues stored in column named
sx
and yvalues stored in column namedsy
between the valuesx1
andx2
(const version)O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

inline double integ(size_t ix, double x1, double x2, size_t iy)¶
Compute the integral of the function defined by xvalues stored in column with index
ix
and yvalues stored in column with indexiy
between the valuesx1
andx2
.O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

inline double integ_const(size_t ix, double x1, double x2, size_t iy) const¶
Compute the integral of the function defined by xvalues stored in column with index
ix
and yvalues stored in column with indexiy
between the valuesx1
andx2
(const version)O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

inline void integ(std::string x, std::string y, std::string ynew)¶
Create a new column named
ynew
which is equal to the integral of the function defined by xvalues stored in column namedx
and yvalues stored in column namedy
.This function is O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.
If the column
ynew
is not already in the table it is automatically created.

inline double max(std::string scol) const¶
Return column maximum. Makes no assumptions about ordering, \( {\cal O}(R) \).

inline double min(std::string scol) const¶
Return column minimum. Makes no assumptions about ordering, \( {\cal O}(R) \).
Subtable method
Clear methods

inline void zero_table()¶
Zero the data entries but keep the column names and nlines fixed.

inline virtual void clear()¶
Clear everything.

inline virtual void clear_table()¶
Clear the table and the column names (but leave constants)

inline void clear_data()¶
Remove all of the data by setting the number of lines to zero.
This leaves the column names intact and does not remove the constants.

inline void clear_constants()¶
CLear all constants.
Sorting methods

inline void sort_table(std::string scol)¶
Sort the entire table by the column
scol
.Note
This function works by allocating space for an entirely new chunk of memory for the data in the table.

inline void sort_column(std::string scol)¶
Individually sort the column
scol
.
Summary method

inline virtual void summary(std::ostream *out = 0, size_t ncol = 79) const¶
Output a summary of the information stored.
Outputs the number of constants, the number of columns, a list of the column names, and the number of lines of data.
Constant manipulation

inline virtual void add_constant(std::string name, double val)¶
Add a constant, or if the constant already exists, change its value.

inline 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.
If
err_on_notfound
istrue
(the default), then this function throws an exception if a constant with namename
is not found. Iferr_on_notfound
isfalse
, then if a constant with namename
is not found this function just silently returns o2scl::exc_enotfound.

inline virtual bool is_constant(std::string name) const¶
Test if
name
is a constant.

inline virtual double get_constant(std::string name) const¶
Get a constant.

inline virtual size_t get_nconsts() const¶
Get the number of constants.

inline virtual void get_constant(size_t ix, std::string &name, double &val) const¶
Get a constant by index.

inline virtual void remove_constant(std::string name)¶
Remove a constant.
Miscellaneous methods

inline virtual void average_col_roll(std::string col_name, size_t window)¶
Compute the rolling average of column named
col
.

inline virtual void average_rows(size_t window, bool rolling = false)¶
Average nearby rows together over the entire table.

inline virtual int read_generic(std::istream &fin, int verbose = 0)¶
Clear the current table and read from a generic data file.

inline void is_valid() const¶
Check if the table object appears to be valid.

inline virtual const char *type()¶
Return the type,
"table"
.