| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
/* |
|
2
|
|
|
|
|
|
|
Copyright (C) 2015-2017 Alexander Borisov |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or |
|
5
|
|
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public |
|
6
|
|
|
|
|
|
|
License as published by the Free Software Foundation; either |
|
7
|
|
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful, |
|
10
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12
|
|
|
|
|
|
|
Lesser General Public License for more details. |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public |
|
15
|
|
|
|
|
|
|
License along with this library; if not, write to the Free Software |
|
16
|
|
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Author: lex.borisov@gmail.com (Alexander Borisov) |
|
19
|
|
|
|
|
|
|
*/ |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#include "mycore/utils/mcsimple.h" |
|
22
|
|
|
|
|
|
|
|
|
23
|
145
|
|
|
|
|
|
mcsimple_t * mcsimple_create(void) |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
145
|
|
|
|
|
|
return mycore_calloc(1, sizeof(mcsimple_t)); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
145
|
|
|
|
|
|
void mcsimple_init(mcsimple_t *mcsimple, size_t pos_size, size_t list_size, size_t struct_size) |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
145
|
|
|
|
|
|
mcsimple->struct_size = struct_size; |
|
31
|
|
|
|
|
|
|
|
|
32
|
145
|
|
|
|
|
|
mcsimple->list_pos_length_used = 0; |
|
33
|
145
|
|
|
|
|
|
mcsimple->list_pos_length = 0; |
|
34
|
145
|
|
|
|
|
|
mcsimple->list_pos_size = pos_size; |
|
35
|
145
|
|
|
|
|
|
mcsimple->list = (uint8_t**)mycore_calloc(pos_size, sizeof(uint8_t*)); |
|
36
|
|
|
|
|
|
|
|
|
37
|
145
|
50
|
|
|
|
|
if(mcsimple->list == NULL) { |
|
38
|
0
|
|
|
|
|
|
return; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
145
|
|
|
|
|
|
mcsimple->list_size = list_size * struct_size; |
|
42
|
|
|
|
|
|
|
|
|
43
|
145
|
50
|
|
|
|
|
if((mcsimple_init_list_entries(mcsimple, mcsimple->list_pos_length) == NULL)) { |
|
44
|
0
|
|
|
|
|
|
return; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
290
|
|
|
|
|
|
void mcsimple_clean(mcsimple_t *mcsimple) |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
290
|
|
|
|
|
|
mcsimple->list_length = 0; |
|
51
|
290
|
|
|
|
|
|
mcsimple->list_pos_length = 0; |
|
52
|
290
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
144
|
|
|
|
|
|
mcsimple_t * mcsimple_destroy(mcsimple_t *mcsimple, bool destroy_self) |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
144
|
50
|
|
|
|
|
if(mcsimple == NULL) |
|
57
|
0
|
|
|
|
|
|
return NULL; |
|
58
|
|
|
|
|
|
|
|
|
59
|
144
|
50
|
|
|
|
|
if(mcsimple->list) { |
|
60
|
288
|
100
|
|
|
|
|
for(size_t i = 0; i < mcsimple->list_pos_length_used; i++) { |
|
61
|
144
|
50
|
|
|
|
|
if(mcsimple->list[i]) |
|
62
|
144
|
|
|
|
|
|
mycore_free(mcsimple->list[i]); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
144
|
|
|
|
|
|
mycore_free(mcsimple->list); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
144
|
50
|
|
|
|
|
if(destroy_self) { |
|
69
|
144
|
|
|
|
|
|
mycore_free(mcsimple); |
|
70
|
144
|
|
|
|
|
|
return NULL; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return mcsimple; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
145
|
|
|
|
|
|
uint8_t * mcsimple_init_list_entries(mcsimple_t *mcsimple, size_t pos) |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
145
|
50
|
|
|
|
|
if(mcsimple->list_pos_length >= mcsimple->list_pos_size) |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
0
|
|
|
|
|
|
size_t new_size = mcsimple->list_pos_size + 128; |
|
81
|
0
|
|
|
|
|
|
uint8_t **list = (uint8_t**)mycore_realloc(mcsimple->list, mcsimple->list_pos_size * sizeof(uint8_t*)); |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if(list) { |
|
84
|
0
|
|
|
|
|
|
mcsimple->list = list; |
|
85
|
0
|
|
|
|
|
|
memset(&mcsimple->list[pos], 0, (new_size - mcsimple->list_pos_size) * sizeof(uint8_t*)); |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
mcsimple->list_pos_size = new_size; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
else |
|
90
|
0
|
|
|
|
|
|
return NULL; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
145
|
|
|
|
|
|
mcsimple->list_length = 0; |
|
94
|
|
|
|
|
|
|
|
|
95
|
145
|
50
|
|
|
|
|
if(mcsimple->list[pos] == NULL) { |
|
96
|
145
|
|
|
|
|
|
mcsimple->list_pos_length_used++; |
|
97
|
145
|
|
|
|
|
|
mcsimple->list[pos] = (uint8_t*)mycore_malloc(mcsimple->list_size * sizeof(uint8_t)); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
145
|
|
|
|
|
|
return mcsimple->list[pos]; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
22
|
|
|
|
|
|
void * mcsimple_malloc(mcsimple_t *mcsimple) |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
22
|
50
|
|
|
|
|
if(mcsimple->list_length >= mcsimple->list_size) |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
0
|
|
|
|
|
|
mcsimple->list_pos_length++; |
|
108
|
0
|
0
|
|
|
|
|
if((mcsimple_init_list_entries(mcsimple, mcsimple->list_pos_length) == NULL)) { |
|
109
|
0
|
|
|
|
|
|
return NULL; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
22
|
|
|
|
|
|
size_t current = mcsimple->list_length; |
|
114
|
22
|
|
|
|
|
|
mcsimple->list_length += mcsimple->struct_size; |
|
115
|
|
|
|
|
|
|
|
|
116
|
22
|
|
|
|
|
|
return &mcsimple->list[mcsimple->list_pos_length][current]; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
9
|
|
|
|
|
|
void * mcsimple_get_by_absolute_position(mcsimple_t *mcsimple, size_t pos) |
|
120
|
|
|
|
|
|
|
{ |
|
121
|
9
|
|
|
|
|
|
pos *= mcsimple->struct_size; |
|
122
|
|
|
|
|
|
|
|
|
123
|
9
|
|
|
|
|
|
size_t list_index = pos / mcsimple->list_size; |
|
124
|
9
|
100
|
|
|
|
|
if(list_index >= mcsimple->list_pos_length_used) |
|
125
|
2
|
|
|
|
|
|
return NULL; |
|
126
|
|
|
|
|
|
|
|
|
127
|
7
|
|
|
|
|
|
return &mcsimple->list[list_index][ (pos % mcsimple->list_size) ]; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|