Hashable이란?

: Hasher를 통해 hash되어 하나의 integer hash value를 만들어낼 수 있는 것

→ hash를 통해 비교가 가능토록 한다

→ 같은 오브젝트가 일관성 있게 같은 값을 가질 수 있도록 표식한다.

Swift의 Hashable

Swift의 Hashable 가능한 타입들

→ int, float, bool, set도 hashable 하다.

<aside> 💡 Many types in the standard library conform to Hashable: Strings, integers, floating-point and Boolean values, and even sets are hashable by default. Some other types, such as optionals, arrays and ranges automatically become hashable when their type arguments implement the same.

</aside>

그리고 그냥 일반 객체들도 hash(into:) 함수를 구현하고 있다면, hashable 한 객체가 된다.

이는 swift에서 제공하는 Hashable Protocol을 채택해서 구현하고 있으면 된다고 한다.

protocol Hashable

Hashable은 언제 쓰이나

→ 두가지의 값은 hash로 유일성을 구분하기 떄문에 hashable 해야한다.

비교: Python의 Hashable

파이썬에서도 Hashable이라는 개념이 동일하게 존재하는데,

각 data model이 __hash__() 함수를 구현하고 있으면 hashable하다고 간주한다.