Doc updates
This commit is contained in:
parent
9d67b223a9
commit
0b5a11ce8c
@ -24,9 +24,9 @@ if(${CMAKE_PROJECT_NAME} STREQUAL flint)
|
|||||||
add_executable(tests tests/tests.c)
|
add_executable(tests tests/tests.c)
|
||||||
target_include_directories(tests PRIVATE include)
|
target_include_directories(tests PRIVATE include)
|
||||||
|
|
||||||
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||||
target_link_libraries(tests flint)
|
|
||||||
else()
|
|
||||||
target_link_libraries(tests flint bsd)
|
target_link_libraries(tests flint bsd)
|
||||||
|
else()
|
||||||
|
target_link_libraries(tests flint)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
# libflint
|
# libflint
|
||||||
|
|
||||||
`libflint` is a library of common C data structures and algorithms, designed to be as agnostic as possible for its
|
`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
|
## 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
|
## Memory Management
|
||||||
|
|
||||||
The parts of this library that create data structures pass all responsibility of memory management to the user. This
|
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.
|
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)
|
![flint](flinty.jpg)
|
@ -1,6 +1,6 @@
|
|||||||
# linkedlist
|
# 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
|
## Usage
|
||||||
|
|
||||||
@ -146,16 +146,24 @@ Members:
|
|||||||
|
|
||||||
### ll_init
|
### 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
|
```c
|
||||||
void ll_init(List *list, void (*destroy)(void *data));
|
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
|
### ll_destroy
|
||||||
|
|
||||||
Destroys the nodes inside a list and calls the deallocation funciton on the data if one was provided. Does not 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.
|
||||||
the list itself, that is left up to the user.
|
|
||||||
|
|
||||||
```c
|
```c
|
||||||
void ll_destroy(List *list);
|
void ll_destroy(List *list);
|
||||||
|
@ -1,3 +1,74 @@
|
|||||||
# stack
|
# stack
|
||||||
|
|
||||||
Coming soon
|
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
|
||||||
|
```
|
@ -5,12 +5,12 @@ theme:
|
|||||||
nav:
|
nav:
|
||||||
- 'index.md'
|
- 'index.md'
|
||||||
- 'Modules':
|
- 'Modules':
|
||||||
|
- 'Binary Tree': 'binarytree.md'
|
||||||
- 'Boolean': 'bool.md'
|
- 'Boolean': 'bool.md'
|
||||||
- 'Input': 'input.md'
|
- 'Input': 'input.md'
|
||||||
- 'Math': 'math.md'
|
|
||||||
- 'Utility': 'utility.md'
|
|
||||||
- 'Data Structures':
|
|
||||||
- 'Binary Tree': 'binarytree.md'
|
|
||||||
- 'Linked List': 'linkedlist.md'
|
- 'Linked List': 'linkedlist.md'
|
||||||
|
- 'Math': 'math.md'
|
||||||
- 'Set': 'set.md'
|
- 'Set': 'set.md'
|
||||||
- 'Stack': 'stack.md'
|
- 'Stack': 'stack.md'
|
||||||
|
- 'Utility': 'utility.md'
|
||||||
|
- 'Vector': 'vector.md'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user