GitHub - BareRose/dynarr: Portable, single-file, multi-purpose, dynamic array library for values of any type

GitHub

Documentation

This is a header-only library, as such most of its functional documentation is contained within the "header section" of the source code in the form of comments. It is highly recommended that you read said documentation before using this library.

Features

The dynarr library provides type-generic general-purpose array data structures, its features include:

No hard dependencies besides the standard library, making it fully portable for most purposes

Configurable memory allocation function, allowing for compatibility with custom memory managers

Usable as a stack, queue, dynamic array, binary-searchable list, or all of the above at once

Supports sorting using either its own linear sort or the standard qsort implemenetation

Example

#defineDYNARR_STATIC//static version#include"dynarr.h"//include dynarr#include<stdio.h>//printfstaticintsortInt(constint*, constint*); intmain () { //declare and initialize dynarrint*darr=DYNARR_NEW(int); //push a couple of elementsDYNARR_PUSH(darr, 4); DYNARR_PUSH(darr, 1); DYNARR_PUSH(darr, 3); DYNARR_PUSH(darr, 2); //sort dynarr in ascending orderDYNARR_SORT_STD(darr, sortInt); //iterate through the dynarr and print its elementsfor (inti=0; i<DYNARR_SIZE(darr); i++) printf("darr[%d] = %d\n", i, DYNARR_AT(darr, i)); //free the dynarrDYNARR_FREE(darr); //returnreturn0; } staticintsortInt (constint*a, constint*b) { return*a-*b; //ascending order }Attribution

You are not required to give attribution when using this library. If you want to give attribution anyway, either link to this repository,

my website

, or credit me as

BareRose

. If you want to support me financially, consider giving to my

Patreon

.

License

Licensed under CC0 aka the most lawyer-friendly way of spelling "public domain".