mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
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:
parent
0558a7bfed
commit
28e5100842
2 changed files with 38 additions and 12 deletions
14
src/List.cc
14
src/List.cc
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue