Skip to content

Commit b130a3a

Browse files
committed
Removed alternative function parameter, better test case handling for Core and Multithreaded
1 parent 3e62406 commit b130a3a

File tree

3 files changed

+79
-471
lines changed

3 files changed

+79
-471
lines changed

inc/llist.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ llist llist_create ( comperator compare_func, equal equal_func, unsigned flags )
102102
* @param[in] destructor alternative destructor, if the previous param is true,
103103
* if NULL is provided standard library c free() will be used
104104
*/
105-
void llist_destroy ( llist list, bool destroy_nodes, node_func destructor);
105+
void llist_destroy ( llist list, bool destroy_nodes, node_func destructor );
106106

107107

108108
/**
@@ -129,23 +129,21 @@ int llist_insert_node ( llist list, llist_node new_node, llist_node pos_node, i
129129
* @brief Delete a node from a list
130130
* @param[in] list the list to operator upon
131131
* @param[in] node the node to delete
132-
* @param[in] alternative an alternative equality function
133132
* @param[in] destroy_node Should we run a destructor
134133
* @param[in] destructor function, if NULL is provided, free() will be used
135134
* @return int LLIST_SUCCESS if success
136135
*/
137-
int llist_delete_node ( llist list, llist_node node, equal alternative, bool destroy_node, node_func destructor );
136+
int llist_delete_node ( llist list, llist_node node, bool destroy_node, node_func destructor );
138137

139138
/**
140139
* @brief Finds a node in a list
141140
* @param[in] list the list to operator upon
142141
* @param[in] data the data to find
143142
* @param[out] found a pointer for found node.
144143
* this pointer can be used only if llist_find_node returned LLIST_SUCCESS
145-
* @param[in] alternative an alternative equality function
146144
* @return LLIST_SUCCESS if success
147145
*/
148-
int llist_find_node ( llist list, void * data, llist_node * found, equal alternative );
146+
int llist_find_node ( llist list, void * data, llist_node * found );
149147

150148
/**
151149
* @brief operate on each element of the list
@@ -162,29 +160,28 @@ int llist_for_each ( llist list, node_func func );
162160
* @param[in] arg passed to func
163161
* @return int LLIST_SUCCESS if success
164162
*/
165-
int llist_for_each_arg ( llist list, node_func_arg func, void * arg);
163+
int llist_for_each_arg ( llist list, node_func_arg func, void * arg );
166164
/**
167165
* @brief sort a lists
168166
* @param[in] list the list to operator upon
169-
* @param[in] alternative if unless an alternative comparator function is provided the default will be used
170167
* @param[in] flags
171168
* @return int LLIST_SUCCESS if success
172169
*/
173-
int llist_sort ( llist list, comperator alternative, int flags );
170+
int llist_sort ( llist list, int flags );
174171

175172
/**
176173
* @brief Returns the head node of the list
177174
* @param[in] list the list to operate on
178175
* @return the head node, NULL on error
179176
*/
180-
llist_node llist_get_head (llist list);
177+
llist_node llist_get_head ( llist list );
181178

182179
/**
183180
* @brief Returns the tail node of the list
184181
* @param[in] list the list to operate on
185182
* @return the tail node, NULL on error
186183
*/
187-
llist_node llist_get_tail (llist list);
184+
llist_node llist_get_tail ( llist list );
188185

189186

190187
/**
@@ -193,28 +190,28 @@ llist_node llist_get_tail (llist list);
193190
* @param[in] node the node to push
194191
* @return int LLIST_SUCCESS if success
195192
*/
196-
int llist_push (llist list, llist_node node);
193+
int llist_push ( llist list, llist_node node );
197194

198195
/**
199196
* @brief peek at the head of the list
200197
* @param[in] list the list to operate on
201198
* @return llist_node the head node
202199
*/
203-
llist_node llist_peek(llist list);
200+
llist_node llist_peek( llist list );
204201

205202
/**
206203
* @brief pop the head of the list
207204
* @param[in] list the list to operate on
208205
* @return llist_node the head node
209206
*/
210-
llist_node llist_pop(llist list);
207+
llist_node llist_pop( llist list );
211208

212209
/**
213210
* @brief return the number of elements in the list
214211
* @param[in] list the list to operate on
215212
* @return int number of elements in the list or -1 if error
216213
*/
217-
int llist_size(llist list);
214+
int llist_size( llist list );
218215

219216
/**
220217
* @brief concatenate the second list to the first list
@@ -224,50 +221,45 @@ int llist_size(llist list);
224221
* Remember to call llist_destroy() on the second list (if it was created by llist_create())
225222
* @return int LLIST_SUCCESS if success
226223
*/
227-
int llist_concat(llist first, llist second);
224+
int llist_concat( llist first, llist second );
228225

229226
/**
230227
* @brief merge the second list to the first list
231228
* @param[in] first the list to operate on
232229
* @param[in] second the list to operate on
233-
* @param[in] alternative Alternative comparator function, if NULL is provided, the default comparator of the first list will be used
234230
* @warning The nodes from the second list will be deleted and merged to the first list
235231
* Remember to call llist_destroy() on the second list (if it was created by llist_create())
236232
* @return int LLIST_SUCCESS if success
237233
*/
238-
int llist_merge(llist first, llist second, comperator alternative);
234+
int llist_merge( llist first, llist second );
239235

