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)
52 if (!typeof (TRest).IsGenericType)
55 Type t = typeof (TRest).GetGenericTypeDefinition ();
56 if (!(t == typeof (Tuple<>) || t == typeof (Tuple<,>) || t == typeof (Tuple<,,>) || t == typeof (Tuple<,,,>) || t == typeof (Tuple<,,,,>) || t == typeof (Tuple <,,,,,>) || t == typeof (Tuple<,,,,,,>) || t == typeof (Tuple<,,,,,,,>)))
60 throw new ArgumentException ("rest", "The last element of an eight element tuple must be a Tuple.");
64 /* The rest is generated by the script at the bottom */
67 public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable
71 public Tuple (T1 item1)
80 int IComparable.CompareTo (object obj)
82 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
85 int IStructuralComparable.CompareTo (object other, IComparer comparer)
87 var t = other as Tuple<T1>;
89 if (other == null) return 1;
90 throw new ArgumentException ("other");
93 return comparer.Compare (item1, t.item1);
96 public override bool Equals (object obj)
98 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
101 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
103 var t = other as Tuple<T1>;
107 return comparer.Equals (item1, t.item1);
110 public override int GetHashCode ()
112 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
115 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
117 return comparer.GetHashCode (item1);
120 public override string ToString ()
122 return String.Format ("({0})", item1);
127 public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable
132 public Tuple (T1 item1, T2 item2)
139 get { return item1; }
143 get { return item2; }
146 int IComparable.CompareTo (object obj)
148 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
151 int IStructuralComparable.CompareTo (object other, IComparer comparer)
153 var t = other as Tuple<T1, T2>;
155 if (other == null) return 1;
156 throw new ArgumentException ("other");
159 int res = comparer.Compare (item1, t.item1);
160 if (res != 0) return res;
161 return comparer.Compare (item2, t.item2);
164 public override bool Equals (object obj)
166 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
169 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
171 var t = other as Tuple<T1, T2>;
175 return comparer.Equals (item1, t.item1) &&
176 comparer.Equals (item2, t.item2);
179 public override int GetHashCode ()
181 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
184 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
187 h0 = comparer.GetHashCode (item1);
188 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
192 public override string ToString ()
194 return String.Format ("({0}, {1})", item1, item2);
199 public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable
205 public Tuple (T1 item1, T2 item2, T3 item3)
213 get { return item1; }
217 get { return item2; }
221 get { return item3; }
224 int IComparable.CompareTo (object obj)
226 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
229 int IStructuralComparable.CompareTo (object other, IComparer comparer)
231 var t = other as Tuple<T1, T2, T3>;
233 if (other == null) return 1;
234 throw new ArgumentException ("other");
237 int res = comparer.Compare (item1, t.item1);
238 if (res != 0) return res;
239 res = comparer.Compare (item2, t.item2);
240 if (res != 0) return res;
241 return comparer.Compare (item3, t.item3);
244 public override bool Equals (object obj)
246 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
249 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
251 var t = other as Tuple<T1, T2, T3>;
255 return comparer.Equals (item1, t.item1) &&
256 comparer.Equals (item2, t.item2) &&
257 comparer.Equals (item3, t.item3);
260 public override int GetHashCode ()
262 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
265 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
268 h0 = comparer.GetHashCode (item1);
269 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
270 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item3);
274 public override string ToString ()
276 return String.Format ("({0}, {1}, {2})", item1, item2, item3);
281 public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable
288 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4)
297 get { return item1; }
301 get { return item2; }
305 get { return item3; }
309 get { return item4; }
312 int IComparable.CompareTo (object obj)
314 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
317 int IStructuralComparable.CompareTo (object other, IComparer comparer)
319 var t = other as Tuple<T1, T2, T3, T4>;
321 if (other == null) return 1;
322 throw new ArgumentException ("other");
325 int res = comparer.Compare (item1, t.item1);
326 if (res != 0) return res;
327 res = comparer.Compare (item2, t.item2);
328 if (res != 0) return res;
329 res = comparer.Compare (item3, t.item3);
330 if (res != 0) return res;
331 return comparer.Compare (item4, t.item4);
334 public override bool Equals (object obj)
336 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
339 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
341 var t = other as Tuple<T1, T2, T3, T4>;
345 return comparer.Equals (item1, t.item1) &&
346 comparer.Equals (item2, t.item2) &&
347 comparer.Equals (item3, t.item3) &&
348 comparer.Equals (item4, t.item4);
351 public override int GetHashCode ()
353 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
356 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
359 h0 = comparer.GetHashCode (item1);
360 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
361 h1 = comparer.GetHashCode (item3);
362 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
363 h0 = (h0 << 5) + h0 ^ h1;
367 public override string ToString ()
369 return String.Format ("({0}, {1}, {2}, {3})", item1, item2, item3, item4);
374 public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable
382 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
392 get { return item1; }
396 get { return item2; }
400 get { return item3; }
404 get { return item4; }
408 get { return item5; }
411 int IComparable.CompareTo (object obj)
413 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
416 int IStructuralComparable.CompareTo (object other, IComparer comparer)
418 var t = other as Tuple<T1, T2, T3, T4, T5>;
420 if (other == null) return 1;
421 throw new ArgumentException ("other");
424 int res = comparer.Compare (item1, t.item1);
425 if (res != 0) return res;
426 res = comparer.Compare (item2, t.item2);
427 if (res != 0) return res;
428 res = comparer.Compare (item3, t.item3);
429 if (res != 0) return res;
430 res = comparer.Compare (item4, t.item4);
431 if (res != 0) return res;
432 return comparer.Compare (item5, t.item5);
435 public override bool Equals (object obj)
437 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
440 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
442 var t = other as Tuple<T1, T2, T3, T4, T5>;
446 return comparer.Equals (item1, t.item1) &&
447 comparer.Equals (item2, t.item2) &&
448 comparer.Equals (item3, t.item3) &&
449 comparer.Equals (item4, t.item4) &&
450 comparer.Equals (item5, t.item5);
453 public override int GetHashCode ()
455 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
458 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
461 h0 = comparer.GetHashCode (item1);
462 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
463 h1 = comparer.GetHashCode (item3);
464 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
465 h0 = (h0 << 5) + h0 ^ h1;
466 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item5);
470 public override string ToString ()
472 return String.Format ("({0}, {1}, {2}, {3}, {4})", item1, item2, item3, item4, item5);
477 public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable
486 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
497 get { return item1; }
501 get { return item2; }
505 get { return item3; }
509 get { return item4; }
513 get { return item5; }
517 get { return item6; }
520 int IComparable.CompareTo (object obj)
522 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
525 int IStructuralComparable.CompareTo (object other, IComparer comparer)
527 var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
529 if (other == null) return 1;
530 throw new ArgumentException ("other");
533 int res = comparer.Compare (item1, t.item1);
534 if (res != 0) return res;
535 res = comparer.Compare (item2, t.item2);
536 if (res != 0) return res;
537 res = comparer.Compare (item3, t.item3);
538 if (res != 0) return res;
539 res = comparer.Compare (item4, t.item4);
540 if (res != 0) return res;
541 res = comparer.Compare (item5, t.item5);
542 if (res != 0) return res;
543 return comparer.Compare (item6, t.item6);
546 public override bool Equals (object obj)
548 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
551 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
553 var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
557 return comparer.Equals (item1, t.item1) &&
558 comparer.Equals (item2, t.item2) &&
559 comparer.Equals (item3, t.item3) &&
560 comparer.Equals (item4, t.item4) &&
561 comparer.Equals (item5, t.item5) &&
562 comparer.Equals (item6, t.item6);
565 public override int GetHashCode ()
567 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
570 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
573 h0 = comparer.GetHashCode (item1);
574 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
575 h1 = comparer.GetHashCode (item3);
576 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
577 h0 = (h0 << 5) + h0 ^ h1;
578 h1 = comparer.GetHashCode (item5);
579 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
580 h0 = (h0 << 5) + h0 ^ h1;
584 public override string ToString ()
586 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5})", item1, item2, item3, item4, item5, item6);
591 public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable
601 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
613 get { return item1; }
617 get { return item2; }
621 get { return item3; }
625 get { return item4; }
629 get { return item5; }
633 get { return item6; }
637 get { return item7; }
640 int IComparable.CompareTo (object obj)
642 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
645 int IStructuralComparable.CompareTo (object other, IComparer comparer)
647 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
649 if (other == null) return 1;
650 throw new ArgumentException ("other");
653 int res = comparer.Compare (item1, t.item1);
654 if (res != 0) return res;
655 res = comparer.Compare (item2, t.item2);
656 if (res != 0) return res;
657 res = comparer.Compare (item3, t.item3);
658 if (res != 0) return res;
659 res = comparer.Compare (item4, t.item4);
660 if (res != 0) return res;
661 res = comparer.Compare (item5, t.item5);
662 if (res != 0) return res;
663 res = comparer.Compare (item6, t.item6);
664 if (res != 0) return res;
665 return comparer.Compare (item7, t.item7);
668 public override bool Equals (object obj)
670 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
673 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
675 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
679 return comparer.Equals (item1, t.item1) &&
680 comparer.Equals (item2, t.item2) &&
681 comparer.Equals (item3, t.item3) &&
682 comparer.Equals (item4, t.item4) &&
683 comparer.Equals (item5, t.item5) &&
684 comparer.Equals (item6, t.item6) &&
685 comparer.Equals (item7, t.item7);
688 public override int GetHashCode ()
690 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
693 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
696 h0 = comparer.GetHashCode (item1);
697 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
698 h1 = comparer.GetHashCode (item3);
699 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
700 h0 = (h0 << 5) + h0 ^ h1;
701 h1 = comparer.GetHashCode (item5);
702 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
703 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item7);
704 h0 = (h0 << 5) + h0 ^ h1;
708 public override string ToString ()
710 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6})", item1, item2, item3, item4, item5, item6, item7);
715 public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable
727 get { return item1; }
731 get { return item2; }
735 get { return item3; }
739 get { return item4; }
743 get { return item5; }
747 get { return item6; }
751 get { return item7; }
758 int IComparable.CompareTo (object obj)
760 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
763 int IStructuralComparable.CompareTo (object other, IComparer comparer)
765 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
767 if (other == null) return 1;
768 throw new ArgumentException ("other");
771 int res = comparer.Compare (item1, t.item1);
772 if (res != 0) return res;
773 res = comparer.Compare (item2, t.item2);
774 if (res != 0) return res;
775 res = comparer.Compare (item3, t.item3);
776 if (res != 0) return res;
777 res = comparer.Compare (item4, t.item4);
778 if (res != 0) return res;
779 res = comparer.Compare (item5, t.item5);
780 if (res != 0) return res;
781 res = comparer.Compare (item6, t.item6);
782 if (res != 0) return res;
783 res = comparer.Compare (item7, t.item7);
784 if (res != 0) return res;
785 return comparer.Compare (rest, t.rest);
788 public override bool Equals (object obj)
790 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
793 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
795 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
799 return comparer.Equals (item1, t.item1) &&
800 comparer.Equals (item2, t.item2) &&
801 comparer.Equals (item3, t.item3) &&
802 comparer.Equals (item4, t.item4) &&
803 comparer.Equals (item5, t.item5) &&
804 comparer.Equals (item6, t.item6) &&
805 comparer.Equals (item7, t.item7) &&
806 comparer.Equals (rest, t.rest);
809 public override int GetHashCode ()
811 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
814 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
817 h0 = comparer.GetHashCode (item1);
818 h0 = (h0 << 5) + h0 ^ comparer.GetHashCode (item2);
819 h1 = comparer.GetHashCode (item3);
820 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item4);
821 h0 = (h0 << 5) + h0 ^ h1;
822 h1 = comparer.GetHashCode (item5);
823 h1 = (h1 << 5) + h1 ^ comparer.GetHashCode (item6);
824 h2 = comparer.GetHashCode (item7);
825 h2 = (h2 << 5) + h2 ^ comparer.GetHashCode (rest);
826 h1 = (h1 << 5) + h1 ^ h2;
827 h0 = (h0 << 5) + h0 ^ h1;
831 public override string ToString ()
833 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", item1, item2, item3, item4, item5, item6, item7, rest);
850 public class TupleGen
852 public static void Main () {
853 for (int arity = 1; arity < 9; ++arity) {
854 string type_name = GetTypeName (arity);
856 Console.WriteLine ("\t[Serializable]");
857 Console.Write ("\tpublic {0}class ", arity < 8 ? null : "partial ");
858 Console.Write (type_name);
859 Console.WriteLine (" : IStructuralEquatable, IStructuralComparable, IComparable");
860 Console.WriteLine ("\t{");
861 for (int i = 1; i <= arity; ++i)
862 Console.WriteLine ("\t\t{0} {1};", GetItemTypeName (i), GetItemName (i));
865 Console.WriteLine ();
866 Console.Write ("\t\tpublic Tuple (");
867 for (int i = 1; i <= arity; ++i) {
868 Console.Write ("{0} {1}", GetItemTypeName (i), GetItemName (i));
870 Console.Write (", ");
872 Console.WriteLine (")");
873 Console.WriteLine ("\t\t{");
874 for (int i = 1; i <= arity; ++i)
875 Console.WriteLine ("\t\t\t this.{0} = {0};", GetItemName (i));
876 Console.WriteLine ("\t\t}");
879 for (int i = 1; i <= arity; ++i) {
880 Console.WriteLine ();
881 Console.WriteLine ("\t\tpublic {0} {1} {{", GetItemTypeName (i),
882 System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase (GetItemName (i)));
883 Console.Write ("\t\t\tget { ");
884 Console.WriteLine ("return {0}; }}", GetItemName (i));
885 Console.WriteLine ("\t\t}");
888 Console.WriteLine ();
889 Console.WriteLine ("\t\tint IComparable.CompareTo (object obj)");
890 Console.WriteLine ("\t\t{");
891 Console.WriteLine ("\t\t\treturn ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);");
892 Console.WriteLine ("\t\t}");
894 Console.WriteLine ();
895 Console.WriteLine ("\t\tint IStructuralComparable.CompareTo (object other, IComparer comparer)");
896 Console.WriteLine ("\t\t{");
897 Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
898 Console.WriteLine ("\t\t\tif (t == null) {");
899 Console.WriteLine ("\t\t\t\tif (other == null) return 1;");
900 Console.WriteLine ("\t\t\t\tthrow new ArgumentException (\"other\");");
901 Console.WriteLine ("\t\t\t}");
902 Console.WriteLine ();
904 for (int i = 1; i < arity; ++i) {
905 Console.Write ("\t\t\t");
907 Console.Write ("int ");
909 Console.WriteLine ("res = comparer.Compare ({0}, t.{0});", GetItemName (i));
910 Console.WriteLine ("\t\t\tif (res != 0) return res;");
912 Console.WriteLine ("\t\t\treturn comparer.Compare ({0}, t.{0});", GetItemName (arity));
913 Console.WriteLine ("\t\t}");
915 Console.WriteLine ();
916 Console.WriteLine ("\t\tpublic override bool Equals (object obj)");
917 Console.WriteLine ("\t\t{");
918 Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);");
919 Console.WriteLine ("\t\t}");
921 Console.WriteLine ();
922 Console.WriteLine ("\t\tbool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)");
923 Console.WriteLine ("\t\t{");
924 Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
925 Console.WriteLine ("\t\t\tif (t == null)");
926 Console.WriteLine ("\t\t\t\treturn false;");
927 Console.WriteLine ();
928 Console.Write ("\t\t\treturn");
930 for (int i = 1; i <= arity; ++i) {
934 Console.Write ("\t\t\t\t");
936 Console.Write ("comparer.Equals ({0}, t.{0})", GetItemName (i));
938 Console.WriteLine (" &&");
940 Console.WriteLine (";");
942 Console.WriteLine ("\t\t}");
944 Console.WriteLine ();
945 Console.WriteLine ("\t\tpublic override int GetHashCode ()");
946 Console.WriteLine ("\t\t{");
947 Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);");
948 Console.WriteLine ("\t\t}");
950 Console.WriteLine ();
951 Console.WriteLine ("\t\tint IStructuralEquatable.GetHashCode (IEqualityComparer comparer)");
952 Console.WriteLine ("\t\t{");
954 Console.WriteLine ("\t\t\treturn comparer.GetHashCode ({0});", GetItemName (arity));
956 int varnum = IntLog2(arity);
957 Console.Write ("\t\t\tint h0");
958 for (int i = 1; i < varnum; ++i)
959 Console.Write (", h{0}", i);
960 Console.WriteLine (";");
962 WriteHash(0, 1, arity);
964 Console.WriteLine ("\t\t\treturn h0;");
967 Console.WriteLine ("\t\t}");
969 Console.WriteLine ();
970 Console.WriteLine ("\t\tpublic override string ToString ()");
971 Console.WriteLine ("\t\t{");
972 Console.Write ("\t\t\treturn String.Format (\"(");
973 for (int i = 1; i <= arity; ++i) {
974 Console.Write ("{" + (i - 1) + "}");
976 Console.Write (", ");
978 Console.Write (")\", ");
979 for (int i = 1; i <= arity; ++i) {
980 Console.Write (GetItemName (i));
982 Console.Write (", ");
984 Console.WriteLine (");");
985 Console.WriteLine ("\t\t}");
987 Console.WriteLine ("\t}\n");
991 static int IntLog2 (int n)
1003 static void WriteHash (int destVar, int start, int count)
1006 Console.WriteLine ("\t\t\th{0} = comparer.GetHashCode ({1});", destVar, GetItemName (start));
1008 int subCount = 1 << IntLog2(count-1);
1009 computeHash(destVar, start, subCount);
1013 Console.WriteLine ("\t\t\th{0} = (h{0} << 5) + h{0} ^ comparer.GetHashCode ({1});", destVar, GetItemName (start));
1015 WriteHash(destVar+1, start, count);
1016 Console.WriteLine ("\t\t\th{0} = (h{0} << 5) + h{0} ^ h{1};", destVar, destVar+1);
1021 static string GetTypeName (int arity)
1023 StringBuilder sb = new StringBuilder ();
1024 sb.Append ("Tuple<");
1025 for (int i = 1; i <= arity; ++i) {
1026 sb.Append (GetItemTypeName (i));
1032 return sb.ToString ();
1035 static string GetItemName (int arity)
1037 return arity < 8 ? "item" + arity.ToString () : "rest";
1040 static string GetItemTypeName (int arity)
1042 return arity < 8 ? "T" + arity.ToString () : "TRest";