1
0

Tuple.cs 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. // defined from .NET Framework 4.0 and NETFX_CORE
  2. // This code is basaed from mono/mcs, but some performance modified
  3. // 1. class to struct
  4. // 2. implements IEquatable<T1, T2,...>
  5. // note, we need to create ValueTuple or UniRxTuple...
  6. #if !(NETFX_CORE || NET_4_6 || NET_STANDARD_2_0 || UNITY_WSA_10_0)
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. namespace UniRx
  11. {
  12. public interface IStructuralEquatable
  13. {
  14. bool Equals(object other, IEqualityComparer comparer);
  15. int GetHashCode(IEqualityComparer comparer);
  16. }
  17. public interface IStructuralComparable
  18. {
  19. int CompareTo(object other, IComparer comparer);
  20. }
  21. interface ITuple
  22. {
  23. string ToString();
  24. }
  25. public static class Tuple
  26. {
  27. public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> Create<T1, T2, T3, T4, T5, T6, T7, T8>
  28. (
  29. T1 item1,
  30. T2 item2,
  31. T3 item3,
  32. T4 item4,
  33. T5 item5,
  34. T6 item6,
  35. T7 item7,
  36. T8 item8)
  37. {
  38. return new Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<T8>(item8));
  39. }
  40. public static Tuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>
  41. (
  42. T1 item1,
  43. T2 item2,
  44. T3 item3,
  45. T4 item4,
  46. T5 item5,
  47. T6 item6,
  48. T7 item7)
  49. {
  50. return new Tuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);
  51. }
  52. public static Tuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>
  53. (
  54. T1 item1,
  55. T2 item2,
  56. T3 item3,
  57. T4 item4,
  58. T5 item5,
  59. T6 item6)
  60. {
  61. return new Tuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6);
  62. }
  63. public static Tuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>
  64. (
  65. T1 item1,
  66. T2 item2,
  67. T3 item3,
  68. T4 item4,
  69. T5 item5)
  70. {
  71. return new Tuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5);
  72. }
  73. public static Tuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>
  74. (
  75. T1 item1,
  76. T2 item2,
  77. T3 item3,
  78. T4 item4)
  79. {
  80. return new Tuple<T1, T2, T3, T4>(item1, item2, item3, item4);
  81. }
  82. public static Tuple<T1, T2, T3> Create<T1, T2, T3>
  83. (
  84. T1 item1,
  85. T2 item2,
  86. T3 item3)
  87. {
  88. return new Tuple<T1, T2, T3>(item1, item2, item3);
  89. }
  90. public static Tuple<T1, T2> Create<T1, T2>
  91. (
  92. T1 item1,
  93. T2 item2)
  94. {
  95. return new Tuple<T1, T2>(item1, item2);
  96. }
  97. public static Tuple<T1> Create<T1>
  98. (
  99. T1 item1)
  100. {
  101. return new Tuple<T1>(item1);
  102. }
  103. }
  104. public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
  105. {
  106. public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
  107. {
  108. this.item1 = item1;
  109. this.item2 = item2;
  110. this.item3 = item3;
  111. this.item4 = item4;
  112. this.item5 = item5;
  113. this.item6 = item6;
  114. this.item7 = item7;
  115. this.rest = rest;
  116. if (!(rest is ITuple))
  117. throw new ArgumentException("rest", "The last element of an eight element tuple must be a Tuple.");
  118. }
  119. }
  120. [Serializable]
  121. public struct Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1>>
  122. {
  123. T1 item1;
  124. public Tuple(T1 item1)
  125. {
  126. this.item1 = item1;
  127. }
  128. public T1 Item1
  129. {
  130. get { return item1; }
  131. }
  132. int IComparable.CompareTo(object obj)
  133. {
  134. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  135. }
  136. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  137. {
  138. if (other == null) return 1;
  139. if (!(other is Tuple<T1>))
  140. {
  141. throw new ArgumentException("other");
  142. }
  143. var t = (Tuple<T1>)other;
  144. return comparer.Compare(item1, t.item1);
  145. }
  146. public override bool Equals(object obj)
  147. {
  148. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  149. }
  150. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  151. {
  152. if (!(other is Tuple<T1>))
  153. return false;
  154. var t = (Tuple<T1>)other;
  155. return comparer.Equals(item1, t.item1);
  156. }
  157. public override int GetHashCode()
  158. {
  159. return EqualityComparer<T1>.Default.GetHashCode(item1);
  160. }
  161. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  162. {
  163. return comparer.GetHashCode(item1);
  164. }
  165. string ITuple.ToString()
  166. {
  167. return String.Format("{0}", item1);
  168. }
  169. public override string ToString()
  170. {
  171. return "(" + ((ITuple)this).ToString() + ")";
  172. }
  173. public bool Equals(Tuple<T1> other)
  174. {
  175. return EqualityComparer<T1>.Default.Equals(item1, other.item1);
  176. }
  177. }
  178. [Serializable]
  179. public struct Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2>>
  180. {
  181. T1 item1;
  182. T2 item2;
  183. public Tuple(T1 item1, T2 item2)
  184. {
  185. this.item1 = item1;
  186. this.item2 = item2;
  187. }
  188. public T1 Item1
  189. {
  190. get { return item1; }
  191. }
  192. public T2 Item2
  193. {
  194. get { return item2; }
  195. }
  196. int IComparable.CompareTo(object obj)
  197. {
  198. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  199. }
  200. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  201. {
  202. if (other == null) return 1;
  203. if (!(other is Tuple<T1, T2>))
  204. {
  205. throw new ArgumentException("other");
  206. }
  207. var t = (Tuple<T1, T2>)other;
  208. int res = comparer.Compare(item1, t.item1);
  209. if (res != 0) return res;
  210. return comparer.Compare(item2, t.item2);
  211. }
  212. public override bool Equals(object obj)
  213. {
  214. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  215. }
  216. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  217. {
  218. if (!(other is Tuple<T1, T2>))
  219. return false;
  220. var t = (Tuple<T1, T2>)other;
  221. return comparer.Equals(item1, t.item1) &&
  222. comparer.Equals(item2, t.item2);
  223. }
  224. public override int GetHashCode()
  225. {
  226. var comparer1 = EqualityComparer<T1>.Default;
  227. var comparer2 = EqualityComparer<T2>.Default;
  228. int h0;
  229. h0 = comparer1.GetHashCode(item1);
  230. h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
  231. return h0;
  232. }
  233. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  234. {
  235. int h0;
  236. h0 = comparer.GetHashCode(item1);
  237. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
  238. return h0;
  239. }
  240. string ITuple.ToString()
  241. {
  242. return String.Format("{0}, {1}", item1, item2);
  243. }
  244. public override string ToString()
  245. {
  246. return "(" + ((ITuple)this).ToString() + ")";
  247. }
  248. public bool Equals(Tuple<T1, T2> other)
  249. {
  250. var comparer1 = EqualityComparer<T1>.Default;
  251. var comparer2 = EqualityComparer<T2>.Default;
  252. return comparer1.Equals(item1, other.item1) &&
  253. comparer2.Equals(item2, other.item2);
  254. }
  255. }
  256. [Serializable]
  257. public struct Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3>>
  258. {
  259. T1 item1;
  260. T2 item2;
  261. T3 item3;
  262. public Tuple(T1 item1, T2 item2, T3 item3)
  263. {
  264. this.item1 = item1;
  265. this.item2 = item2;
  266. this.item3 = item3;
  267. }
  268. public T1 Item1
  269. {
  270. get { return item1; }
  271. }
  272. public T2 Item2
  273. {
  274. get { return item2; }
  275. }
  276. public T3 Item3
  277. {
  278. get { return item3; }
  279. }
  280. int IComparable.CompareTo(object obj)
  281. {
  282. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  283. }
  284. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  285. {
  286. if (other == null) return 1;
  287. if (!(other is Tuple<T1, T2, T3>))
  288. {
  289. throw new ArgumentException("other");
  290. }
  291. var t = (Tuple<T1, T2, T3>)other;
  292. int res = comparer.Compare(item1, t.item1);
  293. if (res != 0) return res;
  294. res = comparer.Compare(item2, t.item2);
  295. if (res != 0) return res;
  296. return comparer.Compare(item3, t.item3);
  297. }
  298. public override bool Equals(object obj)
  299. {
  300. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  301. }
  302. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  303. {
  304. if (!(other is Tuple<T1, T2, T3>))
  305. return false;
  306. var t = (Tuple<T1, T2, T3>)other;
  307. return comparer.Equals(item1, t.item1) &&
  308. comparer.Equals(item2, t.item2) &&
  309. comparer.Equals(item3, t.item3);
  310. }
  311. public override int GetHashCode()
  312. {
  313. var comparer1 = EqualityComparer<T1>.Default;
  314. var comparer2 = EqualityComparer<T2>.Default;
  315. var comparer3 = EqualityComparer<T3>.Default;
  316. int h0;
  317. h0 = comparer1.GetHashCode(item1);
  318. h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
  319. h0 = (h0 << 5) + h0 ^ comparer3.GetHashCode(item3);
  320. return h0;
  321. }
  322. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  323. {
  324. int h0;
  325. h0 = comparer.GetHashCode(item1);
  326. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
  327. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item3);
  328. return h0;
  329. }
  330. string ITuple.ToString()
  331. {
  332. return String.Format("{0}, {1}, {2}", item1, item2, item3);
  333. }
  334. public override string ToString()
  335. {
  336. return "(" + ((ITuple)this).ToString() + ")";
  337. }
  338. public bool Equals(Tuple<T1, T2, T3> other)
  339. {
  340. var comparer1 = EqualityComparer<T1>.Default;
  341. var comparer2 = EqualityComparer<T2>.Default;
  342. var comparer3 = EqualityComparer<T3>.Default;
  343. return comparer1.Equals(item1, other.item1) &&
  344. comparer2.Equals(item2, other.item2) &&
  345. comparer3.Equals(item3, other.item3);
  346. }
  347. }
  348. [Serializable]
  349. public struct Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4>>
  350. {
  351. T1 item1;
  352. T2 item2;
  353. T3 item3;
  354. T4 item4;
  355. public Tuple(T1 item1, T2 item2, T3 item3, T4 item4)
  356. {
  357. this.item1 = item1;
  358. this.item2 = item2;
  359. this.item3 = item3;
  360. this.item4 = item4;
  361. }
  362. public T1 Item1
  363. {
  364. get { return item1; }
  365. }
  366. public T2 Item2
  367. {
  368. get { return item2; }
  369. }
  370. public T3 Item3
  371. {
  372. get { return item3; }
  373. }
  374. public T4 Item4
  375. {
  376. get { return item4; }
  377. }
  378. int IComparable.CompareTo(object obj)
  379. {
  380. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  381. }
  382. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  383. {
  384. if (other == null) return 1;
  385. if (!(other is Tuple<T1, T2, T3, T4>))
  386. {
  387. throw new ArgumentException("other");
  388. }
  389. var t = (Tuple<T1, T2, T3, T4>)other;
  390. int res = comparer.Compare(item1, t.item1);
  391. if (res != 0) return res;
  392. res = comparer.Compare(item2, t.item2);
  393. if (res != 0) return res;
  394. res = comparer.Compare(item3, t.item3);
  395. if (res != 0) return res;
  396. return comparer.Compare(item4, t.item4);
  397. }
  398. public override bool Equals(object obj)
  399. {
  400. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  401. }
  402. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  403. {
  404. if (!(other is Tuple<T1, T2, T3, T4>))
  405. return false;
  406. var t = (Tuple<T1, T2, T3, T4>)other;
  407. return comparer.Equals(item1, t.item1) &&
  408. comparer.Equals(item2, t.item2) &&
  409. comparer.Equals(item3, t.item3) &&
  410. comparer.Equals(item4, t.item4);
  411. }
  412. public override int GetHashCode()
  413. {
  414. var comparer1 = EqualityComparer<T1>.Default;
  415. var comparer2 = EqualityComparer<T2>.Default;
  416. var comparer3 = EqualityComparer<T3>.Default;
  417. var comparer4 = EqualityComparer<T4>.Default;
  418. int h0, h1;
  419. h0 = comparer1.GetHashCode(item1);
  420. h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
  421. h1 = comparer3.GetHashCode(item3);
  422. h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
  423. h0 = (h0 << 5) + h0 ^ h1;
  424. return h0;
  425. }
  426. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  427. {
  428. int h0, h1;
  429. h0 = comparer.GetHashCode(item1);
  430. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
  431. h1 = comparer.GetHashCode(item3);
  432. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
  433. h0 = (h0 << 5) + h0 ^ h1;
  434. return h0;
  435. }
  436. string ITuple.ToString()
  437. {
  438. return String.Format("{0}, {1}, {2}, {3}", item1, item2, item3, item4);
  439. }
  440. public override string ToString()
  441. {
  442. return "(" + ((ITuple)this).ToString() + ")";
  443. }
  444. public bool Equals(Tuple<T1, T2, T3, T4> other)
  445. {
  446. var comparer1 = EqualityComparer<T1>.Default;
  447. var comparer2 = EqualityComparer<T2>.Default;
  448. var comparer3 = EqualityComparer<T3>.Default;
  449. var comparer4 = EqualityComparer<T4>.Default;
  450. return comparer1.Equals(item1, other.item1) &&
  451. comparer2.Equals(item2, other.item2) &&
  452. comparer3.Equals(item3, other.item3) &&
  453. comparer4.Equals(item4, other.item4);
  454. }
  455. }
  456. [Serializable]
  457. public struct Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5>>
  458. {
  459. T1 item1;
  460. T2 item2;
  461. T3 item3;
  462. T4 item4;
  463. T5 item5;
  464. public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
  465. {
  466. this.item1 = item1;
  467. this.item2 = item2;
  468. this.item3 = item3;
  469. this.item4 = item4;
  470. this.item5 = item5;
  471. }
  472. public T1 Item1
  473. {
  474. get { return item1; }
  475. }
  476. public T2 Item2
  477. {
  478. get { return item2; }
  479. }
  480. public T3 Item3
  481. {
  482. get { return item3; }
  483. }
  484. public T4 Item4
  485. {
  486. get { return item4; }
  487. }
  488. public T5 Item5
  489. {
  490. get { return item5; }
  491. }
  492. int IComparable.CompareTo(object obj)
  493. {
  494. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  495. }
  496. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  497. {
  498. if (other == null) return 1;
  499. if (!(other is Tuple<T1, T2, T3, T4, T5>))
  500. {
  501. throw new ArgumentException("other");
  502. }
  503. var t = (Tuple<T1, T2, T3, T4, T5>)other;
  504. int res = comparer.Compare(item1, t.item1);
  505. if (res != 0) return res;
  506. res = comparer.Compare(item2, t.item2);
  507. if (res != 0) return res;
  508. res = comparer.Compare(item3, t.item3);
  509. if (res != 0) return res;
  510. res = comparer.Compare(item4, t.item4);
  511. if (res != 0) return res;
  512. return comparer.Compare(item5, t.item5);
  513. }
  514. public override bool Equals(object obj)
  515. {
  516. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  517. }
  518. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  519. {
  520. if (!(other is Tuple<T1, T2, T3, T4, T5>))
  521. return false;
  522. var t = (Tuple<T1, T2, T3, T4, T5>)other;
  523. return comparer.Equals(item1, t.item1) &&
  524. comparer.Equals(item2, t.item2) &&
  525. comparer.Equals(item3, t.item3) &&
  526. comparer.Equals(item4, t.item4) &&
  527. comparer.Equals(item5, t.item5);
  528. }
  529. public override int GetHashCode()
  530. {
  531. var comparer1 = EqualityComparer<T1>.Default;
  532. var comparer2 = EqualityComparer<T2>.Default;
  533. var comparer3 = EqualityComparer<T3>.Default;
  534. var comparer4 = EqualityComparer<T4>.Default;
  535. var comparer5 = EqualityComparer<T5>.Default;
  536. int h0, h1;
  537. h0 = comparer1.GetHashCode(item1);
  538. h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
  539. h1 = comparer3.GetHashCode(item3);
  540. h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
  541. h0 = (h0 << 5) + h0 ^ h1;
  542. h0 = (h0 << 5) + h0 ^ comparer5.GetHashCode(item5);
  543. return h0;
  544. }
  545. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  546. {
  547. int h0, h1;
  548. h0 = comparer.GetHashCode(item1);
  549. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
  550. h1 = comparer.GetHashCode(item3);
  551. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
  552. h0 = (h0 << 5) + h0 ^ h1;
  553. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item5);
  554. return h0;
  555. }
  556. string ITuple.ToString()
  557. {
  558. return String.Format("{0}, {1}, {2}, {3}, {4}", item1, item2, item3, item4, item5);
  559. }
  560. public override string ToString()
  561. {
  562. return "(" + ((ITuple)this).ToString() + ")";
  563. }
  564. public bool Equals(Tuple<T1, T2, T3, T4, T5> other)
  565. {
  566. var comparer1 = EqualityComparer<T1>.Default;
  567. var comparer2 = EqualityComparer<T2>.Default;
  568. var comparer3 = EqualityComparer<T3>.Default;
  569. var comparer4 = EqualityComparer<T4>.Default;
  570. var comparer5 = EqualityComparer<T5>.Default;
  571. return comparer1.Equals(item1, other.Item1) &&
  572. comparer2.Equals(item2, other.Item2) &&
  573. comparer3.Equals(item3, other.Item3) &&
  574. comparer4.Equals(item4, other.Item4) &&
  575. comparer5.Equals(item5, other.Item5);
  576. }
  577. }
  578. [Serializable]
  579. public struct Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5, T6>>
  580. {
  581. T1 item1;
  582. T2 item2;
  583. T3 item3;
  584. T4 item4;
  585. T5 item5;
  586. T6 item6;
  587. public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
  588. {
  589. this.item1 = item1;
  590. this.item2 = item2;
  591. this.item3 = item3;
  592. this.item4 = item4;
  593. this.item5 = item5;
  594. this.item6 = item6;
  595. }
  596. public T1 Item1
  597. {
  598. get { return item1; }
  599. }
  600. public T2 Item2
  601. {
  602. get { return item2; }
  603. }
  604. public T3 Item3
  605. {
  606. get { return item3; }
  607. }
  608. public T4 Item4
  609. {
  610. get { return item4; }
  611. }
  612. public T5 Item5
  613. {
  614. get { return item5; }
  615. }
  616. public T6 Item6
  617. {
  618. get { return item6; }
  619. }
  620. int IComparable.CompareTo(object obj)
  621. {
  622. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  623. }
  624. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  625. {
  626. if (other == null) return 1;
  627. if (!(other is Tuple<T1, T2, T3, T4, T5, T6>))
  628. {
  629. throw new ArgumentException("other");
  630. }
  631. var t = (Tuple<T1, T2, T3, T4, T5, T6>)other;
  632. int res = comparer.Compare(item1, t.item1);
  633. if (res != 0) return res;
  634. res = comparer.Compare(item2, t.item2);
  635. if (res != 0) return res;
  636. res = comparer.Compare(item3, t.item3);
  637. if (res != 0) return res;
  638. res = comparer.Compare(item4, t.item4);
  639. if (res != 0) return res;
  640. res = comparer.Compare(item5, t.item5);
  641. if (res != 0) return res;
  642. return comparer.Compare(item6, t.item6);
  643. }
  644. public override bool Equals(object obj)
  645. {
  646. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  647. }
  648. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  649. {
  650. if (!(other is Tuple<T1, T2, T3, T4, T5, T6>))
  651. return false;
  652. var t = (Tuple<T1, T2, T3, T4, T5, T6>)other;
  653. return comparer.Equals(item1, t.item1) &&
  654. comparer.Equals(item2, t.item2) &&
  655. comparer.Equals(item3, t.item3) &&
  656. comparer.Equals(item4, t.item4) &&
  657. comparer.Equals(item5, t.item5) &&
  658. comparer.Equals(item6, t.item6);
  659. }
  660. public override int GetHashCode()
  661. {
  662. var comparer1 = EqualityComparer<T1>.Default;
  663. var comparer2 = EqualityComparer<T2>.Default;
  664. var comparer3 = EqualityComparer<T3>.Default;
  665. var comparer4 = EqualityComparer<T4>.Default;
  666. var comparer5 = EqualityComparer<T5>.Default;
  667. var comparer6 = EqualityComparer<T6>.Default;
  668. int h0, h1;
  669. h0 = comparer1.GetHashCode(item1);
  670. h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
  671. h1 = comparer3.GetHashCode(item3);
  672. h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
  673. h0 = (h0 << 5) + h0 ^ h1;
  674. h1 = comparer5.GetHashCode(item5);
  675. h1 = (h1 << 5) + h1 ^ comparer6.GetHashCode(item6);
  676. h0 = (h0 << 5) + h0 ^ h1;
  677. return h0;
  678. }
  679. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  680. {
  681. int h0, h1;
  682. h0 = comparer.GetHashCode(item1);
  683. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
  684. h1 = comparer.GetHashCode(item3);
  685. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
  686. h0 = (h0 << 5) + h0 ^ h1;
  687. h1 = comparer.GetHashCode(item5);
  688. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item6);
  689. h0 = (h0 << 5) + h0 ^ h1;
  690. return h0;
  691. }
  692. string ITuple.ToString()
  693. {
  694. return String.Format("{0}, {1}, {2}, {3}, {4}, {5}", item1, item2, item3, item4, item5, item6);
  695. }
  696. public override string ToString()
  697. {
  698. return "(" + ((ITuple)this).ToString() + ")";
  699. }
  700. public bool Equals(Tuple<T1, T2, T3, T4, T5, T6> other)
  701. {
  702. var comparer1 = EqualityComparer<T1>.Default;
  703. var comparer2 = EqualityComparer<T2>.Default;
  704. var comparer3 = EqualityComparer<T3>.Default;
  705. var comparer4 = EqualityComparer<T4>.Default;
  706. var comparer5 = EqualityComparer<T5>.Default;
  707. var comparer6 = EqualityComparer<T6>.Default;
  708. return comparer1.Equals(item1, other.Item1) &&
  709. comparer2.Equals(item2, other.Item2) &&
  710. comparer3.Equals(item3, other.Item3) &&
  711. comparer4.Equals(item4, other.Item4) &&
  712. comparer5.Equals(item5, other.Item5) &&
  713. comparer6.Equals(item6, other.Item6);
  714. }
  715. }
  716. [Serializable]
  717. public struct Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5, T6, T7>>
  718. {
  719. T1 item1;
  720. T2 item2;
  721. T3 item3;
  722. T4 item4;
  723. T5 item5;
  724. T6 item6;
  725. T7 item7;
  726. public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
  727. {
  728. this.item1 = item1;
  729. this.item2 = item2;
  730. this.item3 = item3;
  731. this.item4 = item4;
  732. this.item5 = item5;
  733. this.item6 = item6;
  734. this.item7 = item7;
  735. }
  736. public T1 Item1
  737. {
  738. get { return item1; }
  739. }
  740. public T2 Item2
  741. {
  742. get { return item2; }
  743. }
  744. public T3 Item3
  745. {
  746. get { return item3; }
  747. }
  748. public T4 Item4
  749. {
  750. get { return item4; }
  751. }
  752. public T5 Item5
  753. {
  754. get { return item5; }
  755. }
  756. public T6 Item6
  757. {
  758. get { return item6; }
  759. }
  760. public T7 Item7
  761. {
  762. get { return item7; }
  763. }
  764. int IComparable.CompareTo(object obj)
  765. {
  766. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  767. }
  768. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  769. {
  770. if (other == null) return 1;
  771. if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7>))
  772. {
  773. throw new ArgumentException("other");
  774. }
  775. var t = (Tuple<T1, T2, T3, T4, T5, T6, T7>)other;
  776. int res = comparer.Compare(item1, t.item1);
  777. if (res != 0) return res;
  778. res = comparer.Compare(item2, t.item2);
  779. if (res != 0) return res;
  780. res = comparer.Compare(item3, t.item3);
  781. if (res != 0) return res;
  782. res = comparer.Compare(item4, t.item4);
  783. if (res != 0) return res;
  784. res = comparer.Compare(item5, t.item5);
  785. if (res != 0) return res;
  786. res = comparer.Compare(item6, t.item6);
  787. if (res != 0) return res;
  788. return comparer.Compare(item7, t.item7);
  789. }
  790. public override bool Equals(object obj)
  791. {
  792. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  793. }
  794. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  795. {
  796. if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7>))
  797. return false;
  798. var t = (Tuple<T1, T2, T3, T4, T5, T6, T7>)other;
  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. }
  807. public override int GetHashCode()
  808. {
  809. var comparer1 = EqualityComparer<T1>.Default;
  810. var comparer2 = EqualityComparer<T2>.Default;
  811. var comparer3 = EqualityComparer<T3>.Default;
  812. var comparer4 = EqualityComparer<T4>.Default;
  813. var comparer5 = EqualityComparer<T5>.Default;
  814. var comparer6 = EqualityComparer<T6>.Default;
  815. var comparer7 = EqualityComparer<T7>.Default;
  816. int h0, h1;
  817. h0 = comparer1.GetHashCode(item1);
  818. h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
  819. h1 = comparer3.GetHashCode(item3);
  820. h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
  821. h0 = (h0 << 5) + h0 ^ h1;
  822. h1 = comparer5.GetHashCode(item5);
  823. h1 = (h1 << 5) + h1 ^ comparer6.GetHashCode(item6);
  824. h1 = (h1 << 5) + h1 ^ comparer7.GetHashCode(item7);
  825. h0 = (h0 << 5) + h0 ^ h1;
  826. return h0;
  827. }
  828. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  829. {
  830. int h0, h1;
  831. h0 = comparer.GetHashCode(item1);
  832. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
  833. h1 = comparer.GetHashCode(item3);
  834. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
  835. h0 = (h0 << 5) + h0 ^ h1;
  836. h1 = comparer.GetHashCode(item5);
  837. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item6);
  838. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item7);
  839. h0 = (h0 << 5) + h0 ^ h1;
  840. return h0;
  841. }
  842. string ITuple.ToString()
  843. {
  844. return String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}", item1, item2, item3, item4, item5, item6, item7);
  845. }
  846. public override string ToString()
  847. {
  848. return "(" + ((ITuple)this).ToString() + ")";
  849. }
  850. public bool Equals(Tuple<T1, T2, T3, T4, T5, T6, T7> other)
  851. {
  852. var comparer1 = EqualityComparer<T1>.Default;
  853. var comparer2 = EqualityComparer<T2>.Default;
  854. var comparer3 = EqualityComparer<T3>.Default;
  855. var comparer4 = EqualityComparer<T4>.Default;
  856. var comparer5 = EqualityComparer<T5>.Default;
  857. var comparer6 = EqualityComparer<T6>.Default;
  858. var comparer7 = EqualityComparer<T7>.Default;
  859. return comparer1.Equals(item1, other.Item1) &&
  860. comparer2.Equals(item2, other.Item2) &&
  861. comparer3.Equals(item3, other.Item3) &&
  862. comparer4.Equals(item4, other.Item4) &&
  863. comparer5.Equals(item5, other.Item5) &&
  864. comparer6.Equals(item6, other.Item6) &&
  865. comparer7.Equals(item7, other.Item7);
  866. }
  867. }
  868. [Serializable]
  869. public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple, IEquatable<Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>>
  870. {
  871. T1 item1;
  872. T2 item2;
  873. T3 item3;
  874. T4 item4;
  875. T5 item5;
  876. T6 item6;
  877. T7 item7;
  878. TRest rest;
  879. public T1 Item1
  880. {
  881. get { return item1; }
  882. }
  883. public T2 Item2
  884. {
  885. get { return item2; }
  886. }
  887. public T3 Item3
  888. {
  889. get { return item3; }
  890. }
  891. public T4 Item4
  892. {
  893. get { return item4; }
  894. }
  895. public T5 Item5
  896. {
  897. get { return item5; }
  898. }
  899. public T6 Item6
  900. {
  901. get { return item6; }
  902. }
  903. public T7 Item7
  904. {
  905. get { return item7; }
  906. }
  907. public TRest Rest
  908. {
  909. get { return rest; }
  910. }
  911. int IComparable.CompareTo(object obj)
  912. {
  913. return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
  914. }
  915. int IStructuralComparable.CompareTo(object other, IComparer comparer)
  916. {
  917. if (other == null) return 1;
  918. if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
  919. {
  920. throw new ArgumentException("other");
  921. }
  922. var t = (Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
  923. int res = comparer.Compare(item1, t.item1);
  924. if (res != 0) return res;
  925. res = comparer.Compare(item2, t.item2);
  926. if (res != 0) return res;
  927. res = comparer.Compare(item3, t.item3);
  928. if (res != 0) return res;
  929. res = comparer.Compare(item4, t.item4);
  930. if (res != 0) return res;
  931. res = comparer.Compare(item5, t.item5);
  932. if (res != 0) return res;
  933. res = comparer.Compare(item6, t.item6);
  934. if (res != 0) return res;
  935. res = comparer.Compare(item7, t.item7);
  936. if (res != 0) return res;
  937. return comparer.Compare(rest, t.rest);
  938. }
  939. public override bool Equals(object obj)
  940. {
  941. return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
  942. }
  943. bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
  944. {
  945. if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
  946. return false;
  947. var t = (Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
  948. return comparer.Equals(item1, t.item1) &&
  949. comparer.Equals(item2, t.item2) &&
  950. comparer.Equals(item3, t.item3) &&
  951. comparer.Equals(item4, t.item4) &&
  952. comparer.Equals(item5, t.item5) &&
  953. comparer.Equals(item6, t.item6) &&
  954. comparer.Equals(item7, t.item7) &&
  955. comparer.Equals(rest, t.rest);
  956. }
  957. public override int GetHashCode()
  958. {
  959. var comparer1 = EqualityComparer<T1>.Default;
  960. var comparer2 = EqualityComparer<T2>.Default;
  961. var comparer3 = EqualityComparer<T3>.Default;
  962. var comparer4 = EqualityComparer<T4>.Default;
  963. var comparer5 = EqualityComparer<T5>.Default;
  964. var comparer6 = EqualityComparer<T6>.Default;
  965. var comparer7 = EqualityComparer<T7>.Default;
  966. var comparer8 = EqualityComparer<TRest>.Default;
  967. int h0, h1, h2;
  968. h0 = comparer1.GetHashCode(item1);
  969. h0 = (h0 << 5) + h0 ^ comparer2.GetHashCode(item2);
  970. h1 = comparer3.GetHashCode(item3);
  971. h1 = (h1 << 5) + h1 ^ comparer4.GetHashCode(item4);
  972. h0 = (h0 << 5) + h0 ^ h1;
  973. h1 = comparer5.GetHashCode(item5);
  974. h1 = (h1 << 5) + h1 ^ comparer6.GetHashCode(item6);
  975. h2 = comparer7.GetHashCode(item7);
  976. h2 = (h2 << 5) + h2 ^ comparer8.GetHashCode(rest);
  977. h1 = (h1 << 5) + h1 ^ h2;
  978. h0 = (h0 << 5) + h0 ^ h1;
  979. return h0;
  980. }
  981. int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
  982. {
  983. int h0, h1, h2;
  984. h0 = comparer.GetHashCode(item1);
  985. h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(item2);
  986. h1 = comparer.GetHashCode(item3);
  987. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item4);
  988. h0 = (h0 << 5) + h0 ^ h1;
  989. h1 = comparer.GetHashCode(item5);
  990. h1 = (h1 << 5) + h1 ^ comparer.GetHashCode(item6);
  991. h2 = comparer.GetHashCode(item7);
  992. h2 = (h2 << 5) + h2 ^ comparer.GetHashCode(rest);
  993. h1 = (h1 << 5) + h1 ^ h2;
  994. h0 = (h0 << 5) + h0 ^ h1;
  995. return h0;
  996. }
  997. string ITuple.ToString()
  998. {
  999. return String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}", item1, item2, item3, item4, item5, item6, item7, ((ITuple)rest).ToString());
  1000. }
  1001. public override string ToString()
  1002. {
  1003. return "(" + ((ITuple)this).ToString() + ")";
  1004. }
  1005. public bool Equals(Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> other)
  1006. {
  1007. var comparer1 = EqualityComparer<T1>.Default;
  1008. var comparer2 = EqualityComparer<T2>.Default;
  1009. var comparer3 = EqualityComparer<T3>.Default;
  1010. var comparer4 = EqualityComparer<T4>.Default;
  1011. var comparer5 = EqualityComparer<T5>.Default;
  1012. var comparer6 = EqualityComparer<T6>.Default;
  1013. var comparer7 = EqualityComparer<T7>.Default;
  1014. var comparer8 = EqualityComparer<TRest>.Default;
  1015. return comparer1.Equals(item1, other.Item1) &&
  1016. comparer2.Equals(item2, other.Item2) &&
  1017. comparer3.Equals(item3, other.Item3) &&
  1018. comparer4.Equals(item4, other.Item4) &&
  1019. comparer5.Equals(item5, other.Item5) &&
  1020. comparer6.Equals(item6, other.Item6) &&
  1021. comparer7.Equals(item7, other.Item7) &&
  1022. comparer8.Equals(rest, other.rest);
  1023. }
  1024. }
  1025. }
  1026. #endif