PMDK C++ bindings  1.9.1
This is the C++ bindings documentation for PMDK's libpmemobj.
Public Member Functions | Private Member Functions | List of all members
pmem::obj::segment_vector< T, Policy > Class Template Reference

Segment table is a data type with a vector-like interface The difference is that it does not do reallocations and iterators are not invalidated when adding new elements. More...

#include <libpmemobj++/container/segment_vector.hpp>

Public Member Functions

 segment_vector ()
 Default constructor. More...
 
 segment_vector (size_type count, const value_type &value)
 Constructs the container with count copies of elements with value value. More...
 
 segment_vector (size_type count)
 Constructs the container with count copies of T default constructed values. More...
 
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * = nullptr>
 segment_vector (InputIt first, InputIt last)
 Constructs the container with the contents of the range [first, last). More...
 
 segment_vector (const segment_vector &other)
 Copy constructor. More...
 
 segment_vector (segment_vector &&other)
 Move constructor. More...
 
 segment_vector (std::initializer_list< T > init)
 Constructs the container with the contents of the initializer list init. More...
 
 segment_vector (const std::vector< T > &other)
 Copy constructor. More...
 
segment_vectoroperator= (const segment_vector &other)
 Copy assignment operator. More...
 
segment_vectoroperator= (segment_vector &&other)
 Move assignment operator. More...
 
segment_vectoroperator= (std::initializer_list< T > ilist)
 Replaces the contents with those identified by initializer list ilist transactionally. More...
 
segment_vectoroperator= (const std::vector< T > &other)
 Copy assignment operator. More...
 
void assign (size_type count, const_reference value)
 Replaces the contents with count copies of value value transactionally. More...
 
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * = nullptr>
void assign (InputIt first, InputIt last)
 Replaces the contents with copies of those in the range [first, last) transactionally. More...
 
void assign (std::initializer_list< T > ilist)
 Replaces the contents with the elements from the initializer list ilist transactionally. More...
 
void assign (const segment_vector &other)
 Copy assignment method. More...
 
void assign (segment_vector &&other)
 Move assignment method. More...
 
void assign (const std::vector< T > &other)
 Copy assignment method. More...
 
 ~segment_vector ()
 Destructor. More...
 
reference at (size_type n)
 Access element at specific index with bounds checking and add it to a transaction. More...
 
const_reference at (size_type n) const
 Access element at specific index with bounds checking. More...
 
const_reference const_at (size_type n) const
 Access element at specific index with bounds checking. More...
 
reference operator[] (size_type n)
 Access element at specific index and add it to a transaction. More...
 
const_reference operator[] (size_type n) const
 Access element at specific index. More...
 
reference front ()
 Access the first element and add this element to a transaction. More...
 
const_reference front () const
 Access the first element. More...
 
const_reference cfront () const
 Access the first element. More...
 
reference back ()
 Access the last element and add this element to a transaction. More...
 
const_reference back () const
 Access the last element. More...
 
const_reference cback () const
 Access the last element. More...
 
iterator begin ()
 Returns an iterator to the beginning. More...
 
const_iterator begin () const noexcept
 Returns const iterator to the beginning. More...
 
const_iterator cbegin () const noexcept
 Returns const iterator to the beginning. More...
 
iterator end ()
 Returns an iterator to past the end. More...
 
const_iterator end () const noexcept
 Returns a const iterator to past the end. More...
 
const_iterator cend () const noexcept
 Returns a const iterator to the end. More...
 
reverse_iterator rbegin ()
 Returns a reverse iterator to the beginning. More...
 
const_reverse_iterator rbegin () const noexcept
 Returns a const reverse iterator to the beginning. More...
 
const_reverse_iterator crbegin () const noexcept
 Returns a const reverse iterator to the beginning. More...
 
reverse_iterator rend ()
 Returns a reverse iterator to the end. More...
 
const_reverse_iterator rend () const noexcept
 Returns a const reverse iterator to the end. More...
 
const_reverse_iterator crend () const noexcept
 Returns a const reverse iterator to the beginning. More...
 
slice< iteratorrange (size_type start, size_type n)
 Returns slice and snapshots requested range. More...
 
slice< const_iteratorrange (size_type start, size_type n) const
 Returns const slice. More...
 
slice< const_iteratorcrange (size_type start, size_type n) const
 Returns const slice. More...
 
constexpr bool empty () const noexcept
 Checks whether the container is empty. More...
 
size_type size () const noexcept
 
constexpr size_type max_size () const noexcept
 
void reserve (size_type capacity_new)
 Increases the capacity of the segment_vector to capacity_new transactionally. More...
 
size_type capacity () const noexcept
 
void shrink_to_fit ()
 Requests transactional removal of unused capacity. More...
 
void clear ()
 Clears the content of a segment_vector transactionally. More...
 
void free_data ()
 Clears the content of a segment_vector and frees all allocated persistent memory for data transactionally. More...
 
iterator insert (const_iterator pos, const T &value)
 Inserts value before pos in the container transactionally. More...
 
iterator insert (const_iterator pos, T &&value)
 Moves value before pos in the container transactionally. More...
 
iterator insert (const_iterator pos, size_type count, const T &value)
 Inserts count copies of the value before pos in the container transactionally. More...
 
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * = nullptr>
iterator insert (const_iterator pos, InputIt first, InputIt last)
 Inserts elements from range [first, last) before pos in the container transactionally. More...
 
