rename hash_xxx to fc_hash_xxx
parent
3331b927b3
commit
9f1d1b6d48
|
|
@ -62,7 +62,7 @@ int conn_pool_init_ex1(ConnectionPool *cp, int connect_timeout,
|
|||
return result;
|
||||
}
|
||||
|
||||
return hash_init(&(cp->hash_array), simple_hash, init_capacity, 0.75);
|
||||
return fc_hash_init(&(cp->hash_array), fc_simple_hash, init_capacity, 0.75);
|
||||
}
|
||||
|
||||
static int coon_pool_close_connections(const int index,
|
||||
|
|
@ -97,8 +97,8 @@ static int coon_pool_close_connections(const int index,
|
|||
void conn_pool_destroy(ConnectionPool *cp)
|
||||
{
|
||||
pthread_mutex_lock(&cp->lock);
|
||||
hash_walk(&(cp->hash_array), coon_pool_close_connections, cp);
|
||||
hash_destroy(&(cp->hash_array));
|
||||
fc_hash_walk(&(cp->hash_array), coon_pool_close_connections, cp);
|
||||
fc_hash_destroy(&(cp->hash_array));
|
||||
pthread_mutex_unlock(&cp->lock);
|
||||
|
||||
pthread_mutex_destroy(&cp->lock);
|
||||
|
|
@ -198,7 +198,7 @@ ConnectionInfo *conn_pool_get_connection(ConnectionPool *cp,
|
|||
conn_pool_get_key(conn, key, &key_len);
|
||||
|
||||
pthread_mutex_lock(&cp->lock);
|
||||
cm = (ConnectionManager *)hash_find(&cp->hash_array, key, key_len);
|
||||
cm = (ConnectionManager *)fc_hash_find(&cp->hash_array, key, key_len);
|
||||
if (cm == NULL)
|
||||
{
|
||||
cm = (ConnectionManager *)fast_mblock_alloc_object(
|
||||
|
|
@ -221,7 +221,7 @@ ConnectionInfo *conn_pool_get_connection(ConnectionPool *cp,
|
|||
pthread_mutex_unlock(&cp->lock);
|
||||
return NULL;
|
||||
}
|
||||
hash_insert(&cp->hash_array, key, key_len, cm);
|
||||
fc_hash_insert(&cp->hash_array, key, key_len, cm);
|
||||
}
|
||||
pthread_mutex_unlock(&cp->lock);
|
||||
|
||||
|
|
@ -376,7 +376,7 @@ int conn_pool_close_connection_ex(ConnectionPool *cp, ConnectionInfo *conn,
|
|||
conn_pool_get_key(conn, key, &key_len);
|
||||
|
||||
pthread_mutex_lock(&cp->lock);
|
||||
cm = (ConnectionManager *)hash_find(&cp->hash_array, key, key_len);
|
||||
cm = (ConnectionManager *)fc_hash_find(&cp->hash_array, key, key_len);
|
||||
pthread_mutex_unlock(&cp->lock);
|
||||
if (cm == NULL)
|
||||
{
|
||||
|
|
@ -456,7 +456,7 @@ int conn_pool_get_connection_count(ConnectionPool *cp)
|
|||
{
|
||||
int count;
|
||||
count = 0;
|
||||
hash_walk(&cp->hash_array, _conn_count_walk, &count);
|
||||
fc_hash_walk(&cp->hash_array, _conn_count_walk, &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
|
|||
66
src/hash.c
66
src/hash.c
|
|
@ -79,7 +79,7 @@ static int _hash_alloc_buckets(HashArray *pHash, const unsigned int old_capacity
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned int *hash_get_prime_capacity(const int capacity)
|
||||
unsigned int *fc_hash_get_prime_capacity(const int capacity)
|
||||
{
|
||||
unsigned int *pprime;
|
||||
unsigned int *prime_end;
|
||||
|
|
@ -95,14 +95,14 @@ unsigned int *hash_get_prime_capacity(const int capacity)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int hash_init_ex(HashArray *pHash, HashFunc hash_func, \
|
||||
int fc_hash_init_ex(HashArray *pHash, HashFunc hash_func, \
|
||||
const unsigned int capacity, const double load_factor, \
|
||||
const int64_t max_bytes, const bool bMallocValue)
|
||||
{
|
||||
int result;
|
||||
|
||||
memset(pHash, 0, sizeof(HashArray));
|
||||
pHash->capacity = hash_get_prime_capacity(capacity);
|
||||
pHash->capacity = fc_hash_get_prime_capacity(capacity);
|
||||
if (pHash->capacity == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
|
|
@ -129,7 +129,7 @@ int hash_init_ex(HashArray *pHash, HashFunc hash_func, \
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hash_set_locks(HashArray *pHash, const int lock_count)
|
||||
int fc_hash_set_locks(HashArray *pHash, const int lock_count)
|
||||
{
|
||||
size_t bytes;
|
||||
pthread_mutex_t *lock;
|
||||
|
|
@ -168,7 +168,7 @@ int hash_set_locks(HashArray *pHash, const int lock_count)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void hash_destroy(HashArray *pHash)
|
||||
void fc_hash_destroy(HashArray *pHash)
|
||||
{
|
||||
HashData **ppBucket;
|
||||
HashData **bucket_end;
|
||||
|
|
@ -238,7 +238,7 @@ void hash_destroy(HashArray *pHash)
|
|||
}
|
||||
|
||||
|
||||
int hash_stat(HashArray *pHash, HashStat *pStat, \
|
||||
int fc_hash_stat(HashArray *pHash, HashStat *pStat, \
|
||||
int *stat_by_lens, const int stat_size)
|
||||
{
|
||||
HashData **ppBucket;
|
||||
|
|
@ -299,13 +299,13 @@ int hash_stat(HashArray *pHash, HashStat *pStat, \
|
|||
return 0;
|
||||
}
|
||||
|
||||
void hash_stat_print(HashArray *pHash)
|
||||
void fc_hash_stat_print(HashArray *pHash)
|
||||
{
|
||||
#define STAT_MAX_NUM 64
|
||||
HashStat hs;
|
||||
int stats[STAT_MAX_NUM];
|
||||
|
||||
if (hash_stat(pHash, &hs, stats, STAT_MAX_NUM) != 0)
|
||||
if (fc_hash_stat(pHash, &hs, stats, STAT_MAX_NUM) != 0)
|
||||
{
|
||||
printf("hash max length exceeds %d!\n", STAT_MAX_NUM);
|
||||
return;
|
||||
|
|
@ -381,7 +381,7 @@ static int _rehash(HashArray *pHash)
|
|||
pOldCapacity = pHash->capacity;
|
||||
if (pHash->is_malloc_capacity)
|
||||
{
|
||||
pHash->capacity = hash_get_prime_capacity(*pOldCapacity);
|
||||
pHash->capacity = fc_hash_get_prime_capacity(*pOldCapacity);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -456,7 +456,7 @@ static int _hash_conflict_count(HashArray *pHash)
|
|||
return conflict_count;
|
||||
}
|
||||
|
||||
int hash_best_op(HashArray *pHash, const int suggest_capacity)
|
||||
int fc_hash_best_op(HashArray *pHash, const int suggest_capacity)
|
||||
{
|
||||
int old_capacity;
|
||||
int conflict_count;
|
||||
|
|
@ -513,7 +513,7 @@ int hash_best_op(HashArray *pHash, const int suggest_capacity)
|
|||
|
||||
pHash->is_malloc_capacity = true;
|
||||
|
||||
//hash_stat_print(pHash);
|
||||
//fc_hash_stat_print(pHash);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -537,7 +537,7 @@ static HashData *_chain_find_entry(HashData **ppBucket, const void *key, \
|
|||
return NULL;
|
||||
}
|
||||
|
||||
HashData *hash_find_ex(HashArray *pHash, const void *key, const int key_len)
|
||||
HashData *fc_hash_find_ex(HashArray *pHash, const void *key, const int key_len)
|
||||
{
|
||||
unsigned int hash_code;
|
||||
HashData **ppBucket;
|
||||
|
|
@ -553,7 +553,7 @@ HashData *hash_find_ex(HashArray *pHash, const void *key, const int key_len)
|
|||
return hash_data;
|
||||
}
|
||||
|
||||
void *hash_find(HashArray *pHash, const void *key, const int key_len)
|
||||
void *fc_hash_find(HashArray *pHash, const void *key, const int key_len)
|
||||
{
|
||||
unsigned int hash_code;
|
||||
HashData **ppBucket;
|
||||
|
|
@ -576,10 +576,10 @@ void *hash_find(HashArray *pHash, const void *key, const int key_len)
|
|||
}
|
||||
}
|
||||
|
||||
int hash_find2(HashArray *pHash, const string_t *key, string_t *value)
|
||||
int fc_hash_find2(HashArray *pHash, const string_t *key, string_t *value)
|
||||
{
|
||||
HashData *hdata;
|
||||
if ((hdata=hash_find1_ex(pHash, key)) == NULL)
|
||||
if ((hdata=fc_hash_find1_ex(pHash, key)) == NULL)
|
||||
{
|
||||
return ENOENT;
|
||||
}
|
||||
|
|
@ -589,12 +589,12 @@ int hash_find2(HashArray *pHash, const string_t *key, string_t *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
HashData *hash_find1_ex(HashArray *pHash, const string_t *key)
|
||||
HashData *fc_hash_find1_ex(HashArray *pHash, const string_t *key)
|
||||
{
|
||||
return hash_find_ex(pHash, key->str, key->len);
|
||||
return fc_hash_find_ex(pHash, key->str, key->len);
|
||||
}
|
||||
|
||||
int hash_get(HashArray *pHash, const void *key, const int key_len,
|
||||
int fc_hash_get(HashArray *pHash, const void *key, const int key_len,
|
||||
void *value, int *value_len)
|
||||
{
|
||||
unsigned int hash_code;
|
||||
|
|
@ -628,7 +628,7 @@ int hash_get(HashArray *pHash, const void *key, const int key_len,
|
|||
return result;
|
||||
}
|
||||
|
||||
int hash_insert_ex(HashArray *pHash, const void *key, const int key_len, \
|
||||
int fc_hash_insert_ex(HashArray *pHash, const void *key, const int key_len,
|
||||
void *value, const int value_len, const bool needLock)
|
||||
{
|
||||
unsigned int hash_code;
|
||||
|
|
@ -760,7 +760,7 @@ int hash_insert_ex(HashArray *pHash, const void *key, const int key_len, \
|
|||
return 1;
|
||||
}
|
||||
|
||||
int64_t hash_inc_value(const HashData *old_data, const int inc,
|
||||
int64_t fc_hash_inc_value(const HashData *old_data, const int inc,
|
||||
char *new_value, int *new_value_len, void *arg)
|
||||
{
|
||||
int64_t n;
|
||||
|
|
@ -788,7 +788,7 @@ int64_t hash_inc_value(const HashData *old_data, const int inc,
|
|||
return n;
|
||||
}
|
||||
|
||||
int hash_inc_ex(HashArray *pHash, const void *key, const int key_len,
|
||||
int fc_hash_inc_ex(HashArray *pHash, const void *key, const int key_len,
|
||||
const int inc, char *value, int *value_len,
|
||||
ConvertValueFunc convert_func, void *arg)
|
||||
{
|
||||
|
|
@ -823,7 +823,7 @@ int hash_inc_ex(HashArray *pHash, const void *key, const int key_len,
|
|||
}
|
||||
}
|
||||
}
|
||||
result = hash_insert_ex(pHash, key, key_len, value, *value_len, false);
|
||||
result = fc_hash_insert_ex(pHash, key, key_len, value, *value_len, false);
|
||||
if (result < 0)
|
||||
{
|
||||
*value = '\0';
|
||||
|
|
@ -839,7 +839,7 @@ int hash_inc_ex(HashArray *pHash, const void *key, const int key_len,
|
|||
return result;
|
||||
}
|
||||
|
||||
int hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
||||
int fc_hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
||||
const char *value, const int offset, const int value_len)
|
||||
{
|
||||
unsigned int hash_code;
|
||||
|
|
@ -881,7 +881,7 @@ int hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
|||
memcpy(pNewBuff, hash_data->value, offset);
|
||||
}
|
||||
memcpy(pNewBuff + offset, value, value_len);
|
||||
result = hash_insert_ex(pHash, key, key_len, pNewBuff,
|
||||
result = fc_hash_insert_ex(pHash, key, key_len, pNewBuff,
|
||||
offset + value_len, false);
|
||||
free(pNewBuff);
|
||||
}
|
||||
|
|
@ -892,8 +892,8 @@ int hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
|||
result = ENOENT;
|
||||
break;
|
||||
}
|
||||
result = hash_insert_ex(pHash, key, key_len, (void *)value,
|
||||
value_len, false);
|
||||
result = fc_hash_insert_ex(pHash, key, key_len,
|
||||
(void *)value, value_len, false);
|
||||
}
|
||||
|
||||
if (result < 0)
|
||||
|
|
@ -910,7 +910,7 @@ int hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
|||
return result;
|
||||
}
|
||||
|
||||
int hash_delete(HashArray *pHash, const void *key, const int key_len)
|
||||
int fc_hash_delete(HashArray *pHash, const void *key, const int key_len)
|
||||
{
|
||||
HashData **ppBucket;
|
||||
HashData *hash_data;
|
||||
|
|
@ -943,7 +943,7 @@ int hash_delete(HashArray *pHash, const void *key, const int key_len)
|
|||
return result;
|
||||
}
|
||||
|
||||
int hash_walk(HashArray *pHash, HashWalkFunc walkFunc, void *args)
|
||||
int fc_hash_walk(HashArray *pHash, HashWalkFunc walkFunc, void *args)
|
||||
{
|
||||
HashData **ppBucket;
|
||||
HashData **bucket_end;
|
||||
|
|
@ -972,12 +972,12 @@ int hash_walk(HashArray *pHash, HashWalkFunc walkFunc, void *args)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hash_count(HashArray *pHash)
|
||||
int fc_hash_count(HashArray *pHash)
|
||||
{
|
||||
return pHash->item_count;
|
||||
}
|
||||
|
||||
int hash_bucket_lock(HashArray *pHash, const unsigned int bucket_index)
|
||||
int fc_hash_bucket_lock(HashArray *pHash, const unsigned int bucket_index)
|
||||
{
|
||||
if (pHash->lock_count <= 0)
|
||||
{
|
||||
|
|
@ -988,7 +988,7 @@ int hash_bucket_lock(HashArray *pHash, const unsigned int bucket_index)
|
|||
pHash->lock_count);
|
||||
}
|
||||
|
||||
int hash_bucket_unlock(HashArray *pHash, const unsigned int bucket_index)
|
||||
int fc_hash_bucket_unlock(HashArray *pHash, const unsigned int bucket_index)
|
||||
{
|
||||
if (pHash->lock_count <= 0)
|
||||
{
|
||||
|
|
@ -1315,12 +1315,12 @@ int calc_hashnr1_ex(const void* key, const int key_len, \
|
|||
\
|
||||
return h; \
|
||||
|
||||
int simple_hash(const void* key, const int key_len)
|
||||
int fc_simple_hash(const void* key, const int key_len)
|
||||
{
|
||||
SIMPLE_HASH_FUNC(0)
|
||||
}
|
||||
|
||||
int simple_hash_ex(const void* key, const int key_len, \
|
||||
int fc_simple_hash_ex(const void* key, const int key_len, \
|
||||
const int init_value)
|
||||
{
|
||||
SIMPLE_HASH_FUNC(init_value)
|
||||
|
|
|
|||
68
src/hash.h
68
src/hash.h
|
|
@ -93,16 +93,16 @@ typedef struct tagHashStat
|
|||
* parameters:
|
||||
* index: item index based 0
|
||||
* data: hash data, including key and value
|
||||
* args: passed by hash_walk function
|
||||
* args: passed by fc_hash_walk function
|
||||
* return 0 for success, != 0 for error
|
||||
*/
|
||||
typedef int (*HashWalkFunc)(const int index, const HashData *data, void *args);
|
||||
|
||||
#define hash_init(pHash, hash_func, capacity, load_factor) \
|
||||
hash_init_ex(pHash, hash_func, capacity, load_factor, 0, false)
|
||||
#define fc_hash_init(pHash, hash_func, capacity, load_factor) \
|
||||
fc_hash_init_ex(pHash, hash_func, capacity, load_factor, 0, false)
|
||||
|
||||
#define hash_insert(pHash, key, key_len, value) \
|
||||
hash_insert_ex(pHash, key, key_len, value, 0, true)
|
||||
#define fc_hash_insert(pHash, key, key_len, value) \
|
||||
fc_hash_insert_ex(pHash, key, key_len, value, 0, true)
|
||||
|
||||
/**
|
||||
* hash init function
|
||||
|
|
@ -115,7 +115,7 @@ typedef int (*HashWalkFunc)(const int index, const HashData *data, void *args);
|
|||
* bMallocValue: if need malloc value buffer
|
||||
* return 0 for success, != 0 for error
|
||||
*/
|
||||
int hash_init_ex(HashArray *pHash, HashFunc hash_func, \
|
||||
int fc_hash_init_ex(HashArray *pHash, HashFunc hash_func, \
|
||||
const unsigned int capacity, const double load_factor, \
|
||||
const int64_t max_bytes, const bool bMallocValue);
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ int hash_init_ex(HashArray *pHash, HashFunc hash_func, \
|
|||
* lock_count: the lock count
|
||||
* return 0 for success, != 0 for error
|
||||
*/
|
||||
int hash_set_locks(HashArray *pHash, const int lock_count);
|
||||
int fc_hash_set_locks(HashArray *pHash, const int lock_count);
|
||||
|
||||
/**
|
||||
* convert the value
|
||||
|
|
@ -137,12 +137,12 @@ int hash_set_locks(HashArray *pHash, const int lock_count);
|
|||
* arg: the user data
|
||||
* return the number after increasement
|
||||
*/
|
||||
int64_t hash_inc_value(const HashData *old_data, const int inc,
|
||||
int64_t fc_hash_inc_value(const HashData *old_data, const int inc,
|
||||
char *new_value, int *new_value_len, void *arg);
|
||||
|
||||
#define hash_inc(pHash, key, key_len, inc, value, value_len) \
|
||||
hash_inc_ex(pHash, key, key_len, inc, value, value_len, \
|
||||
hash_inc_value, NULL)
|
||||
#define fc_hash_inc(pHash, key, key_len, inc, value, value_len) \
|
||||
fc_hash_inc_ex(pHash, key, key_len, inc, value, value_len, \
|
||||
fc_hash_inc_value, NULL)
|
||||
|
||||
/**
|
||||
* atomic increase value
|
||||
|
|
@ -158,7 +158,7 @@ int64_t hash_inc_value(const HashData *old_data, const int inc,
|
|||
* return 0 for success, != 0 for error (errno)
|
||||
*
|
||||
*/
|
||||
int hash_inc_ex(HashArray *pHash, const void *key, const int key_len,
|
||||
int fc_hash_inc_ex(HashArray *pHash, const void *key, const int key_len,
|
||||
const int inc, char *value, int *value_len,
|
||||
ConvertValueFunc convert_func, void *arg);
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ int hash_inc_ex(HashArray *pHash, const void *key, const int key_len,
|
|||
* pHash: the hash table
|
||||
* return none
|
||||
*/
|
||||
void hash_destroy(HashArray *pHash);
|
||||
void fc_hash_destroy(HashArray *pHash);
|
||||
|
||||
/**
|
||||
* hash insert key
|
||||
|
|
@ -182,7 +182,7 @@ void hash_destroy(HashArray *pHash);
|
|||
* return >= 0 for success, 0 for key already exist (update),
|
||||
* 1 for new key (insert), < 0 for error
|
||||
*/
|
||||
int hash_insert_ex(HashArray *pHash, const void *key, const int key_len, \
|
||||
int fc_hash_insert_ex(HashArray *pHash, const void *key, const int key_len, \
|
||||
void *value, const int value_len, const bool needLock);
|
||||
|
||||
/**
|
||||
|
|
@ -193,7 +193,7 @@ int hash_insert_ex(HashArray *pHash, const void *key, const int key_len, \
|
|||
* key_len: length of th key
|
||||
* return user data, return NULL when the key not exist
|
||||
*/
|
||||
void *hash_find(HashArray *pHash, const void *key, const int key_len);
|
||||
void *fc_hash_find(HashArray *pHash, const void *key, const int key_len);
|
||||
|
||||
/**
|
||||
* hash find key
|
||||
|
|
@ -203,7 +203,7 @@ void *hash_find(HashArray *pHash, const void *key, const int key_len);
|
|||
* key_len: length of th key
|
||||
* return hash data, return NULL when the key not exist
|
||||
*/
|
||||
HashData *hash_find_ex(HashArray *pHash, const void *key, const int key_len);
|
||||
HashData *fc_hash_find_ex(HashArray *pHash, const void *key, const int key_len);
|
||||
|
||||
/**
|
||||
* hash find key
|
||||
|
|
@ -212,9 +212,9 @@ HashData *hash_find_ex(HashArray *pHash, const void *key, const int key_len);
|
|||
* key: the key to find
|
||||
* return user data, return NULL when the key not exist
|
||||
*/
|
||||
static inline void *hash_find1(HashArray *pHash, const string_t *key)
|
||||
static inline void *fc_hash_find1(HashArray *pHash, const string_t *key)
|
||||
{
|
||||
return hash_find(pHash, key->str, key->len);
|
||||
return fc_hash_find(pHash, key->str, key->len);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -225,7 +225,7 @@ static inline void *hash_find1(HashArray *pHash, const string_t *key)
|
|||
* value: store the value
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_find2(HashArray *pHash, const string_t *key, string_t *value);
|
||||
int fc_hash_find2(HashArray *pHash, const string_t *key, string_t *value);
|
||||
|
||||
/**
|
||||
* hash find key
|
||||
|
|
@ -234,7 +234,7 @@ int hash_find2(HashArray *pHash, const string_t *key, string_t *value);
|
|||
* key: the key to find
|
||||
* return hash data, return NULL when the key not exist
|
||||
*/
|
||||
HashData *hash_find1_ex(HashArray *pHash, const string_t *key);
|
||||
HashData *fc_hash_find1_ex(HashArray *pHash, const string_t *key);
|
||||
|
||||
/**
|
||||
* hash get the value of the key
|
||||
|
|
@ -247,7 +247,7 @@ HashData *hash_find1_ex(HashArray *pHash, const string_t *key);
|
|||
* output for the length fo the value
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_get(HashArray *pHash, const void *key, const int key_len,
|
||||
int fc_hash_get(HashArray *pHash, const void *key, const int key_len,
|
||||
void *value, int *value_len);
|
||||
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ int hash_get(HashArray *pHash, const void *key, const int key_len,
|
|||
* value_len: length of the value
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
||||
int fc_hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
||||
const char *value, const int offset, const int value_len);
|
||||
|
||||
/**
|
||||
|
|
@ -273,7 +273,7 @@ int hash_partial_set(HashArray *pHash, const void *key, const int key_len,
|
|||
* key_len: length of th key
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_delete(HashArray *pHash, const void *key, const int key_len);
|
||||
int fc_hash_delete(HashArray *pHash, const void *key, const int key_len);
|
||||
|
||||
/**
|
||||
* hash walk (iterator)
|
||||
|
|
@ -283,7 +283,7 @@ int hash_delete(HashArray *pHash, const void *key, const int key_len);
|
|||
* args: extra args which will be passed to walkFunc
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_walk(HashArray *pHash, HashWalkFunc walkFunc, void *args);
|
||||
int fc_hash_walk(HashArray *pHash, HashWalkFunc walkFunc, void *args);
|
||||
|
||||
/**
|
||||
* get hash item count
|
||||
|
|
@ -291,7 +291,7 @@ int hash_walk(HashArray *pHash, HashWalkFunc walkFunc, void *args);
|
|||
* pHash: the hash table
|
||||
* return item count
|
||||
*/
|
||||
int hash_count(HashArray *pHash);
|
||||
int fc_hash_count(HashArray *pHash);
|
||||
|
||||
/**
|
||||
* hash best optimize
|
||||
|
|
@ -300,7 +300,7 @@ int hash_count(HashArray *pHash);
|
|||
* suggest_capacity: suggest init capacity for speed
|
||||
* return >0 for success, < 0 fail (errno)
|
||||
*/
|
||||
int hash_best_op(HashArray *pHash, const int suggest_capacity);
|
||||
int fc_hash_best_op(HashArray *pHash, const int suggest_capacity);
|
||||
|
||||
/**
|
||||
* hash stat
|
||||
|
|
@ -314,7 +314,7 @@ int hash_best_op(HashArray *pHash, const int suggest_capacity);
|
|||
* stat_size: stats array size (contain max elments)
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_stat(HashArray *pHash, HashStat *pStat, \
|
||||
int fc_hash_stat(HashArray *pHash, HashStat *pStat, \
|
||||
int *stat_by_lens, const int stat_size);
|
||||
|
||||
/**
|
||||
|
|
@ -323,7 +323,7 @@ int hash_stat(HashArray *pHash, HashStat *pStat, \
|
|||
* pHash: the hash table
|
||||
* return none
|
||||
*/
|
||||
void hash_stat_print(HashArray *pHash);
|
||||
void fc_hash_stat_print(HashArray *pHash);
|
||||
|
||||
/**
|
||||
* lock the bucket of hash table
|
||||
|
|
@ -332,7 +332,7 @@ void hash_stat_print(HashArray *pHash);
|
|||
* bucket_index: the index of bucket
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_bucket_lock(HashArray *pHash, const unsigned int bucket_index);
|
||||
int fc_hash_bucket_lock(HashArray *pHash, const unsigned int bucket_index);
|
||||
|
||||
/**
|
||||
* unlock the bucket of hash table
|
||||
|
|
@ -341,7 +341,7 @@ int hash_bucket_lock(HashArray *pHash, const unsigned int bucket_index);
|
|||
* bucket_index: the index of bucket
|
||||
* return 0 for success, != 0 fail (errno)
|
||||
*/
|
||||
int hash_bucket_unlock(HashArray *pHash, const unsigned int bucket_index);
|
||||
int fc_hash_bucket_unlock(HashArray *pHash, const unsigned int bucket_index);
|
||||
|
||||
int RSHash(const void *key, const int key_len);
|
||||
|
||||
|
|
@ -383,8 +383,8 @@ int calc_hashnr1(const void* key, const int key_len);
|
|||
int calc_hashnr1_ex(const void* key, const int key_len, \
|
||||
const int init_value);
|
||||
|
||||
int simple_hash(const void* key, const int key_len);
|
||||
int simple_hash_ex(const void* key, const int key_len, \
|
||||
int fc_simple_hash(const void* key, const int key_len);
|
||||
int fc_simple_hash_ex(const void* key, const int key_len, \
|
||||
const int init_value);
|
||||
|
||||
int CRC32(const void *key, const int key_len);
|
||||
|
|
@ -402,7 +402,7 @@ int64_t CRC32_ex(const void *key, const int key_len, \
|
|||
#define CALC_HASH_CODES4(buff, buff_len, hash_codes) \
|
||||
hash_codes[0] = CRC32_ex(buff, buff_len, hash_codes[0]); \
|
||||
hash_codes[1] = ELFHash_ex(buff, buff_len, hash_codes[1]); \
|
||||
hash_codes[2] = simple_hash_ex(buff, buff_len, hash_codes[2]); \
|
||||
hash_codes[2] = fc_simple_hash_ex(buff, buff_len, hash_codes[2]); \
|
||||
hash_codes[3] = Time33Hash_ex(buff, buff_len, hash_codes[3]); \
|
||||
|
||||
|
||||
|
|
@ -410,7 +410,7 @@ int64_t CRC32_ex(const void *key, const int key_len, \
|
|||
hash_codes[0] = CRC32_FINAL(hash_codes[0]); \
|
||||
|
||||
|
||||
unsigned int *hash_get_prime_capacity(const int capacity);
|
||||
unsigned int *fc_hash_get_prime_capacity(const int capacity);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
|
|||
trim(name);
|
||||
name_len = strlen(name);
|
||||
if (name_len > 0) {
|
||||
value = (char *)hash_find(set->vars, name, name_len);
|
||||
value = (char *)fc_hash_find(set->vars, name, name_len);
|
||||
} else {
|
||||
value = NULL;
|
||||
}
|
||||
|
|
@ -553,10 +553,10 @@ static int iniInitContext(IniContext *pContext, const char annotation_type,
|
|||
|
||||
memset(pContext, 0, sizeof(IniContext));
|
||||
pContext->current_section = &pContext->global;
|
||||
if ((result=hash_init(&pContext->sections, Time33Hash, 32, 0.75)) != 0)
|
||||
if ((result=fc_hash_init(&pContext->sections, Time33Hash, 32, 0.75)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"hash_init fail, errno: %d, error info: %s", \
|
||||
"fc_hash_init fail, errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
|
|
@ -586,7 +586,7 @@ static void iniSortItems(IniContext *pContext)
|
|||
sizeof(IniItem), iniCompareByItemName);
|
||||
}
|
||||
|
||||
hash_walk(&pContext->sections, iniSortHashData, NULL);
|
||||
fc_hash_walk(&pContext->sections, iniSortHashData, NULL);
|
||||
}
|
||||
|
||||
int iniLoadFromFile(const char *szFilename, IniContext *pContext)
|
||||
|
|
@ -1142,7 +1142,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
|||
}
|
||||
|
||||
section_len = strlen(section_name);
|
||||
pSection = (IniSection *)hash_find(&pContext->sections,\
|
||||
pSection = (IniSection *)fc_hash_find(&pContext->sections,\
|
||||
section_name, section_len);
|
||||
if (pSection == NULL)
|
||||
{
|
||||
|
|
@ -1154,7 +1154,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
|||
}
|
||||
|
||||
memset(pSection, 0, sizeof(IniSection));
|
||||
result = hash_insert(&pContext->sections, \
|
||||
result = fc_hash_insert(&pContext->sections, \
|
||||
section_name, section_len, pSection);
|
||||
if (result < 0)
|
||||
{
|
||||
|
|
@ -1540,7 +1540,7 @@ static SetDirectiveVars *iniAllocVars(IniContext *pContext, const bool initVars)
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
if (hash_init_ex(set->vars, simple_hash, 17, 0.75, 0, true) != 0)
|
||||
if (fc_hash_init_ex(set->vars, fc_simple_hash, 17, 0.75, 0, true) != 0)
|
||||
{
|
||||
free(set->vars);
|
||||
set->vars = NULL;
|
||||
|
|
@ -2007,7 +2007,7 @@ static bool iniCalcCondition(char *condition, const int condition_len,
|
|||
set = iniGetVars(pContext);
|
||||
if (set != NULL && set->vars != NULL)
|
||||
{
|
||||
value = (char *)hash_find(set->vars, varStr, varLen);
|
||||
value = (char *)fc_hash_find(set->vars, varStr, varLen);
|
||||
if (value == NULL)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
|
|
@ -2164,7 +2164,7 @@ static int iniDoProccessSet(char *pSet, char **ppSetEnd,
|
|||
}
|
||||
}
|
||||
|
||||
result = hash_insert_ex(set->vars, key, strlen(key),
|
||||
result = fc_hash_insert_ex(set->vars, key, strlen(key),
|
||||
new_value, value_len + 1, false);
|
||||
if (new_value != value) {
|
||||
free(new_value);
|
||||
|
|
@ -2786,13 +2786,13 @@ void iniFreeContext(IniContext *pContext)
|
|||
memset(&pContext->global, 0, sizeof(IniSection));
|
||||
}
|
||||
|
||||
hash_walk(&pContext->sections, iniFreeHashData, NULL);
|
||||
hash_destroy(&pContext->sections);
|
||||
fc_hash_walk(&pContext->sections, iniFreeHashData, NULL);
|
||||
fc_hash_destroy(&pContext->sections);
|
||||
|
||||
set = iniGetVars(pContext);
|
||||
if (set != NULL && set->vars != NULL)
|
||||
{
|
||||
hash_destroy(set->vars);
|
||||
fc_hash_destroy(set->vars);
|
||||
free(set->vars);
|
||||
set->vars = NULL;
|
||||
set->offset = 0;
|
||||
|
|
@ -2809,7 +2809,7 @@ do { \
|
|||
} \
|
||||
else \
|
||||
{ \
|
||||
pSection = (IniSection *)hash_find(&pContext->sections, \
|
||||
pSection = (IniSection *)fc_hash_find(&pContext->sections, \
|
||||
szSectionName, strlen(szSectionName)); \
|
||||
if (pSection == NULL) \
|
||||
{ \
|
||||
|
|
@ -3182,7 +3182,7 @@ void iniPrintItems(IniContext *pContext)
|
|||
}
|
||||
printf("\n");
|
||||
|
||||
hash_walk(&pContext->sections, iniPrintHashData, NULL);
|
||||
fc_hash_walk(&pContext->sections, iniPrintHashData, NULL);
|
||||
}
|
||||
|
||||
struct section_name_walk_arg {
|
||||
|
|
@ -3246,7 +3246,7 @@ int iniGetSectionNamesEx(IniContext *pContext, IniSectionNameFilterFunc
|
|||
walk_arg.args = args;
|
||||
walk_arg.size = max_size;
|
||||
walk_arg.count = 0;
|
||||
result = hash_walk(&pContext->sections, iniSectionNameWalkCallback,
|
||||
result = fc_hash_walk(&pContext->sections, iniSectionNameWalkCallback,
|
||||
&walk_arg);
|
||||
*nCount = walk_arg.count;
|
||||
return result;
|
||||
|
|
@ -3317,7 +3317,7 @@ int iniGetSectionCountEx(IniContext *pContext, IniSectionNameFilterFunc
|
|||
walk_arg.filter_func = filter_func;
|
||||
walk_arg.args = args;
|
||||
walk_arg.count = 0;
|
||||
hash_walk(&pContext->sections, iniSectionCountWalkCallback, &walk_arg);
|
||||
fc_hash_walk(&pContext->sections, iniSectionCountWalkCallback, &walk_arg);
|
||||
return walk_arg.count;
|
||||
}
|
||||
|
||||
|
|
@ -3340,7 +3340,7 @@ IniItem *iniGetSectionItems(const char *szSectionName, IniContext *pContext,
|
|||
}
|
||||
else
|
||||
{
|
||||
pSection = (IniSection *)hash_find(&pContext->sections,
|
||||
pSection = (IniSection *)fc_hash_find(&pContext->sections,
|
||||
szSectionName, strlen(szSectionName));
|
||||
if (pSection == NULL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2848,7 +2848,7 @@ ssize_t fc_safe_read(int fd, char *buf, const size_t count)
|
|||
key_t fc_ftok(const char *path, const int proj_id)
|
||||
{
|
||||
int hash_code;
|
||||
hash_code = simple_hash(path, strlen(path));
|
||||
hash_code = fc_simple_hash(path, strlen(path));
|
||||
return (((proj_id & 0xFF) << 24) | (hash_code & 0xFFFFFF));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue