mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Const correctness in toxcore/list.c
This commit is contained in:
parent
55d986270b
commit
e651cc9984
@ -45,7 +45,7 @@
|
||||
* < 0 : no match, returns index (return value is INDEX(index)) where
|
||||
* the data should be inserted
|
||||
*/
|
||||
static int find(BS_LIST *list, void *data)
|
||||
static int find(const BS_LIST *list, const void *data)
|
||||
{
|
||||
//should work well, but could be improved
|
||||
if (list->n == 0) {
|
||||
@ -115,14 +115,14 @@ void bs_list_init(BS_LIST *list, uint32_t element_size)
|
||||
list->ids = NULL;
|
||||
}
|
||||
|
||||
void bs_list_free(BS_LIST *list)
|
||||
void bs_list_free(const BS_LIST *list)
|
||||
{
|
||||
//free both arrays
|
||||
free(list->data);
|
||||
free(list->ids);
|
||||
}
|
||||
|
||||
int bs_list_find(BS_LIST *list, void *data)
|
||||
int bs_list_find(const BS_LIST *list, const void *data)
|
||||
{
|
||||
int r = find(list, data);
|
||||
|
||||
@ -134,7 +134,7 @@ int bs_list_find(BS_LIST *list, void *data)
|
||||
return list->ids[r];
|
||||
}
|
||||
|
||||
int bs_list_add(BS_LIST *list, void *data, int id)
|
||||
int bs_list_add(BS_LIST *list, const void *data, int id)
|
||||
{
|
||||
//find where the new element should be inserted
|
||||
//see: return value of find()
|
||||
@ -180,7 +180,7 @@ int bs_list_add(BS_LIST *list, void *data, int id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int bs_list_remove(BS_LIST *list, void *data, int id)
|
||||
int bs_list_remove(BS_LIST *list, const void *data, int id)
|
||||
{
|
||||
int i = find(list, data);
|
||||
|
||||
|
@ -41,7 +41,7 @@ typedef struct {
|
||||
void bs_list_init(BS_LIST *list, uint32_t element_size);
|
||||
|
||||
/* Free a list initiated with list_init */
|
||||
void bs_list_free(BS_LIST *list);
|
||||
void bs_list_free(const BS_LIST *list);
|
||||
|
||||
/* Retrieve the id of an element in the list
|
||||
*
|
||||
@ -49,7 +49,7 @@ void bs_list_free(BS_LIST *list);
|
||||
* >= 0 : id associated with data
|
||||
* -1 : failure
|
||||
*/
|
||||
int bs_list_find(BS_LIST *list, void *data);
|
||||
int bs_list_find(const BS_LIST *list, const void *data);
|
||||
|
||||
/* Add an element with associated id to the list
|
||||
*
|
||||
@ -57,14 +57,14 @@ int bs_list_find(BS_LIST *list, void *data);
|
||||
* 1 : success
|
||||
* 0 : failure (data already in list)
|
||||
*/
|
||||
int bs_list_add(BS_LIST *list, void *data, int id);
|
||||
int bs_list_add(BS_LIST *list, const void *data, int id);
|
||||
|
||||
/* Remove element from the list
|
||||
*
|
||||
* return value:
|
||||
* 1 : success
|
||||
* 0 : failure (element not found or id does not match
|
||||
* 0 : failure (element not found or id does not match)
|
||||
*/
|
||||
int bs_list_remove(BS_LIST *list, void *data, int id);
|
||||
int bs_list_remove(BS_LIST *list, const void *data, int id);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user