Build TOP Environments

For developer

C API

Debug family(C I/F)
DSO load family(C I/F)
Create/Open/Close family(C I/F)
Transaction archive family(C I / F)
Attribute family(C I / F)
GET family(C I/F)
SET family(C I/F)
Rename family(C I/F)
Direct binary data acquisition / setting family(C I/F)
Delete family(C I/F)
Search family(C I/F)
Direct access family(C I/F)
Queue family(C I/F)
Queue (key & value) family(C I/F)
Dump and status family(C I/F)

C++ API

Debug family(C/C++ I/F)
K2HashDynLib class
K2HTransDynLib class
K2HDAccess class
k2hstream(ik2hstream、ok2hstream) class
K2HArchive class
K2HQueue class
K2HKeyQueue class
K2HShm class


C API

It is an API for C language.
Include the following header files when developing.

#include <k2hash/k2hash.h>

When linking please specify the following as an option.

-lk2hash

The functions for C language are explained below.


Debug family(C I/F)

The K2HASH library can output messages to check internal operation and API operation. This function group is a group of functions for controlling message output

Format

Description

Return Values

K2h_set_debug_file, k2h_unset_debug_file, k2h_load_debug_env, k2h_set_bumpup_debug_signal_user1 will return true on success. If it fails, it returns false.

Note

For the environment variables K2HDBGMODE and K2HDBGFILE, see the Environments in the manual.

Examples

k2h_set_bumpup_debug_signal_user1();
k2h_set_debug_file("/var/log/k2hash/error.log");
k2h_set_debug_level_message();

DSO load family(C I/F)

The K2HASH library can read the internal HASH function and the function for transaction processing as an external shared library (DSO module). This function group loads and unloads these shared libraries.

Format

Description

Return Values

Returns true if it succeeds. If it fails, it returns false.

Note

K2HASH has a built-in HASH function (FNV-1A) in advance, and a transaction plug-in (Bultin transaction plug-in) that performs simple processing. When loading the DSO module with this function group, it takes precedence over the HASH function and transaction plug-in installed inside them and is replaced.

Examples

if(!k2h_load_hash_library("/usr/lib64/myhashfunc.so")){
    return false;
}
if(!k2h_load_transaction_library("/usr/lib64/mytransfunc.so")){
    return false;
}
    //...
    //...
    //...
k2h_unload_hash_library();
k2h_unload_transaction_library();

Create/Open/Close family(C I/F)

It is a group of functions that initialize, open (attach), close (detach) K2HASH (file or on memory).

Format

Description

Parameters

Return Values

Note

The K2HASH handle returned from each function is a handle that you specify to manipulate the K2HASH file (or on memory) with other API functions. Be sure to detach (close) the attached (open) K2HASH handle. MASK, CMASK, and elementcnt are values that determine the structure (HASH table) of the data tree managed internally by the K2HASH library. We recommend that you try out the attached k2hlintool tool, try out the effect of that value, and set the value. When attaching an already existing K2HASH file, these values are ignored and the set value is used.

Examples

if(!k2h_create("/home/myhome/mydata.k2h", 8, 4, 1024, 512)){
    return false;
}
k2h_h k2handle;
if(K2H_INVALID_HANDLE == (k2handle = k2h_open_rw("/home/myhome/mydata.k2h", true, 8, 4, 1024, 512))){
    return false;
}
    //...
    //...
    //...
k2h_close(k2handle);

Transaction archive family(C I / F)

Functions related to transaction processing provided by the K2HASH library.

Format

Description

Parameters

Return Values

Note

Examples

if(!k2h_enable_transaction(k2handle, "/tmp/mytrans.log")){
    return false;
}
    //...
    //...
    //...
k2h_disable_transaction(k2handle);
   
//
// K2HASH can load the file which is made by transaction.
//
if(!k2h_load_archive(k2handle, "/tmp/mytrans.log", true)){
    return false;
}
// Full backup
if(!k2h_put_archive(k2handle, "/tmp/myfullbackup.ar", true)){
    return false;
}

