lib/standard/array: add `Array::sub`
[nit.git] / lib / standard / collection / range.nit
index 665b263..da68294 100644 (file)
@@ -109,6 +109,15 @@ class Range[E: Discrete]
        redef fun ==(o) do
                return o isa Range[E] and self.first == o.first and self.last == o.last
        end
+
+       #     var a = new Range[Int](10, 15)
+       #     assert a.hash == 455
+       #     var b = new Range[Int].without_last(10, 15)
+       #     assert b.hash == 432
+       redef fun hash do
+               # 11 and 23 are magic numbers empirically determined to be not so bad.
+               return first.hash * 11 + last.hash * 23
+       end
 end
 
 private class IteratorRange[E: Discrete]
@@ -130,12 +139,12 @@ end
 redef class Int
        # Returns the range from 0 to `self-1`, is used to do:
        #
-       #    var s = new Array[String]
-       #    for i in 3.times do s.add "cool"
-       #    assert s.join(" ") == "cool cool cool"
+       #     var s = new Array[String]
+       #     for i in 3.times do s.add "cool"
+       #     assert s.join(" ") == "cool cool cool"
        #
-       #    s.clear
-       #    for i in 10.times do s.add(i.to_s)
-       #    assert s.to_s == "0123456789"
+       #     s.clear
+       #     for i in 10.times do s.add(i.to_s)
+       #     assert s.to_s == "0123456789"
        fun times: Range[Int] do return [0 .. self[
 end