~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/library/scala/math/Ordering.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*                     __                                               *\
2
2
**     ________ ___   / /  ___     Scala API                            **
3
 
**    / __/ __// _ | / /  / _ |    (c) 2003-2011, LAMP/EPFL             **
 
3
**    / __/ __// _ | / /  / _ |    (c) 2003-2013, LAMP/EPFL             **
4
4
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
5
5
** /____/\___/_/ |_/____/_/ | |                                         **
6
6
**                          |/                                          **
7
7
\*                                                                      */
8
8
 
9
 
package scala.math
 
9
package scala
 
10
package math
10
11
 
11
12
import java.util.Comparator
 
13
import scala.language.{implicitConversions, higherKinds}
12
14
 
13
15
/** Ordering is a trait whose instances each represent a strategy for sorting
14
16
  * instances of a type.
24
26
  * val pairs = Array(("a", 5, 2), ("c", 3, 1), ("b", 1, 3))
25
27
  *
26
28
  * // sort by 2nd element
27
 
  * Sorting.quickSort(pairs)(Ordering.by[(String, Int, Int), Int](_._2)
 
29
  * Sorting.quickSort(pairs)(Ordering.by[(String, Int, Int), Int](_._2))
28
30
  *
29
31
  * // sort by the 3rd element, then 1st
30
 
  * Sorting.quickSort(pairs)(Ordering[(Int, String)].on[(String, Int, Int)]((_._3, _._1))
 
32
  * Sorting.quickSort(pairs)(Ordering[(Int, String)].on(x => (x._3, x._1)))
31
33
  * }}}
32
34
  *
33
35
  * An Ordering[T] is implemented by specifying compare(a:T, b:T), which
164
166
    /** Not in the standard scope due to the potential for divergence:
165
167
      * For instance `implicitly[Ordering[Any]]` diverges in its presence.
166
168
      */
167
 
    implicit def seqDerivedOrdering[CC[X] <: collection.Seq[X], T](implicit ord: Ordering[T]): Ordering[CC[T]] =
 
169
    implicit def seqDerivedOrdering[CC[X] <: scala.collection.Seq[X], T](implicit ord: Ordering[T]): Ordering[CC[T]] =
168
170
      new Ordering[CC[T]] {
169
171
        def compare(x: CC[T], y: CC[T]): Int = {
170
172
          val xe = x.iterator
262
264
  implicit object Long extends LongOrdering
263
265
 
264
266
  trait FloatOrdering extends Ordering[Float] {
 
267
    outer =>
 
268
 
265
269
    def compare(x: Float, y: Float) = java.lang.Float.compare(x, y)
 
270
 
 
271
    override def lteq(x: Float, y: Float): Boolean = x <= y
 
272
    override def gteq(x: Float, y: Float): Boolean = x >= y
 
273
    override def lt(x: Float, y: Float): Boolean = x < y
 
274
    override def gt(x: Float, y: Float): Boolean = x > y
 
275
    override def equiv(x: Float, y: Float): Boolean = x == y
 
276
    override def max(x: Float, y: Float): Float = math.max(x, y)
 
277
    override def min(x: Float, y: Float): Float = math.min(x, y)
 
278
 
 
279
    override def reverse: Ordering[Float] = new FloatOrdering {
 
280
      override def reverse = outer
 
281
      override def compare(x: Float, y: Float) = outer.compare(y, x)
 
282
 
 
283
      override def lteq(x: Float, y: Float): Boolean = outer.lteq(y, x)
 
284
      override def gteq(x: Float, y: Float): Boolean = outer.gteq(y, x)
 
285
      override def lt(x: Float, y: Float): Boolean = outer.lt(y, x)
 
286
      override def gt(x: Float, y: Float): Boolean = outer.gt(y, x)
 
287
    }
266
288
  }
267
289
  implicit object Float extends FloatOrdering
268
290
 
269
291
  trait DoubleOrdering extends Ordering[Double] {
 
292
    outer =>
 
293
 
270
294
    def compare(x: Double, y: Double) = java.lang.Double.compare(x, y)
 
295
 
 
296
    override def lteq(x: Double, y: Double): Boolean = x <= y
 
297
    override def gteq(x: Double, y: Double): Boolean = x >= y
 
298
    override def lt(x: Double, y: Double): Boolean = x < y
 
299
    override def gt(x: Double, y: Double): Boolean = x > y
 
300
    override def equiv(x: Double, y: Double): Boolean = x == y
 
301
    override def max(x: Double, y: Double): Double = math.max(x, y)
 
302
    override def min(x: Double, y: Double): Double = math.min(x, y)
 
303
 
 
304
    override def reverse: Ordering[Double] = new DoubleOrdering {
 
305
      override def reverse = outer
 
306
      override def compare(x: Double, y: Double) = outer.compare(y, x)
 
307
 
 
308
      override def lteq(x: Double, y: Double): Boolean = outer.lteq(y, x)
 
309
      override def gteq(x: Double, y: Double): Boolean = outer.gteq(y, x)
 
310
      override def lt(x: Double, y: Double): Boolean = outer.lt(y, x)
 
311
      override def gt(x: Double, y: Double): Boolean = outer.gt(y, x)
 
312
    }
271
313
  }
272
314
  implicit object Double extends DoubleOrdering
273
315