bazquk dev

Tue, 02 Sep 2025 00:05:29 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 02 Sep 2025 00:05:29 -0500
branch
dev
changeset 155
45d03cf92c23
parent 154
03f34ba55685
child 156
adf3c425c7a9

bazquk

src/direct_product.rs file | annotate | diff | comparison | revisions
src/instance.rs file | annotate | diff | comparison | revisions
src/sets.rs file | annotate | diff | comparison | revisions
--- a/src/direct_product.rs	Mon Sep 01 23:08:27 2025 -0500
+++ b/src/direct_product.rs	Tue Sep 02 00:05:29 2025 -0500
@@ -392,6 +392,8 @@
     D: Decomposition<A>,
     Q: Decomposition<B>,
 {
+    type OwnedInstance = Pair<D::OwnedInstance, Q::OwnedInstance>;
+
     type Decomposition<'b>
         = Pair<D::Decomposition<'b>, Q::Decomposition<'b>>
     where
@@ -441,7 +443,7 @@
     }
 
     #[inline]
-    fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
+    fn cow<'b>(self) -> MyCow<'b, Pair<D::OwnedInstance, Q::OwnedInstance>>
     where
         Self: 'b,
     {
@@ -449,7 +451,7 @@
     }
 
     #[inline]
-    fn own(self) -> Pair<A, B> {
+    fn own(self) -> Pair<D::OwnedInstance, Q::OwnedInstance> {
         Pair(self.0.own(), self.1.own())
     }
 }
@@ -492,7 +494,7 @@
     }
 
     #[inline]
-    fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
+    fn cow<'b>(self) -> MyCow<'b, Pair<D::OwnedInstance, Q::OwnedInstance>>
     where
         Self: 'b,
     {
@@ -500,7 +502,7 @@
     }
 
     #[inline]
-    fn own(self) -> Pair<A, B> {
+    fn own(self) -> Pair<D::OwnedInstance, Q::OwnedInstance> {
         let Pair(ref u, ref v) = self;
         Pair(u.own(), v.own())
     }
--- a/src/instance.rs	Mon Sep 01 23:08:27 2025 -0500
+++ b/src/instance.rs	Tue Sep 02 00:05:29 2025 -0500
@@ -144,6 +144,9 @@
 
 /// Marker type for decompositions to be used with [`Instance`].
 pub trait Decomposition<X: Space>: Sized {
+    /// Owned instance
+    type OwnedInstance: Instance<X, Self>;
+
     /// Possibly owned form of the decomposition
     type Decomposition<'b>: Instance<X, Self>
     where
@@ -156,8 +159,11 @@
     where
         X: 'b;
 
-    /// Left the lightweight reference type into a full decomposition type.
+    /// Lift the lightweight reference type into a full decomposition type.
     fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b>;
+
+    // /// Lift the lightweight reference type into a fully owned type
+    // fn full_lift<'b>(r: Self::Reference<'b>) -> Self::OwnedInstance;
 }
 
 /// Most common [`Decomposition`] (into `Either<X, &'b X>`) that allows working with owned
@@ -165,7 +171,9 @@
 #[derive(Copy, Clone, Debug)]
 pub struct BasicDecomposition;
 
-impl<X: Space> Decomposition<X> for BasicDecomposition {
+impl<X: Space + Clone> Decomposition<X> for BasicDecomposition {
+    type OwnedInstance = X;
+
     type Decomposition<'b>
         = MyCow<'b, X>
     where
@@ -207,14 +215,14 @@
         Self: 'b;
 
     /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary.
-    fn own(self) -> X;
+    fn own(self) -> D::OwnedInstance;
 
     // ************** automatically implemented methods below from here **************
 
     /// Returns an owned instance or reference to `X`, converting non-true instances when necessary.
     ///
     /// Default implementation uses [`Self::own`]. Consumes the input.
-    fn cow<'b>(self) -> MyCow<'b, X>
+    fn cow<'b>(self) -> MyCow<'b, D::OwnedInstance>
     where
         Self: 'b,
     {
@@ -225,7 +233,7 @@
     /// Evaluates `f` on a reference to self.
     ///
     /// Default implementation uses [`Self::cow`]. Consumes the input.
-    fn eval<'b, R>(self, f: impl FnOnce(&X) -> R) -> R
+    fn eval<'b, R>(self, f: impl FnOnce(&D::OwnedInstance) -> R) -> R
     where
         X: 'b,
         Self: 'b,
@@ -237,7 +245,11 @@
     /// Evaluates `f` or `g` depending on whether a reference or owned value is available.
     ///
     /// Default implementation uses [`Self::cow`]. Consumes the input.
-    fn either<'b, R>(self, f: impl FnOnce(X) -> R, g: impl FnOnce(&X) -> R) -> R
+    fn either<'b, R>(
+        self,
+        f: impl FnOnce(D::OwnedInstance) -> R,
+        g: impl FnOnce(&D::OwnedInstance) -> R,
+    ) -> R
     where
         Self: 'b,
     {
@@ -248,7 +260,7 @@
     }
 }
 
-impl<X: Space> Instance<X, BasicDecomposition> for X {
+impl<X: Space + Clone> Instance<X, BasicDecomposition> for X {
     #[inline]
     fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R
     where
@@ -281,7 +293,7 @@
     }
 }
 
-impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a X {
+impl<'a, X: Space + Clone> Instance<X, BasicDecomposition> for &'a X {
     #[inline]
     fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R
     where
@@ -302,7 +314,7 @@
 
     #[inline]
     fn own(self) -> X {
-        self.into_owned()
+        self.clone()
     }
 
     #[inline]
@@ -314,7 +326,7 @@
     }
 }
 
-impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a mut X {
+impl<'a, X: Space + Clone> Instance<X, BasicDecomposition> for &'a mut X {
     #[inline]
     fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R
     where
@@ -335,7 +347,7 @@
 
     #[inline]
     fn own(self) -> X {
-        self.into_owned()
+        self.clone()
     }
 
     #[inline]
@@ -347,7 +359,7 @@
     }
 }
 
-impl<'a, X: Space> Instance<X, BasicDecomposition> for MyCow<'a, X> {
+impl<'a, X: Space + Clone> Instance<X, BasicDecomposition> for MyCow<'a, X> {
     #[inline]
     fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R
     where
--- a/src/sets.rs	Mon Sep 01 23:08:27 2025 -0500
+++ b/src/sets.rs	Tue Sep 02 00:05:29 2025 -0500
@@ -3,7 +3,7 @@
 */
 
 use crate::euclidean::Euclidean;
-use crate::instance::{Instance, Space};
+use crate::instance::{BasicDecomposition, Instance, Space};
 use crate::loc::Loc;
 use crate::types::*;
 use serde::Serialize;
@@ -51,7 +51,7 @@
         impl<U,Idx> Set<U> for $range<Idx>
         where
             Idx : PartialOrd<U>,
-            U : PartialOrd<Idx> + Space,
+            U : PartialOrd<Idx> + Space<Decomp=BasicDecomposition> + Clone,
             Idx : PartialOrd
         {
             #[inline]
@@ -85,10 +85,7 @@
 {
     #[inline]
     pub fn new(orthogonal: A, offset: F) -> Self {
-        Halfspace {
-            orthogonal: orthogonal,
-            offset: offset,
-        }
+        Halfspace { orthogonal: orthogonal, offset: offset }
     }
 }
 

mercurial