NuDB Logo

PrevUpHomeNext

create

Create a new database.

template<
    class Hasher,
    class File = native_file,
    class... Args>
void
create(
    path_type const& dat_path,
    path_type const& key_path,
    path_type const& log_path,
    std::uint64_t appnum,
    std::uint64_t salt,
    nsize_t key_size,
    nsize_t blockSize,
    float load_factor,
    error_code& ec,
    Args&&... args);

This function creates a set of new database files with the given parameters. The files must not already exist or else an error is returned.

If an error occurs while the files are being created, the function attempts to remove the files before returning.

Example
error_code ec;
create<xxhasher>(
    "db.dat", "db.key", "db.log",
        1, make_salt(), 8, 4096, 0.5f, ec);
Template Parameters

Hasher

The hash function to use. This type must meet the requirements of Hasher. The same hash function must be used every time the database is opened, or else an error is returned. The provided |3|xxhasher is a suitable general purpose hash function.

File

The type of file to use. Use the default of native_file unless customizing the file behavior.

Parameters

dat_path

The path to the data file.

key_path

The path to the key file.

log_path

The path to the log file.

appnum

A caller-defined value stored in the file headers. When opening the database, the same value is preserved and returned to the caller.

salt

A random unsigned integer used to permute the hash function to make it unpredictable. The return value of make_salt returns a suitable value.

key_size

The number of bytes in each key.

blockSize

The size of a key file block. Larger blocks hold more keys but require more I/O cycles per operation. The ideal block size the largest size that may be read in a single I/O cycle, and device dependent. The return value of block_size returns a suitable value for the volume of a given path.

load_factor

A number between zero and one representing the average bucket occupancy (number of items). A value of 0.5 is perfect. Lower numbers waste space, and higher numbers produce negligible savings at the cost of increased I/O cycles.

ec

Set to the error, if any occurred.

args

Optional arguments passed to File constructors.

Requirements

Header: nudb/create.hpp


PrevUpHomeNext