iterator insert (const_iterator pos, std::initializer_list< T > ilist)
 Inserts elements from initializer list ilist before pos in the container transactionally. More...
 
template<class... Args>
iterator emplace (const_iterator pos, Args &&... args)
 Inserts a new element into the container directly before pos. More...
 
template<class... Args>
reference emplace_back (Args &&... args)
 Appends a new element to the end of the container transactionally. More...
 
iterator erase (const_iterator pos)
 Removes the element at pos. More...
 
iterator erase (const_iterator first, const_iterator last)
 Removes the elements in the range [first, last). More...
 
void push_back (const T &value)
 Appends the given element value to the end of the container transactionally. More...
 
void push_back (T &&value)
 Appends the given element value to the end of the container transactionally. More...
 
void pop_back ()
 Removes the last element of the container transactionally. More...
 
void resize (size_type count)
 Resizes the container to count elements transactionally. More...
 
void resize (size_type count, const value_type &value)
 Resizes the container to contain count elements transactionally. More...
 
void swap (segment_vector &other)
 Exchanges the contents of the container with other transactionally.
 

Private Member Functions

void internal_reserve (size_type new_capacity)
 Private helper method. More...
 
template<typename... Args>
void construct (size_type idx, size_type count, Args &&... args)
 Private helper function. More...
 
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * = nullptr>
void construct_range (size_type idx, InputIt first, InputIt last)
 Private helper function. More...
 
void insert_gap (size_type idx, size_type count)
 Private helper function. More...
 
void shrink (size_type size_new)
 Private helper function. More...
 
pool_base get_pool () const noexcept
 Private helper function. More...
 
void snapshot_data (size_type idx_first, size_type idx_last)
 Private helper function. More...
 
reference get (size_type n)
 Private helper function. More...
 
const_reference get (size_type n) const
 Private helper function. More...
 
const_reference cget (size_type n) const
 Private helper function. More...
 
bool segment_capacity_validation () const
 Private helper function. More...
 

Detailed Description

template<typename T, typename Policy = exponential_size_vector_policy<>>
class pmem::obj::segment_vector< T, Policy >

Segment table is a data type with a vector-like interface The difference is that it does not do reallocations and iterators are not invalidated when adding new elements.

Precondition
if SegmentType for policy is specified it must contain such functions as: default constructor, destructor, assign, operator[], free_data, emplace_back, clear, resize, reserve, erase, capacity(), size(). They must have signature the same as in vector. Also must support iterators.

Policy template represents Segments storing type and managing methods.

Example usage:

#include <iostream>
const int N_ELEMENTS = 4096;
const int SEGMENT_SIZE = 1024;
using namespace pmem::obj;
using value_t = p<int>;
using segment_t = pmem::obj::vector<value_t>;
/*
* exponential_size_array_policy<> is equivalent to:
* exponential_size_array_policy<pmem::obj::vector>
*/
using seg_vec_exp_arr =
/*
* exponential_size_vector_policy<> is equivalent to:
* exponential_size_vector_policy<pmem::obj::vector>
*/
using seg_vec_exp_vec =
/*
* fixed_size_vector_policy<SEGMENT_SIZE> is equivalent to:
* fixed_size_vector_policy<SEGMENT_SIZE, pmem::obj::vector>
*/
using seg_vec_fix_vec =
struct root {
};
int
main(int argc, char *argv[])
{
if (argc != 2)
std::cerr << "usage: " << argv[0] << " file-name" << std::endl;
auto path = argv[1];
auto pop = pool<root>::open(path, "segment_vector example");
auto r = pop.root();
if (r->pptr0 == nullptr) {
r->pptr0 = make_persistent<segment_t>();
r->pptr1 = make_persistent<seg_vec_exp_arr>();
r->pptr2 = make_persistent<seg_vec_exp_vec>();
r->pptr3 = make_persistent<seg_vec_fix_vec>();
});
}
auto &seg_vec_0 = *pop.root()->pptr0;
auto &seg_vec_1 = *pop.root()->pptr1;
auto &seg_vec_2 = *pop.root()->pptr2;
auto &seg_vec_3 = *pop.root()->pptr3;
for (int i = 0; i < N_ELEMENTS; ++i) {
seg_vec_0[i] = i;
}
seg_vec_1 = seg_vec_exp_arr(seg_vec_0.cbegin(), seg_vec_0.cend());
seg_vec_2 = seg_vec_exp_vec(seg_vec_1.cbegin(), seg_vec_1.cend());
seg_vec_3 = seg_vec_fix_vec(seg_vec_2.cbegin(), seg_vec_2.cend());
for (int i = 0; i < N_ELEMENTS; ++i) {
assert(seg_vec_1[i] = seg_vec_0[i]);
assert(seg_vec_2[i] = seg_vec_1[i]);
assert(seg_vec_3[i] = seg_vec_2[i]);
}
seg_vec_0.clear();
seg_vec_1.clear();
seg_vec_2.clear();
seg_vec_3.clear();
delete_persistent<segment_t>(r->pptr0);
delete_persistent<seg_vec_exp_arr>(r->pptr1);
delete_persistent<seg_vec_exp_vec>(r->pptr2);
delete_persistent<seg_vec_fix_vec>(r->pptr3);
pop.close();
return 0;
}

