Skip to content

Commit

Permalink
Update get_parent_id to clarify its unsafe and suppress warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed committed Dec 5, 2024
1 parent 6a9a4a4 commit 052d86f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/log_surgeon/finite_automata/PrefixTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ auto PrefixTree::get_reversed_positions(id_t const node_id) const -> std::vector
auto current_node{m_nodes[node_id]};
while (false == current_node.is_root()) {
reversed_positions.push_back(current_node.get_position());
current_node = m_nodes[current_node.get_parent_node_id().value()];
current_node = m_nodes[current_node.get_parent_id_unsafe()];
}
return reversed_positions;
}
Expand Down
13 changes: 7 additions & 6 deletions src/log_surgeon/finite_automata/PrefixTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,23 @@ class PrefixTree {
private:
class Node {
public:
Node(std::optional<id_t> const parent_node_id, position_t const position)
: m_parent_node_id{parent_node_id},
Node(std::optional<id_t> const parent_id, position_t const position)
: m_parent_id{parent_id},
m_position{position} {}

[[nodiscard]] auto is_root() const -> bool { return false == m_parent_node_id.has_value(); }
[[nodiscard]] auto is_root() const -> bool { return false == m_parent_id.has_value(); }

[[nodiscard]] auto get_parent_node_id() const -> std::optional<id_t> {
return m_parent_node_id;
[[nodiscard]] auto get_parent_id_unsafe() const -> id_t {
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
return m_parent_id.value();
}

auto set_position(position_t const position) -> void { m_position = position; }

[[nodiscard]] auto get_position() const -> position_t { return m_position; }

private:
std::optional<id_t> m_parent_node_id;
std::optional<id_t> m_parent_id;
position_t m_position;
};

Expand Down

0 comments on commit 052d86f

Please sign in to comment.