Skip to content

Commit

Permalink
Change function names back to snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-jones committed Apr 24, 2024
1 parent 44ba7de commit 7fbe673
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
22 changes: 11 additions & 11 deletions include/dsc_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ typedef struct DSCList *DSCList;
*
* @return A pointer to the newly created list, or NULL if memory allocation fails.
*/
DSCList DSCList_create(void);
DSCList dsc_list_create(void);

/**
* @brief Destroys the list and frees its memory.
*
* @param list The list to destroy.
* @return true if the list was destroyed successfully, false otherwise.
*/
bool DSCList_destroy(DSCList list);
bool dsc_list_destroy(DSCList list);

/**
* @brief Inserts a value at the beginning of the list.
Expand All @@ -49,7 +49,7 @@ bool DSCList_destroy(DSCList list);
* @param value The value to insert.
* @return true if the value was inserted successfully, false otherwise.
*/
bool DSCList_push_front(DSCList list, int value);
bool dsc_list_push_front(DSCList list, int value);

/**
* @brief Inserts a value at the end of the list.
Expand All @@ -58,7 +58,7 @@ bool DSCList_push_front(DSCList list, int value);
* @param value The value to insert.
* @return true if the value was inserted successfully, false otherwise.
*/
bool DSCList_push_back(DSCList list, int value);
bool dsc_list_push_back(DSCList list, int value);

/**
* @brief Inserts a value at a specific position in the list.
Expand All @@ -68,15 +68,15 @@ bool DSCList_push_back(DSCList list, int value);
* @param position The position at which to insert the value.
* @return true if the value was inserted successfully, false otherwise.
*/
bool DSCList_insert(DSCList list, int value, int position);
bool dsc_list_insert(DSCList list, int value, int position);

/**
* @brief Removes the first node from the list.
*
* @param list The list to remove the first node from.
* @return The popped value, -1 on failure.
*/
int DSCList_pop_front(DSCList list);
int dsc_list_pop_front(DSCList list);

/**
* @brief Removes the first occurrence of a value from the list.
Expand All @@ -85,7 +85,7 @@ int DSCList_pop_front(DSCList list);
* @param value The value to remove.
* @return true if the value was removed successfully, false otherwise.
*/
bool DSCList_remove(DSCList list, int value);
bool dsc_list_remove(DSCList list, int value);

/**
* @brief Removes all occurrences of a value from the list.
Expand All @@ -94,30 +94,30 @@ bool DSCList_remove(DSCList list, int value);
* @param value The value to remove.
* @return true if the values were removed successfully, false otherwise.
*/
bool DSCList_remove_all(DSCList list, int value);
bool dsc_list_remove_all(DSCList list, int value);

/**
* @brief Retrieves the value of the first element in the list.
*
* @param list The list to get the front element from.
* @return The value of the front element, or -1 if the list is empty or NULL.
*/
int DSCList_get_head(const DSCList list);
int dsc_list_get_head(const DSCList list);

/**
* @brief Gets the size of the list.
*
* @param list The list to get the size of.
* @return The size of the list, or -1 if the list is NULL.
*/
int DSCList_size(const DSCList list);
int dsc_list_size(const DSCList list);

/**
* @brief Checks if the list is empty.
*
* @param list The list to check.
* @return true if the list is empty or NULL, false otherwise.
*/
bool DSCList_is_empty(const DSCList list);
bool dsc_list_is_empty(const DSCList list);

#endif // __DSC_LIST_H__
44 changes: 22 additions & 22 deletions src/dsc_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct DSCList {
unsigned int size; // The size of the list
};

