-
Notifications
You must be signed in to change notification settings - Fork 9
/
m_vector.h
51 lines (40 loc) · 1.08 KB
/
m_vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
* Copyright (C) 2016 XD.Yang
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
#ifndef M_VECTOR_H
#define M_VECTOR_H
#include <stdlib.h>
#include <assert.h>
typedef struct
{
void **_store;
int _size;
int _cap;
}LineTable;
#define Linear_New() (LineTable*)malloc(sizeof(LineTable))
#define Linear(LT,SZ) \
{\
LT->_cap = SZ; LT->_size = 0;LT->_store = (void**)calloc(SZ,sizeof(void*));\
}
#define Line_Append(LT,V)\
{\
if ( LT->_size >= LT->_cap )\
_Extend(LT);\
LT->_store[ LT->_size++] = V;\
}
#define _Extend(LT) \
{\
int _cap = LT->_cap * 3;\
LT->_store = (void**)realloc(LT->_store,sizeof(void**)*_cap);\
assert(LT->_store != NULL);\
LT->_cap = _cap;\
}
#define Line_Free(LT) \
{free(LT->_store);}
#define Line_Get(LT,I) (LT->_store[I])
#define Line_Set(LT,I,V) (LT->_store[I] = V)
#endif // M_VECTOR_H