Constructor & Destructor Documentation

◆ segment_vector() [1/8]

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::segment_vector

Default constructor.

Constructs an empty container.

Precondition
must be called in transaction scope.
Exceptions
pmem::pool_errorif an object is not in persistent memory.
pmem::transaction_scope_errorif wasn't called in transaction.

◆ segment_vector() [2/8]

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::segment_vector ( size_type  count,
const value_type &  value 
)

Constructs the container with count copies of elements with value value.

Parameters
[in]countnumber of elements to construct.
[in]valuevalue of all constructed elements.
Precondition
must be called in transaction scope.
Postcondition
size() == count
capacity() == nearest power of 2 greater than count
Exceptions
rethrowsconstructor exception.
pmem::pool_errorif an object is not in persistent memory.
pmem::transaction_scope_errorif wasn't called in transaction.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ segment_vector() [3/8]

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::segment_vector ( size_type  count)
explicit

Constructs the container with count copies of T default constructed values.

Parameters
[in]countnumber of elements to construct.
Precondition
must be called in transaction scope.
Postcondition
size() == count
capacity() == nearest power of 2 greater than count
Exceptions
rethrowsconstructor exception.
pmem::pool_errorif an object is not in persistent memory.
pmem::transaction_scope_errorif wasn't called in transaction.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ segment_vector() [4/8]

template<typename T , typename Policy >
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * >
pmem::obj::segment_vector< T, Policy >::segment_vector ( InputIt  first,
InputIt  last 
)

Constructs the container with the contents of the range [first, last).

The first and last arguments must satisfy InputIterator requirements. This overload only participates in overload resolution if InputIt satisfies InputIterator, to avoid ambiguity with the overload of count-value constructor.

Parameters
[in]firstfirst iterator.
[in]lastlast iterator.
Precondition
must be called in transaction scope.
Postcondition
size() == std::distance(first, last)
capacity() == nearest power of 2 greater than std::distance(first, last)
Exceptions
rethrowsconstructor exception.
pmem::pool_errorif an object is not in persistent memory.
pmem::transaction_scope_errorif wasn't called in transaction.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ segment_vector() [5/8]

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::segment_vector ( const segment_vector< T, Policy > &  other)

Copy constructor.

Constructs the container with the copy of the contents of other.

Parameters
[in]otherreference to the segment_vector to be copied.
Precondition
must be called in transaction scope.
Postcondition
size() == other.size()
capacity() == other.capacity()
Exceptions
rethrowsconstructor exception.
pmem::pool_errorif an object is not in persistent memory.
pmem::transaction_scope_errorif wasn't called in transaction.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ segment_vector() [6/8]

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::segment_vector ( segment_vector< T, Policy > &&  other)

Move constructor.

Constructs the container with the contents of other using move semantics. After the move, other is guaranteed to be empty().

Parameters
[in]otherrvalue reference to the segment_vector to be moved from.
Precondition
must be called in transaction scope.
Postcondition
size() == other.size()
capacity() == other.capacity()
other.capacity() == 0
other.size() == 0
Exceptions
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ segment_vector() [7/8]

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::segment_vector ( std::initializer_list< T >  init)

Constructs the container with the contents of the initializer list init.

Parameters
[in]initinitializer list with content to be constructed.
Precondition
must be called in transaction scope.
Postcondition
size() == init.size()
capacity() == size()
Exceptions
rethrowsconstructor exception.
pmem::pool_errorif an object is not in persistent memory.
pmem::transaction_scope_errorif wasn't called in transaction.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ segment_vector() [8/8]

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::segment_vector ( const std::vector< T > &  other)

Copy constructor.

Constructs the container with the copy of the contents of std::vector<T> other.

Parameters
[in]otherreference to the vector to be copied.
Precondition
must be called in transaction scope.
Postcondition
size() == other.size()
capacity() == other.capacity()
Exceptions
rethrowsconstructor exception.
pmem::pool_errorif an object is not in persistent memory.
pmem::transaction_scope_errorif wasn't called in transaction.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ ~segment_vector()

template<typename T , typename Policy >
pmem::obj::segment_vector< T, Policy >::~segment_vector

Destructor.

Note that free_data may throw an transaction_free_error when freeing underlying segments failed. It is recommended to call free_data manually before object destruction.

Exceptions
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segments failed.

Member Function Documentation

◆ assign() [1/6]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::assign ( const segment_vector< T, Policy > &  other)

Copy assignment method.

Replaces the contents with a copy of the contents of other transactionally.

Postcondition
size() == other.size()
capacity() == max(other.size(), capacity())
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ assign() [2/6]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::assign ( const std::vector< T > &  other)

Copy assignment method.

Replaces the contents with a copy of the contents of std::vector<T> other transactionally.

Postcondition
size() == other.size()
capacity() == max(other.size(), capacity())
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ assign() [3/6]

template<typename T , typename Policy >
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * >
void pmem::obj::segment_vector< T, Policy >::assign ( InputIt  first,
InputIt  last 
)

Replaces the contents with copies of those in the range [first, last) transactionally.

This overload participates in overload resolution only if InputIt satisfies InputIterator. Only the iterators and references in [0, std::distance(first, last)) remain valid.