static DSCNode DSCNode_create(int value) {
static DSCNode dsc_node_create(int value) {
DSCNode new_node = malloc(sizeof new_node);
if (new_node == NULL) {
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
Expand All @@ -45,7 +45,7 @@ static DSCNode DSCNode_create(int value) {
return new_node;
}

static bool DSCNode_destroy(DSCNode node) {
static bool dsc_node_destroy(DSCNode node) {
if (node == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return false;
Expand All @@ -54,7 +54,7 @@ static bool DSCNode_destroy(DSCNode node) {
return true;
}

DSCList DSCList_create(void) {
DSCList dsc_list_create(void) {
DSCList new_list = malloc(sizeof new_list);
if (new_list == NULL) {
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
Expand All @@ -68,7 +68,7 @@ DSCList DSCList_create(void) {
return new_list;
}

bool DSCList_destroy(DSCList list) {
bool dsc_list_destroy(DSCList list) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return false;
Expand All @@ -80,7 +80,7 @@ bool DSCList_destroy(DSCList list) {
while (curr != NULL) {
prev = curr;
curr = curr->next;
DSCNode_destroy(prev);
dsc_node_destroy(prev);
}

free(list);
Expand All @@ -89,13 +89,13 @@ bool DSCList_destroy(DSCList list) {
return true;
}

bool DSCList_push_front(DSCList list, int value) {
bool dsc_list_push_front(DSCList list, int value) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return false;
}

DSCNode new_node = DSCNode_create(value);
DSCNode new_node = dsc_node_create(value);
if (new_node == NULL) {
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
return false;
Expand All @@ -109,13 +109,13 @@ bool DSCList_push_front(DSCList list, int value) {
return true;
}

bool DSCList_push_back(DSCList list, int value) {
bool dsc_list_push_back(DSCList list, int value) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return false;
}

DSCNode new_node = DSCNode_create(value);
DSCNode new_node = dsc_node_create(value);
if (new_node == NULL) {
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
return false;
Expand All @@ -142,7 +142,7 @@ bool DSCList_push_back(DSCList list, int value) {
return true;
}

bool DSCList_insert(DSCList list, int value, int position) {
bool dsc_list_insert(DSCList list, int value, int position) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return false;
Expand All @@ -153,7 +153,7 @@ bool DSCList_insert(DSCList list, int value, int position) {
return false;
}

DSCNode new_node = DSCNode_create(value);
DSCNode new_node = dsc_node_create(value);
if (new_node == NULL) {
dsc_set_error(DSC_ERROR_OUT_OF_MEMORY);
return false;
Expand Down Expand Up @@ -181,7 +181,7 @@ bool DSCList_insert(DSCList list, int value, int position) {
return true;
}

int DSCList_pop_front(DSCList list) {
int dsc_list_pop_front(DSCList list) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return -1;
Expand All @@ -197,13 +197,13 @@ int DSCList_pop_front(DSCList list) {

list->head = old_head->next;
list->size--;
DSCNode_destroy(old_head);
dsc_node_destroy(old_head);

dsc_set_error(DSC_ERROR_NONE);
return result;
}

bool DSCList_remove(DSCList list, int value) {
bool dsc_list_remove(DSCList list, int value) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return false;
Expand All @@ -220,7 +220,7 @@ bool DSCList_remove(DSCList list, int value) {
list->head = old_head->next;
list->size--;

DSCNode_destroy(old_head);
dsc_node_destroy(old_head);

dsc_set_error(DSC_ERROR_NONE);
return true;;
Expand All @@ -234,7 +234,7 @@ bool DSCList_remove(DSCList list, int value) {
prev->next = curr->next;
list->size--;

DSCNode_destroy(curr);
dsc_node_destroy(curr);

dsc_set_error(DSC_ERROR_NONE);
return true;
Expand All @@ -248,7 +248,7 @@ bool DSCList_remove(DSCList list, int value) {
return false;
}

bool DSCList_remove_all(DSCList list, int value) {
bool dsc_list_remove_all(DSCList list, int value) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return false;
Expand All @@ -268,12 +268,12 @@ bool DSCList_remove_all(DSCList list, int value) {
list->head = curr->next;
list->size--;

DSCNode_destroy(curr);
dsc_node_destroy(curr);
} else {
prev->next = curr->next;
list->size--;

DSCNode_destroy(curr);
dsc_node_destroy(curr);
}

curr = curr->next;
Expand All @@ -287,7 +287,7 @@ bool DSCList_remove_all(DSCList list, int value) {
return true;
}

int DSCList_get_head(const DSCList list) {
int dsc_list_get_head(const DSCList list) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_EMPTY_CONTAINER);
return -1;
Expand All @@ -302,7 +302,7 @@ int DSCList_get_head(const DSCList list) {
return list->head->value;
}

int DSCList_size(const DSCList list) {
int dsc_list_size(const DSCList list) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return -1;
Expand All @@ -312,7 +312,7 @@ int DSCList_size(const DSCList list) {
return list->size;
}

bool DSCList_is_empty(const DSCList list) {
bool dsc_list_is_empty(const DSCList list) {
if (list == NULL) {
dsc_set_error(DSC_ERROR_INVALID_ARGUMENT);
return true;
Expand Down

0 comments on commit 7fbe673

Please sign in to comment.