diff --git a/AK/Tests/TestTrie.cpp b/AK/Tests/TestTrie.cpp index cae1b5b63f0..853b9ff18a8 100644 --- a/AK/Tests/TestTrie.cpp +++ b/AK/Tests/TestTrie.cpp @@ -71,10 +71,17 @@ TEST_CASE(iterate) for (size_t i = 0; i < input.size(); ++i) input[i] = i; + bunch_of_numbers.insert(input.begin(), input.end()); + // Iteration order is preorder (order between adjacent nodes is not defined, but parents come before children) // in this case, the tree is linear. size_t i = 0; + bool is_root = true; for (auto& node : bunch_of_numbers) { + if (is_root) { + is_root = false; + continue; + } EXPECT_EQ(input[i], node.value()); ++i; } diff --git a/AK/Trie.h b/AK/Trie.h index ae9f52806f9..c90989c8c11 100644 --- a/AK/Trie.h +++ b/AK/Trie.h @@ -183,6 +183,21 @@ public: return static_cast(*last_root_node); } + template + BaseType& insert( + const It& begin, const It& end, MetadataType metadata, ProvideMetadataFunction provide_missing_metadata) requires(!IsSame::value) + { + auto it = begin; + return insert(it, end, move(metadata), move(provide_missing_metadata)); + } + + template + BaseType& insert(const It& begin, const It& end) requires(IsSame::value) + { + auto it = begin; + return insert(it, end); + } + ConstIterator begin() const { return ConstIterator(*this); } ConstIterator end() const { return ConstIterator::end(); }