Also, the {@code net.openhft.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 net.openhft.koloboke.collect.Container#shrink()}, are disallowed. Other ones are allowed.
Everything is allowed, except removals of individual elements (entries), typically these operations' names contain word "remove" or "retain". Emphasis on "individual" means that {@link net.openhft.koloboke.collect.Container#clear()} is allowed.
Think about updatable containers as "non-decreasing", which could be "reset" from time to time by {@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, prohibit of removals permits faster implementation of {@linkplain net.openhft.koloboke.collect.hash.HashContainer hash containers} and iterators over many data structures.
All operations are allowed.
| Method \ Mutability | Mutable | Updatable | Immutable |
| {@link java.util.Collection#contains(Object) contains(Object)} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#containsAll(java.util.Collection) containsAll(Collection)} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#iterator() iterator()} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#toArray() toArray()} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#toArray(Object[]) toArray(Object[])} | ✓ | ✓ | ✓ |
| {@link java.util.Collection#add(Object) add(Object)} | ✓ | ✓ | - |
| {@link java.util.Collection#addAll(java.util.Collection) addAll(Collection)} | ✓ | ✓ | - |
| {@link java.util.Collection#remove(Object) remove(Object)} | ✓ | - | - |
| {@link java.util.Collection#removeAll(java.util.Collection) removeAll(Collection)} | ✓ | - | - |
| {@link java.util.Collection#retainAll(java.util.Collection) retainAll(Collection)} | ✓ | - | - |
| {@link java.util.Collection#removeIf(java.util.function.Predicate) removeIf(Predicate)} | ✓ | - | - |
| Method \ Mutability | Mutable | Updatable | Immutable |
| {@link java.util.Map#containsKey(Object) containsKey(Object)} | ✓ | ✓ | ✓ |
| {@link java.util.Map#containsValue(Object) containsValue(Object)} | ✓ | ✓ | ✓ |
| {@link java.util.Map#get(Object) get(Object)} | ✓ | ✓ | ✓ |
| {@link java.util.Map#getOrDefault(Object, Object) getOrDefault(Object, Object)} | ✓ | ✓ | ✓ |
| {@link java.util.Map#keySet() keySet()} | ✓ | ✓ | ✓ |
| {@link java.util.Map#entrySet() entrySet()} | ✓ | ✓ | ✓ |
| {@link java.util.Map#values() values()} | ✓ | ✓ | ✓ |
| {@link java.util.Map#forEach(java.util.function.BiConsumer) forEach(BiConsumer)} | ✓ | ✓ | ✓ |
| {@link java.util.Map#put(Object, Object) put(Object, Object)} | ✓ | ✓ | - |
| {@link java.util.Map#putIfAbsent(Object, Object) putIfAbsent(Object, Object)} | ✓ | ✓ | - |
| {@link java.util.Map#computeIfAbsent(Object, java.util.function.Function) computeIfAbsent(Object, Function)} | ✓ | ✓ | - |
| {@link java.util.Map#replace(Object, Object) replace(Object, Object)} | ✓ | ✓ | - |
| {@link java.util.Map#replace(Object, Object, Object) replace(Object, Object, Object)} | ✓ | ✓ | - |
| {@link java.util.Map#putAll(java.util.Map) putAll(Map)} | ✓ | ✓ | - |
| {@link java.util.Map#replaceAll(java.util.function.BiFunction) replaceAll(BiFunction)} | ✓ | ✓ | - |
| {@link java.util.Map#compute(Object, java.util.function.BiFunction) compute(Object, BiFunction)} | ✓ | ✓, except removing on returning {@code null} | - |
| {@link java.util.Map#computeIfPresent(Object, java.util.function.BiFunction) computeIfPresent(Object, BiFunction)} | ✓ | ✓, except removing on returning {@code null} | - |
| {@link java.util.Map#merge(Object, Object, java.util.function.BiFunction) merge(Object, Object, BiFunction)} | ✓ | ✓, except removing on returning {@code null} | - |
| {@link java.util.Map#remove(Object) remove(Object)} | ✓ | - | - |
| {@link java.util.Map#remove(Object, Object) remove(Object, Object)} | ✓ | - | - |
See other matrices for information if the concrete method is supported by the given mutability profile: {@code Container}.
| {@link java.util.Iterator} | {@link net.openhft.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 net.openhft.koloboke.collect.Cursor#remove()} | No | No | Yes, by returning {@code true} |
| Performance, iteration over {@link java.util.Map} | Medium, {@link java.util.Map.Entry} objects are allocated | Very high | |||
| 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 | |||
{@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 net.openhft.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 net.openhft.koloboke.collect.LongCollection},
{@link net.openhft.koloboke.collect.FloatCollection}, etc.
for symmetry. This is because {@code remove(int)}
in {@link net.openhft.koloboke.collect.IntCollection} will conflict with
{@link java.util.List#remove(int)} method in {@code IntList} (not implemented yet, however).