lib: split hash into hash_collection
[nit.git] / lib / standard / hash.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
4 #
5 # This file is free software, which comes along with NIT. This software is
6 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 # is kept unaltered, and a notification of the changes is added.
10 # You are allowed to redistribute it and sell it, alone or is a part of
11 # another product.
12
13 # This module is about hashable things.
14 # It introduces an hash funtion in objects.
15 package hash
16
17 import kernel
18
19 redef class Object
20 # The hash code of the object.
21 # Assuming that a = b -> a.hash = b.hash
22 ##
23 # Without redefinition, it is the `id' of the instance.
24 fun hash: Int do return object_id / 8
25 end
26
27 redef class Int
28 redef fun hash do return self
29 end
30
31 redef class Char
32 redef fun hash do return ascii
33 end
34
35 redef class Bool
36 redef fun hash
37 do
38 if self then
39 return 1
40 else
41 return 0
42 end
43 end
44 end
45