See: Description
Package | Description |
---|---|
net.openhft.koloboke.collect |
The root package of the collection library.
|
net.openhft.koloboke.collect.hash |
Contains basic interfaces and commonly used classes related to containers, based on hash tables.
|
net.openhft.koloboke.collect.map |
Contains interfaces of
Map specializations, their factories and cursors. |
net.openhft.koloboke.collect.map.hash |
Contains interfaces of
Map specializations, based on hash tables,
their factories and static factory methods. |
net.openhft.koloboke.collect.set |
Contains interfaces of
Set specializations and their factories. |
net.openhft.koloboke.collect.set.hash |
Contains interfaces of
Set specializations, based on hash tables,
their factories and static factory methods. |
net.openhft.koloboke.function |
The complete set of functional interfaces, following
java.util.function scheme. |
HashSet
class extends
Set
extends Collection
. In this library
HashCharSet
interface extends
CharSet
, which extends Set
and
CharCollection
, which extends
Collection
and Container
.
Also, a complete set of functional interfaces is defined
in the net.openhft.koloboke.function
package, it is needed because the library
backports many methods from Java 8 Collections API (see API
additions), which employ these interfaces.
HashContainerFactory
to configure all factories
which produce hash sets and maps in the application.
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.
ServiceLoader
. This default factory instance is returned
by getDefaultFactory()
static method in each static factory method holder class.
These classes have a name of container interface plus -s
suffix, for example,
HashIntShortMaps
define static factory methods
which return HashIntShortMap
instances,
delegating to the default
HashIntShortMapFactory
implementation.JDK | The closest equivalent from this library | The recommended equivalent from this library |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
Collections.unmodifiable*
methods
exist. Second, containers of lesser mutability are implemented in more efficient manner, whenever
possible. So using immutable collections when applicable could improve your application's
performance a bit.
Any operations that change the conceptual container state, e. g. insertions and removals,
as well as that could touch internal representation,
e. g. 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 Container.clear()
is allowed.
Think about updatable containers as "non-decreasing", which could be "reset"
from time to time by 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 hash containers and iterators over many data structures.
All operations are allowed.
Collection
mutability matrixMethod \ Mutability | Mutable | Updatable | Immutable |
contains(Object) |
✓ | ✓ | ✓ |
containsAll(Collection)
| ✓ | ✓ | ✓ |
iterator() |
✓ | ✓ | ✓ |
toArray() |
✓ | ✓ | ✓ |
toArray(Object[]) |
✓ | ✓ | ✓ |
add(Object) |
✓ | ✓ | - |
addAll(Collection) |
✓ | ✓ | - |
remove(Object) |
✓ | - | - |
removeAll(Collection) |
✓ | - | - |
retainAll(Collection) |
✓ | - | - |
Map
mutability matrixMethod \ Mutability | Mutable | Updatable | Immutable |
containsKey(Object) |
✓ | ✓ | ✓ |
containsValue(Object) |
✓ | ✓ | ✓ |
get(Object) |
✓ | ✓ | ✓ |
keySet() |
✓ | ✓ | ✓ |
entrySet() |
✓ | ✓ | ✓ |
values() |
✓ | ✓ | ✓ |
put(Object, Object) |
✓ | ✓ | - |
putAll(Map) |
✓ | ✓ | - |
remove(Object) |
✓ | - | - |
See other matrices for information if the concrete method is supported by the given
mutability profile: Container
.
forEach()
-like methods which accept closures.
Iterator |
Cursor |
forEach() |
forEachWhile() |
removeIf() |
|
Available for Collection sub-interfaces in the library |
Yes | ||||
Available for Map sub-interfaces in the library |
Yes | ||||
Coding convenience | High, if elements aren't removed and generic version
of Iterator.next() method is used, Java "for-each" syntax
is applicable. Medium otherwise. |
Medium | Low, nasty anonymous classes declarations | ||
Supports early break from the iteration | Yes, by simple break from the loop | Yes, by simple break from the loop | No | Yes, by returning false |
No |
Supports remove of iterated elements (entries) | Yes, by Iterator.remove() |
Yes, by Cursor.remove() |
No | No | Yes, by returning true |
Performance, iteration over Map |
Medium, Map.Entry objects are allocated |
Very high | |||
Performance, iteration over Collection |
High, if specialized version of Iterator.next() method
is used. Medium otherwise, because every element is boxed. |
Very high |
HashCharSet
extends
java.util.Set<Character>
, and made as similar as possible
to java.util.HashSet<Character>
, which extends the same interface. Non-obvious things,
made compatible with JCF in the library:
null
elements, keys and values, despite this is
an antipattern, because most JCF implementations does. Important: hash maps and sets
with Object
keys,
e. g. HashObjDoubleMap
, don't support
null
key by default, you should configure
factory.
withNullKeyAllowed(true)
.
ConcurrentModificationException
on best-effort basis, i. e. they have
fail-fast semantics. See documentation for ConcurrentModificationException
for more information.Float.NaN
!= Float.NaN
(similarly for Double
)
in Java, in this library in containers these values are treated consistently with their boxed
versions (i. e. new Float(Float.NaN)
, all such objects are equal to each other.null
element, key or value. Obviously,
this is by design and can't be fixed.Cloneable
yet. To be fixed, see
the issue.Serializable
yet. To be fixed, see
the issue.byte
, char
or short
keys
can't be complete, i. e. contain all keys of the type, unlike HashSet<Byte>
,
HashSet<Character>
and HashSet<Short>
. There should be 1-2 absent keys.
On attempt of insertion the last keys
HashOverflowException
is thrown.HashOverflowException
is thrown on attempt
of insertion an element or entry beyond the actual limit. java.util.HashMap
and
java.util.HashSet
have higher limit, if there is enough heap space.CharCollection
extends Collection
,
IntFloatMap
extends Map
.
There are also classes with Obj-
prefix, they bring API
additions to collections of objects, if there are no additions for the class or
interface, Obj-
"specializations" are present anyway, for global API symmetry. 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:
ByteCollection.removeByte(byte)
is a specialized version
of Collection.remove(Object)
, but have a different name (the same
for LongCollection
,
FloatCollection
, etc.
for symmetry. This is because remove(int)
in IntCollection
will conflict with
List.remove(int)
method in IntList
(not implemented yet, however).
-As-
infix, is added to the original method name. Examples:
DoubleCollection.toDoubleArray()
, and others
similar, is exceptional from those rules and have special name.Object.equals(Object)
and Object.hashCode()
. Container
factories in the library allow to configure equivalences for elements, keys and values. This allows to implement some functionality very
easy, without defining new subclasses of the existing collections implementations. See
the documentation to ObjCollection.equivalence()
,
ObjObjMap.keyEquivalence()
and
ObjObjMap.valueEquivalence()
methods for more
information.
Collection
interface:ObjCollection.forEach(net.openhft.koloboke.function.Consumer)
simply performs the given action for each element of the collection. This method
is backported from Java 8 Collection
API.ObjCollection.removeIf(net.openhft.koloboke.function.Predicate)
removes all of the elements of this collection that satisfy the given predicate. This method
is backported from Java 8 Collection
API.ObjCollection.forEachWhile(net.openhft.koloboke.function.Predicate)
performs the given action for each element of the collection, while it returns true
.
Cursor
iteration:
ObjCollection.cursor()
. See also
the comparison of iteration ways in the library.Collection
interface
primitive specializations: ByteCollection
,
CharCollection
, etc.
Map
interface:Map
API:
ObjObjMap.getOrDefault(Object, Object)
ObjObjMap.forEach(net.openhft.koloboke.function.BiConsumer)
ObjObjMap.replaceAll(net.openhft.koloboke.function.BiFunction)
ObjObjMap.putIfAbsent(Object, Object)
ObjObjMap.remove(Object, Object)
ObjObjMap.replace(Object,
Object, Object)
ObjObjMap.replace(Object, Object)
ObjObjMap.computeIfAbsent(Object,
net.openhft.koloboke.function.Function)
ObjObjMap.computeIfPresent(Object,
net.openhft.koloboke.function.BiFunction)
ObjObjMap.compute(Object,
net.openhft.koloboke.function.BiFunction)
ObjObjMap.merge(Object, Object,
net.openhft.koloboke.function.BiFunction)
ObjObjMap.cursor()
— cursor
iteration over maps.ObjObjMap.forEachWhile(net.openhft.koloboke.function.BiPredicate)
performs the given action for each entry of the map, while it returns true
.ObjObjMap.removeIf(net.openhft.koloboke.function.BiPredicate)
removes all of the entries of this map that satisfy the given predicate.ObjIntMap.addValue(Object, int)
and
ObjIntMap.addValue(Object, int, int)
add
the given value to the value associated to the given key. These methods are present
in the map specializations with primitive value.HashMap
, LinkedHashMap
, HashSet
and WeakHashMap
, that allows to control it's memory footprint and performance
characteristics, is loadFactor
constructor argument. IdentityHashMap
don't have even this one. This library allows to tune hash tables very precisely via a bunch
of per-instance methods and factory configurations. See the documentation
to HashContainer
and
HashConfig
classes for more information.