Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/graaflib/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions include/graaflib/graph.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ graph<VERTEX_T, EDGE_T, GRAPH_TYPE_V>::get_edge(
return get_edge(vertex_id_lhs, vertex_id_rhs);
}

static const std::unordered_set<vertex_id_t> empty_list;

template <typename VERTEX_T, typename EDGE_T, graph_type GRAPH_TYPE_V>
typename graph<VERTEX_T, EDGE_T, GRAPH_TYPE_V>::vertices_t
const typename graph<VERTEX_T, EDGE_T, GRAPH_TYPE_V>::vertices_t&
graph<VERTEX_T, EDGE_T, GRAPH_TYPE_V>::get_neighbors(
vertex_id_t vertex_id) const {
if (!adjacency_list_.contains(vertex_id)) {
return {};
return empty_list;
}
return adjacency_list_.at(vertex_id);
}
Expand Down