Attribute family(C I / F)

A set of functions related to attributes (Attribute) provided by the K2HASH library.

Format

Description

Parameters

Return Values

Returns true if it succeeds. If it fails, it returns false.

Note

The Builtin attribute is set with the k2h_set_common_attr function. The K2HASH library can also read the setting value of the Builtin attribute from the environment variable. First, at the time of initialization of the K2HASH library, read the set value of the attribute from the environment variable. After that, the setting of the Builtin attribute is overwritten by a call such as the k2h_set_common_attr function. Therefore, as for the value which does not change from the initial value (including setting of environment variable), initial value can be maintained by specifying NULL. )

Examples

bool    is_mtime = true;
bool    is_defenc= true;
char*   passfile = "/etc/k2hpass";
bool    is_history = true;
time_t  expire = 120;
if(!k2h_set_common_attr(handle, &is_mtime, &is_defenc, passfile, &is_history, &expire)){
    return false;
}
    //...
    //...
    //...
k2h_clean_common_attr(k2handle);
   
if(!k2h_add_attr_plugin_library(k2handle, "/usr/lib/myattrs.so")){
    return false;
}
// Full backup
if(!k2h_put_archive(k2handle, "/tmp/myfullbackup.ar", true)){
    return false;
}

GET family(C I/F)

This is a function group that reads data from K2HASH file (or on memory).

Format

Description

Parameters

Return Values

About the k2h_get_trial_callback callback function

K2h_get_value * _ext, k2h_get_direct_value * _ext, k2h_get_str_value * _ext, k2h_get_str_direct_value * _ext function specifies the callback function (k2h_get_trial_callback) The callback function of k2h_get_trial_callback is called back when its key is read, its value as an argument. The called callback function can change (overwrite) the value. Using this callback function gives the timing to change the value for a particular key. The callback function is called even if the key does not exist in the K2HASH data. For example, if the key is not set, you can return the initial value. This allows you to get the timing to set the initial value in the reading of an unset key.

The callback function has the following prototype.

typedef K2HGETCBRES (*k2h_get_trial_callback)(const unsigned char* byKey, size_t keylen, const unsigned char* byValue, size_t vallen, unsigned char** ppNewValue, size_t* pnewvallen, const PK2HATTRPCK pattrs, int attrscnt, void* pExtData)



The callback function is called with the following arguments.

The callback function returns the following values.

A sample callback function is shown below.

static K2HGETCBRES GetTrialCallback(const unsigned char* byKey, size_t keylen, const unsigned char* byValue, size_t vallen, unsigned char** ppNewValue, size_t* pnewvallen, const PK2HATTRPCK pattrs, int attrscnt, void* pExtData)
{
    if(!byKey || 0 == keylen || !ppNewValue){
        return K2HGETCB_RES_ERROR;
    }
    //
    // Check get results which are byKey and byValue.
    // If you need to reset value for key, you set ppNewValue and return K2HGETCB_RES_OVERWRITE.
    // pExpData is the parameter when you call Get function.
    //
    return K2HGETCB_RES_NOTHING;
}

Note

Please use the special function to release the area, in the extracted value, sub key list, attribute area.
The types of each structure are shown below.

Examples

char* pval;
if(NULL == (pval = k2h_get_str_direct_value(k2handle, "mykey"))){
    return false;
}
printf("KEY=mykey has VALUE=%s\n", pval);
free(pval);

SET family(C I/F)

This is a group of functions to write data to K2HASH file (or on memory).

Format

Description

Parameters

Return Values

Returns true if it succeeds. If it fails, it returns false.

Note

The K2HKEYPCK structure has the following structure.

Examples

if(!k2h_set_str_value(k2handle, "mykey", "myval")){
    return false;
}

Rename family(C I/F)

