Dunaj - Comparison
Dunaj, like Clojure, provides comparison facilities that use identity and value based comparison.
Comparison and hashing facilities are defined in dunaj.compare namespace.
Every object has an identity, whether it is a value object, stateful
reference or a primitive value. Dunaj provides
function for identity based comparison.
There is usually a distinction between object’s identity and a
value this object conveys. Comparison based on value is done with a
function. User defined types can provide a custom implementation for
value comparison by extending an
If no implementation is provided, a comparison based on object’s
identity is used.
When comparing numbers, a dedicated comparision function
dunaj.compare namespace also provides facilities for creating sentinel objects and nil coding (e.g. for use in core.async channels).
Every object has a
that can be used e.g. for a rapid data lookup in a hash map.
As value objects that have a same value must also have a same hash,
IHash protocol for
For some types, such as sequences, the object’s hash can be computed
incrementally. This property can be in certain cases further exploited
to compute hash much faster (e.g. conjoining value to the list). An
IHashBasis protocol together
functions can be used for incremental hashing. Moreover, dunaj
for the computation of collections in line with the way hash is
computed in the built-in collection types.
|The incremental hash feature is a very early experiment with rudimentary features and has currently a nearly non-existent support in Dunaj’s built-in collections.|