Git Product home page Git Product logo

vector's Introduction

vector

GitHub license

vector is a feature-complete, generic and customizable resizable array implementation in pure C that supports almost the entire C++ std::vector API, including iterators.

Usage

#include "vector.h"

int main(int argc, const char* argv[]) {
	Vector vector;
	int x, y, sum;

	/* Choose initial capacity of 10 */
	/* Specify the size of the elements you want to store once */
	vector_setup(&vector, 10, sizeof(int));

	x = 6, y = 9;
	vector_push_back(&vector, &x);
	vector_insert(&vector, 0, &y);
	vector_assign(&vector, 0, &y);

	x = *(int*)vector_get(&vector, 0);
	y = *(int*)vector_back(&vector);
	x = VECTOR_GET_AS(int, &vector, 1);

	vector_remove(&vector, 1);

	/* Iterator support */
	Iterator iterator = vector_begin(&vector);
	Iterator last = vector_end(&vector);
	for (; !iterator_equals(&iterator, &last); iterator_increment(&iterator)) {
		*(int*)iterator_get(&iterator) += 1;
	}

	/* Or just use pretty macros */
	sum = 0;
	VECTOR_FOR_EACH(&vector, i) {
		sum += ITERATOR_GET_AS(int, &i);
	}

	/* Memory management interface */
	vector_resize(&vector, 10);
	vector_reserve(&vector, 100);

	vector_clear(&vector);
	vector_destroy(&vector);
}

LICENSE

This project is released under the MIT License. For more information, see the LICENSE file.

Authors

Peter Goldsborough + cat ❤️

vector's People

Contributors

goldsborough avatar jchnkl avatar vtrlx avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.