Git Product home page Git Product logo

cvec's Introduction

cvec

Fast header-only vector implementation in C

Example

#include <assert.h>
#include "cvec.h"

int main(void){
	int* vec = NULL;
	cvec_init(&vec);
	for(int i = 0;i<20;i++){
		cvec_push_back(&vec,i);
	}
	assert(cvec_len(vec) == 20);
	for(int i = 0;i<10;i++){
		cvec_pop_back(&vec);
	}
	assert(cvec_len(vec) == 10);
	int arr[] = {10,11,12,13,14};
	cvec_insert_data(&vec,cvec_len(vec),arr,sizeof(arr)/sizeof(*arr));
	for(int i = 0;i<15;i++){
		assert(vec[i] == i);
	}
	cvec_destroy(vec);
}

Usage

Functions (macros) taking vecp as an argument require the address of the vector. If they take vec, pass the vector.

cvec_init(vecp)

Creates a new, empty, vector. vecp must be a the address of a non-void pointer set to NULL.

cvec_init_from_data(vecp,data,len)

Creates a new vector with data copied from data. vecp must be a the address of a non-void pointer set to NULL.

cvec_new_len(vecp,len)

Creates a new, empty, vector of size len. vecp must be a the address of a non-void pointer set to NULL.

cvec_new_filled(vecp,value,len)

Creates a new vector filled with len copies of value. vecp must be a the address of a non-void pointer set to NULL.

cvec_copy(vecp,vec)

Makes a copy of vec. vecp must be a the address of a non-void pointer set to NULL.

cvec_destroy(vec)

Frees vec.

cvec_push_back(vecp,element)

Adds element to the back of the vector.

cvec_pop_back(vecp)

Removes the last element from the vector.

cvec_insert_element(vecp,pos,element)

Inserts element into the vector at pos.

cvec_insert_data(vecp,pos,data,size)

Inserts array data of size size into the vector at pos.

cvec_insert_vec(vecp,pos,insert)

Inserts vector insert into the vector at pos.

cvec_erase(vecp,pos)

Removes element in vector at pos.

cvec_erase_range(vecp,start,end)

Removes elements in vector from [start,end).

cvec_reserve(vecp,new_size)

Resizes vector to new_size

cvec_shrink(vecp)

Removes extra space in vector.

cvec_at(vec,i)

Bounds-checked access to vec at index i with assert(). Disable checks with -DNDEBUG.

cvec_empty(vec)

Checks if vec is empty.

cvec_len(vec)

Gets length of vec.

cvec_capacity(vec)

Gets capacity of vec.

cvec_clear(vec)

Removes all elements in vec.

cvec's People

Contributors

doggo4242 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.