acl/lib_acl/include/stdlib/acl_htable.h

327 lines
11 KiB
C
Raw Normal View History

2014-11-19 00:25:21 +08:00
#ifndef ACL_HTABLE_INCLUDE_H
#define ACL_HTABLE_INCLUDE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "acl_define.h"
#include "thread/acl_thread.h"
#include "acl_hash.h" /* just for ACL_HASH_FN */
#include "acl_slice.h"
#include "acl_iterator.h"
/*--------------------------------------------------------------------------*/
typedef struct ACL_HTABLE ACL_HTABLE;
typedef struct ACL_HTABLE_INFO ACL_HTABLE_INFO;
/**
* <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
struct ACL_HTABLE {
int size; /* length of entries array */
int init_size; /* length of initial entryies array */
int used; /* number of entries in table */
ACL_HTABLE_INFO **data; /* entries array, auto-resized */
unsigned int flag; /* properties flag */
int status; /* the operator's status on the htable */
ACL_HASH_FN hash_fn; /* hash function */
ACL_SLICE_POOL *slice;
acl_pthread_mutex_t *rwlock;
/* for acl_iterator */
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD> */
void *(*iter_head)(ACL_ITER*, struct ACL_HTABLE*);
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void *(*iter_next)(ACL_ITER*, struct ACL_HTABLE*);
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD> */
void *(*iter_tail)(ACL_ITER*, struct ACL_HTABLE*);
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void *(*iter_prev)(ACL_ITER*, struct ACL_HTABLE*);
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD> */
ACL_HTABLE_INFO *(*iter_info)(ACL_ITER*, struct ACL_HTABLE*);
};
/**
* <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
struct ACL_HTABLE_INFO {
union {
char *key;
const char *c_key;
} key; /**
* <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_BINHASH_FLAG_KEY_REUSE ʱ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>ռ<EFBFBD>
*/
void *value; /**< associated value */
struct ACL_HTABLE_INFO *next; /**< colliding entry */
struct ACL_HTABLE_INFO *prev; /**< colliding entry */
};
/**
* ACL_HTABLE <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
typedef struct ACL_HTABLE_ITER {
/* public */
ACL_HTABLE_INFO *ptr;
/* private */
int i;
int size;
ACL_HTABLE_INFO **h;
} ACL_HTABLE_ITER;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>
* @param size <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param flag {unsigned int} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>־λ, ACL_BINHASH_FLAG_xxx
* @return <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_API ACL_HTABLE *acl_htable_create(int size, unsigned int flag);
#define ACL_HTABLE_FLAG_KEY_REUSE (1 << 0) /* <20><><EFBFBD><EFBFBD><EFBFBD>µĶ<C2B5><C4B6><EFBFBD>ʱ<EFBFBD>Ƿ<EFBFBD>ֱ<EFBFBD>Ӹ<EFBFBD><D3B8>ü<EFBFBD><C3BC><EFBFBD>ַ */
#define ACL_HTABLE_FLAG_USE_LOCK (1 << 1) /* <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>̻߳<DFB3><CCBB>ʽ */
#define ACL_HTABLE_FLAG_MSLOOK (1 << 2) /* ÿ<>β<EFBFBD>ѯʱ<D1AF>Ƿ񽫲<C7B7>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ */
#define ACL_HTABLE_FLAG_KEY_LOWER (1 << 3) /* ͳһ<CDB3><D2BB><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ΪСд<D0A1><D0B4><EFBFBD>Ӷ<EFBFBD>ʵ<EFBFBD>ּ<EFBFBD><D6BC><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>Сд<D0A1>Ĺ<EFBFBD><C4B9><EFBFBD> */
ACL_API ACL_HTABLE *acl_htable_create3(int size, unsigned int flag, ACL_SLICE_POOL *slice);
/**
* <EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param name <EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>γ<EFBFBD>ʼֵ, name <EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ACL_HTABLE_CTL_END: <EFBFBD><EFBFBD><EFBFBD>α<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
* ACL_HTABLE_CTL_RWLOCK: <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ACL_HTABLE_CTL_HASH_FN: <EFBFBD>û<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void acl_htable_ctl(ACL_HTABLE *table, int name, ...);
#define ACL_HTABLE_CTL_END 0 /**< <20><><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>־ */
#define ACL_HTABLE_CTL_RWLOCK 1 /**< <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> */
#define ACL_HTABLE_CTL_HASH_FN 2 /**< <20><><EFBFBD><EFBFBD>˽<EFBFBD>й<EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD> */
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ι<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬, <EFBFBD>μ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> ACL_HTABLE_STAT_XXX
*/
ACL_API int acl_htable_errno(ACL_HTABLE *table);
#define ACL_HTABLE_STAT_OK 0 /**< ״̬<D7B4><CCAC><EFBFBD><EFBFBD> */
#define ACL_HTABLE_STAT_INVAL 1 /**< <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD> */
#define ACL_HTABLE_STAT_DUPLEX_KEY 2 /**< <20>ظ<EFBFBD><D8B8><EFBFBD> */
/**
* <EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ǰ״̬, error ȡֵ ACL_HTABLE_STAT_XXX
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param error <EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>״̬
*/
ACL_API void acl_htable_set_errno(ACL_HTABLE *table, int error);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key <EFBFBD><EFBFBD>, <EFBFBD>ں<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD> key <EFBFBD><EFBFBD>
* @param value <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>)
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>, == NULL: <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_htable_last_errno() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ(ACL_HTABLE_STAT_DUPLEX_KEY)
*/
ACL_API ACL_HTABLE_INFO *acl_htable_enter(ACL_HTABLE *table, const char *key, void *value);
/**
* <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>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key <EFBFBD><EFBFBD>, <EFBFBD>ں<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD> key <EFBFBD><EFBFBD>
* @param value <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>)
* @param callback <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>
* @param arg callback <EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD>֮һ
* @return {int} 0 <EFBFBD><EFBFBD>ʾ <EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD><EFBFBD><EFBFBD>-1 <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_htable_last_errno() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ(ACL_HTABLE_STAT_DUPLEX_KEY)
*/
ACL_API int acl_htable_enter_r(ACL_HTABLE *table, const char *key, void *value,
void (*callback)(ACL_HTABLE_INFO *ht, void *arg), void *arg);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱijһ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key <EFBFBD><EFBFBD>
* @return <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>˶<EFBFBD>Ӧ<EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD>
* Ϊ<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ʾδ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD>
*/
ACL_API ACL_HTABLE_INFO *acl_htable_locate(ACL_HTABLE *table, const char *key);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱijһ<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>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key <EFBFBD><EFBFBD>
* @param callback <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>֮
* @param arg callback <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮һ
* @return <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>˶<EFBFBD>Ӧ<EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD>
* Ϊ<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ʾδ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD>
*/
ACL_API int acl_htable_locate_r(ACL_HTABLE *table, const char *key,
void (*callback)(ACL_HTABLE_INFO *ht, void *arg), void *arg);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key <EFBFBD><EFBFBD>
* @return <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>˶<EFBFBD>Ӧ<EFBFBD><EFBFBD> key <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> key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void *acl_htable_find(ACL_HTABLE *table, const char *key);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <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>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key <EFBFBD><EFBFBD>
* @param callback <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>֮
* @param arg callback <EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD>֮һ
* @return <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>˶<EFBFBD>Ӧ<EFBFBD><EFBFBD> key <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> key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API int acl_htable_find_r(ACL_HTABLE *table, const char *key,
void (*callback)(void *value, void *arg), void *arg);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ijһ<EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param key <EFBFBD><EFBFBD>
* @param free_fn <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><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>
* @return 0: <EFBFBD>ɹ<EFBFBD>; -1: δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD>
*/
ACL_API int acl_htable_delete(ACL_HTABLE *table, const char *key, void (*free_fn) (void *));
#define acl_htable_delete_r acl_htable_delete
/**
* <EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param free_fn <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_API void acl_htable_free(ACL_HTABLE *table, void (*free_fn) (void *));
/**
* <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>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param free_fn <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>
* @return <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>óɹ<EFBFBD>. 0: OK; < 0: error.
*/
ACL_API int acl_htable_reset(ACL_HTABLE *table, void (*free_fn) (void *));
#define acl_htable_reset_r acl_htable_reset
/**
* <EFBFBD>Թ<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param walk_fn <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>
* @param arg <EFBFBD>û<EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API void acl_htable_walk(ACL_HTABLE *table, void (*walk_fn) (ACL_HTABLE_INFO *, void *), void *arg);
#define acl_htable_walk_r acl_htable_walk
/**
* <EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @return <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С
*/
ACL_API int acl_htable_size(const ACL_HTABLE *table);
/**
* <EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @return <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD>
*/
ACL_API int acl_htable_used(const ACL_HTABLE *table);
/**
* <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>
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>
* @return <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_API ACL_HTABLE_INFO **acl_htable_list(const ACL_HTABLE *table);
/**
* <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD>ķֲ<EFBFBD>״̬
* @param table <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
*/
ACL_API void acl_htable_stat(const ACL_HTABLE *table);
#define acl_htable_stat_r acl_htable_stat
ACL_API ACL_HTABLE_INFO **acl_htable_data(ACL_HTABLE *table);
ACL_API const ACL_HTABLE_INFO *acl_htable_iter_head(ACL_HTABLE *table, ACL_HTABLE_ITER *iter);
ACL_API const ACL_HTABLE_INFO *acl_htable_iter_next(ACL_HTABLE_ITER *iter);
ACL_API const ACL_HTABLE_INFO *acl_htable_iter_tail(ACL_HTABLE *table, ACL_HTABLE_ITER *iter);
ACL_API const ACL_HTABLE_INFO *acl_htable_iter_prev(ACL_HTABLE_ITER *iter);
/*-------------------- һЩ<D2BB><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĺ<DDB5><C4BA><EFBFBD><EFBFBD><EFBFBD> --------------------------------*/
#define ACL_HTABLE_ITER_KEY(iter) ((iter).ptr->key.c_key)
#define acl_htable_iter_key ACL_HTABLE_ITER_KEY
#define ACL_HTABLE_ITER_VALUE(iter) ((iter).ptr->value)
#define acl_htable_iter_value ACL_HTABLE_ITER_VALUE
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ACL_HTABLE
* @param iter {ACL_HTABLE_ITER}
* @param table_ptr {ACL_HTABLE *}
* @example:
void test()
{
ACL_HTABLE *table = acl_htable_create(10, 0);
ACL_HTABLE_ITER iter;
char *value, key[32];
int i;
for (i = 0; i < 100; i++) {
value = (char*) acl_mystrdup("value");
snprintf(key, sizeof(key), "key:%d", i);
(void) acl_htable_enter(table, key, value);
}
acl_htable_foreach(iter, table) {
printf("%s=%s\n", acl_htable_iter_key(iter), acl_htable_iter_value(iter));
if (i == 50)
break;
}
acl_htable_free(table, acl_myfree_fn);
}
*/
#if 0
#define ACL_HTABLE_FOREACH(iter, table_ptr) \
if (table_ptr) \
for((iter).size = acl_htable_size((table_ptr)), (iter).i = 0, \
(iter).h = acl_htable_data((table_ptr)); (iter).i < (iter).size; (iter).i++) \
for ((iter).ptr = *(iter).h++; (iter).ptr; (iter).ptr = (iter).ptr->next)
#define ACL_HTABLE_FOREACH_REVERSE(iter, table_ptr) \
if (table_ptr) \
for((iter).size = acl_htable_size((table_ptr)), (iter).i = (iter).size - 1, \
(iter).h = acl_htable_data((table_ptr)) + (iter).i; (iter).i >= 0; (iter).i--) \
for ((iter).ptr = *(iter).h--; (iter).ptr; (iter).ptr = (iter).ptr->next)
#else
#define ACL_HTABLE_FOREACH(iter, table_ptr) \
if (table_ptr) \
for((void) acl_htable_iter_head((table_ptr), &iter); \
(iter).ptr; \
(void) acl_htable_iter_next(&iter))
#define ACL_HTABLE_FOREACH_REVERSE(iter, table_ptr) \
if (table_ptr) \
for((void) acl_htable_iter_tail((table_ptr), &iter); \
(iter).ptr; \
(void) acl_htable_iter_prev(&iter))
#endif
#define acl_htable_foreach ACL_HTABLE_FOREACH
#define acl_htable_foreach_reverse ACL_HTABLE_FOREACH_REVERSE
#ifdef __cplusplus
}
#endif
#endif