package it.univr.di.labeledvalue; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.IntArraySet; import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.objects.AbstractObject2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectArraySet; import it.unimi.dsi.fastutil.objects.ObjectSet; import it.univr.di.Debug; /** * Simple implementation of {@link it.univr.di.labeledvalue.LabeledIntMap} interface. *

* An experimental result on 2016-01-13 showed that using base there is a small improvement in the performance. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Execution time (ms) for some operations w.r.t the core data structure of the class (Object2IntMap).
OperationUsing AVL or RB Tree (ms)Using OpenHash (ms)Using fastUtil.Array (ms)
Create 1st map0.2364990880.150738230.140981928
min value0.0045230440.0054196350.007725364
Retrieve value0.0006973680.000216167E0.000172576
Simplification~1.275382~1.221648~0.328194
* All code for performance tests is in LabeledIntTreeMapTest class (not public available). * * @author Roberto Posenato * @see LabeledIntMap * @version $Id: $Id */ public class LabeledIntTreeMap extends AbstractLabeledIntMap { /** * A read-only view of an object * * @author posenato */ public static class LabeledIntTreeMapView extends LabeledIntTreeMap implements LabeledIntMapView { /** * */ private static final long serialVersionUID = 1L; /** * @param inputMap */ public LabeledIntTreeMapView(LabeledIntTreeMap inputMap) { this.mainInt2SetMap = inputMap.mainInt2SetMap; this.base = inputMap.base; this.count = inputMap.count; } /** * Object Read-only. It does nothing. */ @Override public int putForcibly(Label l, int i) { return Constants.INT_NULL; } } /** * empty base; */ static private final char[] emptyBase = new char[0]; /** * logger */ static private Logger LOG = Logger.getLogger("LabeledIntTreeMap"); /** * */ static private final long serialVersionUID = 2L; /** * @return an Object2IntMap

* An experiment result on 2016-01-13 showed that using base there is a small improvement in the performance. * * @param l * @return true if l is a component of the base, false otherwise. */ private boolean checkValidityOfTheBaseAfterRemoving(final Label l) { if ((this.base.length == 0) || (l.size() == 0) || (l.size() != this.base.length) || l.containsUnknown()) return false; // l and base have same length. for (char c : this.base) { if (!l.contains(c)) return false; } // l is a component of the base and it was removed. this.base = emptyBase; return true; } /** * Tries to add all given labeled values into the current map: *

    *
  1. Given a set of labeled values to insert (all labels have the same length) *
  2. For each of them, compares all same-length labels already in the map with the current one looking for if there is one with same value and only one * opposite literal (this allows the simplification of the two labels with a shorter one). In case of a positive search, shorten the current label to * insert. *
  3. For each of the labeled values to insert (possibly updated), removes all labeled values in the map greater than it. Ad each round it tries to add * labeled values of the same size. * * @param inputMap contains all the elements that have to be inserted. * @param inputMapLabelLength length of labels contained into inputMap * @return true if any element of inputMap has been inserted into the map. */ private boolean insertAndSimplify(Object2IntMap