mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-08 19:44:45 +08:00
add hash_table_size
This commit is contained in:
parent
84cacc25f1
commit
c95df6bb6a
@ -1,12 +1,13 @@
|
||||
# 最新动态
|
||||
|
||||
2023/09/24
|
||||
* 增加tk\_iostream\_tcp\_create\_client
|
||||
* 增加函数tk\_iostream\_tcp\_create\_client
|
||||
* 增加函数hash\_table\_size
|
||||
|
||||
2023/09/23
|
||||
* 完善socket_helper
|
||||
* 完善serial_helper
|
||||
* 将serial_helper.c/.h移动到tkc目录。
|
||||
* 完善socket\_helper
|
||||
* 完善serial\_helper
|
||||
* 将serial\_helper.c/.h移动到tkc目录。
|
||||
|
||||
2023/09/21
|
||||
* 修改scroll\_view在children\_layout中设置ym垂直间距时,底部没有间距的bug,并在demouiold添加演示(感谢颖健提供补丁)
|
||||
|
@ -112,6 +112,24 @@ ret_t hash_table_remove_all(hash_table_t* hash_table, tk_compare_t cmp, void* ct
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t hash_table_size(hash_table_t* hash_table) {
|
||||
uint32_t i = 0;
|
||||
uint32_t n = 0;
|
||||
int32_t count = 0;
|
||||
darray_t** arrs = NULL;
|
||||
return_value_if_fail(hash_table != NULL, 0);
|
||||
|
||||
n = hash_table->buckets.size;
|
||||
arrs = (darray_t**)(hash_table->buckets.elms);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
darray_t* iter = arrs[i];
|
||||
count += iter->size;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int32_t hash_table_count(hash_table_t* hash_table, tk_compare_t cmp, void* ctx) {
|
||||
uint32_t i = 0;
|
||||
uint32_t n = 0;
|
||||
|
@ -150,10 +150,19 @@ ret_t hash_table_remove(hash_table_t* hash_table, tk_compare_t cmp, void* ctx);
|
||||
*/
|
||||
ret_t hash_table_remove_all(hash_table_t* hash_table, tk_compare_t cmp, void* ctx);
|
||||
|
||||
/**
|
||||
* @method hash_table_size
|
||||
* 返回全部元素个数。
|
||||
* @param {hash_table_t*} hash_table 哈希表对象。
|
||||
*
|
||||
* @return {int32_t} 返回元素个数。
|
||||
*/
|
||||
int32_t hash_table_size(hash_table_t* hash_table);
|
||||
|
||||
/**
|
||||
* @method hash_table_count
|
||||
* 返回满足条件元素的个数。
|
||||
* @param {hash_table_t*} hash_table 单向链表对象。
|
||||
* @param {hash_table_t*} hash_table 哈希表对象。
|
||||
* @param {tk_compare_t} cmp 比较函数,为NULL则使用内置的比较函数。
|
||||
* @param {void*} ctx 比较函数的上下文。
|
||||
*
|
||||
|
@ -14,12 +14,14 @@ TEST(DHashTable, int_add_remove) {
|
||||
for (i = 0; i < n; i++) {
|
||||
ASSERT_EQ(hash_table_add(ht, tk_pointer_from_int(i), TRUE), RET_OK);
|
||||
ASSERT_EQ(hash_table_count(ht, compare_always_equal, NULL), (i + 1));
|
||||
ASSERT_EQ(hash_table_size(ht), (i + 1));
|
||||
ASSERT_EQ(tk_pointer_to_int(hash_table_find(ht, int_compare, tk_pointer_from_int(i))), i);
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
ASSERT_EQ(hash_table_remove(ht, int_compare, tk_pointer_from_int(i)), RET_OK);
|
||||
ASSERT_EQ(hash_table_count(ht, compare_always_equal, NULL), n - i - 1);
|
||||
ASSERT_EQ(hash_table_size(ht), n - i - 1);
|
||||
ASSERT_EQ(tk_pointer_to_int(hash_table_find(ht, int_compare, tk_pointer_from_int(i))), 0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user