#include <ovector_tlate.h>
There are several global binary operators associated with objects of type uvector_tlate. The are documented in the "Functions" section of ovector_tlate.h.
Design notes
At present, the owner variable can be used to distinguish between ovectors and ovector_views: for views, owner is always zero, but for normal ovectors, owner is 1 (even for empty vectors).
The reserve(), pop_back(), and push_back() methods require the ability to have empty vectors which still have memory allocated for them, so the proper test for whether or not memory is allocated is to test whether or not 'block' is zero. This means we should never have a case where the block is non-zero (i.e. there is memory allocated there) but the size of the block is zero. This is the test used in the destructor and the free() method. The free method also sets block to zero accordingly.
Definition at line 922 of file ovector_tlate.h.
Public Member Functions | |
Standard constructor | |
ovector_tlate (size_t n=0) | |
Create an ovector of size n with owner as 'true'. | |
Copy constructors | |
ovector_tlate (const ovector_tlate &v) | |
Deep copy constructor. | |
template<class alt_vec_t > | |
ovector_tlate (size_t nv, alt_vec_t &v) | |
Deep copy constructor for generic vectors. | |
ovector_tlate (const ovector_const_view_tlate< data_t, vparent_t, block_t > &v) | |
Deep copy constructor for other related vectors. | |
ovector_tlate & | operator= (const ovector_tlate &v) |
Deep copy constructor, if owner is true, allocate space and make a new copy, otherwise, just copy into the view. | |
ovector_tlate & | operator= (const ovector_const_view_tlate< data_t, vparent_t, block_t > &v) |
Deep copy constructor, if owner is true, allocate space and make a new copy, otherwise, just copy into the view. | |
ovector_tlate & | operator= (const uvector_const_view_tlate< data_t > &v) |
Deep copy constructor, if owner is true, allocate space and make a new copy, otherwise, just copy into the view. | |
Memory allocation | |
int | allocate (size_t nsize) |
Allocate memory for size n after freeing any memory currently in use. | |
int | free () |
Free the memory. | |
Stack-like operations | |
int | push_back (data_t val) |
Add a value to the end of the vector. | |
int | reserve (size_t cap) |
Reserve memory by increasing capacity. | |
data_t | pop_back () |
Return the last value and shrink the vector size by one. | |
Other methods | |
int | erase (size_t ix) |
Remove element with index ix and decrease the vector size by one. | |
int | sort_unique () |
Sort the vector and ensure all elements are unique by removing duplicates. | |
Protected Member Functions | |
void | intl_sanity_check (size_t ix) |
int | intl_allocate (size_t nsize) |
An internal allocate function. | |
int | intl_free () |
The internal free function. | |
template<class alt_vec_t > | |
int | intl_init (size_t n, alt_vec_t &v) |
An internal init() function. | |
template<class alt_vec_t > | |
ovector_tlate & | intl_assign (size_t n, alt_vec_t &v) |
An internal assignment function for operator=() . |
int allocate | ( | size_t | nsize | ) | [inline] |
Allocate memory for size n
after freeing any memory currently in use.
Note that this automatically deallocates any previously allocated memory before attempting to allocate more. If this allocation fails (i.e. because we ran out of memory) then the original vector will still have been deallocated.
Definition at line 1181 of file ovector_tlate.h.
int free | ( | ) | [inline] |
Free the memory.
This function will safely do nothing if used without first allocating memory or if called multiple times in succession.
Definition at line 1195 of file ovector_tlate.h.
int intl_allocate | ( | size_t | nsize | ) | [inline, protected] |
An internal allocate function.
nsize
is zero. Also, this does not free any already allocated memory first (unlike the user-interface version allocate()). Definition at line 949 of file ovector_tlate.h.
int intl_init | ( | size_t | n, | |
alt_vec_t & | v | |||
) | [inline, protected] |
An internal init() function.
This function calls intl_allocate() first, and then copies the data from the vector v
.
Definition at line 1014 of file ovector_tlate.h.
int reserve | ( | size_t | cap | ) | [inline] |
Reserve memory by increasing capacity.
Increase the maximum capacity of the vector so that calls to push_back() do not need to automatically increase the capacity.
If the argument cap
is smaller than the present vector size given by size(), then this function does nothing and the error handler is not called.
Definition at line 1268 of file ovector_tlate.h.
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page