Parameters
[in]firstfirst iterator.
[in]lastlast iterator.
Postcondition
size() == std::distance(first, last)
capacity() == nearest power of 2 greater than max(capacity(), std::distance(first, last))
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

using vector policy user may call assign with zero count and in that case we can't call assign of uninitialized vector

◆ assign() [4/6]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::assign ( segment_vector< T, Policy > &&  other)

Move assignment method.

Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container) transactionally. Other is in a valid but empty state afterwards.

Postcondition
size() == other.size()
capacity() == other.capacity()
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ assign() [5/6]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::assign ( size_type  count,
const_reference  value 
)

Replaces the contents with count copies of value value transactionally.

Only the iterators and references in [0, std::distance(first, last)) remain valid.

Parameters
[in]countnumber of elements to construct.
[in]valuevalue of all constructed elements.
Postcondition
size() == count
capacity() == nearest power of 2 greater than max(capacity(), count)
Exceptions
std::length_errorif count > max_size().
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::transaction_free_errorwhen freeing underlying segment failed.

using vector policy user may call assign with zero count and in that case we can't call assign of uninitialized vector

◆ assign() [6/6]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::assign ( std::initializer_list< T >  ilist)

Replaces the contents with the elements from the initializer list ilist transactionally.

Only the iterators and references in [0, std::distance(ilist.begin(), ilist.end())) remain valid.

Parameters
[in]ilistinitializer list with content to be constructed.
Postcondition
size() == std::distance(ilist.begin(), ilist.end())
capacity() == nearest power of 2 greater than max(capacity(), std::distance(ilist.begin(), ilist.end()))
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ at() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::reference pmem::obj::segment_vector< T, Policy >::at ( size_type  n)

Access element at specific index with bounds checking and add it to a transaction.

Parameters
[in]nindex number.
Returns
reference to element number n in underlying segments.
Exceptions
std::out_of_rangeif n is not within the range of the container.
pmem::transaction_errorwhen adding the object to the transaction failed.

◆ at() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::at ( size_type  n) const

Access element at specific index with bounds checking.

Parameters
[in]nindex number.
Returns
const_reference to element number n in underlying segments.
Exceptions
std::out_of_rangeif n is not within the range of the container.

◆ back() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::reference pmem::obj::segment_vector< T, Policy >::back

Access the last element and add this element to a transaction.

Returns
reference to the last element in underlying segments.
Exceptions
pmem::transaction_errorwhen adding the object to the transaction failed.

◆ back() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::back

Access the last element.

Returns
const_reference to the last element in underlying segments.

◆ begin() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::begin

Returns an iterator to the beginning.

Returns
iterator pointing to the first element in the segment_vector.

◆ begin() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_iterator pmem::obj::segment_vector< T, Policy >::begin
noexcept

Returns const iterator to the beginning.

Returns
const_iterator pointing to the first element in the segment_vector.

◆ capacity()

template<typename T , typename Policy >
segment_vector< T, Policy >::size_type pmem::obj::segment_vector< T, Policy >::capacity
noexcept
Returns
number of elements that can be held in currently allocated storage.

◆ cback()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::cback

Access the last element.

In contradiction to back(), cback() will return const_reference not depending on the const-qualification of the object it is called on.

Returns
const_reference to the last element in underlying segments.

◆ cbegin()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_iterator pmem::obj::segment_vector< T, Policy >::cbegin
noexcept

Returns const iterator to the beginning.

In contradiction to begin(), cbegin() will return const_iterator not depending on the const-qualification of the object it is called on.

Returns
const_iterator pointing to the first element in the segment_vector.

◆ cend()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_iterator pmem::obj::segment_vector< T, Policy >::cend
noexcept

Returns a const iterator to the end.

In contradiction to end(), cend() will return const_iterator not depending on the const-qualification of the object it is called on.

Returns
const_iterator referring to the past-the-end element in the segment_vector.

◆ cfront()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::cfront

Access the first element.

In contradiction to front(), cfront() will return const_reference not depending on the const-qualification of the object it is called on.

Returns
reference to first element in underlying segments.

◆ cget()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::cget ( size_type  n) const
private

Private helper function.

Not considering if element exist or not.

Returns
const reference to element with given index.

◆ clear()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::clear

Clears the content of a segment_vector transactionally.

Postcondition
size() == 0
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ const_at()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::const_at ( size_type  n) const

Access element at specific index with bounds checking.

In contradiction to at(), const_at() will return const_reference not depending on the const-qualification of the object it is called on.

Parameters
[in]nindex number.
Returns
const_reference to element number n in underlying segments.
Exceptions
std::out_of_rangeif n is not within the range of the container.

◆ construct()

template<typename T , typename Policy >
template<typename... Args>
void pmem::obj::segment_vector< T, Policy >::construct ( size_type  idx,
size_type  count,
Args &&...  args 
)
private

Private helper function.

Must be called during transaction. Assumes that there is free space for additional elements. Constructs elements at given index in underlying segments based on given parameters.

Parameters
[in]idxunderlying segments index where new elements will be constructed.
[in]countnumber of elements to be constructed.
[in]argsvariadic template arguments for value_type constructor.
Precondition
must be called in transaction scope.
if initialized, range [end(), end() + count) must be snapshotted in current transaction.
capacity() >= size() + count
args is valid argument for value_type constructor.
Postcondition
size() == size() + count
Exceptions
rethrowsconstructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate
pmem::transaction_alloc_errorwhen allocating memory for underlying segment in transaction failed.

