Chapter 4.  Db_vector

The db_vector class has the union set of public member functions as std::vector, std::deque and std::list, and each method has identical default semantics to that in the std equivalent containers.

The difference is that the data is maintained using a Berkeley DB database as well as some Berkeley DB related extensions.

See Also

db_container db_container(Db*, DbEnv*) db_container(const db_container&)

Class Template Parameters

T

The type of data to store.

value_type_sub

If T is a class/struct type, do not specify anything for this parameter; Otherwise, specify ElementHolder<T> to it. Database(dbp) and environment(penv) handle requirement(applies for all constructors of this class template): dbp must meet the following requirement: 1. dbp must be a DB_RECNO type of database handle. 2. DB_THREAD must be set to dbp's open flags. 3. An optional flag DB_RENUMBER is required if the container object is supposed to be a std::vector or std::deque equivalent; Not required if it is a std::list equivalent. But dbstl will not check whether DB_RENUMBER is set to this database handle. Setting DB_RENUMBER will cause the index values of all elements in the underlying databse to be maintained consecutive and in order, which involves potentially a lot of work because many indices may be updated. See the db_container(Db*, DbEnv*) for more information about the two parameters.

Public Members

Member Description
begin

Create a read-write or read-only iterator.

end

Create an open boundary iterator.

rbegin

Create a reverse iterator.

rend

Create an open boundary iterator.

max_size

Get max size.

capacity

Get capacity.

operator[]

Index operator, can act as both a left value and a right value.

at

Index function.

front

Return a reference to the first element.

back

Return a reference to the last element.

operator==

Container equality comparison operator.

operator!=

Container in-equality comparison operator.

operator<

Container less than comparison operator.

assign

Assign a range [first, last) to this container.

push_front

Push an element x into the vector from front.

pop_front

Pop out the front element from the vector.

insert

Insert x before position pos.

erase

Erase element at position pos.

remove

Remove all elements whose values are "value" from the list.

remove_if

Remove all elements making "pred" return true.

merge

Merge content with another container.

unique

Remove consecutive duplicate values from this list.

sort

Sort this list.

reverse

Reverse this list.

splice

Moves elements from list x into this list.

size

Return the number of elements in this container.

empty

Returns whether this container is empty.

db_vector

Constructor.

~db_vector
operator=

Container assignment operator.

resize

Resize this container to specified size n, insert values t if need to enlarge the container.

reserve

Reserve space.

push_back

Push back an element into the vector.

pop_back

Pop out last element from the vector.

swap

Swap content with another vector vec.

clear

Remove all elements of the vector, make it an empty vector.

Group

Dbstl Container Classes

begin

Function Details

iterator begin(ReadModifyWriteOption rmw=
    ReadModifyWriteOption::no_read_modify_write(), bool readonly=false,
    BulkRetrievalOption bulk_read=BulkRetrievalOption::no_bulk_retrieval(),
    bool directdb_get=true)
 

Create a read-write or read-only iterator.

We allow users to create a readonly iterator here so that they don't have to use a const container to create a const_iterator. But using const_iterator is faster. The flags set via db_container::set_cursor_oflags() is used as the cursor open flags.

Parameters

directdb_get

Whether always read key/data pair from backing db rather than using the value cached in the iterator. The current key/data pair is cached in the iterator and always kept updated on iterator movement, but in some extreme conditions, errors can happen if you use cached key/data pairs without always refreshing them from database. By default we are always reading from database when we are accessing the data the iterator sits on, except when we are doing bulk retrievals. But your application can gain extra performance promotion if you can set this flag to false.

readonly

Whether the iterator is created as a readonly iterator. Read only iterators can not update its underlying key/data pair.

bulk_read

Whether read database key/data pairs in bulk, by specifying DB_MULTIPLE_KEY flag to underlying cursor's Dbc::get function. Only readonly iterators can do bulk retrieval, if iterator is not read only, this parameter is ignored. Bulk retrieval can accelerate reading speed because each database read operation will read many key/data pairs, thus saved many database read operations. The default bulk buffer size is 32KB, you can set your desired bulk buffer size by specifying BulkRetrievalOpt::bulk_retrieval(your_bulk_buffer_size); If you don't want bulk retrieval, set BulkRetrievalItrOpt::no_bulk_retrieval() as the real parameter.

rmw

Whether this iterator will open a Berkeley DB cursor with DB_RMW flag set. If the iterator is used to read a key/data pair, then update it and store back to db, it is good to set the DB_RMW flag, by specifying RMWItrOpt::read_modify_write() If you don't want to set the DB_RMW flag, specify RMWItrOpt::no_read_modify_write(), which is the default behavior.

Return Value

The created iterator.

See Also

db_container::set_cursor_oflags();

const_iterator begin(BulkRetrievalOption bulkretrieval=
    (BulkRetrievalOption::no_bulk_retrieval()),
    bool directdb_get=true) const
 

Create a const iterator.

The created iterator can only be used to read its referenced data element. Can only be called when using a const reference to the contaienr object. The parameters have identical meanings and usage to those of the other non-const begin function.

Parameters

directdb_get

Same as that of begin(ReadModifyWrite, bool, BulkRetrievalOption, bool);

bulkretrieval

Same as that of begin(ReadModifyWrite, bool, BulkRetrievalOption, bool);

Return Value

The created const iterator.

See Also

begin(ReadModifyWrite, bool, BulkRetrievalOption, bool);

Class

db_vector