Mercurial > projects > ldc
comparison tango/tango/util/collection/impl/DefaultComparator.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /* | |
2 File: DefaultComparator.d | |
3 | |
4 Originally written by Doug Lea and released into the public domain. | |
5 Thanks for the assistance and support of Sun Microsystems Labs, Agorics | |
6 Inc, Loral, and everyone contributing, testing, and using this code. | |
7 | |
8 History: | |
9 Date Who What | |
10 24Sep95 dl@cs.oswego.edu Create from tango.util.collection.d working file | |
11 | |
12 */ | |
13 | |
14 | |
15 module tango.util.collection.impl.DefaultComparator; | |
16 | |
17 private import tango.util.collection.model.Comparator; | |
18 | |
19 | |
20 /** | |
21 * | |
22 * | |
23 * DefaultComparator provides a general-purpose but slow compare | |
24 * operation. | |
25 * | |
26 author: Doug Lea | |
27 * @version 0.93 | |
28 * | |
29 * <P> For an introduction to this package see <A HREF="index.html"> Overview </A>. | |
30 **/ | |
31 | |
32 public class DefaultComparator(T) : Comparator!(T) | |
33 { | |
34 | |
35 /** | |
36 * Try various downcasts to find a basis for | |
37 * comparing two elements. If all else fails, just compare | |
38 * hashCodes(). This can be effective when you are | |
39 * using an ordered implementation data structure like trees, | |
40 * but don't really care about ordering. | |
41 * | |
42 * @param fst first argument | |
43 * @param snd second argument | |
44 * Returns: a negative number if fst is less than snd; a | |
45 * positive number if fst is greater than snd; else 0 | |
46 **/ | |
47 | |
48 public final int compare(T fst, T snd) | |
49 { | |
50 if (fst is snd) | |
51 return 0; | |
52 | |
53 return typeid(T).compare (&fst, &snd); | |
54 } | |
55 } |