This is a function group that changes the key name of data of K2HASH file (or on memory).

Format

Description

Parameters

Return Values

Returns true if it succeeds. If it fails, it returns false.

Examples

if(!k2h_rename_str(k2handle, "mykey", "newmykey")){
    return false;
} 

Direct binary data acquisition / setting family(C I/F)

It is a group of functions that directly acquires multiple data of “K2HASH file” (or on memory) by specifying a range such as HASH value. This function group is a special group of functions used for copying (backup and replication).

Format

Description

Parameters

Note

K2HBIN structure

typedef struct k2hash_binary_data{
    unsigned char*    byptr;
    size_t            length;
}K2HBIN, *PK2HBIN;

Return Values

Returns true if it succeeds. If it fails, it returns false.

Examples

if(!k2h_get_elements_by_hash(k2hash, hashval, startts, endts, target_hash, target_max_hash, target_hash_range, &nexthash, &pbindatas, &datacnt)){
     return false;
}
 
if(!k2h_set_element_by_binary(k2hash, &pbindatas[cnt], &ts)){
     return false;
}

Delete family(C I/F)

This is a function group for deleting data from K2HASH file (or on memory).

Format

Description

Parameters

Return Values

Returns true if it succeeds. If it fails, it returns false.

Note

K2h_remove_subkey, k2h_remove_str_subkey will fail if the key does not have the specified subkey.

Examples

if(!k2h_remove_str_all(k2handle, "mykey")){
    return false;
}

Search family(C I/F)

This is a group of functions to search for data from K2HASH file (or on memory).

Format

Description

Parameters

Return Values

Note

For the period holding a valid search handle (k2h_find_h) (the period until release by k2h_find_free), a lock for reading is set for the K2HASH data pointed to by the search handle. During the period when the lock is set, reading and writing of that key will be blocked. Therefore, we recommend not keeping this explorer handle for a long time. In particular, you should avoid caching the search handle and keep it for long periods within the program.

Examples

// Full dump
for(k2h_find_h fhandle = k2h_find_first(k2handle); K2H_INVALID_HANDLE != fhandle; fhandle = k2h_find_next(fhandle)){
    char*    pkey = k2h_find_get_str_key(fhandle);
    char*    pval = k2h_find_get_direct_value(fhandle);
    printf("KEY=%s  --> VAL=%s\n", pkey ? pkey : "null", pval ? pval : "null");
    if(pkey){
        free(pkey);
    }
    if(pval){
        free(pval);
    }
}

Direct access family(C I/F)

A function group that directly accesses data of “K2HASH file” (or on memory). It is mainly used for reading and writing to data with a large size value. Parts of the value can be overwritten or read by specifying the offset.

Format

Description

Parameters

Return Values

Note

Examples

// get handle
k2h_da_h    dahandle;
if(K2H_INVALID_HANDLE == (dahandle = k2h_da_str_handle_write(k2handle, "mykey"))){
    fprintf(stderr, "Could not get k2h_da_h handle.");
    return false;
}
// offset
if(!k2h_da_set_write_offset(dahandle, 100)){
    fprintf(stderr, "Could not set write offset.");
    k2h_da_free(dahandle);
    return false;
}
// write
if(!k2h_da_set_value_str(dahandle, "test data")){
    fprintf(stderr, "Failed writing value.");
    k2h_da_free(dahandle);
    return false;
}
k2h_da_free(dahandle);

Queue family(C I/F)

The K2HASH library provides functions as a queue (FIFO / LIFO). The queue can push the value as FIFO / LIFO and pop. This function group is a function group related to the queue.

Format

Description

Parameters

Return Values

K2h_q_remove_trial_callback callback function

The k2h_q_remove_ext function specifies the callback function (k2h_q_remove_trial_callback) as an argument. The callback function is called each time the value of the queue is deleted, and it can judge whether or not to delete the value from the queue. With this callback function, deletion can be executed under arbitrary conditions in deletion of the value accumulated in the queue.

