@@ -38,14 +38,20 @@ class hypergraph final {
3838 hypergraph (const hypergraph&) = delete ;
3939 hypergraph& operator =(const hypergraph&) = delete ;
4040
41- hypergraph () = default ;
42-
43- hypergraph (const types::size_type n_vertices) : _n_vertices(n_vertices) {
41+ hypergraph (const types::size_type n_vertices = 0uz, const types::size_type n_hyperedges = 0uz)
42+ : _n_vertices(n_vertices), _n_hyperedges(n_hyperedges) {
4443 if constexpr (type_traits::c_non_empty_properties<vertex_properties_type>) {
4544 this ->_vertex_properties .reserve (n_vertices);
4645 for (const auto _ : this ->vertex_ids ())
4746 this ->_vertex_properties .push_back (std::make_unique<vertex_properties_type>());
4847 }
48+
49+ if constexpr (type_traits::c_non_empty_properties<hyperedge_properties_type>) {
50+ this ->_hyperedge_properties .reserve (n_hyperedges);
51+ for (const auto _ : this ->hyperedge_ids ())
52+ this ->_hyperedge_properties .push_back (std::make_unique<hyperedge_properties_type>()
53+ );
54+ }
4955 }
5056
5157 // --- general methods ---
@@ -71,8 +77,8 @@ class hypergraph final {
7177 requires(type_traits::c_non_empty_properties<vertex_properties_type>)
7278 {
7379 return this ->_vertex_properties | std::views::enumerate
74- | std::views::transform ([](const auto & x ) {
75- const auto & [id, ptr] = x ;
80+ | std::views::transform ([](const auto & property_item ) {
81+ const auto & [id, ptr] = property_item ;
7682 return vertex_type{static_cast <types::id_type>(id), *ptr};
7783 });
7884 }
@@ -199,6 +205,147 @@ class hypergraph final {
199205 return *this ->_vertex_properties [id];
200206 }
201207
208+ // --- hyperedge methods ---
209+
210+ [[nodiscard]] gl_attr_force_inline auto hyperedges () const
211+ requires(type_traits::c_empty_properties<hyperedge_properties_type>)
212+ {
213+ return this ->hyperedge_ids ()
214+ | std::views::transform ([](const types::id_type id) { return hyperedge_type{id}; });
215+ }
216+
217+ [[nodiscard]] gl_attr_force_inline auto hyperedges () const
218+ requires(type_traits::c_non_empty_properties<hyperedge_properties_type>)
219+ {
220+ return this ->_hyperedge_properties | std::views::enumerate
221+ | std::views::transform ([](const auto & property_item) {
222+ const auto & [id, ptr] = property_item;
223+ return vertex_type{static_cast <types::id_type>(id), *ptr};
224+ });
225+ }
226+
227+ [[nodiscard]] gl_attr_force_inline auto hyperedge_ids () const noexcept {
228+ return std::views::iota (constants::initial_id, this ->_n_hyperedges );
229+ }
230+
231+ // [[nodiscard]] vertex_type get_vertex(const types::id_type vertex_id) const {
232+ // this->_verify_vertex_id(vertex_id);
233+ // if constexpr (type_traits::c_non_empty_properties<vertex_properties_type>)
234+ // return vertex_type{vertex_id, *this->_vertex_properties[vertex_id]};
235+ // else
236+ // return vertex_type{vertex_id};
237+ // }
238+
239+ // [[nodiscard]] gl_attr_force_inline bool has_vertex(const types::id_type vertex_id) const {
240+ // return vertex_id < this->_n_vertices;
241+ // }
242+
243+ // [[nodiscard]] gl_attr_force_inline bool has_vertex(const vertex_type& vertex) const {
244+ // return this->has_vertex(vertex.id());
245+ // }
246+
247+ // vertex_type add_vertex() {
248+ // // this->_impl.add_vertex();
249+ // const auto new_vertex_id = this->_n_vertices++;
250+
251+ // if constexpr (type_traits::c_non_empty_properties<vertex_properties_type>)
252+ // return vertex_type{
253+ // new_vertex_id,
254+ // *this->_vertex_properties.emplace_back(std::make_unique<vertex_properties_type>())
255+ // };
256+ // else
257+ // return vertex_type{new_vertex_id};
258+ // }
259+
260+ // vertex_type add_vertex_with(vertex_properties_type properties)
261+ // requires(type_traits::c_non_empty_properties<vertex_properties_type>)
262+ // {
263+ // // this->_impl.add_vertex();
264+ // this->_vertex_properties.push_back(
265+ // std::make_unique<vertex_properties_type>(std::move(properties))
266+ // );
267+ // return vertex_type{this->_n_vertices++, *this->_vertex_properties.back()};
268+ // }
269+
270+ // void add_vertices(const types::size_type n) {
271+ // // this->_impl.add_vertices(n);
272+ // this->_n_vertices += n;
273+
274+ // if constexpr (type_traits::c_non_empty_properties<vertex_properties_type>) {
275+ // const auto old_size = this->_vertex_properties.size();
276+ // this->_vertex_properties.reserve(this->_n_vertices);
277+ // for (types::size_type i = old_size; i < this->_n_vertices; ++i)
278+ // this->_vertex_properties.push_back(std::make_unique<vertex_properties_type>());
279+ // }
280+ // }
281+
282+ // void add_vertices_with(
283+ // const type_traits::c_sized_range_of<vertex_properties_type> auto& properties_range
284+ // )
285+ // requires(type_traits::c_non_empty_properties<vertex_properties_type>)
286+ // {
287+ // const auto n = std::ranges::size(properties_range);
288+
289+ // // this->_impl.add_vertices(n);
290+ // this->_n_vertices += n;
291+
292+ // if constexpr (type_traits::c_non_empty_properties<vertex_properties_type>) {
293+ // for (auto& properties : properties_range) {
294+ // this->_vertex_properties.emplace_back(
295+ // std::make_unique<vertex_properties_type>(properties)
296+ // );
297+ // }
298+ // }
299+ // }
300+
301+ // void remove_vertex(const types::size_type vertex_id) {
302+ // this->_verify_vertex_id(vertex_id);
303+ // this->_remove_vertex_impl(vertex_id);
304+ // }
305+
306+ // gl_attr_force_inline void remove_vertex(const vertex_type& vertex) {
307+ // this->remove_vertex(vertex.id());
308+ // }
309+
310+ // void remove_vertices_from(
311+ // const type_traits::c_forward_range_of<types::id_type> auto& vertex_id_range
312+ // ) {
313+ // // sorts the ids in a descending order and removes duplicate ids
314+ // std::set<types::id_type, std::greater<types::id_type>> vertex_id_set(
315+ // std::ranges::begin(vertex_id_range), std::ranges::end(vertex_id_range)
316+ // );
317+
318+ // // TODO: optimize
319+ // for (const auto vertex_id : vertex_id_set)
320+ // this->_remove_vertex_impl(vertex_id);
321+ // }
322+
323+ // void remove_vertices_from(const type_traits::c_sized_range_of<vertex_type> auto& vertex_range) {
324+ // // sort the ids in a descending order and removes duplicate ids
325+ // std::set<vertex_type, std::greater<vertex_type>> vertex_set(
326+ // std::ranges::begin(vertex_range), std::ranges::end(vertex_range)
327+ // );
328+
329+ // // TODO: optimize
330+ // for (const auto& vertex : vertex_set)
331+ // this->_remove_vertex_impl(vertex.id());
332+ // }
333+
334+ // [[nodiscard]] gl_attr_force_inline auto vertex_properties_map() const noexcept
335+ // requires(type_traits::c_non_empty_properties<vertex_properties_type>)
336+ // {
337+ // return util::deref_view(this->_vertex_properties);
338+ // }
339+
340+ // [[nodiscard]] gl_attr_force_inline vertex_properties_type& get_vertex_properties(
341+ // const types::id_type id
342+ // ) const
343+ // requires(type_traits::c_non_empty_properties<vertex_properties_type>)
344+ // {
345+ // this->_verify_vertex_id(id);
346+ // return *this->_vertex_properties[id];
347+ // }
348+
202349private:
203350 // --- vertex methods ---
204351
0 commit comments