docs/Writerside/topics/list.h.md

changeset 1287
3a3ffc27813f
parent 1244
9a8e781258ac
child 1294
30d7ae76c76a
equal deleted inserted replaced
1286:5492e8ef05f4 1287:3a3ffc27813f
160 ```C 160 ```C
161 #include <cx/list.h> 161 #include <cx/list.h>
162 162
163 void *cxListAt(const CxList *list, size_t index); 163 void *cxListAt(const CxList *list, size_t index);
164 164
165 int cxListSet(CxList *list, size_t index, const void *elem);
166
165 size_t cxListFind(const CxList *list, const void *elem); 167 size_t cxListFind(const CxList *list, const void *elem);
166 168
167 size_t cxListFindRemove(CxList *list, const void *elem); 169 size_t cxListFindRemove(CxList *list, const void *elem);
168 170
169 bool cxListIndexValid(const CxList *list, size_t index); 171 bool cxListIndexValid(const CxList *list, size_t index);
173 175
174 The function `cxListAt()` accesses the element at the specified `index`. 176 The function `cxListAt()` accesses the element at the specified `index`.
175 If the list is storing pointers (i.e. `cxCollectionStoresPointers()` returns `true`), the pointer at the specified index is directly returned. 177 If the list is storing pointers (i.e. `cxCollectionStoresPointers()` returns `true`), the pointer at the specified index is directly returned.
176 Otherwise, a pointer to element at the specified index is returned. 178 Otherwise, a pointer to element at the specified index is returned.
177 If the index is out-of-bounds, the function returns `NULL`. 179 If the index is out-of-bounds, the function returns `NULL`.
180
181 The function `cxListSet()` allows you to modify elements at a specific index in the list.
182 This function replaces the element at the specified `index` with the value pointed to by `elem`.
183 If the list is storing values directly (not pointers), the contents at the memory location `elem` will be copied into the list.
184 If the list is storing pointers, the pointer value itself will be stored.
185 The function returns `0` on success and `1` if the index is out of bounds.
178 186
179 On the other hand, `cxListFind()` searches for the element pointed to by `elem` by comparing each element in the list with the list`s compare function, 187 On the other hand, `cxListFind()` searches for the element pointed to by `elem` by comparing each element in the list with the list`s compare function,
180 and returns the first index when the element was found. 188 and returns the first index when the element was found.
181 Otherwise, the function returns the list size. 189 Otherwise, the function returns the list size.
182 190

mercurial