This callback function has the following prototype.

typedef K2HQRMCBRES (*k2h_q_remove_trial_callback)(const unsigned char* bydata, size_t datalen, const PK2HATTRPCK pattrs, int attrscnt, void* pExtData);

The k2h_q_remove_ext function calls the specified callback function for each queue value deletion process.

The callback function is called with the following arguments.

static K2HQRMCBRES QueueRemoveCallback(const unsigned char* bydata, size_t datalen, const PK2HATTRPCK pattrs, int attrscnt, void* pExtData)
{
    if(!bydata || 0 == datalen){
        return K2HQRMCB_RES_ERROR;
    }
    //
    // Check get queued data as bydata which is queued data(K2HQueue) or key(K2HKeyQueue).
    // If you need to remove it from queue, this function must return K2HQRMCB_RES_CON_RM or K2HQRMCB_RES_FIN_RM.
    // The other do not want to remove it, must return K2HQRMCB_RES_CON_NOTRM or K2HQRMCB_RES_FIN_NOTRM.
    // If you want to stop removing no more, this function can return K2HQRMCB_RES_FIN_*(RM/NOTRM).
    // pExpData is the parameter when you call Remove function.
    //
    return K2HQRMCB_RES_CON_RM;
}

Note

Examples

if(!k2h_create("/home/myhome/mydata.k2h", 8, 4, 1024, 512)){
    return false;
}
k2h_h k2handle;
if(K2H_INVALID_HANDLE == (k2handle = k2h_open_rw("/home/myhome/mydata.k2h", true, 8, 4, 1024, 512))){
    return false;
}
// get queue handle
k2h_q_h    qhandle;
if(K2H_INVALID_HANDLE == (qhandle = k2h_q_handle_str_prefix(k2handle, true/*FIFO*/, "my_queue_prefix_"))){
    k2h_close(k2handle);
    return false;
}
// push
if(!k2h_q_str_push(qhandle, "test_value")){
    k2h_q_free(qhandle);
    k2h_close(k2handle);
    return false;
}
// pop
char*    pdata = NULL;
if(!k2h_q_str_pop(qhandle, &pdata)){
    k2h_q_free(qhandle);
    k2h_close(k2handle);
    return false;
}
free(pdata);
k2h_q_free(qhandle);
k2h_close(k2handle);

Queue (key & value) family(C I/F)

The K2HASH library provides functions as a queue (FIFO / LIFO). The queues provided by this function group can be PUSH and POP in FIFO / LIFO, with one key and one value. This function group is a group of functions related to this key and value queue.

Format

Description

Parameters

Return Values

Note

Examples

if(!k2h_create("/home/myhome/mydata.k2h", 8, 4, 1024, 512)){
    return false;
}
k2h_h k2handle;
if(K2H_INVALID_HANDLE == (k2handle = k2h_open_rw("/home/myhome/mydata.k2h", true, 8, 4, 1024, 512))){
    return false;
}
// get queue handle
k2h_q_h    keyqhandle;
if(K2H_INVALID_HANDLE == (keyqhandle = k2h_keyq_handle_str_prefix(k2handle, , true/*FIFO*/, "my_queue_prefix_"))){
    k2h_close(k2handle);
    return false;
}
// push
if(!k2h_keyq_str_push_keyval(keyqhandle, "test_key", "test_value")){
    k2h_keyq_free(keyqhandle);
    k2h_close(k2handle);
    return false;
}
// test for accessing the key
char*    pvalue = NULL;
if(NULL == (pvalue = k2h_get_str_direct_value(k2handle, "test_key"))){
    // error...
}else{
    if(0 != strcmp(pvalue, "test_value")){
        // error...
    }
    free(pvalue);
}
// pop
char*    pkey = NULL;
pvalue        = NULL;
if(!k2h_keyq_str_pop_keyval(keyqhandle, &pkey, &pval)){
    k2h_q_free(keyqhandle);
    k2h_close(k2handle);
    return false;
}
if(0 != strcmp(pkey, "test_key") || 0 != strcmp(pvalue, "test_value")){
    // error...
}
free(pkey);
free(pvalue);
// check no key
pvalue = NULL;
if(NULL != (pvalue = k2h_get_str_direct_value(k2handle, "test_key"))){
    // error...
    free(pvalue);
}
free(pdata);
k2h_q_free(keyqhandle);
k2h_close(k2handle);