240236

241237
/**
242238
* @brief get the maximum node in a given list
243239
* @param[in] list the list to operate upon
244-
* @param[in] alternative an alternative comparator function
245-
* if NULL is provided, the default comparator will be used
246240
* @return the maximum node
247241
*/
248-
llist_node llist_get_max(llist list, comperator alternative);
242+
llist_node llist_get_max( llist list );
249243

250244
/**
251245
* @brief get the minimum node in a given list
252246
* @param[in] list the list to operate upon
253-
* @param[in] alternative an alternative comparator function
254-
* if NULL is provided, the default comparator will be used
255247
* @return the minimum node
256248
*/
257-
llist_node llist_get_min(llist list, comperator alternative);
249+
llist_node llist_get_min( llist list );
258250

259251
/**
260252
* @brief Reverse a list
261253
* @param[in] list the list to operate upon
262254
* @return int LLIST_SUCCESS if success
263255
*/
264-
int llist_reverse(llist list);
256+
int llist_reverse( llist list );
265257

266258
/**
267259
* @brief check if list is empty
268260
* @param[in] list the list to operate upon
269261
* @return bool True if list is empty
270262
*/
271-
bool llist_is_empty(llist list);
263+
bool llist_is_empty( llist list );
272264

273265
#endif /* LLIST_H_ */

src/llist.c

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ int llist_add_node ( llist list, llist_node node, int flags )
235235
return LLIST_SUCCESS;
236236
}
237237

238-
int llist_delete_node ( llist list, llist_node node, equal alternative,
239-
bool destroy_node, node_func destructor )
238+
int llist_delete_node ( llist list, llist_node node,
239+
bool destroy_node, node_func destructor )
240240
{
241241
_list_node *iterator;
242242
_list_node *temp;
@@ -249,12 +249,7 @@ int llist_delete_node ( llist list, llist_node node, equal alternative,
249249

250250
actual_equal = ( ( _llist * ) list )->equal_func;
251251

252-
if ( alternative )
253-
{
254-
actual_equal = alternative;
255-
}
256-
257-
if ( actual_equal == NULL )
252+
if ( actual_equal == NULL )
258253
{
259254
return LLIST_EQUAL_MISSING;
260255
}
@@ -465,8 +460,7 @@ int llist_insert_node ( llist list, llist_node new_node, llist_node pos_node,
465460

466461
}
467462

468-
int llist_find_node ( llist list, void *data, llist_node *found,
469-
equal alternative )
463+
int llist_find_node ( llist list, void *data, llist_node *found)
470464
{
471465
_list_node *iterator;
472466
equal actual_equal;
@@ -477,11 +471,6 @@ int llist_find_node ( llist list, void *data, llist_node *found,
477471

478472
actual_equal = ( ( _llist * ) list )->equal_func;
479473

480-
if ( alternative )
481-
{
482-
actual_equal = alternative;
483-
}
484-
485474
if ( actual_equal == NULL )
486475
{
487476
return LLIST_EQUAL_MISSING;
@@ -670,27 +659,20 @@ int llist_reverse ( llist list )
670659
return LLIST_SUCCESS;
671660
}
672661

673-
int llist_sort ( llist list, comperator alternative, int flags )
662+
int llist_sort ( llist list, int flags )
674663
{
675664

676665
comperator cmp;
677666
if ( list == NULL )
678667
{
679668
return LLIST_NULL_ARGUMENT;
680669
}
681-
if ( alternative )
682-
{
683-
cmp = alternative;
684-
}
685-
_llist *thelist = ( _llist * ) list;
670+
671+
_llist *thelist = ( _llist * ) list;
686672

687673
cmp = thelist->comp_func;
688-
if ( alternative )
689-
{
690-
cmp = alternative;
691-
}
692674

693-
if ( cmp == NULL )
675+
if ( cmp == NULL )
694676
{
695677
return LLIST_COMPERATOR_MISSING;
696678
}
@@ -810,20 +792,20 @@ static _list_node *listsort ( _list_node *list, _list_node ** updated_tail, comp
810792
* TODO: Implement the below functions
811793
*/
812794

813-
int llist_merge ( llist first, llist second, comperator alternative )
795+
int llist_merge ( llist first, llist second)
814796
{
815797
assert (1 == 0); // Fail, function not implemented yet.
816798
return LLIST_NOT_IMPLEMENTED;
817799
}
818800

819801

820-
llist_node llist_get_max(llist list, comperator alternative)
802+
llist_node llist_get_max(llist list)
821803
{
822804
assert (1 == 0); // Fail, function not implemented yet.
823805
return NULL;
824806
}
825807

826-
llist_node llist_get_min(llist list, comperator alternative)
808+
llist_node llist_get_min(llist list)
827809
{
828810
assert (1 == 0); // Fail, function not implemented yet.
829811
return NULL;

0 commit comments

Comments
 (0)