Created
July 5, 2016 11:58
-
-
Save amanuel2/a95a67ccd9b6901602fd4672a2493923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _VERTEX_AM_H_LB | |
#define _VERTEX_AM_H_LB 1 | |
#pragma once | |
#include<stdint.h> | |
#include<stdbool.h> | |
/** | |
* Vertex Library C | |
* | |
* GCC C99 <Vertex.h> | |
* | |
* @author Amanuel Bogale | |
* @copyright 2016 Amanuel Bogale | |
* @license http://www.opensource.org/licenses/mit-license.html MIT License | |
* | |
*/ | |
//@union for storing | |
//data types supported | |
//for vertex | |
typedef union | |
{ | |
char ch; //1 byte | |
unsigned char uch;//1 byte | |
signed char sch;// 1 byte | |
int in;//2 or 4bytes | |
unsigned int uin;//2 or 4bytes | |
long ln;// 4byte | |
unsigned long uln; //4byte | |
long long lnln; //8byte | |
short sh;// 2byte | |
unsigned short ush; //2bytes | |
float fl;//4byte | |
double db; //8byte | |
long double ldb; //10byte | |
}type; | |
/* | |
* @enum for index | |
* first or last | |
*/ | |
typedef enum | |
{ | |
FIRST, | |
LAST | |
}index; | |
/* | |
* @struct for defining | |
* vertex. Initalize First | |
*/ | |
struct vertex_am | |
{ | |
size_t current_size; | |
type type; | |
long long size_contents; | |
void **contents; //Array Of Void Pointers | |
//Add to the end of array | |
void (*add)(struct vertex_am *self,void*val); | |
}; | |
typedef struct vertex_am vertex_am; | |
/* | |
* Vertex Initalizer | |
* Always call after initalizing a | |
* vertex | |
*/ | |
vertex_am* init_vertex(size_t size, vertex_am* vertex); | |
/* | |
* Vertex "Detilazer" | |
* Always call at the end | |
* of lifetime of a vertex | |
* to stop leaks | |
*/ | |
void end_vertex(vertex_am* vertex); | |
/* | |
* Get Number of elements | |
*/ | |
long long get_elements_num(vertex_am vert); | |
/* | |
* Add to the end | |
* of the Dynamic Array | |
* / "Vertex" | |
*/ | |
void add_end(vertex_am *vert, void* val); | |
/* | |
* Add to the beggining | |
* of the Dynamic Array | |
* / "Vertex" | |
*/ | |
void add_beg(vertex_am *vert, void* val); | |
/* | |
* Add to the specified | |
* index of the Dynamic | |
* Array / "Vertex" | |
*/ | |
void add_index(vertex_am *vert, void* val,long long index); | |
/* | |
* Get Value, based on Index | |
*/ | |
void* get_val(vertex_am vert,long long index); | |
/* | |
* Get index based on value. | |
* Thier might be multiple | |
* values that are the same. | |
* So the param decides this | |
* @param index, FIRST for | |
* first value that appears | |
* LAST for last value that appears | |
*/ | |
int get_index(vertex_am vert, void*key,index in); | |
/* | |
* Get the index based on | |
* after how many occurrences | |
* do you decide to get the index | |
* . If -1 is returned, you have incorrect | |
* specifier. NOTE: START FROM 0 | |
*/ | |
int get_specified_index(vertex_am vert, void*key, int specifier); | |
/* | |
* Delete the Last | |
* Element on the | |
* Dynamic Array. | |
* @param returns true | |
* if successfully deleted, | |
* false if unsuccessful | |
*/ | |
bool pop_end(vertex_am *vert); | |
#endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment