5 // Zoltan Varga (vargaz@gmail.com)
6 // Marek Safar (marek.safar@gmail.com)
8 // Copyright (C) 2009 Novell
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Collections.Generic;
38 public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
40 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
51 if (!(rest is ITuple))
52 throw new ArgumentException ("rest", "The last element of an eight element tuple must be a Tuple.");
61 /* The rest is generated by the script at the bottom */
64 public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
68 public Tuple (T1 item1)
77 int IComparable.CompareTo (object obj)
79 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
82 int IStructuralComparable.CompareTo (object other, IComparer comparer)
84 var t = other as Tuple<T1>;
86 if (other == null) return 1;
87 throw new ArgumentException ("other");
90 return comparer.Compare (item1, t.item1);
93 public override bool Equals (object obj)
95 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
98 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
100 var t = other as Tuple<T1>;
104 return comparer.Equals (item1, t.item1);
107 public override int GetHashCode ()
109 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
112 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
114 return comparer.GetHashCode (item1);
117 string ITuple.ToString ()
119 return String.Format ("{0}", item1);
122 public override string ToString ()
124 return "(" + ((ITuple) this).ToString () + ")";
129 public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
134 public Tuple (T1 item1, T2 item2)
141 get { return item1; }
145 get { return item2; }
148 int IComparable.CompareTo (object obj)
150 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
153 int IStructuralComparable.CompareTo (object other, IComparer comparer)
155 var t = other as Tuple<T1, T2>;
157 if (other == null) return 1;
158 throw new ArgumentException ("other");
161 int res = comparer.Compare (item1, t.item1);
162 if (res != 0) return res;
163 return comparer.Compare (item2, t.item2);
166 public override bool Equals (object obj)
168 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
171 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
173 var t = other as Tuple<T1, T2>;
177 return comparer.Equals (item1, t.item1) &&
178 comparer.Equals (item2, t.item2);
181 public override int GetHashCode ()
183 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
186 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
189 h0 = comparer.GetHashCode (item1);
190 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
194 string ITuple.ToString ()
196 return String.Format ("{0}, {1}", item1, item2);
199 public override string ToString ()
201 return "(" + ((ITuple) this).ToString () + ")";
206 public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
212 public Tuple (T1 item1, T2 item2, T3 item3)
220 get { return item1; }
224 get { return item2; }
228 get { return item3; }
231 int IComparable.CompareTo (object obj)
233 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
236 int IStructuralComparable.CompareTo (object other, IComparer comparer)
238 var t = other as Tuple<T1, T2, T3>;
240 if (other == null) return 1;
241 throw new ArgumentException ("other");
244 int res = comparer.Compare (item1, t.item1);
245 if (res != 0) return res;
246 res = comparer.Compare (item2, t.item2);
247 if (res != 0) return res;
248 return comparer.Compare (item3, t.item3);
251 public override bool Equals (object obj)
253 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
256 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
258 var t = other as Tuple<T1, T2, T3>;
262 return comparer.Equals (item1, t.item1) &&
263 comparer.Equals (item2, t.item2) &&
264 comparer.Equals (item3, t.item3);
267 public override int GetHashCode ()
269 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
272 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
275 h0 = comparer.GetHashCode (item1);
276 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
277 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item3);
281 string ITuple.ToString ()
283 return String.Format ("{0}, {1}, {2}", item1, item2, item3);
286 public override string ToString ()
288 return "(" + ((ITuple) this).ToString () + ")";
293 public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
300 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4)
309 get { return item1; }
313 get { return item2; }
317 get { return item3; }
321 get { return item4; }
324 int IComparable.CompareTo (object obj)
326 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
329 int IStructuralComparable.CompareTo (object other, IComparer comparer)
331 var t = other as Tuple<T1, T2, T3, T4>;
333 if (other == null) return 1;
334 throw new ArgumentException ("other");
337 int res = comparer.Compare (item1, t.item1);
338 if (res != 0) return res;
339 res = comparer.Compare (item2, t.item2);
340 if (res != 0) return res;
341 res = comparer.Compare (item3, t.item3);
342 if (res != 0) return res;
343 return comparer.Compare (item4, t.item4);
346 public override bool Equals (object obj)
348 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
351 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
353 var t = other as Tuple<T1, T2, T3, T4>;
357 return comparer.Equals (item1, t.item1) &&
358 comparer.Equals (item2, t.item2) &&
359 comparer.Equals (item3, t.item3) &&
360 comparer.Equals (item4, t.item4);
363 public override int GetHashCode ()
365 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
368 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
371 h0 = comparer.GetHashCode (item1);
372 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
373 h1 = comparer.GetHashCode (item3);
374 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
375 h0 = (h0 << 5) + h0 ^ h1;
379 string ITuple.ToString ()
381 return String.Format ("{0}, {1}, {2}, {3}", item1, item2, item3, item4);
384 public override string ToString ()
386 return "(" + ((ITuple) this).ToString () + ")";
391 public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
399 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
409 get { return item1; }
413 get { return item2; }
417 get { return item3; }
421 get { return item4; }
425 get { return item5; }
428 int IComparable.CompareTo (object obj)
430 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
433 int IStructuralComparable.CompareTo (object other, IComparer comparer)
435 var t = other as Tuple<T1, T2, T3, T4, T5>;
437 if (other == null) return 1;
438 throw new ArgumentException ("other");
441 int res = comparer.Compare (item1, t.item1);
442 if (res != 0) return res;
443 res = comparer.Compare (item2, t.item2);
444 if (res != 0) return res;
445 res = comparer.Compare (item3, t.item3);
446 if (res != 0) return res;
447 res = comparer.Compare (item4, t.item4);
448 if (res != 0) return res;
449 return comparer.Compare (item5, t.item5);
452 public override bool Equals (object obj)
454 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
457 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
459 var t = other as Tuple<T1, T2, T3, T4, T5>;
463 return comparer.Equals (item1, t.item1) &&
464 comparer.Equals (item2, t.item2) &&
465 comparer.Equals (item3, t.item3) &&
466 comparer.Equals (item4, t.item4) &&
467 comparer.Equals (item5, t.item5);
470 public override int GetHashCode ()
472 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
475 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
478 h0 = comparer.GetHashCode (item1);
479 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
480 h1 = comparer.GetHashCode (item3);
481 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
482 h0 = (h0 << 5) + h0 ^ h1;
483 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item5);
487 string ITuple.ToString ()
489 return String.Format ("{0}, {1}, {2}, {3}, {4}", item1, item2, item3, item4, item5);
492 public override string ToString ()
494 return "(" + ((ITuple) this).ToString () + ")";
499 public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
508 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
519 get { return item1; }
523 get { return item2; }
527 get { return item3; }
531 get { return item4; }
535 get { return item5; }
539 get { return item6; }
542 int IComparable.CompareTo (object obj)
544 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
547 int IStructuralComparable.CompareTo (object other, IComparer comparer)
549 var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
551 if (other == null) return 1;
552 throw new ArgumentException ("other");
555 int res = comparer.Compare (item1, t.item1);
556 if (res != 0) return res;
557 res = comparer.Compare (item2, t.item2);
558 if (res != 0) return res;
559 res = comparer.Compare (item3, t.item3);
560 if (res != 0) return res;
561 res = comparer.Compare (item4, t.item4);
562 if (res != 0) return res;
563 res = comparer.Compare (item5, t.item5);
564 if (res != 0) return res;
565 return comparer.Compare (item6, t.item6);
568 public override bool Equals (object obj)
570 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
573 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
575 var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
579 return comparer.Equals (item1, t.item1) &&
580 comparer.Equals (item2, t.item2) &&
581 comparer.Equals (item3, t.item3) &&
582 comparer.Equals (item4, t.item4) &&
583 comparer.Equals (item5, t.item5) &&
584 comparer.Equals (item6, t.item6);
587 public override int GetHashCode ()
589 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
592 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
595 h0 = comparer.GetHashCode (item1);
596 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
597 h1 = comparer.GetHashCode (item3);
598 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
599 h0 = (h0 << 5) + h0 ^ h1;
600 h1 = comparer.GetHashCode (item5);
601 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
602 h0 = (h0 << 5) + h0 ^ h1;
606 string ITuple.ToString ()
608 return String.Format ("{0}, {1}, {2}, {3}, {4}, {5}", item1, item2, item3, item4, item5, item6);
611 public override string ToString ()
613 return "(" + ((ITuple) this).ToString () + ")";
618 public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
628 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
640 get { return item1; }
644 get { return item2; }
648 get { return item3; }
652 get { return item4; }
656 get { return item5; }
660 get { return item6; }
664 get { return item7; }
667 int IComparable.CompareTo (object obj)
669 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
672 int IStructuralComparable.CompareTo (object other, IComparer comparer)
674 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
676 if (other == null) return 1;
677 throw new ArgumentException ("other");
680 int res = comparer.Compare (item1, t.item1);
681 if (res != 0) return res;
682 res = comparer.Compare (item2, t.item2);
683 if (res != 0) return res;
684 res = comparer.Compare (item3, t.item3);
685 if (res != 0) return res;
686 res = comparer.Compare (item4, t.item4);
687 if (res != 0) return res;
688 res = comparer.Compare (item5, t.item5);
689 if (res != 0) return res;
690 res = comparer.Compare (item6, t.item6);
691 if (res != 0) return res;
692 return comparer.Compare (item7, t.item7);
695 public override bool Equals (object obj)
697 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
700 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
702 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
706 return comparer.Equals (item1, t.item1) &&
707 comparer.Equals (item2, t.item2) &&
708 comparer.Equals (item3, t.item3) &&
709 comparer.Equals (item4, t.item4) &&
710 comparer.Equals (item5, t.item5) &&
711 comparer.Equals (item6, t.item6) &&
712 comparer.Equals (item7, t.item7);
715 public override int GetHashCode ()
717 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
720 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
723 h0 = comparer.GetHashCode (item1);
724 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
725 h1 = comparer.GetHashCode (item3);
726 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
727 h0 = (h0 << 5) + h0 ^ h1;
728 h1 = comparer.GetHashCode (item5);
729 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
730 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item7);
731 h0 = (h0 << 5) + h0 ^ h1;
735 string ITuple.ToString ()
737 return String.Format ("{0}, {1}, {2}, {3}, {4}, {5}, {6}", item1, item2, item3, item4, item5, item6, item7);
740 public override string ToString ()
742 return "(" + ((ITuple) this).ToString () + ")";
747 public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
759 get { return item1; }
763 get { return item2; }
767 get { return item3; }
771 get { return item4; }
775 get { return item5; }
779 get { return item6; }
783 get { return item7; }
790 int IComparable.CompareTo (object obj)
792 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
795 int IStructuralComparable.CompareTo (object other, IComparer comparer)
797 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
799 if (other == null) return 1;
800 throw new ArgumentException ("other");
803 int res = comparer.Compare (item1, t.item1);
804 if (res != 0) return res;
805 res = comparer.Compare (item2, t.item2);
806 if (res != 0) return res;
807 res = comparer.Compare (item3, t.item3);
808 if (res != 0) return res;
809 res = comparer.Compare (item4, t.item4);
810 if (res != 0) return res;
811 res = comparer.Compare (item5, t.item5);
812 if (res != 0) return res;
813 res = comparer.Compare (item6, t.item6);
814 if (res != 0) return res;
815 res = comparer.Compare (item7, t.item7);
816 if (res != 0) return res;
817 return comparer.Compare (rest, t.rest);
820 public override bool Equals (object obj)
822 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
825 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
827 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
831 return comparer.Equals (item1, t.item1) &&
832 comparer.Equals (item2, t.item2) &&
833 comparer.Equals (item3, t.item3) &&
834 comparer.Equals (item4, t.item4) &&
835 comparer.Equals (item5, t.item5) &&
836 comparer.Equals (item6, t.item6) &&
837 comparer.Equals (item7, t.item7) &&
838 comparer.Equals (rest, t.rest);
841 public override int GetHashCode ()
843 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
846 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
849 h0 = comparer.GetHashCode (item1);
850 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
851 h1 = comparer.GetHashCode (item3);
852 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
853 h0 = (h0 << 5) + h0 ^ h1;
854 h1 = comparer.GetHashCode (item5);
855 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
856 h2 = comparer.GetHashCode (item7);
857 h2 = (h2 << 5) + h2 ^ comparer.GetHashCode (rest);
858 h1 = (h1 << 5) + h1 ^ h2;
859 h0 = (h0 << 5) + h0 ^ h1;
863 string ITuple.ToString ()
865 return String.Format ("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", item1, item2, item3, item4, item5, item6, item7, ((ITuple)rest).ToString ());
868 public override string ToString ()
870 return "(" + ((ITuple) this).ToString () + ")";
887 public class TupleGen
889 public static void Main () {
890 for (int arity = 1; arity < 9; ++arity) {
891 string type_name = GetTypeName (arity);
893 Console.WriteLine ("\t[Serializable]");
894 Console.Write ("\tpublic {0}class ", arity < 8 ? null : "partial ");
895 Console.Write (type_name);
896 Console.WriteLine (" : IStructuralEquatable, IStructuralComparable, IComparable, ITuple");
897 Console.WriteLine ("\t{");
898 for (int i = 1; i <= arity; ++i)
899 Console.WriteLine ("\t\t{0} {1};", GetItemTypeName (i), GetItemName (i));
902 Console.WriteLine ();
903 Console.Write ("\t\tpublic Tuple (");
904 for (int i = 1; i <= arity; ++i) {
905 Console.Write ("{0} {1}", GetItemTypeName (i), GetItemName (i));
907 Console.Write (", ");
909 Console.WriteLine (")");
910 Console.WriteLine ("\t\t{");
911 for (int i = 1; i <= arity; ++i)
912 Console.WriteLine ("\t\t\t this.{0} = {0};", GetItemName (i));
913 Console.WriteLine ("\t\t}");
916 for (int i = 1; i <= arity; ++i) {
917 Console.WriteLine ();
918 Console.WriteLine ("\t\tpublic {0} {1} {{", GetItemTypeName (i),
919 System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase (GetItemName (i)));
920 Console.Write ("\t\t\tget { ");
921 Console.WriteLine ("return {0}; }}", GetItemName (i));
922 Console.WriteLine ("\t\t}");
925 Console.WriteLine ();
926 Console.WriteLine ("\t\tint IComparable.CompareTo (object obj)");
927 Console.WriteLine ("\t\t{");
928 Console.WriteLine ("\t\t\treturn ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);");
929 Console.WriteLine ("\t\t}");
931 Console.WriteLine ();
932 Console.WriteLine ("\t\tint IStructuralComparable.CompareTo (object other, IComparer comparer)");
933 Console.WriteLine ("\t\t{");
934 Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
935 Console.WriteLine ("\t\t\tif (t == null) {");
936 Console.WriteLine ("\t\t\t\tif (other == null) return 1;");
937 Console.WriteLine ("\t\t\t\tthrow new ArgumentException (\"other\");");
938 Console.WriteLine ("\t\t\t}");
939 Console.WriteLine ();
941 for (int i = 1; i < arity; ++i) {
942 Console.Write ("\t\t\t");
944 Console.Write ("int ");
946 Console.WriteLine ("res = comparer.Compare ({0}, t.{0});", GetItemName (i));
947 Console.WriteLine ("\t\t\tif (res != 0) return res;");
949 Console.WriteLine ("\t\t\treturn comparer.Compare ({0}, t.{0});", GetItemName (arity));
950 Console.WriteLine ("\t\t}");
952 Console.WriteLine ();
953 Console.WriteLine ("\t\tpublic override bool Equals (object obj)");
954 Console.WriteLine ("\t\t{");
955 Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);");
956 Console.WriteLine ("\t\t}");
958 Console.WriteLine ();
959 Console.WriteLine ("\t\tbool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)");
960 Console.WriteLine ("\t\t{");
961 Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
962 Console.WriteLine ("\t\t\tif (t == null)");
963 Console.WriteLine ("\t\t\t\treturn false;");
964 Console.WriteLine ();
965 Console.Write ("\t\t\treturn");
967 for (int i = 1; i <= arity; ++i) {
971 Console.Write ("\t\t\t\t");
973 Console.Write ("comparer.Equals ({0}, t.{0})", GetItemName (i));
975 Console.WriteLine (" &&");
977 Console.WriteLine (";");
979 Console.WriteLine ("\t\t}");
981 Console.WriteLine ();
982 Console.WriteLine ("\t\tpublic override int GetHashCode ()");
983 Console.WriteLine ("\t\t{");
984 Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);");
985 Console.WriteLine ("\t\t}");
987 Console.WriteLine ();
988 Console.WriteLine ("\t\tint IStructuralEquatable.GetHashCode (IEqualityComparer comparer)");
989 Console.WriteLine ("\t\t{");
991 Console.WriteLine ("\t\t\treturn comparer.GetHashCode ({0});", GetItemName (arity));
993 int varnum = IntLog2 (arity);
994 Console.Write ("\t\t\tint h0");
995 for (int i = 1; i < varnum; ++i)
996 Console.Write (", h{0}", i);
997 Console.WriteLine (";");
999 WriteHash (0, 1, arity);
1001 Console.WriteLine ("\t\t\treturn h0;");
1004 Console.WriteLine ("\t\t}");
1006 Console.WriteLine ();
1007 Console.WriteLine ("\t\tstring ITuple.ToString ()");
1008 Console.WriteLine ("\t\t{");
1009 Console.Write ("\t\t\treturn String.Format (\"");
1010 for (int i = 1; i <= arity; ++i) {
1011 Console.Write ("{" + (i - 1) + "}");
1013 Console.Write (", ");
1015 Console.Write ("\", ");
1016 for (int i = 1; i <= arity; ++i) {
1017 var item_name = GetItemName (i);
1018 Console.Write (i == 8 ? "((ITuple){0}).ToString ()" : "{0}", item_name);
1020 Console.Write (", ");
1022 Console.WriteLine (");");
1023 Console.WriteLine ("\t\t}");
1025 Console.WriteLine ();
1026 Console.WriteLine ("\t\tpublic override string ToString ()");
1027 Console.WriteLine ("\t\t{");
1028 Console.WriteLine ("\t\t\treturn \"(\" + ((ITuple) this).ToString () + \")\";");
1029 Console.WriteLine ("\t\t}");
1031 Console.WriteLine ("\t}\n");
1035 static int IntLog2 (int n)
1047 static void WriteHash (int destVar, int start, int count)
1050 Console.WriteLine ("\t\t\th{0} = comparer.GetHashCode ({1});", destVar, GetItemName (start));
1052 int subCount = 1 << IntLog2 (count - 1);
1053 WriteHash (destVar, start, subCount);
1057 Console.WriteLine ("\t\t\th{0} = (h{0} << 5) + h{0} ^ comparer.GetHashCode ({1});", destVar, GetItemName (start));
1059 WriteHash (destVar + 1, start, count);
1060 Console.WriteLine ("\t\t\th{0} = (h{0} << 5) + h{0} ^ h{1};", destVar, destVar + 1);
1065 static string GetTypeName (int arity)
1067 StringBuilder sb = new StringBuilder ();
1068 sb.Append ("Tuple<");
1069 for (int i = 1; i <= arity; ++i) {
1070 sb.Append (GetItemTypeName (i));
1076 return sb.ToString ();
1079 static string GetItemName (int arity)
1081 return arity < 8 ? "item" + arity.ToString () : "rest";
1084 static string GetItemTypeName (int arity)
1086 return arity < 8 ? "T" + arity.ToString () : "TRest";