ktchen14 / vector

An unobtrusive vector implementation in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vector

CI Status Code Coverage Documentation Status

API Documentation

Introduction

This is an implementation of vectors, or dynamic arrays, for C. A vector in this library behaves like a normal array when its dynamic allocation properties aren't being used. For example:

#include <vector.h>

int main(int argc, char *argv[]) {
  int *vector = vector_define(int, 1, 2, 3, 4);
  vector = vector_extend(vector, (int[]) { 5, 6, 7, 8 }, 4);

  for (size_t i = 0; i < vector_length(vector); i++)
    printf("%i ", vector[i]);
}

Output:

1 2 3 4 5 6 7 8

Most functions that change the size of the vector return the resultant vector.

The element size or type isn't stored in the vector. Most of the time the "implicit interface" should be used. All implicit interface functions calculate the element size of the vector from its type. An alternative "explicit interface" is available where the element size of the vector needs to be passed in. These can be mixed freely:

int *vector = vector_create();
int number = 1;
vector = vector_append(vector, &number);

number = 2;
vector = vector_append_z(vector, &number, sizeof(int));

Almost all functions in the "explicit interface" have a _z suffix.

Implementation

Installation

git clone --branch stable https://github.com/ktchen14/vector.git
cd vector
autoreconf --install
./configure
make
make install

About

An unobtrusive vector implementation in C

License:GNU Lesser General Public License v3.0


Languages

Language:C 84.4%Language:CMake 8.5%Language:Makefile 2.9%Language:M4 1.6%Language:Python 1.2%Language:Shell 0.7%Language:CSS 0.4%Language:Perl 0.4%