Hashable

public protocol Hashable

Protocol for types whose values can be hashed.

Hashable extends Equatable: the contract is that a == b implies a.hash(into:) and b.hash(into:) feed the same bytes to the hasher. Violating this breaks Set and Dictionary — equal lookups won't land on the equal stored value. The hasher is generic so the same hash impl works across hashing algorithms (SipHash, FxHash, etc.).

Examples

public struct Tag: Hashable { public var name: String public func isEqual(to other: Tag) -> Bool { self.name == other.name } public func hash[H](mutating into hasher: H) where H: Hasher { self.name.hash(into: hasher) } }

Methods

func hash[H](into: mutating H) where H: Hasher

Feeds this value's bytes into hasher. Must be deterministic across calls and consistent with isEqual.

ImplementsEquatable

Associated Types

type Output = Bool

Methods

public func equal(to: Self) -> Bool

Bridges Equal.equal(to:) to Equatable.isEqual(to:).

func isEqual(to: Self) -> Bool

Returns true iff self and other are considered equal. Should be reflexive, symmetric, and transitive — Hashable requires equal values to hash equal, so don't drift from those laws.

public func notEqual(to: Self) -> Bool

Default !=: delegates to == so there's a single source of truth.

Defined in lang/std/core/protocols.ks