1313#include < hgraph/types/time_series_visitor.h>
1414
1515namespace hgraph {
16- struct SetDelta : nb::intrusive_base {
17- using ptr = nb::ref<SetDelta>;
18-
19- virtual ~SetDelta () = default ;
20-
21- /* *
22- * Get the elements that were added in this delta
23- * @return Reference to the set of added elements
24- */
25- [[nodiscard]] virtual nb::object py_added () const = 0;
26-
27- /* *
28- * Get the elements that were removed in this delta
29- * @return Reference to the set of removed elements
30- */
31- [[nodiscard]] virtual nb::object py_removed () const = 0;
32-
33- [[nodiscard]] virtual nb::object py_type () const = 0;
34-
35- [[nodiscard]] virtual size_t hash () const = 0;
36-
37- // Default to False, then the overrides will sort out the rest
38- [[nodiscard]] virtual bool operator ==(const SetDelta &other) const = 0 ;
39-
40- static void register_with_nanobind (nb::module_ &m);
41- };
42-
4316 template <typename T>
44- struct SetDelta_T : SetDelta {
45- using ptr = nb::ref<SetDelta_T<T> >;
17+ struct SetDelta_T {
4618 using scalar_type = T;
4719 using collection_type = std::unordered_set<T>;
4820
@@ -54,23 +26,21 @@ namespace hgraph {
5426 requires (std::is_same_v<U, nb::object>)
5527 SetDelta_T (collection_type added, collection_type removed, nb::object tp);
5628
57- [[nodiscard]] nb::object py_added () const override ;
29+ [[nodiscard]] nb::object py_added () const ;
5830
59- [[nodiscard]] nb::object py_removed () const override ;
31+ [[nodiscard]] nb::object py_removed () const ;
6032
6133 [[nodiscard]] const collection_type &added () const ;
6234
6335 [[nodiscard]] const collection_type &removed () const ;
6436
65- [[nodiscard]] bool operator ==(const SetDelta &other) const override ;
66-
6737 [[nodiscard]] bool operator ==(const SetDelta_T<T> &other) const ;
6838
69- [[nodiscard]] size_t hash () const override ;
39+ [[nodiscard]] size_t hash () const ;
7040
71- [[nodiscard]] nb::ref< SetDelta_T<T> > operator +(const SetDelta_T<T> &other) const ;
41+ [[nodiscard]] SetDelta_T<T> operator +(const SetDelta_T<T> &other) const ;
7242
73- [[nodiscard]] nb::object py_type () const override ;
43+ [[nodiscard]] nb::object py_type () const ;
7444
7545 private:
7646 collection_type _added;
@@ -79,13 +49,12 @@ namespace hgraph {
7949 };
8050
8151 template <typename T>
82- SetDelta_T<T>::ptr make_set_delta (std::unordered_set<T> added, std::unordered_set<T> removed) {
83- auto v{new SetDelta_T<T>(std::move (added), std::move (removed))};
84- return typename SetDelta_T<T>::ptr (v);
52+ SetDelta_T<T> make_set_delta (std::unordered_set<T> added, std::unordered_set<T> removed) {
53+ return SetDelta_T<T>(std::move (added), std::move (removed));
8554 }
8655
8756 template <>
88- inline SetDelta_T<nb::object>::ptr make_set_delta (std::unordered_set<nb::object> added,
57+ inline SetDelta_T<nb::object> make_set_delta (std::unordered_set<nb::object> added,
8958 std::unordered_set<nb::object> removed) {
9059 nb::object tp;
9160 if (!added.empty ()) {
@@ -95,7 +64,7 @@ namespace hgraph {
9564 } else {
9665 tp = get_object ();
9766 }
98- return new SetDelta_T<nb::object>(added, removed, tp);
67+ return SetDelta_T<nb::object>(added, removed, tp);
9968 }
10069
10170 template <typename T_TS>
@@ -189,7 +158,6 @@ namespace hgraph {
189158 using element_type = T_Key;
190159 using collection_type = std::unordered_set<T_Key>;
191160 using set_delta = SetDelta_T<T_Key>;
192- using set_delta_ptr = nb::ref<set_delta>;
193161
194162 static constexpr bool is_py_object = std::is_same_v<T_Key, nb::object>;
195163
@@ -327,7 +295,6 @@ namespace hgraph {
327295 using element_type = typename TimeSeriesSetOutput_T<T>::element_type;
328296 using collection_type = typename TimeSeriesSetOutput_T<T>::collection_type;
329297 using set_delta = typename TimeSeriesSetOutput_T<T>::set_delta;
330- using set_delta_ptr = nb::ref<typename TimeSeriesSetOutput_T<T>::set_delta>;
331298
332299 [[nodiscard]] nb::object py_value () const override ;
333300
@@ -351,7 +318,7 @@ namespace hgraph {
351318
352319 [[nodiscard]] const collection_type &value () const ;
353320
354- [[nodiscard]] set_delta_ptr delta_value () const ;
321+ [[nodiscard]] set_delta delta_value () const ;
355322
356323 [[nodiscard]] bool contains (const element_type &item) const ;
357324
@@ -406,6 +373,7 @@ namespace hgraph {
406373 mutable collection_type _removed{};
407374 };
408375
376+ void register_set_delta_with_nanobind (nb::module_ & m);
409377 void tss_register_with_nanobind (nb::module_ & m);
410378} // namespace hgraph
411379
0 commit comments