Skip to content

Commit

Permalink
Add prefix matching for patricia_map
Browse files Browse the repository at this point in the history
  • Loading branch information
mavam committed Mar 19, 2024
1 parent c0731b4 commit 2c60c5a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions libtenzir/include/tenzir/detail/patricia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,29 @@ class patricia_map {
return _find_node(key);
}

auto _prefix_match_node(patricia_key const& key) noexcept -> node_ptr {
return _trie.prefix_match(key);
}

auto _prefix_match_node(patricia_key const& key) const noexcept
-> const_node_ptr {
return _trie.prefix_match(key);
}

template <typename V>
auto _prefix_match_node(V const& value) noexcept -> node_ptr {
typename KeyMaker::template rebind<V>::other key_maker;
auto key = key_maker(value);
return _prefix_match_node(key);
}

template <typename V>
auto _prefix_match_node(V const& value) const noexcept -> const_node_ptr {
typename KeyMaker::template rebind<V>::other key_maker;
auto key = key_maker(value);
return _prefix_match_node(key);
}

public:
patricia_map() noexcept = default;
~patricia_map() noexcept(std::is_nothrow_destructible_v<trie_type>) = default;
Expand Down Expand Up @@ -1837,6 +1860,28 @@ class patricia_map {
return const_iterator();
}

template <typename V>
auto prefix_match(V const& key) noexcept -> iterator {
auto node = _prefix_match_node(key);

if (node && node->value.has_value()) {
return iterator(node);
}

return iterator();
}

template <typename V>
auto prefix_match(V const& key) const noexcept -> const_iterator {
auto node = _prefix_match_node(key);

if (node && node->value.has_value()) {
return const_iterator(node);
}

return const_iterator();
}

template <typename V>
auto contains(V const& key) const noexcept -> bool {
auto node = _find_node(key);
Expand Down

0 comments on commit 2c60c5a

Please sign in to comment.