diff options
author | michelou <michelou@epfl.ch> | 2006-10-10 16:00:00 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2006-10-10 16:00:00 +0000 |
commit | 2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025 (patch) | |
tree | 401e18f07778ba1bb58d66eff6b91ede4146ab71 /docs/examples/maps.scala | |
parent | dcbcc2938384bd08794e6776c17e8c33b69672a7 (diff) | |
download | scala-2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025.tar.gz scala-2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025.tar.bz2 scala-2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025.zip |
updated docs/examples/*.scala
Diffstat (limited to 'docs/examples/maps.scala')
-rw-r--r-- | docs/examples/maps.scala | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/docs/examples/maps.scala b/docs/examples/maps.scala index 1b5d41df54..5b1af51ac3 100644 --- a/docs/examples/maps.scala +++ b/docs/examples/maps.scala @@ -90,18 +90,18 @@ object maps { def extend(key: kt, value: vt): map = if (key < k) new Node(k, v, l.extend(key, value), r) else if (key > k) new Node(k, v, l, r.extend(key, value)) - else new Node(k, value, l, r); + else new Node(k, value, l, r) def remove(key: kt): map = if (key < k) new Node(k, v, l.remove(key), r) else if (key > k) new Node(k, v, l, r.remove(key)) else if (l == empty) r else if (r == empty) l else { - val midKey = r.domain.head; + val midKey = r.domain.head new Node(midKey, r(midKey), l, r.remove(midKey)) } - def domain: Stream[kt] = l.domain append Stream.cons(k, r.domain); - def range: Stream[vt] = l.range append Stream.cons(v, r.range); + def domain: Stream[kt] = l.domain append Stream.cons(k, r.domain) + def range: Stream[vt] = l.range append Stream.cons(v, r.range) } } @@ -129,24 +129,24 @@ object maps { def remove(key: kt): map = if (this == empty) this - else if (key < k) { l = l.remove(key) ; this } - else if (key > k) { r = r.remove(key) ; this } + else if (key < k) { l = l.remove(key); this } + else if (key > k) { r = r.remove(key); this } else if (l == empty) r else if (r == empty) l else { var mid = r while (!(mid.l == empty)) { mid = mid.l } - mid.r = r.remove(mid.k); - mid.l = l; + mid.r = r.remove(mid.k) + mid.l = l mid } def domain: Stream[kt] = - if (this == empty) Stream.empty; + if (this == empty) Stream.empty else l.domain append Stream.cons(k, r.domain) def range: Stream[vt] = - if (this == empty) Stream.empty; + if (this == empty) Stream.empty else l.range append Stream.cons(v, r.range) } val empty = new MutMap(null, null) @@ -157,21 +157,17 @@ object maps { def month = m def day = d - override def compare [b >: Date <% Ordered[b]](that: b): Int = that match { - case other: Date => - if ((year == other.year) && - (month == other.month) && - (day == other.day)) - 0 - else if ((year < other.year) || - (year == other.year && month < other.month) || - (month == other.month && day < other.day)) - -1 - else - 1 - case _ => - -(that compareTo this) - } + def compare(other: Date): Int = + if (year == other.year && + month == other.month && + day == other.day) + 0 + else if (year < other.year || + year == other.year && month < other.month || + month == other.month && day < other.day) + -1 + else + 1 override def equals(that: Any): Boolean = that.isInstanceOf[Date] && { |