• Stars
    star
    40
  • Rank 657,988 (Top 14 %)
  • Language
    C
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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));
  }
}

More Repositories

1

sort

Sorting routine implementations in "template" C
C
441
star
2

ace_spell_check_js

Add spell checking in the Ace JS editor
JavaScript
24
star
3

python-xr

Python source code cross reference
HTML
15
star
4

scanty_wordpress_import

Import Wordpress XML files into Scanty
Ruby
12
star
5

jtux

Patched version of jtux library
C
8
star
6

aesrng

AES-based random number generator in C
C
8
star
7

ttyrec2gif

Convert ttyrec files to animated gifs
Python
7
star
8

atom-jsonpp

Atom editor JSON pretty printer
CoffeeScript
6
star
9

docker-ghost

Run ghost blogging platform in a Docker container.
Shell
5
star
10

lords-of-cyberspace

Lords of Cyberspace source
C
4
star
11

cpython-internals

CPython Internals talk from PyCon AU 2016
CSS
4
star
12

mcrypt

mcrypt snapshot http://mcrypt.sourceforge.net/
Shell
4
star
13

littlereader

Small, single-user RSS reader
Go
3
star
14

sagewiki

Tools for the Sage wiki
Python
3
star
15

adventure-talk-pycon

TeX
3
star
16

cray-blitz

Cray Blitz Chess Engine
Fortran
3
star
17

intermediate_python

An Intermediate Python Coursebook
Python
3
star
18

adventwure

Adventure for Twilio!
Python
3
star
19

python_remote_debugger

A remote debugging protocol and implementation in Python.
Python
2
star
20

docker-sage

Docker container for Sage
Shell
2
star
21

keysafe

A simple way to encrypt multiple files for multiple users using keybase.io
Python
2
star
22

rubyzipload

Loads ZIP code and US location information from US Census into a database
2
star
23

projectpier

Project Pier fork (to add templating)
PHP
2
star
24

slacker

Slacker is a simple Slack bot library written in Go.
Go
2
star
25

sublime_whitespace

Only trim trailing whitespace on new lines.
Python
2
star
26

zelda-randomizer-helper

Zelda Randomizer Map Helper
CSS
2
star
27

screenrun

Send a terminal session to the web
Go
2
star
28

goconf

A configuration file template for Go
Go
2
star
29

dotfiles

My dotfiles
Vim Script
2
star
30

adventure-talk

Colossal Cave Adventure in Python talk from North Bay Python 2017
JavaScript
2
star
31

atom-gofmt

Gofmt plugin for the Atom editor
CoffeeScript
1
star
32

wavegaming

Google Wave tools and gadgets for board gaming
1
star
33

shortcodes

URL shortening codes from a random number generator
Python
1
star
34

fairygloss

Updated fork of sailorhg/fairyfloss
CSS
1
star
35

t-essentials

Terra Essentials main repository.
Ruby
1
star
36

pizza

Pizza -- a dumb geocoding system based on US Census data.
Scala
1
star
37

tito-zapier

ti.to webhook to zapier connector using AWS Lambda
Python
1
star
38

chapel_libs

Chapel libraries and miscellaneous files
Vim Script
1
star
39

adventurejs

Colossal Cave Adventure (1977)
JavaScript
1
star
40

binary_matrix

Rust implementation of dense binary matrices and vectors.
Rust
1
star
41

rust-qsieve

Rust implementation of the Quadratic Sieve
Rust
1
star
42

math-ruining-everything-since-forever

Talk presented at ConFoo: "Math: Ruining Everything Since Forever"
Python
1
star
43

sage_sliderepl

sliderepl hack that works with Sage
Python
1
star
44

sobg

Science of Board Games code
Python
1
star
45

mfa-talk-pycon-au-2018

MFA Talk from PyCon AU 2018
TeX
1
star
46

solarjs

Javascript model of the solar system
JavaScript
1
star
47

findimagedupes

Finds similar and duplicate images.
Go
1
star