The unordered set to store unique keys.
More...
Go to the source code of this file.
|
typedef struct _HashSetData | HashSetData |
| HashSetData is the data type for the container private information. More...
|
|
|
int32_t | HashSetInit (HashSet **ppObj) |
| The constructor for HashSet. More...
|
|
void | HashSetDeinit (HashSet **ppObj) |
| The destructor for HashSet. More...
|
|
int32_t | HashSetAdd (HashSet *self, Key key, size_t size) |
| Insert a key into the set. More...
|
|
int32_t | HashSetFind (HashSet *self, Key key, size_t size) |
| Check if the set contains the designated key. More...
|
|
int32_t | HashSetRemove (HashSet *self, Key key, size_t size) |
| Delete the designated key from the set. More...
|
|
int32_t | HashSetSize (HashSet *self) |
| Return the number of stored unique keys. More...
|
|
int32_t | HashSetIterate (HashSet *self, bool bReset, Key *pKey) |
| Iterate through the set to retrieve each key. More...
|
|
int32_t | HashSetSetDestroy (HashSet *self, void(*pFunc)(Key)) |
| Set the custom key resource clean method. More...
|
|
int32_t | HashSetSetHash (HashSet *self, uint32_t(*pFunc)(Key, size_t)) |
| Set the custom hash function. More...
|
|
int32_t | HashSetUnion (HashSet *pFst, HashSet *pSnd, HashSet **ppDst) |
| Perform union operation for the designated two sets and create the result set. More...
|
|
int32_t | HashSetIntersect (HashSet *pFst, HashSet *pSnd, HashSet **ppDst) |
| Perform intersection operation for the designated two sets and create the result set. More...
|
|
int32_t | HashSetDifference (HashSet *pFst, HashSet *pSnd, HashSet **ppDst) |
| Perform difference operation for the first source set against the second source set and create the result set. More...
|
|
The unordered set to store unique keys.
Definition in file hash_set.h.
HashSetData is the data type for the container private information.
Definition at line 11 of file hash_set.h.
int32_t HashSetInit |
( |
HashSet ** |
ppObj | ) |
|
The constructor for HashSet.
- Parameters
-
ppObj | The double pointer to the to be constructed set |
- Return values
-
SUCC | |
ERR_NOMEM | Insufficient memory for set construction |
void HashSetDeinit |
( |
HashSet ** |
ppObj | ) |
|
The destructor for HashSet.
If the custom resource clean method is set, it also runs the clean method for each pair.
- Parameters
-
ppObj | The double pointer to the to be destructed set |
int32_t HashSetAdd |
( |
HashSet * |
self, |
|
|
Key |
key, |
|
|
size_t |
size |
|
) |
| |
Insert a key into the set.
This function inserts a key into the set. If the designated key is the same with a certain one stored in the set, that key will be replaced to maintain the element uniqueness. Also, if the custom resource clean method is set, it runs the resource clean method for the replaced key.
- Parameters
-
self | The pointer to HashSet structure |
key | The designated key |
size | Key size in bytes |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NOMEM | Insufficient memory for set extension |
ERR_KEYSIZE | Invalid key size |
- Note
- The key should be the pointer to the data you plan to hash for.
int32_t HashSetFind |
( |
HashSet * |
self, |
|
|
Key |
key, |
|
|
size_t |
size |
|
) |
| |
Check if the set contains the designated key.
- Parameters
-
self | The pointer to HashSet structure |
key | The designated key |
size | Key size in bytes |
- Return values
-
SUCC | The key can be found |
NOKEY | The key cannot be found |
ERR_NOINIT | Uninitialized container |
ERR_KEYSIZE | Invalid key size |
- Note
- The key should be the pointer to the data you plan to hash for.
int32_t HashSetRemove |
( |
HashSet * |
self, |
|
|
Key |
key, |
|
|
size_t |
size |
|
) |
| |
Delete the designated key from the set.
This function deletes the designated key from the set. If the custom resource clean method is set, it also runs the clean method for the deleted key.
- Parameters
-
self | The pointer to HashSet structure |
key | The designated key |
size | Key size in bytes |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NODATA | No set entry can be found |
ERR_KEYSIZE | Invalid key size |
- Note
- The key should be the pointer to the data you plan to hash for.
int32_t HashSetSize |
( |
HashSet * |
self | ) |
|
Return the number of stored unique keys.
- Parameters
-
self | The pointer to HashSet structure |
- Returns
- The number of stored pairs
- Return values
-
ERR_NOINIT | Uninitialized container |
int32_t HashSetIterate |
( |
HashSet * |
self, |
|
|
bool |
bReset, |
|
|
Key * |
pKey |
|
) |
| |
Iterate through the set to retrieve each key.
Before iterating through the set, it is necessary to pass:
- bReset = true
- pKey = NULL for iterator initialization.
After initialization, you can pass:
- bReset = false
- pKey = the pointer to get the returned key at each iteration.
- Parameters
-
self | The pointer to HashSet structure |
bReset | The knob to restart the iteration |
pKey | The pointer to the returned key |
- Return values
-
SUCC | Iterator initialized successfully |
CONTINUE | Iteration in progress |
END | Iteration terminated |
ERR_NOINIT | Uninitialized container |
ERR_GET | Invalid parameter to store returned key |
- Note
- Please do not insert or delete keys during set traversal
int32_t HashSetSetDestroy |
( |
HashSet * |
self, |
|
|
void(*)(Key) |
pFunc |
|
) |
| |
Set the custom key resource clean method.
- Parameters
-
self | The pointer to HashSet structure |
pFunc | The function pointer to the custom method |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized container |
int32_t HashSetSetHash |
( |
HashSet * |
self, |
|
|
uint32_t(*)(Key, size_t) |
pFunc |
|
) |
| |
Set the custom hash function.
The default hash function is HashMurMur32.
- Parameters
-
self | The pointer to HashSet structure |
pFunc | The function pointer to the custom method |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized container |
Perform union operation for the designated two sets and create the result set.
- Parameters
-
pFst | The pointer to the first source set |
pSnd | The pointer to the second source set |
ppDst | The double pointer to the to be created result set |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized source sets |
ERR_NOMEM | Insufficient memory for new set creation |
- Note
- The newly created set will not delegate any key resource clean methods from two source sets. You can still set the clean method for it. However, to avoid the "double-free" problem, it is better to let the source sets handle the resource clean issue and treat the new set as the pure result from the union operation.
Perform intersection operation for the designated two sets and create the result set.
- Parameters
-
pFst | The pointer to the first source set |
pSnd | The pointer to the second source set |
ppDst | The double pointer to the to be created result set |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized source sets |
ERR_NOMEM | Insufficient memory for new set creation |
- Note
- The newly created set will not delegate any key resource clean methods from two source sets. You can still set the clean method for it. However, to avoid the "double-free" problem, it is better to let the source sets handle the resource clean issue and treat the new set as the pure result from the intersection operation.
Perform difference operation for the first source set against the second source set and create the result set.
- Parameters
-
pFst | The pointer to the first source set |
pSnd | The pointer to the second source set |
ppDst | The double pointer to the to be created result set |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized source sets |
ERR_NOMEM | Insufficient memory for new set creation |
- Note
- The newly created set will not delegate any key resource clean methods from two source sets. You can still set the clean method for it. However, to avoid the "double-free" problem, it is better to let the source sets handle the resource clean issue and treat the new set as the pure result from the difference operation.