Dump and status family(C I/F)

This is a set of debugging functions for dumping K2HASH data.

Format

Description

Parameters

Return Values

Note

Examples

k2h_print_state(k2handle, NULL);
k2h_dump_full(k2handle, NULL);

C++ API

This is the I/F of the C ++ language API for using the K2HASH library.

Include the following header file at development time.

#include <k2hash/k2hash.h>
#include <k2hash/k2hshm.h>


When linking please specify the following as an option.

-lk2hash


The functions for the C ++ language are explained below.

Debug family(C/C++ I/F)

The K2HASH library can output messages to check internal operation and API operation. This function group is a group of functions for controlling message output.

Format

Description

Parameters

Return Values

Note


K2HashDynLib class

Description

The K2HASH library can read the HASH function used internally as an external shared library (DSO module). This class is a management class that loads and unloads this shared library. This class object is a singleton which exists only in the K2HASH library. To use the method of this class, please obtain the singleton’s K2HashDynLib object pointer and use it.

HASH function prototype

The DSO module must contain the following three functions.

// First hash value returns, the value is used Key Index
k2h_hash_t k2h_hash(const void* ptr, size_t length);
 
// Second hash value returns, the value is used the Element in collision keys.
k2h_hash_t k2h_second_hash(const void* ptr, size_t length);
 
// Hash function(library) version string, the value is stamped into SHM file.
// This retuned value length must be under 32 byte.
const char* k2h_hash_version(void);

For details, see k2hashfunc.h.

Method

Method Description

Method return value

Note

Please handle singleton handling.

Examples

if(!K2HashDynLib::get()->Load("/home/myhome/myhashfunc.so")){
 exit(-1);
}
 ・
 ・
 ・
K2HashDynLib::get()->Unload();

K2HTransDynLib class

Description

The K2HASH library can read internal transaction processing as an external shared library (DSO module). This class is a management class that loads and unloads this shared library. This class object is a singleton which exists only in the K2HASH library. To use the method of this class, please acquire the singleton’s K2HTransDynLib object pointer and use it.

Transaction system function prototype

The DSO module must contain the following three functions.

// transaction callback function
bool k2h_trans(k2h_h handle, PBCOM pBinCom);
 
// Transaction function(library) version string.
const char* k2h_trans_version(void);
 
// transaction control function
bool k2h_trans_cntl(k2h_h handle, PTRANSOPT pOpt);

For details, see k2htransfunc.h.

Method

Method Description

Method return value

Note

Please handle singleton handling.

Examples

if(!K2HTransDynLib::get()->Load("/home/myhome/mytransfunc.so")){
 exit(-1);
}
 ・
 ・
 ・
K2HTransDynLib::get()->Unload();
 

K2HDAccess class

Description

It is a class that directly accesses data of K2HASH file (or on memory). From the k2hshm class, you can retrieve and use objects of this class by specifying the key. It is mainly used for reading and writing to data with a large size value. Parts of the value can be overwritten or read by specifying the offset.

Method

Method Description

Method return value

Note

When direct access is used, it is not affected by attributes such as encryption. This means, for example, direct access to encrypted data, it will destroy the data itself, so do not use it for the key that sets the attribute.

Examples

k2hshm*    pk2hash;
    ・
    ・
    ・
 
// attach write object
K2HDAccess*    pAccess;
if(NULL == (pAccess = pk2hash->GetDAccessObj("mykey", K2HDAccess::WRITE_ACCESS, 0))){
    return false
}
 
