Comparison, hashing and equality.

IComparable

Available since version 1.0 (view source)

not referred automatically

PROTOCOL with method -compare-to

extensions of this protocol on existing types are forbidden (performance and/or backwards compatibility reasons).

A value protocol for natural total ordering.

-compare-to

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-compare-to this other)

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

Returns a negative integer, zero, or a positive integer if this is less than, equal to, or greater than the other. When implementing -compare-to, mind not to mix ordered and unordered collections.

See also: IComparable

IEquiv

Available since version 1.0 (view source)

not referred automatically

PROTOCOL with method -equiv

extensions of this protocol on existing types are forbidden (performance and/or backwards compatibility reasons).

A value protocol for custom equivalence. Types which do not extend this protocol will use their identity for comparison.

JVM host specific: For compatibility reasons, implementations should also implement j.l.Object/equals.

-equiv

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-equiv this other)

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

Returns true if this is equal to other, otherwise returns false. Note that two objects that are equivalent with -equiv must also return same value for -hash.

When implementing -equiv, mind not to mix ordered and unordered collections. Sequential collections are usually not equal to non-sequential ones, but may be equal to other sequential collections even if are not of a same type.

See also: IEquiv

IHash

Available since version 1.0 (view source)

not referred automatically

PROTOCOL with method -hash

extensions of this protocol on existing types are forbidden (performance and/or backwards compatibility reasons).

A value protocol for a custom hash. Types that don’t extend this protocol get their hash value computed from their identity.

JVM host specific: For compatibility with host, implementations should also implement j.l.Object/hashCode.

See also: hash, =

-hash

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-hash this)

Type signature:
  • (Any) → Int

Returns a hash value for this.

Two objects which are equivalent with -equiv must return same value for -hash.

See also: IHash

IHashBasis

Available since version 1.0 (view source)

not referred automatically

PROTOCOL with method -hash-basis

A value protocol for collections with incremental hash basis.

-hash-basis

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-hash-basis this)

Type signature:
  • (Any) → Int

Returns the hash basis for this.

See also: IHashBasis

IIncrementalHashFactory

Available since version 1.0 (view source)

not referred automatically

PROTOCOL with methods -basis-seed, -next-basis

A factory protocol for incremental hashes.

-basis-seed

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-basis-seed this)

Type signature:
  • (Any) → Int

Returns the hash basis seed. Throws if this factory does not provide a seed.

-next-basis

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-next-basis this old val)

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

Returns a new hash basis based on old basis and val.