Also, the {@code com.koloboke.function} package polyfills {@link java.util.function} functional interface set with the rest specializations ({@link java.util.function} package defines only some specializations for {@code int}, {@code long} and {@code double} types.)
Note that all factories in the library are immutable, on changing any configuration a new copy of the factory is returned, with the target configuration changed.
| JDK | The closest equivalent from this library | The recommended equivalent from this library |
|---|---|---|
{@code new HashMap |
{@code HashObjObjMaps.getDefaultFactory()
.withNullKeyAllowed(true)
.
|
{@code HashObjObjMaps. |
{@code // unclear how "capacity" (100)
// is translated to size. 50? 75? 100?
new HashMap |
{@code HashIntObjMaps. |
{@code // 50 is expected _size_
HashIntObjMaps. |
{@code new IdentityHashMap |
{@code HashObjDoubleMaps.getDefaultFactory()
// these loads used in IdentityHashMap internally
.withHashConfig(HashConfig.fromLoads(1./3., 2./3., 2./3.))
.withNullKeyAllowed(true)
.withKeyEquivalence(Equivalence.identity())
.newMutableMap(map);} |
{@code HashObjDoubleMaps.getDefaultFactory()
.withKeyEquivalence(Equivalence.identity())
.newImmutableMap(map);} |
{@code Collections.unmodifiableSet(new HashSet<>() {{
add("Summer");
add("Autumn");
add("Winter");
add("Spring");
}});} |
{@code HashObjSets.newImmutableSetOf("Summer", "Autumn", "Winter", "Spring");} |
|
Any operations that change the conceptual container state, e. g. insertions and removals, as well as that could touch internal representation, e. g. {@link com.koloboke.collect.Container#shrink()}, are disallowed. Other ones are allowed.
Everything is allowed, except removals of individual elements (entries), typically names of these operations include "remove" or "retain" verb. Emphasis on "individual" means that {@link com.koloboke.collect.Container#clear()} (i. e. removal all elements or entries at once) is allowed.
Think about updatable containers as "non-decreasing", which could be "reset" from time to time by calling {@code clear()}.
In real practice individual removals are rarely needed, so most of the time you should use updatable containers rather than fully mutable ones. On the other hand, prohibition of removals permits faster implementation of {@linkplain com.koloboke.collect.hash.HashContainer hash containers} and iterators over many data structures.
All operations are allowed.
In Koloboke Compile, the {@link com.koloboke.compile.mutability.Updatable @Updatable} and {@link com.koloboke.compile.mutability.Mutable @Mutable} annotations specify that Koloboke Compile should generate an updatable or a mutable implementation of a container interface, respectively.
| Method \ Mutability | Mutable | Updatable | Immutable |
| {@link java.util.Collection#size() size()} | ✓ | ✓ | ✓ |
| {@link com.koloboke.collect.Container#sizeAsLong() sizeAsLong()} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#isEmpty() isEmpty()} | ✓ | ✓ | ✓ |
| {@code contains(e)} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#containsAll(java.util.Collection) containsAll(c)} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#toArray() toArray()} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#toArray(Object[]) toArray(array)} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#iterator() iterator()} | ✓ | ✓, except {@link java.util.Iterator#remove()} | |
| {@code cursor()} | ✓ | ✓, except {@link com.koloboke.collect.Cursor#remove()} | |
| {@link com.koloboke.collect.Container#ensureCapacity(long) ensureCapacity(minSize)} | ✓ | ✓ | - |
| {@link com.koloboke.collect.Container#shrink() shrink()} | ✓ | ✓ | - |
| {@link java.util.Collection#clear() clear()} | ✓ | ✓ | - |
| {@code add(e)} | ✓ | ✓ | - |
| {@link java.util.Collection#addAll(java.util.Collection) addAll(c)} | ✓ | ✓ | - |
| {@code remove(e)} | ✓ | - | - |
| {@link java.util.Collection#removeAll(java.util.Collection) removeAll(c)} | ✓ | - | - |
| {@link java.util.Collection#retainAll(java.util.Collection) retainAll(c)} | ✓ | - | - |
| {@code removeIf(filter)} | ✓ | - | - |
| Method \ Mutability | Mutable | Updatable | Immutable |
| {@link java.util.Map#size() size()} | ✓ | ✓ | ✓ |
| {@link com.koloboke.collect.Container#sizeAsLong() sizeAsLong()} | ✓ | ✓ | ✓ |
| {@link java.util.Map#isEmpty() isEmpty()} | ✓ | ✓ | ✓ |
| {@code containsKey(key)} | ✓ | ✓ | ✓ |
| {@code containsValue(value)} | ✓ | ✓ | ✓ |
| {@code get(key)} | ✓ | ✓ | ✓ |
| {@code getOrDefault(key, defaultValue)} | ✓ | ✓ | ✓ |
| {@code forEach(action)} | ✓ | ✓ | ✓ |
| {@code cursor()} | ✓ | ✓, except {@link com.koloboke.collect.Cursor#remove()} | |
| {@link java.util.Map#keySet() keySet()} | ✓ | ✓, same mutability applied to the returned {@code Set} | |
| {@link java.util.Map#values() values()} | ✓ | ✓, same mutability applied to the returned {@code Collection} | |
| {@link java.util.Map#entrySet() entrySet()} | ✓ | ✓, same mutability
applied to the returned {@code Set}, if Immutable - additionally, {@link java.util.Map.Entry#setValue(java.lang.Object) Map.Entry.setValue(value)} not supported | |
| {@link com.koloboke.collect.Container#ensureCapacity(long) ensureCapacity(minSize)} | ✓ | ✓ | - |
| {@link com.koloboke.collect.Container#shrink() shrink()} | ✓ | ✓ | - |
| {@link java.util.Map#clear() clear()} | ✓ | ✓ | - |
| {@code put(key, value)} | ✓ | ✓ | - |
| {@code putIfAbsent(key, value)} | ✓ | ✓ | - |
| {@code computeIfAbsent(key, mappingFunction)} | ✓ | ✓ | - |
| {@code replace(key, value)} | ✓ | ✓ | - |
| {@code replace(key, oldValue, newValue)} | ✓ | ✓ | - |
| {@link java.util.Map#putAll(java.util.Map) putAll(m)} | ✓ | ✓ | - |
| {@code replaceAll(function)} | ✓ | ✓ | - |
| {@code compute(key, remappingFunction)} | ✓ | ✓, except removing entry on returning {@code null} from the {@code remappingFunction} | - |
| {@code computeIfPresent(key, remappingFunction)} | ✓ | ✓, except removing entry on returning {@code null} from the {@code remappingFunction} | - |
| {@code merge(key, value, remappingFunction)} | ✓ | ✓, except removing entry on returning {@code null} from the {@code remappingFunction} | - |
| {@code remove(key)} | ✓ | - | - |
| {@code remove(key, value)} | ✓ | - | - |
| {@code removeIf(filter)} | ✓ | - | - |
See other matrices for information if the concrete method is supported by the given mutability profile: {@code Container}.
| {@link java.util.Iterator} | {@link com.koloboke.collect.Cursor} | {@code forEach()} | {@code forEachWhile()} | {@code removeIf()} | |
| Available for {@link java.util.Collection} sub-interfaces in the library | Yes | ||||
| Available for {@link java.util.Map} sub-interfaces in the library | Yes | ||||
| Coding convenience | High, if elements aren't removed and generic version of {@link java.util.Iterator#next()} method is used, Java "for-each" syntax is applicable. Medium otherwise. | Medium | High, lambda syntax | ||
| Supports early break from the iteration | Yes, by simple break from the loop | Yes, by simple break from the loop | No | Yes, by returning {@code false} | No |
| Supports remove of iterated elements (entries) | Yes, by {@link java.util.Iterator#remove()} | Yes, by {@link com.koloboke.collect.Cursor#remove()} | No | No | Yes, by returning {@code true} |
| Performance, iteration over {@link java.util.Collection} | High, if specialized version of {@link java.util.Iterator#next()} method is used. Medium otherwise, because every element is boxed. | Very high | |||
| Performance, iteration over {@link java.util.Map} | Medium, {@link java.util.Map.Entry} objects are allocated | Very high | |||
{@code
IntIntMap map = HashIntIntMaps.newUpdatableMap();
Integer key = 1;
map.put(key, 2); // ambiguous method call
map.put((int) key, 2); // correct}
There is one exception from this rule:
{@link com.koloboke.collect.ByteCollection#removeByte(byte)} is a specialized version
of {@link java.util.Collection#remove(Object)}, but have a different name (the same
for {@link com.koloboke.collect.LongCollection},
{@link com.koloboke.collect.FloatCollection}, etc.
for symmetry). This is because {@code remove(int)}
in {@link com.koloboke.collect.IntCollection} will conflict with
{@link java.util.List#remove(int)} method in {@code IntList} (not implemented yet, however).