@@ -20,7 +20,7 @@ class adjacency_list final {
2020 using edge_type = typename GraphTraits::edge_type;
2121 using edge_directional_tag = typename GraphTraits::edge_directional_tag;
2222
23- using edge_list_type = std::vector<specialized::al_edge_frame >;
23+ using edge_list_type = std::vector<specialized::edge_list_item >;
2424 using edge_iterator_type =
2525 types::dereferencing_iterator<typename edge_list_type::const_iterator>;
2626
@@ -102,61 +102,92 @@ class adjacency_list final {
102102 specialized_impl::add_edges_from (*this , edge_ids, source_id, target_ids);
103103 }
104104
105- [[nodiscard]] bool has_edge (const types::id_type first_id, const types::id_type second_id)
106- const {
107- const auto & adjacent_edges = this ->_list [first_id];
108- return std::ranges::find_if (
109- adjacent_edges,
110- [first_id, second_id](const auto & frame) {
111- // TODO: align
112- return specialized_impl::is_edge_incident_with (edge, second_id, first_id);
113- }
114- )
115- != adjacent_edges.end ();
105+ [[nodiscard]] gl_attr_force_inline bool has_edge (
106+ const types::id_type source_id, const types::id_type target_id
107+ ) const {
108+ return std::ranges::contains (this ->_list [source_id], target_id, [](const auto & item) {
109+ return item.target_id ;
110+ });
116111 }
117112
118113 [[nodiscard]] gl_attr_force_inline bool has_edge (const edge_type& edge) const {
119- // find the edge by address
120114 return std::ranges::contains (
121- this ->_list [edge.first ()], specialized::al_edge_frame {edge.id (), edge.second ()}
115+ this ->_list [edge.first ()], specialized::edge_list_item {edge.id (), edge.second ()}
122116 );
123117 }
124118
125- [[nodiscard]] std::optional<types::id_type> get_edge_id (
126- const types::id_type first_id , const types::id_type second_id
119+ [[nodiscard]] std::optional<edge_type> get_edge (
120+ const types::id_type source_id , const types::id_type target_id
127121 ) const {
128- const auto & adjacent_edges = this ->_list [first_id ];
129- const auto frame_it = std::ranges::find (adjacent_edges, second_id , [](const auto & frame ) {
130- return frame .target_id ;
122+ const auto & adjacent_edges = this ->_list [source_id ];
123+ const auto item_it = std::ranges::find (adjacent_edges, target_id , [](const auto & item ) {
124+ return item .target_id ;
131125 });
132- if (it == adjacent_edges.cend ())
126+ if (item_it == adjacent_edges.cend ())
133127 return std::nullopt ;
134- return return frame_it-> id ;
128+ return std::make_optional<edge_type>(source_id, target_id) ;
135129 }
136130
137- [[nodiscard]] std::vector<types::id_type> get_edge_ids (
138- const types::id_type first_id, const types::id_type second_id
131+ [[nodiscard]] std::optional<edge_type> get_edge (
132+ const types::id_type source_id,
133+ const types::id_type target_id,
134+ const auto & edge_properties_map
139135 ) const {
140- const auto & adjacent_edges = this ->_list [first_id];
141-
142- std::vector<types::id_type> ids;
143- ids.reserve (adjacent_edges.size ());
136+ const auto & adjacent_edges = this ->_list [source_id];
137+ const auto item_it = std::ranges::find (adjacent_edges, target_id, [](const auto & item) {
138+ return item.target_id ;
139+ });
140+ if (item_it == adjacent_edges.cend ())
141+ return std::nullopt ;
142+ return std::make_optional<edge_type>(
143+ item_it->id , source_id, target_id, edge_properties_map[item_it->id ]
144+ );
145+ }
144146
145- for (const auto & frame : adjacent_edges)
146- if (specialized_impl::is_edge_incident_with (frame, second_id, first_id)) // TODO: align
147- matching_edges.emplace_back (frame.id );
147+ [[nodiscard]] auto get_edges (const types::id_type source_id, const types::id_type target_id)
148+ const {
149+ return this ->_list [source_id] | std::views::filter ([&target_id](const auto & item) {
150+ return item.target_id == target_id;
151+ })
152+ | std::views::transform ([source_id](const auto & item) {
153+ return edge_type{item.id , source_id, item.target_id };
154+ });
155+ }
148156
149- ids.shrink_to_fit ();
150- return ids;
157+ [[nodiscard]] auto get_edges (
158+ const types::id_type source_id,
159+ const types::id_type target_id,
160+ const auto & edge_properties_map
161+ ) const {
162+ return this ->_list [source_id] | std::views::filter ([&target_id](const auto & item) {
163+ return item.target_id == target_id;
164+ })
165+ | std::views::transform ([source_id, &edge_properties_map](const auto & item) {
166+ return edge_type{
167+ item.id , source_id, item.target_id , edge_properties_map[item.id ]
168+ };
169+ });
151170 }
152171
153172 gl_attr_force_inline void remove_edge (const edge_type& edge) {
154173 specialized_impl::remove_edge (*this , edge);
155174 }
156175
157- [[nodiscard]] gl_attr_force_inline auto adjacent_edge_ids (const types::id_type vertex_id
176+ [[nodiscard]] gl_attr_force_inline auto adjacent_edges (const types::id_type vertex_id) const {
177+ return this ->_list [vertex_id] | std::views::transform ([vertex_id](const auto & item) {
178+ return edge_type{item.id , vertex_id, item.target_id };
179+ });
180+ }
181+
182+ [[nodiscard]] gl_attr_force_inline auto adjacent_edges (
183+ const types::id_type vertex_id, const auto & edge_properties_map
158184 ) const {
159- return this ->_list [vertex_id];
185+ return this ->_list [vertex_id]
186+ | std::views::transform ([vertex_id, &edge_properties_map](const auto & item) {
187+ return edge_type{
188+ item.id , vertex_id, item.target_id , edge_properties_map[item.id ]
189+ };
190+ });
160191 }
161192
162193private:
0 commit comments