aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 7f2a7eb37f38a597e62a71ae274651ec73241642 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# LS Vector

Minimal, single-header dynamic array (vector) for C.

- Type-safe via macro code generation (not macro function calls)
- ANSI C
- Header-only
- Dynamic resizing
- Configurable memory allocators

## Quick Start

1. Copy `ls_vec.h` to your project.
2. Define any number of vector types:
    ```c
    LS_VEC_INLINE(int, int_vector)
    ```

    **OR** for separate declaration/implementation:

    ```c
    // In header:
    LS_VEC_DECL(int, int_vector)

    // In source file:
    LS_VEC_IMPL(int, int_vector)
    ```
3. Use the vector with normal C function calls:
    ```c
    int_vector vec;
    int_vector_init(&vec);
    if (!int_vector_push(&vec, 42)) {
        // push failed, allocation failure, handle that here
    }
    // Access elements via vec.data[i]
    // Check size via vec.size
    int_vector_free(&vec);
    ```

See [`ls_vec.h`](ls_vec.h) for detailed documentation and usage patterns.

## Custom Memory Allocators

Configure custom allocators by defining these macros before including the header:

```c
#define LS_REALLOC my_realloc
#define LS_FREE my_free
#include "ls_vec.h"
```

The allocators must behave exactly like standard `realloc` and `free`.

See [`ls_vec.h`](ls_vec.h) for detailed documentation and usage patterns.

## License

MIT.

## Links

- [Website](https://libls.org)
- [GitHub](https://github.com/libls/vec.git)
- [LibLS Git](https://git.libls.org/vec.git)