Hashing

interface Hashing<in Element> : KoneContext(source)

Describes a context that provides hash operator besides inherited coincidesWith operator. This operator should return the same value for elements that are equal according to coincidesWith operator.

Such contexts are used instead of usual hashCode overloading for several reasons. Some of them are:

  • Following structural pattern, any behaviour between elements should not be a part of the elements' logic but a part of assumed context. (For example, summing two integers together, we assume that we are summing them as two integer, but not as a residue of some modulo.)

  • Such separation of entities and operations over them brings modularity: you can change operations context leaving the entities the same.

Type Parameters

Element

The type of elements for which this hashing context is defined.

Types

Link copied to clipboard
object Companion

Companion object for Hashing interface providing factory methods for creating Hashing instances.

Properties

Link copied to clipboard

Returns a Hashing context for nullable elements based on this non-nullable hashing context.

Functions

Link copied to clipboard
open fun Element.hash(): Int

Computes hash code of this element.