Concept

Hashable allows a type to be converted into a hash value
for fast comparison and lookup.

It enables a value to be used in:


Why Hashing Exists

Goal: O(1) lookup instead of O(n)

Instead of scanning all elements:

Array → linear search (slow)
Set/Dictionary → hash-based lookup (fast)

Core Requirement

A type conforming to Hashable must:

1. Provide a hash value
2. Support equality comparison (Equatable)

Swift automatically synthesizes this for simple structs.


Basic Example

struct Framework: Hashable {
    let name: String
}

Swift auto-generates: