150
You can read more about cmap engine internal algorithms and data
structures in Chapter 13.
• Line 58: The pmem::kv::db class provides a static errormsg() method
for extended error messages. In this example, we use the errormsg()
function as a part of the error-handling routine.
• Line 63 and 67: The put() method inserts a key-value pair into the
database. This function is guaranteed to be implemented by all
engines. In this example, we are inserting two key-value pairs into
database and compare returned statuses with status::OK. It’s a
recommended way to check if function succeeded.
• Line 74: The count_all() has a single argument of type size_t. The
method returns the number of elements (phonebook entries) stored
in the database by the argument variable (cnt).
• Line 82: Here, we use the get() method to return the value of the
“John” key. The value is copied into the user-provided number
variable. The get() function returns status::OK on success or an
error on failure. This function is guaranteed to be implemented by all
engines.
• Line 86: For this example, the expected value of variable number for
“John” is “123-456-789”. If we do not get this value, an assertion error
is thrown.
• Line 89: The get_all() method used in this example gives the
application direct, read-only access to the data. Both key and value
variables are references to data stored in persistent memory. In this
example, we simply print the name and the number of every visited pair.
• Line 99: Here, we are removing “John” and his phone number from
the database by calling the remove() method. It is guaranteed to be
implemented by all engines.
• Line 105: After removal of the pair “John, 123-456-789”, we verify if
the pair still exists in database. The API method exists() checks
the existence of an element with given key. If the element is present,
status::OK is returned; otherwise status::NOT_FOUND is returned.
Chapter 9 pmemkv: a persistent in- memory key-value store
Précédent

- 175/457

Suivant