LibCDS
|
The ordered map to store key value pairs. More...
Go to the source code of this file.
Data Structures | |
struct | TreeMap |
The implementation for ordered map. More... | |
Typedefs | |
typedef struct _TreeMapData | TreeMapData |
TreeMapData is the data type for the container private information. More... | |
Functions | |
int32_t | TreeMapInit (TreeMap **ppObj) |
The constructor for TreeMap. More... | |
void | TreeMapDeinit (TreeMap **ppObj) |
The destructor for TreeMap. More... | |
int32_t | TreeMapPut (TreeMap *self, Pair *pPair) |
Insert a key value pair into the map. More... | |
int32_t | TreeMapGet (TreeMap *self, Key key, Value *pValue) |
Retrieve the value corresponding to the designated key. More... | |
int32_t | TreeMapFind (TreeMap *self, Key key) |
Check if the map contains the designated key. More... | |
int32_t | TreeMapRemove (TreeMap *self, Key key) |
Delete the key value pair corresponding to the designated key. More... | |
int32_t | TreeMapSize (TreeMap *self) |
Return the number of stored key value pairs. More... | |
int32_t | TreeMapMinimum (TreeMap *self, Pair **ppPair) |
Retrieve the key value pair with the minimum order from the map. More... | |
int32_t | TreeMapMaximum (TreeMap *self, Pair **ppPair) |
Retrieve the key value pair with the maximum order from the map. More... | |
int32_t | TreeMapPredecessor (TreeMap *self, Key key, Pair **ppPair) |
Retrieve the key value pair which is the predecessor of the given key. More... | |
int32_t | TreeMapSuccessor (TreeMap *self, Key key, Pair **ppPair) |
Retrieve the key value pair which is the successor of the given key. More... | |
int32_t | TreeMapIterate (TreeMap *self, bool bReset, Pair **ppPair) |
Iterate through the map from the minimum order to the maximum order. More... | |
int32_t | TreeMapReverseIterate (TreeMap *self, bool bReset, Pair **ppPair) |
Reversely iterate through the map from the minimum order to the maximum order. More... | |
int32_t | TreeMapSetCompare (TreeMap *self, int32_t(*pFunc)(Key, Key)) |
Set the custom key comparison method. More... | |
int32_t | TreeMapSetDestroy (TreeMap *self, void(*pFunc)(Pair *)) |
Set the custom key value pair resource clean method. More... | |
The ordered map to store key value pairs.
Definition in file tree_map.h.
typedef struct _TreeMapData TreeMapData |
TreeMapData is the data type for the container private information.
Definition at line 11 of file tree_map.h.
int32_t TreeMapInit | ( | TreeMap ** | ppObj | ) |
The constructor for TreeMap.
ppObj | The double pointer to the to be constructed map |
SUCC | |
ERR_NOMEM | Insufficient memory for map construction |
void TreeMapDeinit | ( | TreeMap ** | ppObj | ) |
The destructor for TreeMap.
If the custom resource clean method is set, it also runs the clean method for each pair.
ppObj | The double pointer to the to be destructed map |
int32_t TreeMapPut | ( | TreeMap * | self, |
Pair * | pPair | ||
) |
Insert a key value pair into the map.
This function inserts a key value pair into the map. If the order of the designated pair is the same with a certain one stored in the map, that pair will be replaced. Also, if the custom resource clean method is set, it runs the clean method for the replaced pair.
self | The pointer to TreeMap structure |
pPair | The pointer to the designated pair |
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NOMEM | Insufficient memory for map extension |
int32_t TreeMapGet | ( | TreeMap * | self, |
Key | key, | ||
Value * | pValue | ||
) |
Retrieve the value corresponding to the designated key.
This function retrieves the value corresponding to the designated key from the map. If the key can be found, the value will be returned by the third parameter. Otherwise, the error code in returned and the third parameter is updated with NULL.
self | The pointer to TreeMap structure |
key | The designated key |
pValue | The pointer to the returned value |
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NODATA | No map entry can be found |
ERR_GET | Invalid parameter to store returned value |
int32_t TreeMapFind | ( | TreeMap * | self, |
Key | key | ||
) |
Check if the map contains the designated key.
self | The pointer to TreeMap structure |
key | The designated key |
SUCC | The key can be found |
NOKEY | The key cannot be found |
ERR_NOINIT | Uninitialized container |
int32_t TreeMapRemove | ( | TreeMap * | self, |
Key | key | ||
) |
Delete the key value pair corresponding to the designated key.
This function deletes the key value pair corresponding to the designated key. If the custom resource clean method is set, it runs the clean methods for the deleted pair.
self | The pointer to TreeMap structure |
key | The designated key |
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NODATA | No map entry can be found |
int32_t TreeMapSize | ( | TreeMap * | self | ) |
Return the number of stored key value pairs.
self | The pointer to TreeMap structure |
ERR_NOINIT | Uninitialized container |
int32_t TreeMapMinimum | ( | TreeMap * | self, |
Pair ** | ppPair | ||
) |
Retrieve the key value pair with the minimum order from the map.
self | The pointer to TreeMap structure |
ppPair | The double pointer to the returned pair |
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_IDX | Empty map |
ERR_GET | Invalid parameter to store returned pair |
int32_t TreeMapMaximum | ( | TreeMap * | self, |
Pair ** | ppPair | ||
) |
Retrieve the key value pair with the maximum order from the map.
self | The pointer to TreeMap structure |
ppPair | The double pointer to the returned pair |
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_IDX | Empty map |
ERR_GET | Invalid parameter to store returned pair |
int32_t TreeMapPredecessor | ( | TreeMap * | self, |
Key | key, | ||
Pair ** | ppPair | ||
) |
Retrieve the key value pair which is the predecessor of the given key.
self | The pointer to TreeMap structure |
key | The designated key |
ppPair | The double pointer to the returned pair |
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NODATA | Non-existent immediate predecessor |
ERR_GET | Invalid parameter to store returned pair |
int32_t TreeMapSuccessor | ( | TreeMap * | self, |
Key | key, | ||
Pair ** | ppPair | ||
) |
Retrieve the key value pair which is the successor of the given key.
self | The pointer to TreeMap structure |
key | The designated key |
ppPair | The double pointer to the returned pair |
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NODATA | Non-existent immediate successor |
ERR_GET | Invalid parameter to store returned pair |
int32_t TreeMapIterate | ( | TreeMap * | self, |
bool | bReset, | ||
Pair ** | ppPair | ||
) |
Iterate through the map from the minimum order to the maximum order.
Before iterating through the map, it is necessary to pass:
After initialization, you can pass:
self | The pointer to TreeMap structure |
bReset | The knob to restart the iteration |
ppPair | The double pointer to the returned pair |
SUCC | Iterator initialized successfully |
CONTINUE | Iteration in progress |
END | Iteration terminiated |
ERR_NOINIT | Uninitialized container |
ERR_GET | Invalid parameter to store returned pair |
int32_t TreeMapReverseIterate | ( | TreeMap * | self, |
bool | bReset, | ||
Pair ** | ppPair | ||
) |
Reversely iterate through the map from the minimum order to the maximum order.
Before iterating through the map, it is necessary to pass:
After initialization, you can pass:
self | The pointer to TreeMap structure |
bReset | The knob to restart the iteration |
ppPair | The double pointer to the returned pair |
SUCC | Iterator initialized successfully |
CONTINUE | Iteration in progress |
END | Iteration terminiated |
ERR_NOINIT | Uninitialized container |
ERR_GET | Invalid parameter to store returned pair |
int32_t TreeMapSetCompare | ( | TreeMap * | self, |
int32_t(*)(Key, Key) | pFunc | ||
) |
Set the custom key comparison method.
self | The pointer to TreeMap structure |
pFunc | The function pointer to the custom method |
SUCC | |
ERR_NOINIT | Uninitialized container |