Skip to content

Commit

Permalink
Start to implement doubly linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-jones committed Apr 26, 2024
1 parent 06ea31e commit 162cf8a
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 226 deletions.
18 changes: 2 additions & 16 deletions include/dsc_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @enum DSCError
* @brief Represents the error codes used in the DSC library.
*
* @constant DSC_ERROR_NONE No error occurred.
* @constant DSC_ERROR_OK No error occurred.
* @constant DSC_ERROR_INVALID_ARGUMENT An invalid argument was passed to a function.
* @constant DSC_ERROR_OUT_OF_RANGE The index is out of bounds.
* @constant DSC_ERROR_OUT_OF_MEMORY Failed to allocate memory.
Expand All @@ -33,7 +33,7 @@
* @constant DSC_ERROR_QUEUE_FULL The queue is full.
*/
typedef enum DSCError {
DSC_ERROR_NONE,
DSC_ERROR_OK,
DSC_ERROR_INVALID_ARGUMENT,
DSC_ERROR_OUT_OF_RANGE,
DSC_ERROR_OUT_OF_MEMORY,
Expand All @@ -44,18 +44,4 @@ typedef enum DSCError {
DSC_ERROR_QUEUE_FULL
} DSCError;

/**
* @brief Sets the last error code.
*
* @param error The error code to set.
*/
void dsc_set_error(DSCError error);

/**
* @brief Gets the last error code.
*
* @return The last error code.
*/
DSCError dsc_get_error(void);

#endif // __DSC_ERROR_H__
51 changes: 24 additions & 27 deletions include/dsc_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ DSCList dsc_list_init(void);
*
* @param list The list to destroy.
*
* @return true if the list was destroyed successfully, false otherwise.
* @return true if the list was successfully destroyed, false otherwise.
*/
bool dsc_list_deinit(DSCList list);

Expand All @@ -48,7 +48,7 @@ bool dsc_list_deinit(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.
* @return true if the list is empty, false otherwise.
*/
bool dsc_list_is_empty(const DSCList list);

Expand All @@ -63,33 +63,40 @@ int dsc_list_size(const DSCList list);
/* Element access */

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

/**
* @brief Retrieves the value of the last element in the list.
* @brief Gets the data in the last element of the list.
*
* @param list The list to get the last element from.
* @return The value of the last element, or -1 if the list is empty or NULL.
* @return The last element, or -1 if the list is empty or NULL.
*/
void *dsc_list_back(const DSCList list);


/**
* @brief Gets the data in the element at the specified position in the list.
*
* @param list The list to get the element from.
* @return The element at the specified position, or NULL if the list is empty or NULL.
*/
int dsc_list_back(const DSCList list);
void *dsc_list_at(const DSCList list, int position);

/* Modifiers */

/**
* @brief Inserts a value at the beginning of the list.
* @brief Inserts an element at the beginning of the list.
*
* @param list The list to insert the value into.
* @param value The value to insert.
*
* @param list The list to insert the data into.
* @param value The data to insert.
* @return true if the value was inserted successfully, false otherwise.
*/
bool dsc_list_push_front(DSCList list, int value);
bool dsc_list_push_front(DSCList list, void *data);

/**
* @brief Removes the first node from the list.
Expand All @@ -116,20 +123,20 @@ bool dsc_list_push_back(DSCList list, int value);
*
* @param list The list to remove the last node from.
*
* @return The popped value, or -1 on failure.
* @return The removed element, or -1 on failure.
*/
int dsc_list_pop_back(DSCList list);
void *dsc_list_pop_back(DSCList list);

/**
* @brief Inserts a value at a specific position in the list.
*
* @param list The list to insert the value into.
* @param value The value to insert.
* @param position The position at which to insert the value.
* @param index The index at which to insert the data.
*
* @return true if the value was inserted successfully, false otherwise.
*/
bool dsc_list_insert(DSCList list, int value, int position);
bool dsc_list_insert(DSCList list, void *data, int index);

/**
* @brief Erases the element at the specified position.
Expand All @@ -151,14 +158,4 @@ bool dsc_list_erase(DSCList list, int position);
*/
bool dsc_list_remove(DSCList list, int value);

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

#endif // __DSC_LIST_H__
30 changes: 20 additions & 10 deletions src/dsc_error.c → include/dsc_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
* libdsc. If not, see <https://www.gnu.org/licenses/>.
*/

#include "../include/dsc_error.h"
#ifndef __DSC_TYPE_H__
#define __DSC_TYPE_H__

// Global variable to store the last error code
static DSCError last_error = DSC_ERROR_NONE;

DSCError dsc_get_error(void) {
return last_error;
}
/**
* @enum DSCType
* @brief Represents the data types available in the DSC library.
*
* @constant DSC_TYPE_CHAR
* @constant DSC_TYPE_STRING
* @constant DSC_TYPE_INT
* @constant DSC_TYPE_UINT
* @constant DSC_TYPE_UINT64
* @constant DSC_TYPE_FLOAT
* @constant DSC_TYPE_DOUBLE
*/
typedef enum DSCType {
DSC_TYPE_CHAR,
DSC_TYPE_INT,
DSC_TYPE_FLOAT,
} DSCType;

void dsc_set_error(DSCError error) {
last_error = error;
}
#endif // __DSC_TYPE_H__
Loading

0 comments on commit 162cf8a

Please sign in to comment.