Class LabeledIntTreeMap
java.lang.Object
it.univr.di.labeledvalue.AbstractLabeledIntMap
it.univr.di.labeledvalue.LabeledIntTreeMap
- All Implemented Interfaces:
LabeledIntMap
,Serializable
- Direct Known Subclasses:
LabeledIntTreeMap.LabeledIntTreeMapView
,LabeledIntTreeSimpleMap
Simple implementation of
All code for performance tests is in LabeledIntTreeMapTest class (not public available).
LabeledIntMap
interface.
An experimental result on 2024-10-16 showed that using base there is a small improvement in the performance.
Operation | Using Object2IntOpenHashMap (ms) | Using Object2IntArrayMap (ms) |
---|---|---|
Creating a map of 26 elements adding 60 elements (some entries are simplified) | 0.222982625 | 0.08684075 |
Finding the min value | 0.002990083 | 0.003209583 |
Retrieve the value of label abd¿f | 3.9083E-5 | 6.6917E-5 |
Simplification after insertion of (c,11) and (¬c,11) | 0.056917 | 0.020042 |
- Version:
- $Rev: 851 $
- Author:
- Roberto Posenato
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A read-only view of an objectNested classes/interfaces inherited from interface it.univr.di.labeledvalue.LabeledIntMap
LabeledIntMap.LabeledIntMapView
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) char[]
Set of propositions forming a base for the labels of the map.(package private) it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap
<it.unimi.dsi.fastutil.objects.Object2IntMap<Label>> Design choice: the set of labeled values of this map is organized as a collection of sets each containing labels of the same length.Fields inherited from class it.univr.di.labeledvalue.AbstractLabeledIntMap
count, labeledValueRE, labeledValueSetREPattern, optimize, splitterEntryPattern, splitterPair, valueRE, valueREPattern
Fields inherited from interface it.univr.di.labeledvalue.LabeledIntMap
entryComparator
-
Constructor Summary
ConstructorsConstructorDescriptionNecessary constructor for the factory.LabeledIntTreeMap
(boolean optimize) Necessary constructor for the factory.Constructor to clone the structure.LabeledIntTreeMap
(LabeledIntMap lvm, boolean optimize) Constructor to clone the structure. -
Method Summary
Modifier and TypeMethodDescriptionboolean
alreadyRepresents
(Label newLabel, int newValue) void
clear()
Remove all entries of the map.it.unimi.dsi.fastutil.objects.ObjectSet
<it.unimi.dsi.fastutil.objects.Object2IntMap.Entry<Label>> entrySet()
The set of all entries of the map.int
int
int
int
Returns the minimal value among those associated to labels subsumed byl
if it exists,Constants.INT_NULL
otherwise.it.unimi.dsi.fastutil.objects.ObjectSet
<Label> keySet()
A copy of all labels in the map.FactorynewInstance
(boolean optimize) FactorynewInstance
(LabeledIntMap lim) FactorynewInstance
(LabeledIntMap lim, boolean optimize) Factoryboolean
Put a label with valuei
if labell
is not null and there is not a labeled value in the set with labell
or it is present but with a value higher thanl
.void
putForcibly
(Label l, int i) Put the labeled value without any control.int
Remove the labell
from the map.it.unimi.dsi.fastutil.ints.IntSet
values()
Methods inherited from class it.univr.di.labeledvalue.AbstractLabeledIntMap
entryAsString, entryAsString, equals, hashCode, isEmpty, parse, parse, size, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface it.univr.di.labeledvalue.LabeledIntMap
getMaxValueSubsumedBy, getMinLabeledValue, getMinValueAmongLabelsWOUnknown, getMinValueConsistentWith, putAll
-
Field Details
-
base
char[] baseSet of propositions forming a base for the labels of the map. -
mainInt2SetMap
it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap<it.unimi.dsi.fastutil.objects.Object2IntMap<Label>> mainInt2SetMapDesign choice: the set of labeled values of this map is organized as a collection of sets each containing labels of the same length. This allows the label minimization task to be performed in a more systematic and efficient way. The efficiency has been proved comparing this implementation with one in which the map has been realized with a standard map and the minimization task determines the same length labels every time it needs it.
-
-
Constructor Details
-
LabeledIntTreeMap
LabeledIntTreeMap(LabeledIntMap lvm, boolean optimize) Constructor to clone the structure. For optimization issue, this method clone only LabeledIntTreeMap object.- Parameters:
lvm
- the LabeledValueTreeMap to clone. If lvm is null, this will be an empty map.optimize
- true for having the label shortest as possible, false otherwise. For example, the set {(0, ¬C), (1, C)} is represented as {(0, ⊡), (1, C)} if this parameter is true.
-
LabeledIntTreeMap
LabeledIntTreeMap(LabeledIntMap lvm) Constructor to clone the structure. For optimization issue, this method clone only LabeledIntTreeMap object.- Parameters:
lvm
- the LabeledValueTreeMap to clone. If lvm is null, this will be an empty map.
-
LabeledIntTreeMap
LabeledIntTreeMap(boolean optimize) Necessary constructor for the factory. The internal structure is built and empty.- Parameters:
optimize
- true for having the label shortest as possible, false otherwise. For example, the set {(0, ¬C), (1, C)} is represented as {(0, ⊡), (1, C)} if this parameter is true.
-
LabeledIntTreeMap
LabeledIntTreeMap()Necessary constructor for the factory. The internal structure is built and empty.
-
-
Method Details
-
alreadyRepresents
- Parameters:
newLabel
- aLabel
object.newValue
- the new value.- Returns:
- true if the current map can represent the value. In positive case, an add of the element does not change the map. If returns false, then the adding of the value to the map would modify the map.
-
clear
public void clear()Description copied from interface:LabeledIntMap
Remove all entries of the map.- See Also:
-
entrySet
public it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.fastutil.objects.Object2IntMap.Entry<Label>> entrySet()The set of all entries of the map. The set is a view of the map. A modification of the map is reflected on 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 byLabeledIntMap.keySet()
and use methods likeLabeledIntMap.remove(Label)
and/orLabeledIntMap.put(Label, int)
.
Up to 1000 items in the map it is better to use this method instead ofkeySet()
andget(Label)
.
With 1000 or more items, it is better to usekeySet()
approach.- Returns:
- The set of all entries of the map.
- See Also:
-
get
- Parameters:
l
- anLabel
object.- Returns:
- the value associated to
l
if it exists,Constants.INT_NULL
otherwise.
-
getMaxValue
public int getMaxValue()- Returns:
- the maximum int value present in the set if the set is not empty;
Constants.INT_NULL
otherwise.
-
getMinValue
public int getMinValue()- Returns:
- the minimum int value present in the set if the set is not empty;
Constants.INT_NULL
otherwise.
-
getMinValueSubsumedBy
Description copied from interface:LabeledIntMap
Returns the minimal value among those associated to labels subsumed byl
if it exists,Constants.INT_NULL
otherwise.- Parameters:
l
- If it is null,Constants.INT_NULL
is returned.- Returns:
- minimal value among those associated to labels subsumed by
l
if it exists,Constants.INT_NULL
otherwise.
-
keySet
Description copied from interface:LabeledIntMap
A copy of all labels in the map.
The returned set must not be connected with the map.
The semantics of this method is different from theMap.keySet()
!
It can costs time and memory because it should duplicate 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 are removed.
It is important to modify this map using only methodLabeledIntMap.remove(Label)
.
MethodLabeledIntMap.entrySet()
returns a view of the entries of the map. Therefore, it cannot use to scan the map to modify it.- Returns:
- a copy of all labels in the map.
-
newInstance
-
newInstance
Description copied from interface:LabeledIntMap
Factory- Parameters:
optimize
- true for having the label shortest 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
Description copied from interface:LabeledIntMap
Factory- Parameters:
lim
- a map to clone.- Returns:
- an object of type LabeledIntMap.
-
newInstance
Description copied from interface:LabeledIntMap
Factory- Parameters:
lim
- a map to clone.optimize
- true for having the label shortest 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
Put a label with valuei
if labell
is not null and there is not a labeled value in the set with labell
or it is present but with a value higher thanl
.Not mandatory: the method can remove or modify other labeled values of the set in order to minimize the labeled values present guaranteeing that no info is lost.
IMPORTANT!
This implementation tries to eliminate all labels that are redundant. Moreover, its code is sometime redundant, but simple to check!- Parameters:
newLabel
- a not null label.newValue
- a notConstants.INT_NULL
value.- Returns:
- true if
(l,i)
has been inserted. Since an insertion can remove more than one redundant labeled values, it is nonsensical to return "the old value" as expected from a classical put method.
-
putForcibly
Description copied from interface:LabeledIntMap
Put the labeled value without any control. It is dangerous, but it can help in some cases.- Parameters:
l
- aLabel
object.i
- the new value. If it is Constants#INT_NULL, the method does nothing.
-
remove
Description copied from interface:LabeledIntMap
Remove the labell
from the map. If thel
is not present, it does nothing.- Parameters:
l
- a not null label.- Returns:
- the previous value associated with
l
, orConstants.INT_NULL
if there was no mapping forl
.
-
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.
-