https://github.com/juripan/jplist
A dynamic array list implementation in C, usable for custom types
https://github.com/juripan/jplist
abstraction arraylist c c-programming c-programming-language dynamic-array list low-level-programming typed-array
Last synced: 4 months ago
JSON representation
A dynamic array list implementation in C, usable for custom types
- Host: GitHub
- URL: https://github.com/juripan/jplist
- Owner: juripan
- Created: 2025-02-22T19:40:57.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-02-22T19:52:26.000Z (4 months ago)
- Last Synced: 2025-02-22T20:29:20.197Z (4 months ago)
- Topics: abstraction, arraylist, c, c-programming, c-programming-language, dynamic-array, list, low-level-programming, typed-array
- Language: C
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JPLIST
A dynamic array list implementation in C. Works for any type (even your custom structs)
## Quick start:
1. Include the jplist header file
```C
#include "jplist.h"
```
2. Make a print format macro for the types that you will use inside of the JPList struct (used for printing out the list)
```C
#define format_Person(i) "(name: \"%s\", age: %d)", iget(list, Person, i).name, iget(list, Person, i).age
```
3. Make a comparison function that gets called when comparing items in the JPList struct (it should act like strcmp from "string.h")
```C
int int_cmp(int x, int y){return x - y;}
```
4. Call the "add_base_func" macro to initialize all of the functions that can be used for the JPList (pass in the type, print format macro you made earlier, and the comparison function)
```C
add_base_func(int, format_int, int_cmp)
```
**IMPORTANT: you cannot use pointers as a type in the list UNLESS you typedef it** \
For example:
```C
typedef int* int_ptr
add_base_func(int_ptr, format_int_ptr, int_ptr_cmp)
```
NOTE: you can also add specific features only by using the "add" macros defined in the jplist header file