◆ construct_range()

template<typename T , typename Policy >
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * >
void pmem::obj::segment_vector< T, Policy >::construct_range ( size_type  idx,
InputIt  first,
InputIt  last 
)
private

Private helper function.

Must be called during transaction. Assumes that there is free space for additional elements and input arguments satisfy InputIterator requirements. Copies elements at index idx in underlying segments with the contents of the range [first, last). This overload participates in overload resolution only if InputIt satisfies InputIterator.

Parameters
[in]idxunderlying array index where new elements will be constructed.
[in]firstfirst iterator.
[in]lastlast iterator.
Precondition
must be called in transaction scope.
if initialized, range [end(), end() + std::distance(first, last)) must be snapshotted in current transaction.
capacity() >= size() + std::distance(first, last)
InputIt is InputIterator.
InputIt::reference is valid argument for value_type copy constructor.
Postcondition
size() == size() + std::distance(first, last)
Exceptions
rethrowsconstructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate
pmem::transaction_alloc_errorwhen allocating memory for underlying segment in transaction failed.

◆ crange()

template<typename T , typename Policy >
slice< typename segment_vector< T, Policy >::const_iterator > pmem::obj::segment_vector< T, Policy >::crange ( size_type  start,
size_type  n 
) const

Returns const slice.

This method is not specified by STL standards.

Parameters
[in]startstart index of requested range.
[in]nnumber of elements in range.
Returns
slice from start to start + n.
Exceptions
std::out_of_rangeif any element of the range would be outside of the segment_vector.

◆ crbegin()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reverse_iterator pmem::obj::segment_vector< T, Policy >::crbegin
noexcept

Returns a const reverse iterator to the beginning.

In contradiction to rbegin(), crbegin() will return const_reverse_iterator not depending on the const-qualification of the object it is called on.

Returns
const_reverse_iterator pointing to the last element in the segment_vector.

◆ crend()

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reverse_iterator pmem::obj::segment_vector< T, Policy >::crend
noexcept

Returns a const reverse iterator to the beginning.

In contradiction to rend(), crend() will return const_reverse_iterator not depending on the const-qualification of the object it is called on.

Returns
const_reverse_iterator pointing to the theoretical element preceding the first element in the segment_vector.

◆ emplace()

template<typename T , typename Policy >
template<class... Args>
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::emplace ( const_iterator  pos,
Args &&...  args 
)

Inserts a new element into the container directly before pos.

The element is constructed in-place. The arguments args... are forwarded to the constructor as std::forward<Args>(args).... Note that standard allows args to be a self reference and internal emplace implementation handles this case by creating temporary element_type object. This object is being stored either on stack or on pmem, see pmem::detail::temp_value for details.

Parameters
[in]positerator before which the new element will be constructed.
[in]argsarguments to forward to the constructor of the element.
Returns
Iterator pointing to the emplaced element.
Precondition
value_type must meet the requirements of MoveAssignable, MoveInsertable and EmplaceConstructible.
Postcondition
capacity() == nearest power of 2 greater than size() + 1, or remains the same if there is enough space.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ emplace_back()

template<typename T , typename Policy >
template<class... Args>
segment_vector< T, Policy >::reference pmem::obj::segment_vector< T, Policy >::emplace_back ( Args &&...  args)

Appends a new element to the end of the container transactionally.

The element is constructed in-place. The arguments args... are forwarded to the constructor as std::forward<Args>(args).... Past-the-end iterator is invalidated.

Parameters
[in]argsarguments to forward to the constructor of the element.
Returns
Iterator pointing to the emplaced element.
Precondition
value_type must meet the requirements of MoveInsertable and EmplaceConstructible.
size() must be less than max_size()
Postcondition
capacity() == nearest power of 2 greater than size() + 1, or remains the same if there is enough space.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ empty()

template<typename T , typename Policy >
constexpr bool pmem::obj::segment_vector< T, Policy >::empty
constexprnoexcept

Checks whether the container is empty.

Returns
true if container is empty, false otherwise.

◆ end() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::end

Returns an iterator to past the end.

Returns
iterator referring to the past-the-end element in the segment_vector.

◆ end() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_iterator pmem::obj::segment_vector< T, Policy >::end
noexcept

Returns a const iterator to past the end.

Returns
const_iterator referring to the past-the-end element in the segment_vector.

◆ erase() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::erase ( const_iterator  first,
const_iterator  last 
)

Removes the elements in the range [first, last).

Invalidates iterators and references at or after the point of the erase, including the end() iterator. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.

Parameters
[in]firstbeginning of the range of elements to be removed.
[in]lastend of range of elements to be removed.
Returns
Iterator following the last removed element. If the iterator pos refers to the last element, the end() iterator is returned. If first and last refer to the same element, iterator to this element is returned.
Precondition
value_type must meet the requirements of MoveAssignable.
Postcondition
size() = size() - std::distance(first, last).
Exceptions
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ erase() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::erase ( const_iterator  pos)

Removes the element at pos.

Invalidates iterators and references at or after the point of the erase, including the end() iterator. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.

