Module: core.hash

Source: ./core/hash.reef


Overview

core.hash — the Hash trait and its primitive implementations.

Collections 0.9.2 / D4. Hash lives in core, at the same layer as Option, and not in collections: a user struct must be able to impl Hash without importing a container. Containers bound their key parameter with where K: Hash.

THE CONTRACT, which is not statically checked: if a == b then a.hash() must equal b.hash(). Reef's == is value equality for int, string and bool, and REFERENCE IDENTITY for structs and objects (D3) — two separately constructed structs with identical fields compare false. So a struct used as a map key is keyed by identity, not by contents. That is legal and occasionally what you want, but it is not the shape to reach for: key by an int or string field instead.

There is deliberately NO impl Hash for float and none for pointer types (D4). NaN != NaN and -0.0 == 0.0 both break the contract above, and a language-level Eq trait that could express the exception needs Self, which 0.9 does not have.

A type must not declare both an own hash method and impl Hash — one method name on one type is one callable (D42). User types write only the impl.


Generated by reefc doc