Browse Source

JDDVars: add mergeVarsFrom(), sortByIndex() and removeVar() methods

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11822 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Joachim Klein 9 years ago
parent
commit
0fb6ab0a53
  1. 40
      prism/src/jdd/JDDVars.java

40
prism/src/jdd/JDDVars.java

@ -26,6 +26,8 @@
package jdd; package jdd;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
@ -133,6 +135,29 @@ public class JDDVars implements Iterable<JDDNode>
return result; 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. * Removes the JDDNodes contained in ddv from this JDDVars container.
* Does not decrease the refcount! * Does not decrease the refcount!
@ -346,6 +371,21 @@ public class JDDVars implements Iterable<JDDNode>
} }
return result; 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<JDDNode>() {
@Override
public int compare(JDDNode a, JDDNode b)
{
return new Integer(a.getIndex()).compareTo(b.getIndex());
}
});
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Loading…
Cancel
Save