A function mapping keys into values.
Instances of this class represent functions: the main difference with
java.util.Map is that functions do not in principle allow enumeration of their domain or range. The need for
this interface lies in the existence of several highly optimized implementations of
functions (e.g., minimal perfect hashes) which do not actually store their domain or range explicitly.
In case the domain is known,
Function.containsKey(Object) can be used to perform membership queries.
The choice of naming all methods exactly as in
java.util.Map makes it possible
for all type-specific maps to extend type-specific functions (e.g.,
it.unimi.dsi.fastutil.ints.Int2IntMap extends
it.unimi.dsi.fastutil.ints.Int2IntFunction ). However,
Function.size() is allowed to return -1 to denote
that the number of keys is not available (e.g., in the case of a string hash function).
Note that there is an
it.unimi.dsi.fastutil.objects.Object2ObjectFunction that
can also set its default return value.
Warning: Equality of functions is by reference. Since there
is no way to enumerate the keys, there is no way to establish whether two functions represent the same
mathematical entity.
See Also: java.util.Map |