feat(library/init/data/hashable): add hashable nat instance

This commit is contained in:
Leonardo de Moura 2018-05-06 07:53:29 -07:00
parent 3079d2d007
commit 89b4bb7210
2 changed files with 9 additions and 3 deletions

View file

@ -10,14 +10,20 @@ universes u
class hashable (α : Type u) :=
(hash : α → usize)
export hashable (hash)
-- TODO: mark as builtin and opaque
def mix_hash (u₁ u₂ : usize) : usize :=
default usize
-- TODO: mark as builtin
def string.hash (s : string) : usize :=
protected def string.hash (s : string) : usize :=
default usize
instance : hashable string := ⟨string.hash⟩
export hashable (hash)
-- TODO: add builtin
protected def nat.hash (n : nat) : usize :=
usize.of_nat n
instance : hashable nat := ⟨nat.hash⟩

View file

@ -32,7 +32,7 @@ namespace name
private def hash_aux : name → usize → usize
| anonymous r := r
| (mk_string n s) r := hash_aux n (mix_hash r (hash s))
| (mk_numeral n k) r := hash_aux n (mix_hash r (usize.of_nat k))
| (mk_numeral n k) r := hash_aux n (mix_hash r (hash k))
-- TODO: mark as opaque and builtin, and add as builtin
protected def hash (n : name) : usize :=