acl/lib_dict/include/dict_pool.h

179 lines
5.3 KiB
C
Raw Normal View History

#ifndef __DICT_POOL_INCLUDE_H__
#define __DICT_POOL_INCLUDE_H__
#include "lib_acl.h"
#include "dict.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct DICT_POOL DICT_POOL;
typedef struct DICT_POOL_DB DICT_POOL_DB;
/**
* <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
*/
DICT_API void dict_pool_init(void);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param partions {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param partions_size {int} partions <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>
* @param dict_type {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (btree/hash/cdb)
* @param dict_name {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dict_size {int} <EFBFBD>ô<EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {DICT_POOL*} <EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>Ϊ NULL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
DICT_API DICT_POOL *dict_pool_new(const char **partions, int partions_size,
const char *dict_type, const char *dict_path,
const char *dict_name, int pool_size);
/**
* <EFBFBD>رղ<EFBFBD><EFBFBD>ͷ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
*/
DICT_API void dict_pool_free(DICT_POOL *pool);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> key/value <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key {char*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ַ
* @param key_len {size_t} key <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @param value {char*} <EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
* @param len {size_t} value <EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD>ȴ<EFBFBD>С(<EFBFBD>ֽ<EFBFBD>)
* @return {int} 0: OK, < 0: Error
*/
DICT_API int dict_pool_set(DICT_POOL *pool, char *key, size_t key_len, char *value, size_t len);
/**
* <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key {char*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ַ
* @param key_len {size_t} key <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD>ȴ<EFBFBD>С(<EFBFBD>ֽ<EFBFBD>)
* @param {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ö<EFBFBD><EFBFBD>󲻴<EFBFBD><EFBFBD><EFBFBD>,
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ<EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> acl_myfree/1 <EFBFBD>ͷŵ<EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD>صĶ<EFBFBD>̬<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
*/
DICT_API char *dict_pool_get(DICT_POOL *pool, char *key, size_t key_len, size_t *size);
/**
* <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key {char*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ַ
* @param key_len {size_t} key <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @return {int} 0: ok; != 0: error
*/
DICT_API int dict_pool_del(DICT_POOL *pool, char *key, size_t key_len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key {char**} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> key <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: acl_myfree/1, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й
* @param key_size {size_t*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @param val {char**} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> val <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: acl_myfree/1, <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й
* @param val_size {size_t*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @return {int} 0: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>, != 0: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>
*/
DICT_API int dict_pool_seq(DICT_POOL *pool, char **key, size_t *key_size,
char **val, size_t *val_size);
/**
* <EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
*/
DICT_API void dict_pool_seq_reset(DICT_POOL *pool);
/**
* ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @return {int} 0: ɾ<EFBFBD><EFBFBD>OK, != 0: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ɾ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
DICT_API int dict_pool_seq_delcur(DICT_POOL *pool);
/**
* <EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD>ֵ<EFBFBD>Ӵ<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD>øý<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵĴDB
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key {char*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ַ
* @param key_len {size_t} key <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @return {DICT_POOL_DB*} <EFBFBD>DB
*/
DICT_API DICT_POOL_DB *dict_pool_db(DICT_POOL *pool, const char *key, size_t key_len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>DB<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ȫ·<EFBFBD><EFBFBD>
* @param pool {DICT_POOL*} ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @return {const char*} <EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
*/
DICT_API const char *dict_pool_db_path(DICT_POOL_DB *db);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>DB
* @param {DICT_POOL_DB*} <EFBFBD>DB
*/
DICT_API void dict_pool_db_lock(DICT_POOL_DB *db);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>DB
* @param {DICT_POOL_DB*} <EFBFBD>DB
*/
DICT_API void dict_pool_db_unlock(DICT_POOL_DB *db);
/**
* <EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param {DICT_POOL_DB*} <EFBFBD>DB
* @param key {char*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ַ
* @param key_len {size_t} key <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @param value {char*} ֵ
* @param len {size_t} value <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {int} 0: ok; < 0: error
*/
DICT_API int dict_pool_db_set(DICT_POOL_DB *db, char *key, size_t key_len, char *value, size_t len);
/**
* <EFBFBD>ӴDB<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>ֵ
* @param {DICT_POOL_DB*} <EFBFBD>DB
* @param key {char*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ַ
* @param key_len {size_t} key <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @return {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>ֵ, <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD> acl_myfree()/1 <EFBFBD>ͷ<EFBFBD>
*/
DICT_API char *dict_pool_db_get(DICT_POOL_DB *db, char *key, size_t key_len, size_t *size);
/**
* <EFBFBD>ӴDB<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>ֵ
* @param {DICT_POOL_DB*} <EFBFBD>DB
* @param key {char*} <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ַ
* @param key_len {size_t} key <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @return {int} 0: ok; != 0: error
*/
DICT_API int dict_pool_db_del(DICT_POOL_DB *db, char *key, size_t key_len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĴDB
* @param {DICT_POOL_DB*} <EFBFBD>DB
*/
DICT_API void dict_pool_db_seq_reset(DICT_POOL_DB *db);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>DB
* @param {DICT_POOL_DB*} <EFBFBD>DB
* @param key {char**} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ
* @param key_size {size_t*} <EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
* @param value {char**} <EFBFBD>ֵ<EFBFBD>ĵ<EFBFBD>ַ
* @param value_size {size_t*} <EFBFBD><EFBFBD><EFBFBD> value <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
* @return {int} 0: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>, != 0: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>
*/
DICT_API int dict_pool_db_seq(DICT_POOL_DB *db, char **key, size_t *key_size,
char **val, size_t *val_size);
#ifdef __cplusplus
}
#endif
#endif