Package de.tilman_neumann.util
Class SortedMultiset_BottomUp<T extends java.lang.Comparable<T>>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.TreeMap<T,java.lang.Integer>
de.tilman_neumann.util.SortedMultiset_BottomUp<T>
- Type Parameters:
T
- element class
- All Implemented Interfaces:
Multiset<T>
,SortedMultiset<T>
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<SortedMultiset<T>>
,java.util.Map<T,java.lang.Integer>
,java.util.NavigableMap<T,java.lang.Integer>
,java.util.SortedMap<T,java.lang.Integer>
- Direct Known Subclasses:
IntegerPartition
public class SortedMultiset_BottomUp<T extends java.lang.Comparable<T>> extends java.util.TreeMap<T,java.lang.Integer> implements SortedMultiset<T>
A sorted set of elements with multiple occurrences, sorted smallest elements first.
Sorting is due to extending TreeMap; with HashMap the sorting behavior would be undefined.
Elements must implement the Comparable interface.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,V extends java.lang.Object>
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
-
Constructor Summary
Constructors Constructor Description SortedMultiset_BottomUp()
Constructor for an empty multiset, sorted smallest elements first.SortedMultiset_BottomUp(Multiset<T> original)
Copy constructor for a multiset, sorted smallest elements first.SortedMultiset_BottomUp(java.util.Collection<T> values)
Constructor for a multiset, sorted smallest elements first, from a collection.SortedMultiset_BottomUp(T[] values)
Constructor for a multiset, sorted smallest elements first, from a value array. -
Method Summary
Modifier and Type Method Description int
add(T entry)
Add an entry with multiplicity 1.int
add(T entry, int mult)
Add one entry with given multiplicity.void
addAll(Multiset<T> other)
Add another multiset to this.void
addAll(java.util.Collection<T> values)
Add all values of the given collection.void
addAll(T[] values)
Add all values of the given array.int
compareTo(SortedMultiset<T> other)
Compares this to another SortedMultiset.boolean
equals(java.lang.Object o)
Sorted multisets are equal if they have exactly the same elements and these elements the same multiplicity.T
getBiggestElement()
T
getSmallestElement()
java.util.Iterator<java.util.Map.Entry<T,java.lang.Integer>>
getTopDownIterator()
int
hashCode()
SortedMultiset<T>
intersect(Multiset<T> other)
Returns the multiset of elements contained in both this and in the other multiset.java.lang.Integer
remove(java.lang.Object key)
Removes one instance of the given value from this multiset, if at least one element is contained.int
remove(T key, int mult)
Remove the given key multiple times.int
removeAll(T key)
Removes the key-value pair of the given key no matter what its multiplicity wasjava.util.List<T>
toList()
java.lang.String
toString(java.lang.String entrySep, java.lang.String expSep)
Conversion to String, withint
totalCount()
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, merge, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, putIfAbsent, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
Methods inherited from class java.util.AbstractMap
isEmpty, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, forEach, get, getOrDefault, isEmpty, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, size
Methods inherited from interface de.tilman_neumann.util.Multiset
entrySet, get, keySet, size, toString
Methods inherited from interface java.util.SortedMap
comparator, entrySet, firstKey, keySet, lastKey, values
-
Constructor Details
-
SortedMultiset_BottomUp
public SortedMultiset_BottomUp()Constructor for an empty multiset, sorted smallest elements first. This sort order is particularly adequate for the parts of multiplicative partitions (prime factorizations). -
SortedMultiset_BottomUp
Constructor for a multiset, sorted smallest elements first, from a collection.- Parameters:
values
-
-
SortedMultiset_BottomUp
Constructor for a multiset, sorted smallest elements first, from a value array.- Parameters:
values
-
-
SortedMultiset_BottomUp
Copy constructor for a multiset, sorted smallest elements first.- Parameters:
original
-
-
-
Method Details
-
add
Description copied from interface:Multiset
Add an entry with multiplicity 1. -
add
Description copied from interface:Multiset
Add one entry with given multiplicity. -
addAll
Description copied from interface:Multiset
Add another multiset to this. -
addAll
Description copied from interface:Multiset
Add all values of the given collection. -
addAll
Description copied from interface:Multiset
Add all values of the given array. -
remove
public java.lang.Integer remove(java.lang.Object key)Description copied from interface:Multiset
Removes one instance of the given value from this multiset, if at least one element is contained. The key is declared as Object and not as T to match exactly the signature of the same method in the Map-interface. Nevertheless, of course the arguments should be of type T.- Specified by:
remove
in interfacejava.util.Map<T extends java.lang.Comparable<T>,java.lang.Integer>
- Specified by:
remove
in interfaceMultiset<T extends java.lang.Comparable<T>>
- Overrides:
remove
in classjava.util.TreeMap<T extends java.lang.Comparable<T>,java.lang.Integer>
- Returns:
- previous multiplicity of the argument
-
remove
Description copied from interface:Multiset
Remove the given key multiple times. -
removeAll
Description copied from interface:Multiset
Removes the key-value pair of the given key no matter what its multiplicity was -
intersect
Description copied from interface:SortedMultiset
Returns the multiset of elements contained in both this and in the other multiset. -
totalCount
public int totalCount()- Specified by:
totalCount
in interfaceMultiset<T extends java.lang.Comparable<T>>
- Returns:
- Total number of elements, i.e. the sum of multiplicities of all different elements
-
getSmallestElement
- Specified by:
getSmallestElement
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Returns:
- The smallest element.
-
getBiggestElement
- Specified by:
getBiggestElement
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Returns:
- The biggest element.
-
toList
-
getTopDownIterator
- Specified by:
getTopDownIterator
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Returns:
- an iterator that returns biggest elements first.
-
compareTo
Compares this to another SortedMultiset. A sorted multiset is bigger than another one if it's biggest element is bigger than the largest element of the other multiset, or the 2.nd-biggest if the biggest elements are equal, or the 3.rd biggest, and so on. -
equals
public boolean equals(java.lang.Object o)Sorted multisets are equal if they have exactly the same elements and these elements the same multiplicity. -
hashCode
public int hashCode() -
toString
public java.lang.String toString(java.lang.String entrySep, java.lang.String expSep)Description copied from interface:SortedMultiset
Conversion to String, with- Specified by:
toString
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Parameters:
entrySep
- e.g. "*" for multiplicative elementsexpSep
- e.g. "^" for multiplicative elements- Returns:
- a string representation of this
-