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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
ctl -- C Template Library
It contain some useful objects, functions, macros about some data
structure.
Compile:
Type "make" and it will create "lib/libctl.a", "obj/$.o" where $
means all the objects.
By the way, you can type "make example" to compile a example
file which name is "example.c", and the results are "example",
which is an executive file. To run it, you will be shown a simple
example about how to use the objects and functions in this project
-- "C Template Library".
Target/goal:
-utility:
This object contain some useful functions, constants and types.
Enums:
ErrorType contain kinds of errors.
Structures:
Types:
uint unsigned int
pchar char*
ppchar char**
pvoid void*
ppvoid void**
cchar const char
pcchar (const char)*
ppcchar (const char)**
cvoid const void
pcvoid (cosnt void)*
ppcvoid (const void)**
Type transform:
Char(), pChar(), ppChar()
Void(), pVoid(), ppVoid()
cChar(), pcChar(), ppcChar()
cVoid(), pcVoid(), ppcVoid()
Functions:
ctl_malloc like malloc(), but will exit on error
ctl_realloc like realloc(), but will exit on erro
ctl_die print some message and exit()
ctl_swap swap two elements with given type
-vector:
This object is an array with dynamic table size.
methods:
init(addr of the vector, size per entry, size)
The vector's type depends on what user want to
store. For example: if you want an array for int,
you should decleare like "int* v", and call the
init() like this "init(&v, sizeof(int), 5)", and
it will initalize an array with 5 elements.
free(addr of the vector)
Free the memory the vector use. Yous should call
it when you don't need the container.
getSize(addr of the vector)
Return the number of elements.
getEntrySize(addr of the vector)
Return the size per entry, it dependent on what
type of data you store in the container.
getEntry(addr of the vector, index)
Return a const pointer which point to the entry
with the index you give.
setSize(addr of the vector, new_size)
Resize the table to new_size. Note that it won't
initalize the newly element if you increase size.
setEntry(addr of the vector, index, data)
Let the element with index you give be data.
addBack(addr of the vector, data)
Add an element which contain data at the back of
the vector.
delBack(addr of the vector)
Remove the last element of the vector.
addFront(addr of the vector, data) !! UNFINISHED !!
Add an element which contain data at the front of
the vector.
delFront(addr of the vector) !! UNFINISHED !!
Remove the first element of the vector.
cat(addr of the v1, addr of the v2)
Concatenate the vector2 to the back of vector1.
copy(addr of the v1, addr of the v2)
Let the contain in the v1 be the one in the v2
replace(addr of the v1, a, b, addr of the v2, x, y)
If b == 0, it will insert v2[x ... x+y-1] into
the place between v[a]
and v[a-1]
If y >= 0, it will replace v1[a ... a+b-1]
to v2[x ... x+y-1]
If y < 0, it will replace v1[a ... a+b-1]
to v2[x-y-1 ... x] with
reverse order.
-list:
-stack:
-queue:
-dequeue:
-heap:
-map:
-hash:
--cathook, cat_leopard
|