tuya hasmap module
更多...
#include "tuya_cloud_types.h"
浏览源代码.
|
|
#define | MAP_MISSING -2 /* No such element */ |
| | define some special error code for hashmap module
|
| |
|
#define | MAP_OK 0 /* OK */ |
| |
|
#define | MAP_OMEM -1 /* Out of Memory */ |
| |
|
#define | TUYA_HASHMAP_FOR_EACH_DATA(in, key, data_iter) for(data_iter = NULL; tuya_hashmap_data_traversal(in, key, (ANY_T_ITER *)&data_iter) == MAP_OK; /*empty*/) |
| | traverse all data with same key
|
| |
|
|
typedef void * | ANY_T |
| | any_t is a pointer. This allows you to put arbitrary structures in the hashmap.
|
| |
|
typedef ANY_T * | ANY_T_ITER |
| | any_t_iter is a iterator which used to traverse the hashmap
|
| |
|
typedef ANY_T | MAP_T |
| | map_t is a pointer to an internally maintained data structure. Clients of this package do not need to know how hashmaps are represented. They see and manipulate only map_t's.
|
| |
tuya hasmap module
- 版本
- 1.0
- 日期
- 2019-10-30
- 版权所有
- Copyright 2021-2025 Tuya Inc. All Rights Reserved.
◆ tuya_hashmap_data_traversal()
| INT_T tuya_hashmap_data_traversal |
( |
MAP_T |
in, |
|
|
const CHAR_T * |
key, |
|
|
ANY_T_ITER * |
arg_iterator |
|
) |
| |
traverse all data with same key
- 参数
-
| [in] | in | the hashmap |
| [in] | key | the key of element |
| [in,out] | arg_iterator | the traverse iterator |
- 返回
- MAP_OK on success, others on failed, please refer to the define of hashmap error code
- 注解
- if arg_iterator is NULL, fetch the first element, otherwise, fetch the next element
◆ tuya_hashmap_free()
| void tuya_hashmap_free |
( |
MAP_T |
in | ) |
|
free the hashmap
- 参数
-
| [in] | in | the hashmap need to free |
- 警告
- must remove all element first, otherwise, it will cause element leak
◆ tuya_hashmap_get()
| INT_T tuya_hashmap_get |
( |
MAP_T |
in, |
|
|
const CHAR_T * |
key, |
|
|
ANY_T * |
arg |
|
) |
| |
get an element from the hashmap
- 参数
-
| [in] | in | the hashmap |
| [in] | key | the key of the element |
| [out] | arg | the first value that the key matches |
- 返回
- MAP_OK on success, others on failed, please refer to the define of hashmap error code
◆ tuya_hashmap_length()
| INT_T tuya_hashmap_length |
( |
MAP_T |
in | ) |
|
get current size of the hashmap
- 参数
-
- 返回
- the current size
◆ tuya_hashmap_new()
| MAP_T tuya_hashmap_new |
( |
UINT_T |
table_size | ) |
|
create a new empty hashmap
- 参数
-
| [in] | table_size | the hash table size |
- 返回
- a new empty hashmap
◆ tuya_hashmap_put()
| INT_T tuya_hashmap_put |
( |
MAP_T |
in, |
|
|
const CHAR_T * |
key, |
|
|
const ANY_T |
data |
|
) |
| |
Add an element to the hashmap
- 参数
-
| [in] | in | the hashmap |
| [in] | key | the key of hash element |
| [in] | data | the data of hash element |
- 返回
- MAP_OK on success, others on failed, please refer to the define of hashmap error code
- 注解
- For same key, it does not replace it. it is inserted in the head of the list
◆ tuya_hashmap_remove()
| INT_T tuya_hashmap_remove |
( |
MAP_T |
in, |
|
|
CHAR_T * |
key, |
|
|
ANY_T |
data |
|
) |
| |
remove an element from the hashmap
- 参数
-
| [in] | in | the hashmap |
| [in] | key | the key of element |
| [in] | data | the data of the element |
- 返回
- MAP_OK on success, others on failed, please refer to the define of hashmap error code
- 注解
- if data is NULL,then delete the first note match key.if data is not null, then delete the node match key and data.