diff --git a/include/graaflib/graph.h b/include/graaflib/graph.h index 66359666..1a1e4f78 100644 --- a/include/graaflib/graph.h +++ b/include/graaflib/graph.h @@ -169,7 +169,7 @@ class graph { * @param vertex_id The ID of the vertex * @return vertices_t - A list of neighboring vertices */ - [[nodiscard]] vertices_t get_neighbors(vertex_id_t vertex_id) const; + [[nodiscard]] const vertices_t& get_neighbors(vertex_id_t vertex_id) const; /** * Add a vertex to the graph diff --git a/include/graaflib/graph.tpp b/include/graaflib/graph.tpp index 04194a58..4401cb8b 100644 --- a/include/graaflib/graph.tpp +++ b/include/graaflib/graph.tpp @@ -118,12 +118,14 @@ graph::get_edge( return get_edge(vertex_id_lhs, vertex_id_rhs); } +static const std::unordered_set empty_list; + template -typename graph::vertices_t +const typename graph::vertices_t& graph::get_neighbors( vertex_id_t vertex_id) const { if (!adjacency_list_.contains(vertex_id)) { - return {}; + return empty_list; } return adjacency_list_.at(vertex_id); }