Library Version 11.2.5.3

Chapter 5. Db_map
Prev |  | Next

## Chapter 5. Db_map

db_map has identical methods to std::map and the semantics for each method is identical to its std::map counterpart, except that it stores data into underlying Berkeley DB btree or hash database.

Passing a database handle of btree or hash type creates a db_map equivalent to std::map and std::hashmap respectively. Database(dbp) and environment(penv) handle requirement(applies to all constructors in this class template): 0. The dbp is opened inside the penv environment. Either one of the two handles can be NULL. If dbp is NULL, an anonymous database is created by dbstl. 1. Database type of dbp should be DB_BTREE or DB_HASH. 2. No DB_DUP or DB_DUPSORT flag set in dbp. 3. No DB_RECNUM flag set in dbp. 4. No DB_TRUNCATE specified in dbp's database open flags. 5. DB_THREAD must be set if you are sharing the dbp across multiple threads directly, or indirectly by sharing the container object across multiple threads.

#### See Also

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

### Class Template Parameters

#### kdt

The key data type.

#### ddt

The data data type. db_map stores key/data pairs.

#### value_type_sub

Do not specify anything if ddt type is a class/struct type; Otherwise, specify ElementHolder<ddt> to it.

#### iterator_t

Never specify anything to this type parameter. It is only used internally.

#### Public Members

Member | Description
--- | ---
db_map | Create a std::map/hash_map equivalent associative container.
~db_map |
insert | Insert a single key/data pair if the key is not in the container.
begin | Begin a read-write or readonly iterator which sits on the first key/data pair of the database.
end | Create an open boundary iterator.
rbegin | Begin a read-write or readonly reverse iterator which sits on the first key/data pair of the database.
rend | Create an open boundary iterator.
is_hash | Get container category.
bucket_count | Only for std::hash_map, return number of hash bucket in use.
size | This function supports auto-commit.
max_size | Get max size.
empty | Returns whether this container is empty.
erase | Erase a key/data pair at specified position.
find | Find the key/data pair with specified key x.
lower_bound | Find the greatest key less than or equal to x.
equal_range | Find the range within which all keys equal to specified key x.
count | Count the number of key/data pairs having specified key x.
upper_bound | Find the least key greater than x.
key_eq | Function to get key compare functor.
hash_funct | Function to get hash key generating functor.
value_comp | Function to get value compare functor.
key_comp | Function to get key compare functor.
operator= | Container content assignment operator.
operator[] | Retrieve data element by key.
swap | Swap content with container mp.
clear | Clear contents in this container.
operator== | Map content equality comparison operator.
operator!= | Container unequality comparison operator.

#### Group

Dbstl Container Classes

## db_map

### Function Details

    db_map(Db *dbp=NULL,
        DbEnv *envp=NULL)

Create a std::map/hash_map equivalent associative container.

See the handle requirement in class details to pass correct database/environment handles.

#### Parameters

##### dbp

The database handle.

##### envp

The database environment handle.

#### See Also

db_container(Db*, DbEnv*)

    db_map(Db *dbp, DbEnv *envp, InputIterator first,
        InputIterator last)

Iteration constructor.

Iterates between first and last, setting a copy of each of the sequence of elements as the content of the container object. Create a std::map/hash_map equivalent associative container. Insert a range of elements into the database. The range is [first, last), which contains elements that can be converted to type ddt automatically. See the handle requirement in class details to pass correct database/environment handles. This function supports auto-commit.

#### Parameters

##### dbp

The database handle.

##### envp

The database environment handle.

##### last

The open boundary of the range.

##### first

The closed boundary of the range.

#### See Also

db_container(Db*, DbEnv*)

    db_map(const db_map< kdt, ddt, value_type_sub,
        iterator > &x)

Copy constructor.

Create an database and insert all key/data pairs in x into this container. x's data members are not copied. This function supports auto-commit.

#### Parameters

##### x

The other container to initialize this container.

#### See Also

db_container(const db_container&)

### Class

db_map

Prev |  | Next
clear | Home | ~db_map