// write
if(!pAccess->Write("my test data")){
    delete pAccess;
    return false;
}
delete pAccess;
 
// attach read object
if(NULL == (pAccess = pk2hash->GetDAccessObj("mykey", K2HDAccess::READ_ACCESS, 0))){
    return false
}
 
// read
unsigned char*    byValue   = NULL;
size_t        vallength = 20;        // this is about :-p
if(!pAccess->Read(&byValue, vallength)){
    delete pAccess;
    return false;
}
delete pAccess;
if(byValue){
    free(byValue);
}

k2hstream(ik2hstream、ok2hstream) class

Description

Class for handling access to data of “K2HASH file (or on memory)” as iostream.
We implement direct access (reading and writing) to values as iostream derived classes.
You can specify k2hshm class and key, initialize the stream class (k2hstream, ik2hstream, ok2hstream) and use it as an iostream.
It is equivalent to std :: stringstream and you can use seekpos.
Please refer to std :: stringstream for detailed explanation.

Base class

k2hstream std::basic_stream
ik2hstreamstd::basic_istream
ok2hstreamstd::basic_ostream

Examples

k2hshm*    pk2hash;
    ・
    ・
    ・
 
// output stream test
{
    ok2hstream    strm(pk2hash, "mykey");
    string        strTmp("test string");
 
    strm << strTmp << endl;
    strm << strTmp << ends;
 
    printf("output string     = \"%s\\n%s\\0\"", strTmp.c_str(), strTmp.c_str());
}
 
// input stream test
{
    ik2hstream    strm(pk2hash, "mykey");
    string        strTmp1;
    string        strTmp2;
 
    strm >> strTmp1;
    strm >> strTmp2;
 
    printf("string     = \"%s\",\"%s\"", strTmp1.c_str(), strTmp2.c_str());
 
    if(!strm.eof()){
        ・
        ・
        ・
    }
}

Note

At the time this class was created (precisely when the key was opened through this class), locking will occur on the key. Read lock in ik2hstream class, and write lock in ok2hstream and k2hstream classes are applied. In order to avoid unnecessary locked state, this class should be discarded or closed when use is completed.


K2HArchive class

Description

Class for archiving K2HASH data. The K2HASH data managed by the K2HShm class is archived by the K2HArchive class.

Method

Method Description

Method return value

Returns true if it succeeds. If it fails, it returns false.

Examples

K2HArchive    archiveobj;
if(!archiveobj.Initialize("/tmp/k2hash.ar", false)){
    return false;
}
if(!archiveobj.Serialize(&k2hash, false)){
    return false;
}

K2HQueue class

Description

The K2HASH library provides functions as a queue (FIFO / LIFO).
The queue can push and pop values as FIFO / LIFO.
This class is a class for manipulating queues.
With this class you can manipulate pushing, popping, and deleting data into the queue.

The queue provided by the K2HASH library is implemented with keys and values, so a specific prefix is given to the internal key names stored in the queue. If prefix is not specified, “\0K2HQUEUE_PREFIX_” (note that the first byte is ‘\0’(0x00)) is used as the default. You can use the Builtin attribute to specify queue encryption and valid(Expire) time.

Method

Method Description

Method return value

Note

This class is an operation class, and it does not operate on K2HASH data at the time of creating a class instance. The actual operation occurs when a method such as Push, Pop, etc. is executed. Performance is not good when using K2HQueue :: GetCount, K2HQueue :: Read with a lot of data accumulated in the queue. Please take care when using it.

Examples

k2hshm*    pk2hash;
    ・
    ・
    ・
  
