Add ability for List to be ordered/unordered

This fixes a "bug" with List where remove_nth() can be an O(n) operation when it doesn't
need to be. remove_nth for lists that don't necessarily need to keep an order can be an
O(1) operation instead.
This commit is contained in:
Tim Wojtulewicz 2020-04-30 13:26:00 -07:00
parent 0558a7bfed
commit 28e5100842
2 changed files with 38 additions and 12 deletions

View file

@ -114,3 +114,17 @@ TEST_CASE("plists")
delete v;
list.clear();
}
TEST_CASE("unordered list operation")
{
List<int, LIST_UNORDERED> list({1, 2, 3, 4});
CHECK(list.size() == 4);
// An unordered list doesn't maintain the ordering of the elements when
// one is removed. It just swaps the last element into the hole.
list.remove(2);
CHECK(list.size() == 3);
CHECK(list[0] == 1);
CHECK(list[1] == 4);
CHECK(list[2] == 3);
}