Parameters
[in]positerator to the element to be removed.
Returns
Iterator following the last removed element. If the iterator pos refers to the last element, the end() iterator is returned.
Precondition
value_type must meet the requirements of MoveAssignable.
Postcondition
size() = size() - 1.
Exceptions
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ free_data()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::free_data

Clears the content of a segment_vector and frees all allocated persistent memory for data transactionally.

Postcondition
size() == 0
capacity() == 0
Exceptions
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segments failed.

◆ front() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::reference pmem::obj::segment_vector< T, Policy >::front

Access the first element and add this element to a transaction.

Returns
reference to first element in underlying segments.
Exceptions
pmem::transaction_errorwhen adding the object to the transaction failed.

◆ front() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::front

Access the first element.

Returns
const_reference to first element in underlying segments.

◆ get() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::reference pmem::obj::segment_vector< T, Policy >::get ( size_type  n)
private

Private helper function.

Not considering if element exist or not.

Returns
reference to element with given index in segment_vector.

◆ get() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::get ( size_type  n) const
private

Private helper function.

Not considering if element exist or not.

Returns
const reference to element with given index.

◆ get_pool()

template<typename T , typename Policy >
pool_base pmem::obj::segment_vector< T, Policy >::get_pool
privatenoexcept

Private helper function.

Precondition
underlying segments must reside in persistent memory pool.
Returns
reference to pool_base object where segment_vector resides.

◆ insert() [1/5]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::insert ( const_iterator  pos,
const T &  value 
)

Inserts value before pos in the container transactionally.

Causes allocation if the new size() is greater than the old capacity(). Only the iterators and references before the insertion point remain valid.

Parameters
[in]positerator before which the content will be inserted. pos may be the end() iterator.
[in]valueelement value to be inserted.
Returns
Iterator pointing to the inserted value.
Precondition
value_type must meet the requirements of CopyAssignable and CopyInsertable.
Postcondition
capacity() == nearest power of 2 greater than size() + 1, or remains the same if there is enough space.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ insert() [2/5]

template<typename T , typename Policy >
template<typename InputIt , typename std::enable_if< detail::is_input_iterator< InputIt >::value, InputIt >::type * >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::insert ( const_iterator  pos,
InputIt  first,
InputIt  last 
)

Inserts elements from range [first, last) before pos in the container transactionally.

Causes allocation if the new size() is greater than the old capacity(). Only the iterators and references before the insertion point remain valid. This overload participates in overload resolution only if InputIt qualifies as InputIterator, to avoid ambiguity with the pos-count-value overload. The behavior is undefined if first and last are iterators into *this.

Parameters
[in]positerator before which the content will be inserted. pos may be the end() iterator.
[in]firstbegin of the range of elements to insert, can't be iterator into container for which insert is called.
[in]lastend of the range of elements to insert, can't be iterator into container for which insert is called.
Returns
Iterator pointing to the first element inserted or pos if first == last.
Precondition
value_type must meet the requirements of EmplaceConstructible, Swappable, CopyAssignable, CopyConstructible and CopyInsertable.
InputIt must satisfies requirements of InputIterator.
Postcondition
capacity() == nearest power of 2 greater than size() + std::distance(first, last), or remains the same if there is enough space.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ insert() [3/5]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::insert ( const_iterator  pos,
size_type  count,
const T &  value 
)

Inserts count copies of the value before pos in the container transactionally.

Causes allocation if the new size() is greater than the old capacity(). Only the iterators and references before the insertion point remain valid.

Parameters
[in]positerator before which the content will be inserted. pos may be the end() iterator.
[in]countnumber of copies to be inserted.
[in]valueelement value to be inserted.
Returns
Iterator pointing to the first element inserted, or pos if count == 0.
Precondition
value_type must meet the requirements of CopyAssignable and CopyInsertable.
Postcondition
capacity() == nearest power of 2 greater than size() + count, or remains the same if there is enough space.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ insert() [4/5]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::insert ( const_iterator  pos,
std::initializer_list< T >  ilist 
)

Inserts elements from initializer list ilist before pos in the container transactionally.

Causes allocation if the new size() is greater than the old capacity(). Only the iterators and references before the insertion point remain valid.

Parameters
[in]positerator before which the content will be inserted. pos may be the end() iterator.
[in]ilistinitializer list to insert the values from.
Returns
Iterator pointing to the first element inserted, or pos if ilist is empty.
Precondition
value_type must meet the requirements of EmplaceConstructible, Swappable, CopyAssignable, CopyConstructible and CopyInsertable.
Postcondition
capacity() == nearest power of 2 greater than size() + std::distance(ilist.begin(), ilist.end()), or remains the same if there is enough space.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ insert() [5/5]

template<typename T , typename Policy >
segment_vector< T, Policy >::iterator pmem::obj::segment_vector< T, Policy >::insert ( const_iterator  pos,
T &&  value 
)

Moves value before pos in the container transactionally.

Causes allocation if the new size() is greater than the old capacity(). Only the iterators and references before the insertion pointremain valid.

Parameters
[in]positerator before which the content will be inserted. pos may be the end() iterator.
[in]valueelement value to be inserted.
Returns
Iterator pointing to the inserted value.
Precondition
value_type must meet the requirements of MoveAssignable and MoveInsertable.
Postcondition
capacity() == nearest power of 2 greater than size() + 1, or remains the same if there is enough space.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ insert_gap()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::insert_gap ( size_type  idx,
size_type  count 
)
private

