Class LabeledIntHierarchyMap

java.lang.Object
it.univr.di.labeledvalue.AbstractLabeledIntMap
it.univr.di.labeledvalue.LabeledIntHierarchyMap
All Implemented Interfaces:
LabeledIntMap, Serializable
Direct Known Subclasses:
LabeledIntHierarchyMap.LabeledIntHierarchyMapView

public class LabeledIntHierarchyMap extends AbstractLabeledIntMap
Simple implementation of LabeledIntMap interface.

When creating an object, it is possible to specify if the labeled values represented in the map should be maintained as the minimal equivalent ones.

Version:
$Rev: 993 $
Author:
Roberto Posenato
See Also:
  • Field Details

    • wellFormatCheck

      public boolean wellFormatCheck
      Just to force the control that, after each put, the format of hierarchy is still valid. Don't set true in a production program!
    • root

      Root of hierarchy

      Design choice: the set of labeled values of this map is organized as a double-linked hierarchy of labeled values. A labeled value (label, value) is the father of another labeled value (label1, value1) if label1 subsumes label and value1 < value.

  • Constructor Details

    • LabeledIntHierarchyMap

      LabeledIntHierarchyMap(LabeledIntMap lvm)
      Constructor to clone the structure.
      Parameters:
      lvm - the LabeledValueTreeMap to clone. If LVM is null, this will be an empty map.
    • LabeledIntHierarchyMap

      LabeledIntHierarchyMap()
      Necessary constructor for the factory. The internal structure is built and empty.
  • Method Details

    • main

      public static void main(String[] args)
      Parameters:
      args - an array of String objects.
    • alreadyRepresents

      public boolean alreadyRepresents(Label newLabel, int newValue)
      Parameters:
      newLabel - a Label object.
      newValue - the new value.
      Returns:
      true if the current map can represent the value. In a positive case, the addition of the element does not change the map. If it returns false, then adding the value to the map would modify the map.
    • clear

      public void clear()
      Description copied from interface: LabeledIntMap
      Remove all entries from the map.
      See Also:
    • entrySet

      public it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.fastutil.objects.Object2IntMap.Entry<Label>> entrySet()
      Description copied from interface: LabeledIntMap
      The set of all map entries. The set is a view of the map. A modification of the map is reflected in the entries of the returned set.
      If it is necessary to scan all the entries to modify the map, the only right way is to consider the keys returned by LabeledIntMap.keySet() and use methods like LabeledIntMap.remove(Label) and/or LabeledIntMap.put(Label, int).
      Returns:
      The set of all map entries.
      See Also:
    • get

      public int get(Label l)
      Parameters:
      l - an Label object.
      Returns:
      the value associated to l if it exists, Constants.INT_NULL otherwise.
    • getMinValueConsistentWith

      public int getMinValueConsistentWith(Label l)
      Description copied from interface: LabeledIntMap
      Returns the value associated with the l if it exists, otherwise the minimal value among all labels consistent with l.
      Parameters:
      l - If it is null, Constants.INT_NULL is returned.
      Returns:
      the value associated with the l if it exists or the minimal value among values associated with labels consistent with l. If no labels are consistent by l, Constants.INT_NULL is returned.
    • getMinValueSubsumedBy

      public int getMinValueSubsumedBy(Label l)
      Description copied from interface: LabeledIntMap
      Returns the minimal value among those associated with labels subsumed by l if it exists, Constants.INT_NULL otherwise.
      Parameters:
      l - If it is null, Constants.INT_NULL is returned.
      Returns:
      minimal value among those associated with labels subsumed by l if it exists, Constants.INT_NULL otherwise.
    • keySet

      public it.unimi.dsi.fastutil.objects.ObjectSet<Label> keySet()
      Description copied from interface: LabeledIntMap
      A copy of all labels in the map.

      The returned set must not be connected to the map.

      The semantics of this method is different from the Map.keySet()!

      It can cost time and memory because it duplicates all the keys of the map.

      This method allows one to scan all the keys of the map, even if during the scan, some key of the map is removed.

      It is important to modify this map using only the method LabeledIntMap.remove(Label).

      Method LabeledIntMap.entrySet() returns a view of the entries of the map. Therefore, it cannot be used to scan or modify the map.

      Returns:
      a copy of all labels in the map.
    • newInstance

      public LabeledIntHierarchyMap newInstance()
      Description copied from interface: LabeledIntMap
      Factory
      Returns:
      an object of type LabeledIntMap.
    • newInstance

      public LabeledIntMap newInstance(boolean optimize)
      Factory
      Parameters:
      optimize - true for having the label as short as possible, false otherwise. For example, the set {(0, ¬C), (1, C)} is represented as {(0, ⊡), (1, C)} if this parameter is true.
      Returns:
      an object of type LabeledIntMap.
    • newInstance

      public LabeledIntHierarchyMap newInstance(LabeledIntMap lim)
      Description copied from interface: LabeledIntMap
      Factory
      Parameters:
      lim - a map to clone.
      Returns:
      an object of type LabeledIntMap.
    • newInstance

      public LabeledIntMap newInstance(LabeledIntMap lim, boolean optimize)
      Factory
      Parameters:
      lim - an object to clone.
      optimize - true for having the label as short as possible, false otherwise. For example, the set {(0, ¬C), (1, C)} is represented as {(0, ⊡), (1, C)} if this parameter is true.
      Returns:
      an object of type LabeledIntMap.
    • put

      public boolean put(Label newLabel, int newValue)
      Description copied from interface: LabeledIntMap
      Put a label with value i if label l is not null and there is no labeled value in the set with label l, or it is present but with a value higher than l.

      Not mandatory: the method can remove or modify other labeled values of the set to minimize the labeled values present, guaranteeing that no info is lost.

      Parameters:
      newLabel - a non-null label.
      newValue - a not Constants.INT_NULL value.
      Returns:
      true if (l,i) has been inserted. Since an insertion can remove more than one redundant labeled value, it is nonsensical to return "the old value" as expected from a classical put method.
    • putForcibly

      public void putForcibly(Label l, int i)
      Put the labeled value without any control. It is dangerous, but it can help in some cases.
      Parameters:
      l - a Label object.
      i - the new value.
    • remove

      public int remove(@Nonnull Label l)
      Description copied from interface: LabeledIntMap
      Remove the label l from the map. If the l is not present, it does nothing.
      Parameters:
      l - a non-null label.
      Returns:
      the previous value associated with l, or Constants.INT_NULL if there was no mapping for l.
    • size

      public int size()
      Specified by:
      size in interface LabeledIntMap
      Overrides:
      size in class AbstractLabeledIntMap
      Returns:
      the number of labeled values (value with empty label included).
      See Also:
    • unmodifiable

      public LabeledIntMap.LabeledIntMapView unmodifiable()
      Returns:
      a read-only view of this.
    • values

      public it.unimi.dsi.fastutil.ints.IntSet values()
      Returns:
      the set of all integer values present in the map as an ordered list.