// queue object
K2HQueue   myqueue(pk2hash, true/*FIFO*/, reinterpret_cast<const unsigned char*>("MYQUEUE_PREFIX_"), 15);  // without end of nil
// push
if(!myqueue.Push(reinterpret_cast<const unsigned char*>("test_data1"), 11) ||
   !myqueue.Push(reinterpret_cast<const unsigned char*>("test_data2"), 12) )
{
    return false
}
// pop
unsigned char* pdata   = NULL;
size_t         datalen = 0;
if(!myqueue.Pop(&pdata, datalen)){
    return false
}
free(pdata);
// remove
if(!myqueue.Remove(1)){
    return false
}

K2HKeyQueue class

Description

The K2HASH library provides functions as a queue (FIFO / LIFO). Queues provided by this function group can be pushed and popped with FIFO / LIFO with a key and values as one pair. This class is a derived class of K2HQueue, it will be a class supporting this key and value queue. The key name associated with the queue has a specific prefix and is the same as K2HQueue.
With this class you can manipulate push, pop, and delete data (keys and values) into the queue. If you push by specifying the key and value in the queue of this class, the key and value are created in the K2HASH data and the key is accumulated in the queue. In the pop from the queue, you can retrieve it with a set of keys and values. (It is also possible to retrieve only the value) If you pop from the queue, the key is deleted from the queue and the set of keys and values is also deleted from the K2HASH data.
With this class, you can accumulate the written (updated) order of keys and values simultaneously with writing to K2HASH data. By extracting from the queue, keys and values can be erased simultaneously from K2HASH data.
Encryption and expiration time (Expire) can be set using the Builtin attribute of the keys accumulated in the queue and their keys and values.

Method

Method Description

Method return value

Note

This class is an operation class, and it does not operate on K2HASH data at the time of creating a class instance. The actual operation occurs when a method such as Push, Pop, etc. is executed. Performance is not good when using K2HKeyQueue::GetCount, K2HKeyQueue::Read with a large amount of data accumulated in the queue. Please take care when using it.

Examples

k2hshm*    pk2hash;
    ・
    ・
    ・
  
// queue object
K2HKeyQueue   myqueue(pk2hash, true/*FIFO*/, reinterpret_cast<const unsigned char*>("MYQUEUE_PREFIX_"), 15);  // without end of nil
// push
if(!myqueue.Push(reinterpret_cast<const unsigned char*>("test_key1"), 10, reinterpret_cast<const unsigned char*>("test_value1"), 12) ||
   !myqueue.Push(reinterpret_cast<const unsigned char*>("test_key2"), 10, reinterpret_cast<const unsigned char*>("test_value2"), 12) )
{
    return false
}
// pop
unsigned char* pkey     = NULL;
size_t         keylen   = 0;
unsigned char* pvalue   = NULL;
size_t         valuelen = 0;
if(!myqueue.Pop(&pkey, keylen, &pvalue, valuelen)){
    return false
}
free(pkey);
free(pvalue);
// remove
if(!myqueue.Remove(1)){
    return false
}

K2HShm class

Description

K2HASH Data manipulation and implementation class. Through this class, we will manipulate the K2HASH data. Basic K2HASH data manipulation in the C ++ language performs all operations after creating instances of this class. An instance can be created by opening (attaching) the K2HASH file or on memory. When the operation is completed (at the time of termination) close (detach) please.

Class method

Method

Method Description

Method return value

See individual prototypes.
The prototype of the return value of the bool value returns true if it succeeds. If it fails, it returns false.

Examples

K2HShm    k2hash;
if(!k2hash.Attach("/tmp/myk2hash.k2h", false, true, false, true, 8, 4, 1024, 512)){
    exit(-1);
}
if(!k2hash.Set("my key", "my value")){
    k2hash.Detach();
    exit(-1);
}
char*    pValue = k2hash.Get("my key");
if(pValue){
    printf("my key = %s\n", pValue);
    free(pValue);
}
if(!k2hash.Dump(stdout, K2HShm::DUMP_PAGE_LIST)){
    k2hash.Detach();
    exit(-1);
}
k2hash.Detach();
Build TOP Environments