Comparison, hashing and equality.

Identity based comparison is represented by identical?, while = uses equivalence based on a value-based comparison.

Design notes
  • Any object can be compared for equality with identical? or with =, regardless of whether it implements custom equivalence through IEquiv.

  • Every object has a hash, regardless of whether it implements custom hash through IHash.

  • Dunaj does not provide protocol predicate for custom equivalence, nor for a custom hash.

Primary

=

Available since version 1.0 (alias of clojure.core/=)

Usage:
  • (= x)

  • (= x y)

  • (= x y & more)

Type signatures:
  • (Any) → true

  • (Any ⨯ Any) → Boolean+

  • (Any ⨯ Any ⨯ (Va Any)) → Boolean+

Returns true if x equals y, otherwise returns false. Contrary to the identical?, = is an equivalence comparison based on values, not identities.

decode-nil

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (decode-nil x)

Type signature:
  • (Any) → Any

Returns nil if x is the nil-sentinel, otherwise returns x.

defsentinel

Available since version 1.0 (view source)

not referred automatically

MACRO (defsentinel sname)

Defines a private sentinel object named sname and a corresponding private predicate function.

distinct?

Available since version 1.0 (alias of clojure.core/distinct?)

Usage:
  • (distinct? x)

  • (distinct? x y)

  • (distinct? x y & more)

Type signatures:
  • (Any) → true

  • (Any ⨯ Any) → Boolean+

  • (Any ⨯ Any ⨯ (Va Any)) → Boolean+

Returns true if no two of given arguments are =.

encode-nil

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (encode-nil x)

Type signature:
  • (Any) → Any

Returns nil-sentinel if x is nil, otherwise returns x.

identical?

Available since version 1.0 (alias of clojure.core/identical?)

Usage:
  • (identical? x y)

Type signature:
  • (Any ⨯ Any) → Boolean+

Returns true if both arguments are the same object (have the same identity), otherwise returns false.

nil-sentinel

Available since version 1.0 (view source)

not referred automatically

VAR of type Unknown

A sentinel value used for nil encoding/decoding.

nil?

Available since version 1.0 (alias of clojure.core/nil?)

Usage:
  • (nil? x)

Type signature: Predicate

Returns true if x is nil, otherwise returns false.

not=

Available since version 1.0 (alias of clojure.core/not=)

Usage:
  • (not= x)

  • (not= x y)

  • (not= x y & more)

Type signatures:
  • (Any) → false

  • (Any ⨯ Any) → Boolean+

  • (Any ⨯ Any ⨯ (Va Any)) → Boolean+

Returns true if x does not equal y, otherwise returns false.

sentinel

Available since version 1.0 (view source)

Usage:
  • (sentinel)

Type signature:
  • () → Unknown

Returns a unique object, of an unspecified type, for each call. The returned object is not equal (not = nor identical?) to any object other than itself. Is safe to put into channels or into functions that don’t accept nil.

some?

Available since version 1.0 (alias of clojure.core/some?)

Usage:
  • (some? x)

Type signature: Predicate

Returns true if x is not nil, otherwise returns false.

Comparison

comparable?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (comparable? x)

Type signature: Predicate

Returns true if object x satisfies IComparable protocol, false otherwise.

compare

Available since version 1.0 (alias of clojure.core/compare)

Usage:
  • (compare x y)

Type signature:
  • (IComparable ⨯ Any) → Integer+

Returns a negative integer, zero, or a positive integer if this is less than, equal to, or greater than the other.

natural-comparator

Available since version 1.0 (view source)

not referred automatically

VAR of type (Fn [Integer+ Any Any])

A comparator which uses object’s natural ordering (implemented with IComparable) for comparison.

Hashing

basis-seed

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (basis-seed factory)

Type signature:
  • (IIncrementalHashFactory) → Int

Returns the hash basis seed of a given factory.

hash

Available since version 1.0 (alias of clojure.core/hash)

not referred automatically

Usage:
  • (hash x)

Type signature:
  • (Any) → Int

Returns a hash code of x that is consistent with =.

See also: IHash, =, hash-from-basis

hash-basis

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (hash-basis x)

Type signature:
  • (IHashBasis) → Int

Returns the hash basis of x.

hash-basis?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (hash-basis? x)

Type signature: Predicate

Returns true if object x satisfies IHashBasis protocol, false otherwise.

hash-from-basis

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (hash-from-basis hash-basis count)

Type signature:
  • (Int ⨯ Int) → Int

Returns the hash value from a given hash-basis and count.

next-basis

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (next-basis factory old val)

Type signature:
  • (IIncrementalHashFactory ⨯ Int ⨯ Any) → Int

Returns a new hash basis computed with a given factory, based on old basis and val.

ordered-hash-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type (R IIncrementalHashFactory)

An incremental hash factory for ordered collections.

unordered-hash-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type (R IIncrementalHashFactory)

An incremental hash factory for unordered collections.