2
Lightweight C Container Library
4
Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
6
Original code was written by Chris Schlaeger <cs@kde.org>
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Library General Public
10
License as published by the Free Software Foundation; either
11
version 2 of the License, or (at your option) any later version.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Library General Public License for more details.
18
You should have received a copy of the GNU Library General Public License
19
along with this library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
Boston, MA 02110-1301, USA.
29
#define NIL ((void*) 0)
32
#define destr_ctnr(x, y) zero_destr_ctnr(x, y); x=0
35
struct container* next;
36
struct container* prev;
40
typedef struct container T_CONTAINER;
41
typedef struct container* CONTAINER;
45
typedef void (*DESTR_FUNC)(void*);
46
typedef int (*COMPARE_FUNC)(void*, void*);
49
* Initialize the container @p ctnr.
51
CONTAINER new_ctnr(void);
54
* Remove all entries from @p ctnr and reset its
55
* internal structure. Use @ref new_ctnr() @em before @em
56
* accessing the container again.
58
* Note: use the 'destr_ctnr' macro to get zeroed pointer
61
* @param destr_func The function that is called to
62
* free the single entries.
64
void zero_destr_ctnr(CONTAINER ctnr, DESTR_FUNC destr_func);
67
* Remove all entries from @p ctnr. There is no need to use
68
* @ref new_ctnr() for subsequent access to the container.
71
void empty_ctnr(CONTAINER rootNode);
74
* @return the number of entries in @p ctnr.
76
INDEX level_ctnr(CONTAINER ctnr);
79
* Insert a new entry in container.
81
* @param object A pointer to the object.
82
* @param pos The position where the object should be insert.
84
void insert_ctnr(CONTAINER ctnr, void* object, INDEX pos);
87
* Add a new entry at the end of container.
89
* @param object The object that should be added.
91
void push_ctnr(CONTAINER ctnr, void* object);
94
* Remove an entry from container.
96
* @param pos The position of the object that should be removed.
98
* @return A pointer to the removed object or @p 0L if it doesn't exist.
100
void* remove_at_ctnr(CONTAINER ctnr, INDEX pos);
103
* Remove the first entry of container.
105
* @return A pointer to the removed object or @p 0L if there is now entry.
107
void* pop_ctnr(CONTAINER ctnr);
110
* @return A pointer to the object at position @a pos
111
* or @p 0L if it doesn't exist.
113
void* get_ctnr(CONTAINER ctnr, INDEX pos);
116
* @return The position of a matching entry.
118
* @param compare_func A Pointer to the function that is
119
* called to compare all entries in the
120
* container with the given pattern.
121
* @param pattern The pattern for coparison.
123
INDEX search_ctnr(CONTAINER ctnr, COMPARE_FUNC compare_func, void* pattern);
126
* Swap two objects in container.
128
* @param pos1 Position of the first object.
129
* @param pos2 Position of the second object.
131
void swap_ctnr(CONTAINER ctnr, INDEX pos1, INDEX pos2);
134
* Sort all entries of container.
136
* @param compare_func A Pointer to the function that is
137
* called to compare to entries of the
140
void bsort_ctnr(CONTAINER ctnr, COMPARE_FUNC compare_func);
143
* Use this function to iterate over the container.
145
* for (ptr = first_ctnr(ctnr); ptr; ptr = next_ctnr(ctnr)) {
149
* @return A Pointer to the first object in container.
151
void* first_ctnr(CONTAINER ctnr);
154
* Use this function to iterate over the container.
156
* @return A Pointer to the next object in container.
158
void* next_ctnr(CONTAINER ctnr);
161
* Use this function to remove the current entry while
162
* iterating over the container.
164
* @return A Pointer to the removed object or @p 0L if it doesn't exist.
166
void* remove_ctnr(CONTAINER ctnr);