Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/Utilities/Pair.cs @ 10391

Last change on this file since 10391 was 8516, checked in by spimming, 12 years ago

#1894:

  • solution restructured
  • removed obsolete and outdated parts
File size: 1013 bytes
Line 
1
2using System;
3using System.Collections.Generic;
4namespace HeuristicLab.Algorithms.GraphRouting.Utilities {
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.