2020#include < memory>
2121#include < nanobind/nanobind.h>
2222#include < nanobind/trampoline.h>
23+ #include < nanobind/intrusive/counter.h>
24+ #include < nanobind/intrusive/ref.h>
2325
2426#ifndef _TUPLE_POLICY_HPP_
2527#define _TUPLE_POLICY_HPP_
@@ -33,10 +35,10 @@ namespace datasketches {
3335 * which native Python policies ultimately inherit. The actual
3436 * policies implement TuplePolicy, as shown in TuplePolicy.py
3537 */
36- struct tuple_policy {
37- virtual nb::object create_summary () = 0;
38- virtual nb::object update_summary (nb::object& summary, const nb::object& update) = 0;
39- virtual nb::object operator ()(nb::object& summary, const nb::object& update) = 0;
38+ struct tuple_policy : public nb ::intrusive_base {
39+ virtual nb::object create_summary () const = 0;
40+ virtual nb::object update_summary (nb::object& summary, const nb::object& update) const = 0;
41+ virtual nb::object operator ()(nb::object& summary, const nb::object& update) const = 0;
4042 virtual ~tuple_policy () = default ;
4143};
4244
@@ -53,7 +55,7 @@ struct TuplePolicy : public tuple_policy {
5355 *
5456 * @return nb::object representing a new summary
5557 */
56- nb::object create_summary () override {
58+ nb::object create_summary () const override {
5759 NB_OVERRIDE_PURE (
5860 create_summary, // Name of function in C++ (must match Python name)
5961 // Argument(s) -- if any
@@ -67,7 +69,7 @@ struct TuplePolicy : public tuple_policy {
6769 * @param update The new value with which to update the summary
6870 * @return nb::object The updated summary
6971 */
70- nb::object update_summary (nb::object& summary, const nb::object& update) override {
72+ nb::object update_summary (nb::object& summary, const nb::object& update) const override {
7173 NB_OVERRIDE_PURE (
7274 update_summary, // Name of function in C++ (must match Python name)
7375 summary, update // Arguments
@@ -81,7 +83,7 @@ struct TuplePolicy : public tuple_policy {
8183 * @param update An update to apply to the current summary
8284 * @return nb::object The potentially modified summary
8385 */
84- nb::object operator ()(nb::object& summary, const nb::object& update) override {
86+ nb::object operator ()(nb::object& summary, const nb::object& update) const override {
8587 NB_OVERRIDE_PURE_NAME (
8688 " __call__" , // Name of function in python
8789 operator (), // Name of function in C++
@@ -96,7 +98,7 @@ struct TuplePolicy : public tuple_policy {
9698 * never need to use this directly.
9799 */
98100struct tuple_policy_holder {
99- explicit tuple_policy_holder (std::shared_ptr< tuple_policy> policy) : _policy(policy) {}
101+ explicit tuple_policy_holder (tuple_policy* policy) : _policy(policy) {}
100102 tuple_policy_holder (const tuple_policy_holder& other) : _policy(other._policy) {}
101103 tuple_policy_holder (tuple_policy_holder&& other) : _policy(std::move(other._policy)) {}
102104 tuple_policy_holder& operator =(const tuple_policy_holder& other) { _policy = other._policy ; return *this ; }
@@ -113,7 +115,7 @@ struct tuple_policy_holder {
113115 }
114116
115117 private:
116- std::shared_ptr <tuple_policy> _policy;
118+ nb::ref <tuple_policy> _policy;
117119};
118120
119121/* A degenerate policy used to enable Jaccard Similarity on tuple sketches,
0 commit comments