Private helper function.

Must be called during transaction. Inserts a gap for count elements starting at index idx. If there is not enough space available, reallocation occurs.

param[in] idx index number where gap should be made. param[in] count length (expressed in number of elements) of the gap.

Precondition
must be called in transaction scope.
Postcondition
if there is not enough space for additional gap, new segment will be allocated and capacity() will equal to nearest power of 2 greater than size()
  • count.
Exceptions
rethrowsconstructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ internal_reserve()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::internal_reserve ( size_type  new_capacity)
private

Private helper method.

Increases capacity. Allocs new segments if new_capacity is greater than current capacity.

Precondition
must be called in transaction scope
Parameters
[in]new_capacitynew desired capacity of the container.
Postcondition
capacity() = nearest power of 2 larger than new_capacity
Exceptions
pmem::length_errorwhen new_capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ max_size()

template<typename T , typename Policy >
constexpr segment_vector< T, Policy >::size_type pmem::obj::segment_vector< T, Policy >::max_size
constexprnoexcept
Returns
maximum number of elements the container is able to hold due to PMDK limitations.

◆ operator=() [1/4]

template<typename T , typename Policy >
segment_vector< T, Policy > & pmem::obj::segment_vector< T, Policy >::operator= ( const segment_vector< T, Policy > &  other)

Copy assignment operator.

Replaces the contents with a copy of the contents of other transactionally.

Postcondition
size() == other.size()
capacity() == nearest power of 2 greater than max(other.size(), capacity())
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ operator=() [2/4]

template<typename T , typename Policy >
segment_vector< T, Policy > & pmem::obj::segment_vector< T, Policy >::operator= ( const std::vector< T > &  other)

Copy assignment operator.

Replaces the contents with a copy of the contents of std::vector<T> other transactionally.

Postcondition
size() == other.size()
capacity() == nearest power of 2 greater than max(other.size(), capacity())
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ operator=() [3/4]

template<typename T , typename Policy >
segment_vector< T, Policy > & pmem::obj::segment_vector< T, Policy >::operator= ( segment_vector< T, Policy > &&  other)

Move assignment operator.

Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container) transactionally. Other is in a valid but empty state afterwards.

Postcondition
size() == other.size()
capacity() == other.capacity()
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ operator=() [4/4]

template<typename T , typename Policy >
segment_vector< T, Policy > & pmem::obj::segment_vector< T, Policy >::operator= ( std::initializer_list< T >  ilist)

Replaces the contents with those identified by initializer list ilist transactionally.

Postcondition
size() == std::distance(ilist.begin(), ilist.end())
capacity() == nearest power of 2 greater than max(capacity(), std::distance(ilist.begin(), ilist.end()))
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ operator[]() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::reference pmem::obj::segment_vector< T, Policy >::operator[] ( size_type  n)

Access element at specific index and add it to a transaction.

No bounds checking is performed.

Parameters
[in]nindex number.
Returns
reference to element number n in underlying segments.
Exceptions
pmem::transaction_errorwhen adding the object to the transaction failed.

◆ operator[]() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reference pmem::obj::segment_vector< T, Policy >::operator[] ( size_type  n) const

Access element at specific index.

No bounds checking is performed.

Parameters
[in]nindex number.
Returns
const_reference to element number n in underlying segments.

◆ pop_back()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::pop_back

Removes the last element of the container transactionally.

Calling pop_back on an empty container does nothing. No iterators or references except for back() and end() are invalidated.

Postcondition
size() == std::max(0, size() - 1)
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ push_back() [1/2]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::push_back ( const T &  value)

Appends the given element value to the end of the container transactionally.

The new element is initialized as a copy of value.

Parameters
[in]valuethe value of the element to be appended.
Precondition
value_type must meet the requirements of CopyInsertable.
Postcondition
size() == size() + 1.
capacity() == nearest power of 2 greater than size() + 1, or remains the same if there is enough space.
Exceptions
pmem::length_errorwhen new capacity larger than max_size().
rethrowsconstructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ push_back() [2/2]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::push_back ( T &&  value)

Appends the given element value to the end of the container transactionally.

value is moved into the new element.

Parameters
[in]valuethe value of the element to be appended.
Precondition
value_type must meet the requirements of MoveInsertable.
Postcondition
size() == size() + 1.
capacity() == nearest power of 2 greater than size() + 1, or remains the same if there is enough space.
Exceptions
pmem::length_errorwhen new capacity larger than max_size().
rethrowsconstructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ range() [1/2]

template<typename T , typename Policy >
slice< typename segment_vector< T, Policy >::iterator > pmem::obj::segment_vector< T, Policy >::range ( size_type  start,
size_type  n 
)

Returns slice and snapshots requested range.

This method is not specified by STL standards.

Parameters
[in]startstart index of requested range.
[in]nnumber of elements in range.
Returns
slice from start to start + n.
Exceptions
std::out_of_rangeif any element of the range would be outside of the segment_vector.
pmem::transaction_errorwhen snapshotting failed.

◆ range() [2/2]

template<typename T , typename Policy >
slice< typename segment_vector< T, Policy >::const_iterator > pmem::obj::segment_vector< T, Policy >::range ( size_type  start,
size_type  n 
) const

