The class BCP_vec serves the same purpose as the vector class in the standard template library. More...
#include <BCP_vector.hpp>
Public Types | |
Type definitions (needed for using the STL) | |
typedef size_t | size_type |
typedef T | value_type |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef T & | reference |
typedef const T & | const_reference |
Public Member Functions | |
template<> | |
BCP_vec (const size_t n, const_reference value) | |
template<> | |
BCP_vec (const_iterator first, const_iterator last) | |
template<> | |
BCP_vec (const bool *x, const size_t num) | |
template<> | |
void | reserve (const size_t n) |
template<> | |
BCP_vec< bool > & | operator= (const BCP_vec< bool > &x) |
template<> | |
void | assign (const void *x, const size_t num) |
template<> | |
void | insert (bool *position, const void *first, const size_t n) |
template<> | |
void | insert (iterator position, const_iterator first, const_iterator last) |
template<> | |
void | insert (iterator position, const size_t n, const_reference x) |
template<> | |
BCP_vec< bool >::iterator | insert (iterator position, const_reference x) |
template<> | |
void | push_back (const_reference x) |
template<> | |
void | unchecked_push_back (const_reference x) |
template<> | |
void | pop_back () |
template<> | |
void | unchecked_update (const BCP_vec< int > &positions, const BCP_vec< bool > &values) |
template<> | |
void | update (const BCP_vec< int > &positions, const BCP_vec< bool > &values) |
template<> | |
void | keep (iterator pos) |
template<> | |
void | keep (iterator first, iterator last) |
template<> | |
void | erase (iterator position) |
template<> | |
void | erase (iterator first, iterator last) |
template<> | |
BCP_vec (const size_t n, const_reference value) | |
template<> | |
BCP_vec (const_iterator first, const_iterator last) | |
template<> | |
BCP_vec (const short *x, const size_t num) | |
template<> | |
void | reserve (const size_t n) |
template<> | |
BCP_vec< short > & | operator= (const BCP_vec< short > &x) |
template<> | |
void | assign (const void *x, const size_t num) |
template<> | |
void | insert (short *position, const void *first, const size_t n) |
template<> | |
void | insert (iterator position, const_iterator first, const_iterator last) |
template<> | |
void | insert (iterator position, const size_t n, const_reference x) |
template<> | |
BCP_vec< short >::iterator | insert (iterator position, const_reference x) |
template<> | |
void | push_back (const_reference x) |
template<> | |
void | unchecked_push_back (const_reference x) |
template<> | |
void | pop_back () |
template<> | |
void | unchecked_update (const BCP_vec< int > &positions, const BCP_vec< short > &values) |
template<> | |
void | update (const BCP_vec< int > &positions, const BCP_vec< short > &values) |
template<> | |
void | keep (iterator pos) |
template<> | |
void | keep (iterator first, iterator last) |
template<> | |
void | erase (iterator position) |
template<> | |
void | erase (iterator first, iterator last) |
template<> | |
BCP_vec (const size_t n, const_reference value) | |
template<> | |
BCP_vec (const_iterator first, const_iterator last) | |
template<> | |
BCP_vec (const bool *x, const size_t num) | |
template<> | |
void | reserve (const size_t n) |
template<> | |
BCP_vec< bool > & | operator= (const BCP_vec< bool > &x) |
template<> | |
void | assign (const void *x, const size_t num) |
template<> | |
void | insert (bool *position, const void *first, const size_t n) |
template<> | |
void | insert (iterator position, const_iterator first, const_iterator last) |
template<> | |
void | insert (iterator position, const size_t n, const_reference x) |
template<> | |
BCP_vec (const size_t n, const_reference value) | |
template<> | |
BCP_vec (const_iterator first, const_iterator last) | |
template<> | |
BCP_vec (const short *x, const size_t num) | |
template<> | |
void | reserve (const size_t n) |
template<> | |
BCP_vec< short > & | operator= (const BCP_vec< short > &x) |
template<> | |
void | assign (const void *x, const size_t num) |
template<> | |
void | insert (short *position, const void *first, const size_t n) |
template<> | |
void | insert (iterator position, const_iterator first, const_iterator last) |
template<> | |
void | insert (iterator position, const size_t n, const_reference x) |
Constructors / Destructor | |
BCP_vec () | |
The default constructor initializes the data members as 0 pointers. More... | |
BCP_vec (const BCP_vec< T > &x) | |
The copy constructor copies over the content of x . More... | |
BCP_vec (const size_t n, const_reference value=T()) | |
Construct a BCP_vec with n elements, all initialized with the second argument (or initialized with the default constructor of T if the second argument is missing). More... | |
BCP_vec (const_iterator first, const_iterator last) | |
Construct a BCP_vec by copying the elements from first to last-1 . More... | |
BCP_vec (const T *x, const size_t num) | |
Construct a BCP_vec by copying num objects of type T from the memory starting at x . More... | |
virtual | ~BCP_vec () |
The destructor deallocates the memory allocated for the BCP_vec . More... | |
Query methods | |
iterator | begin () |
Return an iterator to the beginning of the object. More... | |
const_iterator | begin () const |
Return a const iterator to the beginning of the object. More... | |
iterator | end () |
Return an iterator to the end of the object. More... | |
const_iterator | end () const |
Return a const iterator to the end of the object. More... | |
iterator | entry (const int i) |
Return an iterator to the i -th entry. More... | |
const_iterator | entry (const int i) const |
Return a const iterator to the i -th entry. More... | |
size_t | index (const_iterator pos) const |
Return the index of the entry pointed to by pos . More... | |
size_t | size () const |
Return the current number of entries. More... | |
size_t | capacity () const |
Return the capacity of the object (space allocated for this many entries). More... | |
bool | empty () const |
Test if there are any entries in the object. More... | |
reference | operator[] (const size_t i) |
Return a reference to the i -th entry. More... | |
const_reference | operator[] (const size_t i) const |
Return a const reference to the i -th entry. More... | |
reference | front () |
Return a reference to the first entry. More... | |
const_reference | front () const |
Return a const reference to the first entry. More... | |
reference | back () |
Return a reference to the last entry. More... | |
const_reference | back () const |
Return a const reference to the last entry. More... | |
General modifying methods | |
void | reserve (const size_t n) |
Reallocate the object to make space for n entries. More... | |
void | swap (BCP_vec< T > &x) |
Exchange the contents of the object with that of x . More... | |
BCP_vec< T > & | operator= (const BCP_vec< T > &x) |
Copy the contents of x into the object and return a reference the the object itself. More... | |
void | assign (const void *x, const size_t num) |
Copy num entries of type T starting at the memory location x into the object. More... | |
void | insert (iterator position, const void *first, const size_t num) |
Insert num entries starting from memory location first into the vector from position pos . More... | |
void | insert (iterator position, const_iterator first, const_iterator last) |
Insert the entries [first,last) into the vector from position pos . More... | |
void | insert (iterator position, const size_t n, const_reference x) |
Insert n copies of x into the vector from position pos . More... | |
iterator | insert (iterator position, const_reference x) |
Insert x (a single entry) into the vector at position pos . More... | |
void | append (const BCP_vec< T > &x) |
Append the entries in x to the end of the vector. More... | |
void | append (const_iterator first, const_iterator last) |
Append the entries [first,last) to the end of the vector. More... | |
void | push_back (const_reference x) |
Append x to the end of the vector. More... | |
void | unchecked_push_back (const_reference x) |
Append x to the end of the vector. More... | |
void | pop_back () |
Delete the last entry. More... | |
void | clear () |
Delete every entry. More... | |
void | update (const BCP_vec< int > &positions, const BCP_vec< T > &values) |
Update those entries listed in positions to the given values . More... | |
void | unchecked_update (const BCP_vec< int > &positions, const BCP_vec< T > &values) |
Same as the previous method but without sanity checks. More... | |
Methods for selectively keeping entries | |
void | keep (iterator pos) |
Keep only the entry pointed to by pos . More... | |
void | keep (iterator first, iterator last) |
Keep the entries [first,last) . More... | |
void | keep_by_index (const BCP_vec< int > &positions) |
Keep the entries indexed by indices . More... | |
void | unchecked_keep_by_index (const BCP_vec< int > &positions) |
Same as the previous method but without the sanity checks. More... | |
void | keep_by_index (const int *firstpos, const int *lastpos) |
Keep the entries indexed by the values in [firstpos,lastpos) . More... | |
void | unchecked_keep_by_index (const int *firstpos, const int *lastpos) |
Same as the previous method but without the sanity checks. More... | |
Methods for selectively erasing entries | |
void | erase (iterator pos) |
Erase the entry pointed to by pos . More... | |
void | erase (iterator first, iterator last) |
Erase the entries [first,last) . More... | |
void | erase_by_index (const BCP_vec< int > &positions) |
Erase the entries indexed by indices . More... | |
void | unchecked_erase_by_index (const BCP_vec< int > &positions) |
Same as the previous method but without the sanity check. More... | |
void | erase_by_index (const int *firstpos, const int *lastpos) |
Like the other erase_by_index method (including sanity checks), just the indices of the entries to be erased are given in [firstpos,lastpos) . More... | |
void | unchecked_erase_by_index (const int *firstpos, const int *lastpos) |
Same as the previous method but without the sanity checks. More... | |
Protected Member Functions | |
template<> | |
void | deallocate () |
template<> | |
void | insert_aux (iterator position, const_reference x) |
template<> | |
void | deallocate () |
template<> | |
void | insert_aux (iterator position, const_reference x) |
template<> | |
void | insert_aux (iterator position, const_reference x) |
template<> | |
void | insert_aux (iterator position, const_reference x) |
Internal methods | |
iterator | allocate (size_t len) |
allocate raw, uninitialized memory for len entries. More... | |
void | deallocate () |
Destroy the entries in the vector and free the memory allocated for the vector. More... | |
void | insert_aux (iterator position, const_reference x) |
insert x into the given position in the vector. More... | |
Protected Attributes | |
Data members | |
iterator | start |
Iterator pointing to the beginning of the memory array where the vector is stored. More... | |
iterator | finish |
Iterator pointing to right after the last entry in the vector. More... | |
iterator | end_of_storage |
Iterator pointing to right after the last memory location usable by the vector without reallocation. More... | |
Private Member Functions | |
void | destroy (iterator pos) |
void | destroy_range (iterator first, iterator last) |
void | construct (iterator pos) |
void | construct (iterator pos, const_reference x) |
template<> | |
void | destroy (iterator pos) |
template<> | |
void | destroy_range (iterator first, iterator last) |
template<> | |
void | construct (iterator pos) |
template<> | |
void | construct (iterator pos, const_reference x) |
template<> | |
void | destroy (iterator pos) |
template<> | |
void | destroy_range (iterator first, iterator last) |
template<> | |
void | construct (iterator pos) |
template<> | |
void | construct (iterator pos, const_reference x) |
The class BCP_vec serves the same purpose as the vector class in the standard template library.
The main difference is that while the vector class is likely to be implemented as a memory array, BCP_vec is implemented that way. Also, BCP_vec has a number of extra member methods, most of them exist to speed up operations (e.g., there are unchecked versions of the insert member methods, i.e., the method does not check whether there is enough space allocated to fit the new elements).
Definition at line 24 of file BCP_vector.hpp.
Definition at line 29 of file BCP_vector.hpp.
typedef T BCP_vec< T >::value_type |
Definition at line 31 of file BCP_vector.hpp.
Definition at line 33 of file BCP_vector.hpp.
typedef const T* BCP_vec< T >::const_iterator |
Definition at line 35 of file BCP_vector.hpp.
Definition at line 37 of file BCP_vector.hpp.
typedef const T& BCP_vec< T >::const_reference |
Definition at line 39 of file BCP_vector.hpp.
The default constructor initializes the data members as 0 pointers.
Definition at line 65 of file BCP_vector_general.hpp.
The copy constructor copies over the content of x
.
Definition at line 68 of file BCP_vector_general.hpp.
BCP_vec< T >::BCP_vec | ( | const size_t | n, |
const_reference | value = T() |
||
) |
Construct a BCP_vec
with n
elements, all initialized with the second argument (or initialized with the default constructor of T
if the second argument is missing).
Definition at line 75 of file BCP_vector_general.hpp.
BCP_vec< T >::BCP_vec | ( | const_iterator | first, |
const_iterator | last | ||
) |
Construct a BCP_vec
by copying the elements from first
to last-1
.
Definition at line 86 of file BCP_vector_general.hpp.
Construct a BCP_vec
by copying num
objects of type T
from the memory starting at x
.
Definition at line 97 of file BCP_vector_general.hpp.
The destructor deallocates the memory allocated for the BCP_vec
.
Definition at line 93 of file BCP_vector.hpp.
BCP_vec< bool >::BCP_vec | ( | const size_t | n, |
const_reference | value | ||
) |
BCP_vec< bool >::BCP_vec | ( | const_iterator | first, |
const_iterator | last | ||
) |
BCP_vec< short >::BCP_vec | ( | const size_t | n, |
const_reference | value | ||
) |
BCP_vec< short >::BCP_vec | ( | const_iterator | first, |
const_iterator | last | ||
) |
BCP_vec< bool >::BCP_vec | ( | const size_t | n, |
const_reference | value | ||
) |
Definition at line 36 of file BCP_vector_bool.cpp.
BCP_vec< bool >::BCP_vec | ( | const_iterator | first, |
const_iterator | last | ||
) |
Definition at line 47 of file BCP_vector_bool.cpp.
Definition at line 58 of file BCP_vector_bool.cpp.
BCP_vec< short >::BCP_vec | ( | const size_t | n, |
const_reference | value | ||
) |
Definition at line 36 of file BCP_vector_short.cpp.
BCP_vec< short >::BCP_vec | ( | const_iterator | first, |
const_iterator | last | ||
) |
Definition at line 47 of file BCP_vector_short.cpp.
Definition at line 58 of file BCP_vector_short.cpp.
Definition at line 6 of file BCP_vector_general.hpp.
Definition at line 11 of file BCP_vector_general.hpp.
Definition at line 18 of file BCP_vector_general.hpp.
|
inlineprivate |
Definition at line 23 of file BCP_vector_general.hpp.
allocate raw, uninitialized memory for len
entries.
Definition at line 30 of file BCP_vector_general.hpp.
Destroy the entries in the vector and free the memory allocated for the vector.
Definition at line 35 of file BCP_vector_general.hpp.
|
protected |
insert x
into the given position
in the vector.
Reallocate the vector if necessary.
Definition at line 43 of file BCP_vector_general.hpp.
Return an iterator to the beginning of the object.
Definition at line 99 of file BCP_vector.hpp.
|
inline |
Return a const iterator to the beginning of the object.
Definition at line 101 of file BCP_vector.hpp.
Return an iterator to the end of the object.
Definition at line 104 of file BCP_vector.hpp.
|
inline |
Return a const iterator to the end of the object.
Definition at line 106 of file BCP_vector.hpp.
Return an iterator to the i
-th entry.
Definition at line 109 of file BCP_vector.hpp.
|
inline |
Return a const iterator to the i
-th entry.
Definition at line 111 of file BCP_vector.hpp.
|
inline |
Return the index of the entry pointed to by pos
.
Definition at line 114 of file BCP_vector.hpp.
|
inline |
Return the current number of entries.
Definition at line 116 of file BCP_vector.hpp.
|
inline |
Return the capacity of the object (space allocated for this many entries).
Definition at line 119 of file BCP_vector.hpp.
|
inline |
Test if there are any entries in the object.
Definition at line 121 of file BCP_vector.hpp.
Return a reference to the i
-th entry.
Definition at line 124 of file BCP_vector.hpp.
|
inline |
Return a const reference to the i
-th entry.
Definition at line 126 of file BCP_vector.hpp.
Return a reference to the first entry.
Definition at line 129 of file BCP_vector.hpp.
|
inline |
Return a const reference to the first entry.
Definition at line 131 of file BCP_vector.hpp.
Return a reference to the last entry.
Definition at line 133 of file BCP_vector.hpp.
|
inline |
Return a const reference to the last entry.
Definition at line 135 of file BCP_vector.hpp.
Reallocate the object to make space for n
entries.
Definition at line 112 of file BCP_vector_general.hpp.
Exchange the contents of the object with that of x
.
Definition at line 124 of file BCP_vector_general.hpp.
Copy the contents of x
into the object and return a reference the the object itself.
Definition at line 131 of file BCP_vector_general.hpp.
Copy num
entries of type T
starting at the memory location x
into the object.
(x
is a void pointer since it might be located somewhere in a buffer and therefore might not be aligned for type T
entries.)
Definition at line 157 of file BCP_vector_general.hpp.
void BCP_vec< T >::insert | ( | iterator | position, |
const void * | first, | ||
const size_t | num | ||
) |
Insert num
entries starting from memory location first
into the vector from position pos
.
Definition at line 176 of file BCP_vector_general.hpp.
void BCP_vec< T >::insert | ( | iterator | position, |
const_iterator | first, | ||
const_iterator | last | ||
) |
Insert the entries [first,last)
into the vector from position pos
.
Definition at line 225 of file BCP_vector_general.hpp.
void BCP_vec< T >::insert | ( | iterator | position, |
const size_t | n, | ||
const_reference | x | ||
) |
Insert n
copies of x
into the vector from position pos
.
Definition at line 256 of file BCP_vector_general.hpp.
|
inline |
Insert x
(a single entry) into the vector at position pos
.
Return an iterator to the newly inserted entry.
Definition at line 287 of file BCP_vector_general.hpp.
Append the entries in x
to the end of the vector.
Definition at line 169 of file BCP_vector.hpp.
|
inline |
Append the entries [first,last)
to the end of the vector.
Definition at line 173 of file BCP_vector.hpp.
|
inline |
Append x
to the end of the vector.
Check if enough space is allocated (reallocate if necessary).
Definition at line 300 of file BCP_vector_general.hpp.
|
inline |
Append x
to the end of the vector.
Does not check if enough space is allcoated.
Definition at line 308 of file BCP_vector_general.hpp.
Delete the last entry.
Definition at line 313 of file BCP_vector_general.hpp.
Delete every entry.
Definition at line 318 of file BCP_vector_general.hpp.
|
inline |
Update those entries listed in positions
to the given values
.
The two argument vector must be of equal length. Sanity checks are done on the given positions.
Definition at line 336 of file BCP_vector_general.hpp.
|
inline |
Same as the previous method but without sanity checks.
Definition at line 324 of file BCP_vector_general.hpp.
Keep only the entry pointed to by pos
.
Definition at line 347 of file BCP_vector_general.hpp.
Keep the entries [first,last)
.
Definition at line 354 of file BCP_vector_general.hpp.
Keep the entries indexed by indices
.
Abort if the indices are not in increasing order, if there are duplicate indices or if any of the indices is outside of the range [0,size())
.
Definition at line 362 of file BCP_vector_general.hpp.
|
inline |
Same as the previous method but without the sanity checks.
Definition at line 369 of file BCP_vector_general.hpp.
|
inline |
Keep the entries indexed by the values in [firstpos,lastpos)
.
Abort if the indices are not in increasing order, if there are duplicate indices or if any of the indices is outside of the range [0,size())
.
void BCP_vec< T >::unchecked_keep_by_index | ( | const int * | firstpos, |
const int * | lastpos | ||
) |
Same as the previous method but without the sanity checks.
Erase the entry pointed to by pos
.
Definition at line 399 of file BCP_vector_general.hpp.
Erase the entries [first,last)
.
Definition at line 406 of file BCP_vector_general.hpp.
Erase the entries indexed by indices
.
Abort if the indices are not in increasing order, if there are duplicate indices or if any of the indices is outside of the range [0,size())
.
Definition at line 414 of file BCP_vector_general.hpp.
|
inline |
Same as the previous method but without the sanity check.
Definition at line 421 of file BCP_vector_general.hpp.
|
inline |
Like the other erase_by_index
method (including sanity checks), just the indices of the entries to be erased are given in [firstpos,lastpos)
.
void BCP_vec< T >::unchecked_erase_by_index | ( | const int * | firstpos, |
const int * | lastpos | ||
) |
Same as the previous method but without the sanity checks.
Definition at line 16 of file BCP_vector_bool.hpp.
Definition at line 20 of file BCP_vector_bool.hpp.
Definition at line 24 of file BCP_vector_bool.hpp.
|
inlineprivate |
Definition at line 29 of file BCP_vector_bool.hpp.
Definition at line 38 of file BCP_vector_bool.hpp.
|
protected |
void BCP_vec< bool >::insert | ( | iterator | position, |
const_iterator | first, | ||
const_iterator | last | ||
) |
void BCP_vec< bool >::insert | ( | iterator | position, |
const size_t | n, | ||
const_reference | x | ||
) |
|
inline |
Definition at line 82 of file BCP_vector_bool.hpp.
|
inline |
Definition at line 94 of file BCP_vector_bool.hpp.
|
inline |
Definition at line 102 of file BCP_vector_bool.hpp.
Definition at line 107 of file BCP_vector_bool.hpp.
|
inline |
Definition at line 115 of file BCP_vector_bool.hpp.
|
inline |
Definition at line 128 of file BCP_vector_bool.hpp.
Definition at line 139 of file BCP_vector_bool.hpp.
Definition at line 145 of file BCP_vector_bool.hpp.
Definition at line 168 of file BCP_vector_bool.hpp.
Definition at line 175 of file BCP_vector_bool.hpp.
Definition at line 13 of file BCP_vector_short.hpp.
Definition at line 17 of file BCP_vector_short.hpp.
Definition at line 21 of file BCP_vector_short.hpp.
|
inlineprivate |
Definition at line 26 of file BCP_vector_short.hpp.
Definition at line 35 of file BCP_vector_short.hpp.
|
protected |
void BCP_vec< short >::insert | ( | iterator | position, |
const_iterator | first, | ||
const_iterator | last | ||
) |
void BCP_vec< short >::insert | ( | iterator | position, |
const size_t | n, | ||
const_reference | x | ||
) |
|
inline |
Definition at line 79 of file BCP_vector_short.hpp.
|
inline |
Definition at line 91 of file BCP_vector_short.hpp.
|
inline |
Definition at line 99 of file BCP_vector_short.hpp.
Definition at line 104 of file BCP_vector_short.hpp.
|
inline |
Definition at line 112 of file BCP_vector_short.hpp.
|
inline |
Definition at line 124 of file BCP_vector_short.hpp.
Definition at line 135 of file BCP_vector_short.hpp.
Definition at line 141 of file BCP_vector_short.hpp.
Definition at line 164 of file BCP_vector_short.hpp.
Definition at line 171 of file BCP_vector_short.hpp.
|
protected |
Definition at line 12 of file BCP_vector_bool.cpp.
Definition at line 70 of file BCP_vector_bool.cpp.
Definition at line 84 of file BCP_vector_bool.cpp.
Definition at line 103 of file BCP_vector_bool.cpp.
Definition at line 114 of file BCP_vector_bool.cpp.
void BCP_vec< bool >::insert | ( | iterator | position, |
const_iterator | first, | ||
const_iterator | last | ||
) |
Definition at line 138 of file BCP_vector_bool.cpp.
void BCP_vec< bool >::insert | ( | iterator | position, |
const size_t | n, | ||
const_reference | x | ||
) |
Definition at line 163 of file BCP_vector_bool.cpp.
|
protected |
Definition at line 12 of file BCP_vector_short.cpp.
Definition at line 70 of file BCP_vector_short.cpp.
Definition at line 84 of file BCP_vector_short.cpp.
Definition at line 103 of file BCP_vector_short.cpp.
Definition at line 114 of file BCP_vector_short.cpp.
void BCP_vec< short >::insert | ( | iterator | position, |
const_iterator | first, | ||
const_iterator | last | ||
) |
Definition at line 138 of file BCP_vector_short.cpp.
void BCP_vec< short >::insert | ( | iterator | position, |
const size_t | n, | ||
const_reference | x | ||
) |
Definition at line 163 of file BCP_vector_short.cpp.
Iterator pointing to the beginning of the memory array where the vector is stored.
Definition at line 66 of file BCP_vector.hpp.
Iterator pointing to right after the last entry in the vector.
Definition at line 68 of file BCP_vector.hpp.
Iterator pointing to right after the last memory location usable by the vector without reallocation.
Definition at line 71 of file BCP_vector.hpp.