diff --git a/btypes_big_integer/src/main/cpp/BRelation.hpp b/btypes_big_integer/src/main/cpp/BRelation.hpp index 0219e90efd7bccb451420e6306c7ea93b0c60129..9fff4ac933fb9c61b93ed29ff28791b48a9f54fb 100644 --- a/btypes_big_integer/src/main/cpp/BRelation.hpp +++ b/btypes_big_integer/src/main/cpp/BRelation.hpp @@ -967,6 +967,22 @@ class BRelation : public BObject { return BRelation<T,T>(resultMap); } + static BRelation<BTuple<S,T>,BTuple<S,T>> identity2(const BRelation<S,T>& relation) { + immer::map<BTuple<S,T>,immer::set<BTuple<S,T>, typename BSet<BTuple<S,T>>::Hash, typename BSet<BTuple<S,T>>::HashEqual>, + typename BSet<BTuple<S,T>>::Hash, + typename BSet<BTuple<S,T>>::HashEqual> resultMap; + for(const std::pair<S,immer::set<T, typename BSet<T>::Hash, typename BSet<T>::HashEqual>>& pair : relation.map) { + T domainElement = pair.first; + immer::set<T, typename BSet<T>::Hash, typename BSet<T>::HashEqual> range = pair.second; + for(const T& rangeElement : range) { + immer::set<BTuple<S,T>, typename BSet<BTuple<S,T>>::Hash, typename BSet<BTuple<S,T>>::HashEqual> range; + range = range.insert(BTuple<S,T>(domainElement, rangeElement)); + resultMap = resultMap.set(BTuple<S,T>(domainElement, rangeElement), range); + } + } + return BRelation<BTuple<S,T>,BTuple<S,T>>(resultMap); + } + BRelation<S,S> iterate(const BInteger& n) const { BRelation<S,S> thisRelation = (BRelation<S,S>) *this; BRelation<S,S> result = BRelation<S,S>::identity(this->domain()._union(thisRelation.range())); diff --git a/btypes_primitives/src/main/cpp/BRelation.hpp b/btypes_primitives/src/main/cpp/BRelation.hpp index 12097c5d9f3fe0b0d28e7b265aba63236c7aea3a..f6f4eb08f009513a5e1b0747167681af5006b597 100644 --- a/btypes_primitives/src/main/cpp/BRelation.hpp +++ b/btypes_primitives/src/main/cpp/BRelation.hpp @@ -967,6 +967,23 @@ class BRelation : public BObject { return BRelation<T,T>(resultMap); } + + static BRelation<BTuple<S,T>,BTuple<S,T>> identity2(const BRelation<S,T>& relation) { + immer::map<BTuple<S,T>,immer::set<BTuple<S,T>, typename BSet<BTuple<S,T>>::Hash, typename BSet<BTuple<S,T>>::HashEqual>, + typename BSet<BTuple<S,T>>::Hash, + typename BSet<BTuple<S,T>>::HashEqual> resultMap; + for(const std::pair<S,immer::set<T, typename BSet<T>::Hash, typename BSet<T>::HashEqual>>& pair : relation.map) { + T domainElement = pair.first; + immer::set<T, typename BSet<T>::Hash, typename BSet<T>::HashEqual> range = pair.second; + for(const T& rangeElement : range) { + immer::set<BTuple<S,T>, typename BSet<BTuple<S,T>>::Hash, typename BSet<BTuple<S,T>>::HashEqual> range; + range = range.insert(BTuple<S,T>(domainElement, rangeElement)); + resultMap = resultMap.set(BTuple<S,T>(domainElement, rangeElement), range); + } + } + return BRelation<BTuple<S,T>,BTuple<S,T>>(resultMap); + } + BRelation<S,S> iterate(const BInteger& n) const { BRelation<S,S> thisRelation = (BRelation<S,S>) *this; BRelation<S,S> result = BRelation<S,S>::identity(this->domain()._union(thisRelation.range())); diff --git a/src/main/java/de/hhu/stups/codegenerator/generators/ExpressionGenerator.java b/src/main/java/de/hhu/stups/codegenerator/generators/ExpressionGenerator.java index 03bb7c3a4d95e39e19c4d592fe3faf8f33f65449..b03809d2449afcc8b8b7531c473ed9359915dc0b 100644 --- a/src/main/java/de/hhu/stups/codegenerator/generators/ExpressionGenerator.java +++ b/src/main/java/de/hhu/stups/codegenerator/generators/ExpressionGenerator.java @@ -794,8 +794,13 @@ public class ExpressionGenerator { */ private String generateIdentity(List<String> expressionList, BType type) { ST identity = currentGroup.getInstanceOf("identity"); + if(type instanceof CoupleType) { + TemplateHandler.add(identity, "leftType", typeGenerator.generate(((CoupleType) type).getLeft())); + TemplateHandler.add(identity, "rightType", typeGenerator.generate(((CoupleType) type).getRight())); + } TemplateHandler.add(identity, "type", typeGenerator.generate(type)); TemplateHandler.add(identity, "arg", expressionList.get(0)); + TemplateHandler.add(identity, "relationalArg", type instanceof CoupleType); return identity.render(); } diff --git a/src/main/resources/de/hhu/stups/codegenerator/CppTemplate.stg b/src/main/resources/de/hhu/stups/codegenerator/CppTemplate.stg index 2a6377c51f2064ad7e149e388d13fbcbb1fb72c1..5e8a39fa9924d26e54ad50767d862e70ea62ea79 100644 --- a/src/main/resources/de/hhu/stups/codegenerator/CppTemplate.stg +++ b/src/main/resources/de/hhu/stups/codegenerator/CppTemplate.stg @@ -779,8 +779,12 @@ projection_tuple(arg, isProjection1) ::= << (<arg>.<if(isProjection1)>projection1<else>projection2<endif>()) >> -identity(type, arg) ::= << +identity(leftType, rightType, type, arg, relationalArg) ::= << +<if(relationalArg)> +(BRelation\<<leftType>, <rightType> >::identity2(<arg>)) +<else> (BRelation\<<type>, <type> >::identity(<arg>)) +<endif> >> cartesian_product(leftType, rightType, arg1, arg2) ::= <<