Commit 6b23e496b9ac4a180d9815dee3cff76fe5e58a65
1 parent
b9502cd9
start find and delete action on list
Showing
4 changed files
with
85 additions
and
5 deletions
... | ... | @@ -44,10 +44,12 @@ TR_CLASS(TR_List) { |
44 | 44 | TR_INSTANCE_INIT(TR_List); |
45 | 45 | TR_CLASSVARS_DECL(TR_List) {}; |
46 | 46 | |
47 | -void TR_listPut(TR_List, void *); | |
48 | -void TR_listPutFirst(TR_List, void *); | |
49 | -void * TR_listGet(TR_List); | |
50 | -void * TR_listGetFirst(TR_List); | |
47 | +void TR_listPut(TR_List, void *); | |
48 | +void TR_listPutFirst(TR_List, void *); | |
49 | +void * TR_listGet(TR_List); | |
50 | +void * TR_listGetFirst(TR_List); | |
51 | +ssize_t TR_listFind(TR_List, void *); | |
52 | +void TR_listDelete(TR_List, void *); | |
51 | 53 | |
52 | 54 | #define TR_listEmpty(this) (this->start == this->end) |
53 | 55 | #define TR_listFirst(this) ((this)->start) | ... | ... |
src/list/delete.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2014 Georg Hopp | |
8 | + * | |
9 | + * This program is free software: you can redistribute it and/or modify | |
10 | + * it under the terms of the GNU General Public License as published by | |
11 | + * the Free Software Foundation, either version 3 of the License, or | |
12 | + * (at your option) any later version. | |
13 | + * | |
14 | + * This program is distributed in the hope that it will be useful, | |
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | + * GNU General Public License for more details. | |
18 | + * | |
19 | + * You should have received a copy of the GNU General Public License | |
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | + */ | |
22 | + | |
23 | +#include "trbase.h" | |
24 | +#include "tr/list.h" | |
25 | + | |
26 | +void | |
27 | +TR_listDelete(TR_List this, void * msg) | |
28 | +{ | |
29 | +} | |
30 | + | |
31 | +// vim: set ts=4 sw=4: | ... | ... |
src/list/find.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2014 Georg Hopp | |
8 | + * | |
9 | + * This program is free software: you can redistribute it and/or modify | |
10 | + * it under the terms of the GNU General Public License as published by | |
11 | + * the Free Software Foundation, either version 3 of the License, or | |
12 | + * (at your option) any later version. | |
13 | + * | |
14 | + * This program is distributed in the hope that it will be useful, | |
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | + * GNU General Public License for more details. | |
18 | + * | |
19 | + * You should have received a copy of the GNU General Public License | |
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | + */ | |
22 | + | |
23 | +#include "trbase.h" | |
24 | +#include "tr/list.h" | |
25 | + | |
26 | +#include "_resize.h" | |
27 | + | |
28 | +ssize_t | |
29 | +TR_listFind(TR_List this, void * msg) | |
30 | +{ | |
31 | + /* | |
32 | + * With an array I know no better way than doing it in O(n). | |
33 | + * The list pattern needs to keep the elements in the order in | |
34 | + * which they were added. | |
35 | + */ | |
36 | + size_t i = this->start; | |
37 | + while (i++ < this->end) { | |
38 | + if (this->data[i] == msg) { | |
39 | + return i; | |
40 | + } | |
41 | + } | |
42 | + return -1; | |
43 | +} | |
44 | + | |
45 | +// vim: set ts=4 sw=4: | ... | ... |
Please
register
or
login
to post a comment