From 0b5a11ce8cbfe24ef4f0681765a7b268c9423f5f Mon Sep 17 00:00:00 2001 From: Evan Burkey Date: Wed, 25 Oct 2023 09:21:59 -0700 Subject: [PATCH] Doc updates --- CMakeLists.txt | 6 ++-- docs/index.md | 14 ++++++--- docs/linkedlist.md | 16 +++++++--- docs/stack.md | 73 +++++++++++++++++++++++++++++++++++++++++++++- mkdocs.yml | 8 ++--- 5 files changed, 101 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac5b3f0..8f66843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,9 +24,9 @@ if(${CMAKE_PROJECT_NAME} STREQUAL flint) add_executable(tests tests/tests.c) target_include_directories(tests PRIVATE include) - if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - target_link_libraries(tests flint) - else() + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") target_link_libraries(tests flint bsd) + else() + target_link_libraries(tests flint) endif() endif() diff --git a/docs/index.md b/docs/index.md index 8436a95..275daa6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,19 +1,25 @@ # libflint `libflint` is a library of common C data structures and algorithms, designed to be as agnostic as possible for its -users. +users. Over time, it has become my personal library of reusable C code. ## Requirements -The only requirement is `libbsd`. This should be available on all major Linux distros. If building on a bsd, then +### Linux + +Requires `libbsd`. This should be available on all major Linux distros. + +### macOS, OpenBSD, FreeBSD + +Requires no extra dependencies ## Memory Management The parts of this library that create data structures pass all responsibility of memory management to the user. This is clearly documented in the individual module's documentation. -## Why 'libflint'? +## Why the name 'libflint'? -`libflint` is named after my dog Flint, who passed away in 2021. I miss you, buddy. +`libflint` is named after my dog Flint, who passed away in 2021. I miss you buddy. ![flint](flinty.jpg) \ No newline at end of file diff --git a/docs/linkedlist.md b/docs/linkedlist.md index 58c82b7..d717deb 100644 --- a/docs/linkedlist.md +++ b/docs/linkedlist.md @@ -1,6 +1,6 @@ # linkedlist -A dual sided linked list structure. Used as the foundation for many of the structures in `libflint` +A dual sided linked list structure. Used as the foundation for many other modules in `libflint` ## Usage @@ -146,16 +146,24 @@ Members: ### ll_init -Initalize the list. User is responsible for freeing memory with `ll_destroy()`. +Initialize the list. User is responsible for creating the initial `List` structure and freeing memory with `ll_destroy()`. `destroy` is a deallocation function for the members of `List`, pass `NULL` if the memory is stack-allocated ```c void ll_init(List *list, void (*destroy)(void *data)); + +/* Usage */ +List *list = malloc(sizeof(Stack)); + +// Pass NULL for stack-allocated memory +ll_init(list, NULL); + +// Pass free or a custom freeing function for heap allocated memory +ll_init(list, free); ``` ### ll_destroy -Destroys the nodes inside a list and calls the deallocation funciton on the data if one was provided. Does not destroy -the list itself, that is left up to the user. +Destroys the nodes inside a list and calls the deallocation funciton on the data if one was provided. Does not destroy the list itself, that is left up to the user. ```c void ll_destroy(List *list); diff --git a/docs/stack.md b/docs/stack.md index 76a5d01..9453637 100644 --- a/docs/stack.md +++ b/docs/stack.md @@ -1,3 +1,74 @@ # stack -Coming soon \ No newline at end of file +LIFO (last in first out) stack structure + +## Structs + +`Stack` is a linked list with stack-based operations available + +```c +#define Stack List +``` + +## Functions + +### stack_init + +Intializes the stack. The user is responsible for creating the initial `Stack` structure and freeing memory with `stack_destroy()`. `destroy` is a deallocation function for the members of `Stack`, pass `NULL` if the memory is stack-allocated + +```c +void stack_init(Stack *stack, void (*destroy)(void *data)); + +/* Usage */ +Stack *stack = malloc(sizeof(Stack)); + +// Pass NULL for stack-allocated memory +stack_init(stack, NULL); + +// Pass free or a custom freeing function for heap allocated memory +stack_init(stack, free); +``` + +### stack_destroy + +Destroys the nodes inside a `Stack` and calls the deallocation funciton on the data if one was provided. Does not destroy the list itself, that is left up to the user. + +```c +void stack_destroy(Stack *stack); +``` + +### stack_push + +Push a new element onto the top of the stack + +```c +int stack_push(Stack *stack, void *data); +``` + +### stack_peek + +Returns a `void *` to the top element of the stack. Does not remove the element + +```c +void *stack_peek(Stack *stack); + +/* Usage */ +// stack: 1 2 3 +int *t = (int*)stack_peek(stack); +assert(*t == 3); +// stack: 1 2 3 +``` + +### stack_pop + +Returns a `void *` to the top element of the stack and removes the element + +```c +int stack_pop(Stack *stack, void **data); + +/* Usage */ +// stack: 1 2 3 +int *t = (int*)stack_peek(stack); +assert(*t == 3); +// stack: 1 2 +``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 6d3946f..9a013d5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -5,12 +5,12 @@ theme: nav: - 'index.md' - 'Modules': + - 'Binary Tree': 'binarytree.md' - 'Boolean': 'bool.md' - 'Input': 'input.md' - - 'Math': 'math.md' - - 'Utility': 'utility.md' - - 'Data Structures': - - 'Binary Tree': 'binarytree.md' - 'Linked List': 'linkedlist.md' + - 'Math': 'math.md' - 'Set': 'set.md' - 'Stack': 'stack.md' + - 'Utility': 'utility.md' + - 'Vector': 'vector.md'