C header library for typed lists (using macros and "template" C).

Overview

vector.h

C header library for typed lists (using macros and "template" C).

Essentially, this is a resizable array of elements of your choosing that is automatically managed by a few simple functions.

Similar in spirit to sort.h.

Instructions

Download vector.h and put it somewhere in your -I include path.

Define the VECTOR_TYPE macro with the type you want your vector to be of. Like, int, float, etc.

Define the VECTOR_NAME to be the "name" of the vector type, in that, all functions will look like vec_VECTOR_NAME_somefun. (See below.)

#include "vector.h"

For example, if your VECTOR_NAME is int, then you now have vec_int_t as your type. You can pass them around normally as value types, but you always need to init them.

vec_int_t myvec;
vec_int_init(myvec);

You also have access to all the functions you need, including:

  • init (initialize an vec_whatever_t)
  • get
  • pop (remove and return the last element)
  • del (delete an element anywhere in the vector; WARNING: could rewrite the whole list.)
  • size
  • append

Sample usage

#include <stdio.h>
#define VECTOR_TYPE int
#define VECTOR_NAME int
#include "vector.h"

int main(void) {
  int i;
  vec_int_t vec;
  vec_int_init(vec);
  vec_int_append(vec, 2);
  vec_int_append(vec, 100);
  vec_int_pop(vec);
  vec_int_del(vec, 0);

  for (i = 0; i < vec_int_size(vec); i++) {
    printf("%d\n", vec_int_get(vec, i));
  }
}
You might also like...
R :package: and header-only C++ library for geospatial space-division based compression and encoding
R :package: and header-only C++ library for geospatial space-division based compression and encoding

spress spress provides utilities for encoding and compressing geospatial objects, such as sf objects. Installation This package requires C++11 for com

ring-span lite - A C++yy-like ring_span type for C++98, C++11 and later in a single-file header-only library

ring-span lite: A circular buffer view for C++98 and later Contents Example usage In a nutshell Dependencies Installation Synopsis Reported to work wi

Step is a C++17, header-only library of STL-like algorithms and data structures
Step is a C++17, header-only library of STL-like algorithms and data structures

Step is a C++17, header-only library of STL-like algorithms and data structures. Installation git clone --depth 1 https://github.com/storm-ptr/step.gi

nanoplan is a header-only C++11 library for search-based robot planning.
nanoplan is a header-only C++11 library for search-based robot planning.

nanoplan is a header-only C++11 library for search-based robot planning. The primary design goals are correctness, ease-of-use, and efficiency (in tha

A family of header-only, very fast and memory-friendly hashmap and btree containers.
A family of header-only, very fast and memory-friendly hashmap and btree containers.

The Parallel Hashmap Overview This repository aims to provide a set of excellent hash map implementations, as well as a btree alternative to std::map

Easy to use, header only, macro generated, generic and type-safe Data Structures in C
Easy to use, header only, macro generated, generic and type-safe Data Structures in C

C Macro Collections Easy to use, header only, macro generated, generic and type-safe Data Structures in C. Table of Contents Installation Contributing

A reverse engineering tool to interactively reconstruct structures and generate header files
A reverse engineering tool to interactively reconstruct structures and generate header files

ReGenny ReGenny is a reverse engineering tool to interactively reconstruct structures and generate usable C++ header files. Header file generation is

Miniz in a single C header.

MiniMiniZ This the amalgamated miniz library in a single header. Usage Copy miniminiz.h into your C or C++ project, include it anywhere you want to us

Owner
Christopher Swenson
Christopher Swenson
A collection of multiple types of lists used during pentesting, collected in one place. List types include usernames, passwords, combos, wordlist and may more..

Access list is a collection of multiple types of lists used during pentesting, collected in one place, created by Undercode This list include a collec

UNDERCODE UTILITIES 10 Nov 21, 2022
100daysofDSA - Explore about arrays, linked lists, stacks & queues, graphs, and more to master the foundations of data structures & algorithms!

Explore about arrays, linked lists, stacks & queues, graphs, and more to master the foundations of data structures & algorithms!

null 27 Oct 29, 2022
merge two sorted lists fast

Py Merge Merge sorted list faster than using list.sort or heapq.merge. import merge # create some sorted lists a = list(range(-100, 1700)) b = list(r

Earthly 10 Nov 21, 2021
Implementing dynamic lists in C

Dynamic-Lists Implementing dynamic lists in C <begginer level> DESCRIPTION: This header file <list.h> implements python-like lists and it's functions.

null 2 Feb 2, 2022
A simple single header 64 and 32 bit hash function using only add, sub, ror, and xor.

K-HASH A simple single header 64 bit hash function using only add, sub, ror, and xor. This a just general-purpose hash function for like making hash m

null 70 Dec 27, 2022
Strong typedef - A class template that creates a new type that is distinct from the underlying type, but convertible to and from it

jss::strong_typedef <Tag, ValueType, Properties...> This is an implementation of a C++17 class template that provides a wrapper type that is convertib

Anthony Williams 101 Dec 21, 2022
Golang template grammar for tree-sitter

tree-sitter-go-template Golang templates grammar for tree-sitter. NeoVim integration using nvim-treesitter Add gotmpl parser following nvim-treesitter

Nikita Galaiko 28 Nov 30, 2022
STX B+ Tree C++ Template Classes

STX B+ Tree C++ Template Classes v0.9 Author: Timo Bingmann (Mail: tb a-with-circle panthema dot net) Date: 2013-05-05 The STX B+ Tree package is obso

Timo Bingmann 198 Dec 21, 2022
C++ Custom Vector Template Class

C++ Custom Vector Template Class This is an implementation of a template class for storing data in any type. It includes user-friendly interface with

Ozan Armağan 2 Apr 12, 2022
R :package: and header-only C++ library for geospatial space-division based compression and encoding

spress spress provides utilities for encoding and compressing geospatial objects, such as sf objects. Installation This package requires C++11 for com

UF-OKN 5 Dec 9, 2021