linked-list: Remove unused replace() method
Its functionality can be replicated by calling insert_before() followed by remove_at(). Not the other way around, though, because remove_at() changes the enumerator position.
This commit is contained in:
@@ -316,20 +316,6 @@ METHOD(linked_list_t, insert_before, void,
|
||||
this->count++;
|
||||
}
|
||||
|
||||
METHOD(linked_list_t, replace, void*,
|
||||
private_linked_list_t *this, private_enumerator_t *enumerator,
|
||||
void *item)
|
||||
{
|
||||
void *old = NULL;
|
||||
|
||||
if (enumerator->current)
|
||||
{
|
||||
old = enumerator->current->value;
|
||||
enumerator->current->value = item;
|
||||
}
|
||||
return old;
|
||||
}
|
||||
|
||||
METHOD(linked_list_t, get_last, status_t,
|
||||
private_linked_list_t *this, void **item)
|
||||
{
|
||||
@@ -556,7 +542,6 @@ linked_list_t *linked_list_create()
|
||||
.insert_first = _insert_first,
|
||||
.insert_last = _insert_last,
|
||||
.insert_before = (void*)_insert_before,
|
||||
.replace = (void*)_replace,
|
||||
.remove_first = _remove_first,
|
||||
.remove_last = _remove_last,
|
||||
.remove = _remove_,
|
||||
|
||||
@@ -117,16 +117,6 @@ struct linked_list_t {
|
||||
void (*insert_before)(linked_list_t *this, enumerator_t *enumerator,
|
||||
void *item);
|
||||
|
||||
/**
|
||||
* Replaces the item the enumerator currently points to with the given item.
|
||||
*
|
||||
* @param enumerator enumerator with position
|
||||
* @param item item value to replace current item with
|
||||
* @return current item or NULL if the enumerator is at an
|
||||
* invalid position
|
||||
*/
|
||||
void *(*replace)(linked_list_t *this, enumerator_t *enumerator, void *item);
|
||||
|
||||
/**
|
||||
* Remove an item from the list where the enumerator points to.
|
||||
*
|
||||
|
||||
@@ -215,49 +215,9 @@ START_TEST(test_insert_before_empty)
|
||||
END_TEST
|
||||
|
||||
/*******************************************************************************
|
||||
* replace / remove_at
|
||||
* remove_at
|
||||
*/
|
||||
|
||||
START_TEST(test_replace)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
intptr_t x, y;
|
||||
int round;
|
||||
|
||||
round = 1;
|
||||
enumerator = list->create_enumerator(list);
|
||||
while (enumerator->enumerate(enumerator, &x))
|
||||
{
|
||||
ck_assert_int_eq(round, x);
|
||||
y = (intptr_t)list->replace(list, enumerator, (void*)(intptr_t)(6 - round));
|
||||
ck_assert_int_eq(round, y);
|
||||
round++;
|
||||
}
|
||||
list->reset_enumerator(list, enumerator);
|
||||
round = 5;
|
||||
while (enumerator->enumerate(enumerator, &x))
|
||||
{
|
||||
ck_assert_int_eq(round, x);
|
||||
round--;
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_replace_first)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
intptr_t x;
|
||||
|
||||
enumerator = list->create_enumerator(list);
|
||||
x = (intptr_t)list->replace(list, enumerator, (void*)6);
|
||||
ck_assert_int_eq(x, 0);
|
||||
ck_assert(enumerator->enumerate(enumerator, &x));
|
||||
ck_assert_int_eq(x, 1);
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_remove_at)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
@@ -312,6 +272,58 @@ START_TEST(test_remove_at_ends)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_insert_before_remove_at)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
intptr_t x;
|
||||
int round;
|
||||
|
||||
round = 1;
|
||||
enumerator = list->create_enumerator(list);
|
||||
while (enumerator->enumerate(enumerator, &x))
|
||||
{
|
||||
ck_assert_int_eq(round, x);
|
||||
if (round == 2)
|
||||
{ /* this replaces the current item, as insert_before does not change
|
||||
* the enumerator position */
|
||||
list->insert_before(list, enumerator, (void*)42);
|
||||
list->remove_at(list, enumerator);
|
||||
}
|
||||
else if (round == 4)
|
||||
{ /* this does not replace the item, as remove_at moves the enumerator
|
||||
* position to the previous item */
|
||||
list->remove_at(list, enumerator);
|
||||
list->insert_before(list, enumerator, (void*)21);
|
||||
}
|
||||
round++;
|
||||
}
|
||||
ck_assert_int_eq(list->get_count(list), 5);
|
||||
list->reset_enumerator(list, enumerator);
|
||||
round = 1;
|
||||
while (enumerator->enumerate(enumerator, &x))
|
||||
{
|
||||
if (round == 2)
|
||||
{ /* check replaced item */
|
||||
ck_assert_int_eq(42, x);
|
||||
}
|
||||
else if (round == 3)
|
||||
{ /* check misplaced item */
|
||||
ck_assert_int_eq(21, x);
|
||||
}
|
||||
else if (round == 4)
|
||||
{ /* check misplaced item */
|
||||
ck_assert_int_eq(3, x);
|
||||
}
|
||||
else
|
||||
{
|
||||
ck_assert_int_eq(round, x);
|
||||
}
|
||||
round++;
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/*******************************************************************************
|
||||
* create list from enumerator
|
||||
*/
|
||||
@@ -366,10 +378,9 @@ Suite *linked_list_enumerator_suite_create()
|
||||
|
||||
tc = tcase_create("modify");
|
||||
tcase_add_checked_fixture(tc, setup_list, teardown_list);
|
||||
tcase_add_test(tc, test_replace);
|
||||
tcase_add_test(tc, test_replace_first);
|
||||
tcase_add_test(tc, test_remove_at);
|
||||
tcase_add_test(tc, test_remove_at_ends);
|
||||
tcase_add_test(tc, test_insert_before_remove_at);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("create_from_enumerator");
|
||||
|
||||
Reference in New Issue
Block a user