Skip to content

Commit

Permalink
[641146] Implemented IStructuralComparable.CompareTo
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Sep 23, 2010
1 parent 133b340 commit a572542
Showing 1 changed file with 139 additions and 20 deletions.
159 changes: 139 additions & 20 deletions mcs/class/corlib/System/Tuples.cs
Expand Up @@ -82,9 +82,15 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

return comparer.Compare (item1, t.item1);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -144,9 +150,17 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1, T2>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

int res = comparer.Compare (item1, t.item1);
if (res != 0) return res;
return comparer.Compare (item2, t.item2);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -215,9 +229,19 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1, T2, T3>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

int res = comparer.Compare (item1, t.item1);
if (res != 0) return res;
res = comparer.Compare (item2, t.item2);
if (res != 0) return res;
return comparer.Compare (item3, t.item3);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -294,9 +318,21 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1, T2, T3, T4>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

int res = comparer.Compare (item1, t.item1);
if (res != 0) return res;
res = comparer.Compare (item2, t.item2);
if (res != 0) return res;
res = comparer.Compare (item3, t.item3);
if (res != 0) return res;
return comparer.Compare (item4, t.item4);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -381,9 +417,23 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1, T2, T3, T4, T5>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

int res = comparer.Compare (item1, t.item1);
if (res != 0) return res;
res = comparer.Compare (item2, t.item2);
if (res != 0) return res;
res = comparer.Compare (item3, t.item3);
if (res != 0) return res;
res = comparer.Compare (item4, t.item4);
if (res != 0) return res;
return comparer.Compare (item5, t.item5);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -476,9 +526,25 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

int res = comparer.Compare (item1, t.item1);
if (res != 0) return res;
res = comparer.Compare (item2, t.item2);
if (res != 0) return res;
res = comparer.Compare (item3, t.item3);
if (res != 0) return res;
res = comparer.Compare (item4, t.item4);
if (res != 0) return res;
res = comparer.Compare (item5, t.item5);
if (res != 0) return res;
return comparer.Compare (item6, t.item6);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -579,9 +645,27 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

int res = comparer.Compare (item1, t.item1);
if (res != 0) return res;
res = comparer.Compare (item2, t.item2);
if (res != 0) return res;
res = comparer.Compare (item3, t.item3);
if (res != 0) return res;
res = comparer.Compare (item4, t.item4);
if (res != 0) return res;
res = comparer.Compare (item5, t.item5);
if (res != 0) return res;
res = comparer.Compare (item6, t.item6);
if (res != 0) return res;
return comparer.Compare (item7, t.item7);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -678,9 +762,29 @@ int IComparable.CompareTo (object obj)
return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
}

[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
throw new NotImplementedException ();
var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
if (t == null) {
if (other == null) return 1;
throw new ArgumentException ();
}

int res = comparer.Compare (item1, t.item1);
if (res != 0) return res;
res = comparer.Compare (item2, t.item2);
if (res != 0) return res;
res = comparer.Compare (item3, t.item3);
if (res != 0) return res;
res = comparer.Compare (item4, t.item4);
if (res != 0) return res;
res = comparer.Compare (item5, t.item5);
if (res != 0) return res;
res = comparer.Compare (item6, t.item6);
if (res != 0) return res;
res = comparer.Compare (item7, t.item7);
if (res != 0) return res;
return comparer.Compare (rest, t.rest);
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -788,10 +892,25 @@ public class TupleGen
Console.WriteLine ("\t\t}");

Console.WriteLine ();
Console.WriteLine ("\t\t[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)");
Console.WriteLine ("\t\tint IStructuralComparable.CompareTo (object other, IComparer comparer)");
Console.WriteLine ("\t\t{");
Console.WriteLine ("\t\t\tthrow new NotImplementedException ();");
Console.WriteLine ("\t\t}");
Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
Console.WriteLine ("\t\t\tif (t == null) {");
Console.WriteLine ("\t\t\t\tif (other == null) return 1;");
Console.WriteLine ("\t\t\t\tthrow new ArgumentException ();");
Console.WriteLine ("\t\t\t}");
Console.WriteLine ();

for (int i = 1; i < arity; ++i) {
Console.Write ("\t\t\t");
if (i == 1)
Console.Write ("int ");

Console.WriteLine ("res = comparer.Compare ({0}, t.{0});", GetItemName (i));
Console.WriteLine ("\t\t\tif (res != 0) return res;");
}
Console.WriteLine ("\t\t\treturn comparer.Compare ({0}, t.{0});", GetItemName (arity));
Console.WriteLine ("\t\t}");

Console.WriteLine ();
Console.WriteLine ("\t\tpublic override bool Equals (object obj)");
Expand Down Expand Up @@ -827,7 +946,7 @@ public class TupleGen
Console.WriteLine ();
Console.WriteLine ("\t\tpublic override int GetHashCode ()");
Console.WriteLine ("\t\t{");
Console.WriteLine ("\t\t\treturn GetHashCode (EqualityComparer<object>.Default);");
Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);");
Console.WriteLine ("\t\t}");

Console.WriteLine ();
Expand Down

0 comments on commit a572542

Please sign in to comment.