Make as many variables const as possible.
This commit is contained in:
18
include/ht.h
18
include/ht.h
@@ -45,21 +45,21 @@ struct ht_s {
|
||||
* @param input the data being hashed.
|
||||
* @return the data's hash.
|
||||
*/
|
||||
unsigned long (*hash_func)(void* input);
|
||||
unsigned long (*hash_func)(const void* input);
|
||||
/**
|
||||
* Function to compare two keys.
|
||||
* @param given_key the key being used to retrieve data
|
||||
* @param current_key the key of a hash table node
|
||||
* @return nonzero value if the keys match.
|
||||
*/
|
||||
int (*cmp_func)(void* given_key, void* current_key);
|
||||
int (*cmp_func)(const void* given_key, const void* current_key);
|
||||
/**
|
||||
* Function used to duplicate the given key and
|
||||
* store it in a node.
|
||||
* @param key the key to copy
|
||||
* @return pointer to a new key.
|
||||
*/
|
||||
void* (*copy_func)(void* key);
|
||||
void* (*copy_func)(const void* key);
|
||||
/**
|
||||
* Function used to free a previously copied key.
|
||||
* @param key the key to free.
|
||||
@@ -76,7 +76,7 @@ typedef struct ht_s ht;
|
||||
* @param key the data to hash.
|
||||
* @return the produced hashed integer.
|
||||
*/
|
||||
unsigned long ht_default_hash_func(void* key);
|
||||
unsigned long ht_default_hash_func(const void* key);
|
||||
/**
|
||||
* The default key comparison function.
|
||||
* Assumes both keys are strings and uses strcmp.
|
||||
@@ -84,13 +84,13 @@ unsigned long ht_default_hash_func(void* key);
|
||||
* @param b the key compared against
|
||||
* @return true if the keys represent the same string.
|
||||
*/
|
||||
int ht_default_cmp_func(void* a, void* b);
|
||||
int ht_default_cmp_func(const void* a, const void* b);
|
||||
/**
|
||||
* The default key copy function.
|
||||
* @param key the key being copied
|
||||
* @return a pointer to the copy of the key.
|
||||
*/
|
||||
void* ht_default_copy_func(void* key);
|
||||
void* ht_default_copy_func(const void* key);
|
||||
/**
|
||||
* The default key free function. Simply calls free()
|
||||
* @param key the key to free.
|
||||
@@ -117,20 +117,20 @@ void ht_free(ht* ht);
|
||||
* @param value the value to store.
|
||||
* @return LIBDS_SUCCESS if all goes well, LIBDS_MALLOC if an allocation fails.
|
||||
*/
|
||||
libds_result ht_put(ht* ht, void* key, void* value);
|
||||
libds_result ht_put(ht* ht, const void* key, void* value);
|
||||
/**
|
||||
* Retrieves a value from the hash table.
|
||||
* @param ht the hash table to retrieve a value from.
|
||||
* @param key the key to use to find the data.
|
||||
* @return the data, or NULL if it is not found.
|
||||
*/
|
||||
void* ht_get(ht* ht, void* key);
|
||||
void* ht_get(ht* ht, const void* key);
|
||||
/**
|
||||
* Removes a value from the hash table.
|
||||
* @param ht the hash table to remove a value from.
|
||||
* @param key the key to use to find the data.
|
||||
*/
|
||||
void ht_remove(ht* ht, void* key);
|
||||
void ht_remove(ht* ht, const void* key);
|
||||
|
||||
/**
|
||||
* Runs through every element in the hash table, and compares it against the
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef enum libds_result_e libds_result;
|
||||
* The function should take two elements, and, if they match, return 1. Otherwise, it should
|
||||
* return 0.
|
||||
*/
|
||||
typedef int (*compare_func)(void*, void*);
|
||||
typedef int (*compare_func)(const void*, const void*);
|
||||
/**
|
||||
* Foreach function type.
|
||||
* Foreach functions are passed to _foreach calls.
|
||||
@@ -29,13 +29,13 @@ typedef int (*foreach_func)(void*, va_list);
|
||||
* @param b The second piece of data being compared
|
||||
* @return always true, i.e 1
|
||||
*/
|
||||
int compare_always(void* a, void* b);
|
||||
int compare_always(const void* a, const void* b);
|
||||
/**
|
||||
* A compare_func implementation that compares two pointers using ==.
|
||||
* @param a the first piece of data being compared
|
||||
* @param b the second piece of data being compared
|
||||
* @return true if a and b are the same value.
|
||||
*/
|
||||
int compare_pointer(void* a, void* b);
|
||||
int compare_pointer(const void* a, const void* b);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user