Line | |
---|
1 |
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | namespace HeuristicLab.Algorithms.GraphRouting {
|
---|
5 | public class Pair<T> {
|
---|
6 | public T First { get; private set; }
|
---|
7 | public T Second { get; private set; }
|
---|
8 |
|
---|
9 | public Pair(T first, T second) {
|
---|
10 | First = first;
|
---|
11 | Second = second;
|
---|
12 | }
|
---|
13 |
|
---|
14 | public override int GetHashCode() {
|
---|
15 | return First.GetHashCode() ^ Second.GetHashCode();
|
---|
16 | }
|
---|
17 |
|
---|
18 | public override bool Equals(object other) {
|
---|
19 | Pair<T> pair = other as Pair<T>;
|
---|
20 | if (pair == null) {
|
---|
21 | return false;
|
---|
22 | }
|
---|
23 | return (this.First.Equals(pair.First) && this.Second.Equals(pair.Second));
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | class PairComparer<T> : IComparer<Pair<T>> where T : IComparable {
|
---|
28 | public int Compare(Pair<T> x, Pair<T> y) {
|
---|
29 | if (x.First.CompareTo(y.First) < 0) {
|
---|
30 | return -1;
|
---|
31 | } else if (x.First.CompareTo(y.First) > 0) {
|
---|
32 | return 1;
|
---|
33 | } else {
|
---|
34 | return x.Second.CompareTo(y.Second);
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.