From 0fb6ab0a5374879aae310347f35b92154fdc027f Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Wed, 14 Sep 2016 11:36:48 +0000 Subject: [PATCH] JDDVars: add mergeVarsFrom(), sortByIndex() and removeVar() methods git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11822 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/jdd/JDDVars.java | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/prism/src/jdd/JDDVars.java b/prism/src/jdd/JDDVars.java index 8ce236fd..d1c70b40 100644 --- a/prism/src/jdd/JDDVars.java +++ b/prism/src/jdd/JDDVars.java @@ -26,6 +26,8 @@ package jdd; +import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.Vector; @@ -133,6 +135,29 @@ public class JDDVars implements Iterable return result; } + + /** + * Copy JDDNodes from another JDDVars, merge into the existing variables, + * sorting by the variable indices. Afterwards, this JDDVars container + * is fully sorted by variable indices, i.e., the existing variables are + * sorted as well. + * @param ddv the new variables + */ + public void mergeVarsFrom(JDDVars ddv) { + copyVarsFrom(ddv); + sortByIndex(); + } + + /** + * Remove variable v from container. Does not decrease the refcount. + */ + public void removeVar(JDDNode v) + { + vars.remove(v); + if (arrayBuilt) DDV_FreeArray(array); + arrayBuilt = false; + } + /** * Removes the JDDNodes contained in ddv from this JDDVars container. * Does not decrease the refcount! @@ -346,6 +371,21 @@ public class JDDVars implements Iterable } return result; } + + /** Sort the variables in this container by their variable index. */ + public void sortByIndex() + { + if (arrayBuilt) DDV_FreeArray(array); + arrayBuilt = false; + + Collections.sort(vars, new Comparator() { + @Override + public int compare(JDDNode a, JDDNode b) + { + return new Integer(a.getIndex()).compareTo(b.getIndex()); + } + }); + } } //------------------------------------------------------------------------------