CArray v1.0.0-build
Minimal and Extensible Array Implementation for C
Loading...
Searching...
No Matches
CArray

1.0.0-build

20261025

CARR is a lightweight C vector library that stores pointers to elements (void *). It supports insertion, replacement, deletion, reversal, and dynamic resizing.

Requirements

  • C standard: C99 or later.
  • Compilers: GCC, Clang, or MSVC. Other compilers might also support CArray
  • Minimum compiler versions: GCC 3.0+, Clang 3.0+, or MSVC 2013+
  • Dependencies: Standard C headers and the CARR implementation, no other dependencies needed

Setup

Run the following commands from the project root:

./gen.sh
./gen.sh link
./compile.sh setup
./compile.sh settings

The interactive settings step (./compile.sh settings) is optional.

Building Tests and Library Manually

Compile the project using:

./compile.sh

Run the compiled program tests using:

./run.sh

Minimal Usage

Include the CARR header:

#include "carray/carr.h"

Initialize a vector, add elements, reverse, delete an element, and destroy it:

int a = 10;
int b = 20;
CARR vec = carr_init(4, true);
carr_pushBack(&vec, &a);
carr_pushBack(&vec, &b);
carr_pushFront(&vec, &b);
carr_replaceIndex(&vec, &a, 1);
carr_deleteIndex(&vec, 0, true);
CARRError carr_deleteIndex(CARR *vec, const size_t index, const bool fall)
Deletes an element at a specified index.
void carr_destroy(CARR *vec)
Destroys a vector and releases its internal resources.
CARR carr_init(const size_t cap, const bool dynamic)
Initializes a new CARR vector.
CARRError carr_pushFront(CARR *vec, void *item)
Inserts an element at the beginning of the vector.
CARRError carr_reverse(CARR *vec)
Reverses the order of elements in the vector.
CARRError carr_pushBack(CARR *vec, void *item)
Appends an element to the end of the vector.
CARRError carr_replaceIndex(CARR *vec, void *item, const size_t idx)
Replaces an element at a specified index.
Represents a pointer-based vector container.
Definition carr.h:40

Check returned CARRError values to handle operation failures.

Notes

  • CARR stores pointers rather than copies of elements. Ensure the pointed-to objects remain valid while they are used.
  • carr_init(4, true) initializes the vector with a capacity of four and enables dynamic resizing.
  • carr_destroy() releases the vector's internal resources; it does not necessarily free the pointed-to elements.
  • The meaning of the fall parameter in carr_deleteIndex() depends on the implementation.