Returns const slice.

This method is not specified by STL standards.

Parameters
[in]startstart index of requested range.
[in]nnumber of elements in range.
Returns
slice from start to start + n.
Exceptions
std::out_of_rangeif any element of the range would be outside of the segment_vector.

◆ rbegin() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::reverse_iterator pmem::obj::segment_vector< T, Policy >::rbegin

Returns a reverse iterator to the beginning.

Returns
reverse_iterator pointing to the last element in the segment_vector.

◆ rbegin() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reverse_iterator pmem::obj::segment_vector< T, Policy >::rbegin
noexcept

Returns a const reverse iterator to the beginning.

Returns
const_reverse_iterator pointing to the last element in the segment_vector.

◆ rend() [1/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::reverse_iterator pmem::obj::segment_vector< T, Policy >::rend

Returns a reverse iterator to the end.

Returns
reverse_iterator pointing to the theoretical element preceding the first element in the segment_vector.

◆ rend() [2/2]

template<typename T , typename Policy >
segment_vector< T, Policy >::const_reverse_iterator pmem::obj::segment_vector< T, Policy >::rend
noexcept

Returns a const reverse iterator to the end.

Returns
const_reverse_iterator pointing to the theoretical element preceding the first element in the segment_vector.

◆ reserve()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::reserve ( size_type  capacity_new)

Increases the capacity of the segment_vector to capacity_new transactionally.

If segment where should be capacity_new is greater than the current capacity's segment, new segments allocated, otherwise the method does nothing. Past-the-end iterator invalidated if allocation occurs.

Parameters
[in]capacity_newnew capacity.
Postcondition
capacity() == max(capacity(), capacity_new)
Exceptions
pmem::length_errorwhen capacity_new larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.

◆ resize() [1/2]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::resize ( size_type  count)

Resizes the container to count elements transactionally.

If the current size is greater than count, the container is reduced to its first count elements. If the current size is less than count, additional default-inserted elements are appended.

Parameters
[in]countnew size of the container
Postcondition
capacity() == nearest power of 2 greater than std::max(capacity(), count)
size() == count
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ resize() [2/2]

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::resize ( size_type  count,
const value_type &  value 
)

Resizes the container to contain count elements transactionally.

If the current size is greater than count, the container is reduced to its first count elements. If the current size is less than count, additional copies of value are appended.

Parameters
[in]countnew size of the container.
[in]valuethe value to initialize the new elements with.
Postcondition
capacity() == nearest power of 2 greater than std::max(capacity(), count)
size() == count
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.
pmem::length_errorwhen new capacity larger than max_size().
pmem::transaction_alloc_errorwhen allocating new memory failed.
pmem::transaction_out_of_memorywhen not enough memory to allocate.

◆ segment_capacity_validation()

template<typename T , typename Policy >
bool pmem::obj::segment_vector< T, Policy >::segment_capacity_validation
private

Private helper function.

Checks if each allocated segment match its expected capacity according to static_segment_policy.

Returns
true if capacity of all segments matches to expected capacity, false otherwise.

◆ shrink()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::shrink ( size_type  size_new)
private

Private helper function.

Must be called during transaction. Destroys elements in underlying array beginning from position size_new.

Parameters
[in]size_newnew size
Precondition
must be called in transaction scope.
if initialized, range [begin(), end()) must be snapshotted in current transaction.
size_new <= size()
Postcondition
size() == size_new
Exceptions
rethrowsconstructor exception.
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ shrink_to_fit()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::shrink_to_fit

Requests transactional removal of unused capacity.

New capacity will be set to nearest power of 2 greater than current size().

Postcondition
capacity() == nearest power of 2 bigger than size()
Exceptions
rethrowsdestructor exception.
pmem::transaction_errorwhen snapshotting failed.
pmem::transaction_free_errorwhen freeing underlying segment failed.

◆ size()

template<typename T , typename Policy >
segment_vector< T, Policy >::size_type pmem::obj::segment_vector< T, Policy >::size
noexcept
Returns
number of elements.

◆ snapshot_data()

template<typename T , typename Policy >
void pmem::obj::segment_vector< T, Policy >::snapshot_data ( size_type  first,
size_type  last 
)
private

Private helper function.

Takes a “snapshot” of data in range [this[first], this[last])

Parameters
[in]firstfirst index.
[in]lastlast index.
Exceptions
pmem::transaction_errorwhen snapshotting failed.

The documentation for this class was generated from the following file:
pmem::obj::segment_vector
Segment table is a data type with a vector-like interface The difference is that it does not do reall...
Definition: segment_vector.hpp:526
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:64
pmem::obj::pool::root
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:651
pool.hpp
C++ pmemobj pool.
pmem::obj::transaction::run
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:422
pmem::obj
Main libpmemobj namespace.
Definition: allocation_flag.hpp:47
pmem::obj::vector
pmem::obj::vector - persistent container with std::vector compatible interface.
Definition: vector.hpp:69
pmem::obj::persistent_ptr
Persistent pointer class.
Definition: persistent_ptr.hpp:212
p.hpp
Resides on pmem property template.
segment_vector.hpp
A persistent version of segment vector implementation.
pmem::obj::pool::open
static pool< T > open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:679
persistent_ptr.hpp
Persistent smart pointer.