暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnsafeHashSetExtensions.gen.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. using System;
  2. using Unity.Collections.LowLevel.Unsafe;
  3. namespace Unity.Collections.LowLevel.Unsafe
  4. {
  5. /// <summary>
  6. /// Provides extension methods for sets.
  7. /// </summary>
  8. public unsafe static class HashSetExtensions
  9. {
  10. /// <summary>
  11. /// Removes the values from this set which are also present in another collection.
  12. /// </summary>
  13. /// <typeparam name="T">The type of values.</typeparam>
  14. /// <param name="container">The set to remove values from.</param>
  15. /// <param name="other">The collection to compare with.</param>
  16. public static void ExceptWith<T>(this NativeHashSet<T> container, UnsafeHashSet<T> other)
  17. where T : unmanaged, IEquatable<T>
  18. {
  19. foreach (var item in other)
  20. {
  21. container.Remove(item);
  22. }
  23. }
  24. /// <summary>
  25. /// Removes the values from this set which are absent in another collection.
  26. /// </summary>
  27. /// <typeparam name="T">The type of values.</typeparam>
  28. /// <param name="container">The set to remove values from.</param>
  29. /// <param name="other">The collection to compare with.</param>
  30. public static void IntersectWith<T>(this NativeHashSet<T> container, UnsafeHashSet<T> other)
  31. where T : unmanaged, IEquatable<T>
  32. {
  33. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  34. foreach (var item in other)
  35. {
  36. if (container.Contains(item))
  37. {
  38. result.Add(item);
  39. }
  40. }
  41. container.Clear();
  42. container.UnionWith(result);
  43. result.Dispose();
  44. }
  45. /// <summary>
  46. /// Adds all values from a collection to this set.
  47. /// </summary>
  48. /// <typeparam name="T">The type of values.</typeparam>
  49. /// <param name="container">The set to add values to.</param>
  50. /// <param name="other">The collection to copy values from.</param>
  51. public static void UnionWith<T>(this NativeHashSet<T> container, UnsafeHashSet<T> other)
  52. where T : unmanaged, IEquatable<T>
  53. {
  54. foreach (var item in other)
  55. {
  56. container.Add(item);
  57. }
  58. }
  59. /// <summary>
  60. /// Removes the values from this set which are also present in another collection.
  61. /// </summary>
  62. /// <typeparam name="T">The type of values.</typeparam>
  63. /// <param name="container">The set to remove values from.</param>
  64. /// <param name="other">The collection to compare with.</param>
  65. public static void ExceptWith<T>(this NativeHashSet<T> container, UnsafeList<T> other)
  66. where T : unmanaged, IEquatable<T>
  67. {
  68. foreach (var item in other)
  69. {
  70. container.Remove(item);
  71. }
  72. }
  73. /// <summary>
  74. /// Removes the values from this set which are absent in another collection.
  75. /// </summary>
  76. /// <typeparam name="T">The type of values.</typeparam>
  77. /// <param name="container">The set to remove values from.</param>
  78. /// <param name="other">The collection to compare with.</param>
  79. public static void IntersectWith<T>(this NativeHashSet<T> container, UnsafeList<T> other)
  80. where T : unmanaged, IEquatable<T>
  81. {
  82. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  83. foreach (var item in other)
  84. {
  85. if (container.Contains(item))
  86. {
  87. result.Add(item);
  88. }
  89. }
  90. container.Clear();
  91. container.UnionWith(result);
  92. result.Dispose();
  93. }
  94. /// <summary>
  95. /// Adds all values from a collection to this set.
  96. /// </summary>
  97. /// <typeparam name="T">The type of values.</typeparam>
  98. /// <param name="container">The set to add values to.</param>
  99. /// <param name="other">The collection to copy values from.</param>
  100. public static void UnionWith<T>(this NativeHashSet<T> container, UnsafeList<T> other)
  101. where T : unmanaged, IEquatable<T>
  102. {
  103. foreach (var item in other)
  104. {
  105. container.Add(item);
  106. }
  107. }
  108. /// <summary>
  109. /// Removes the values from this set which are also present in another collection.
  110. /// </summary>
  111. /// <typeparam name="T">The type of values.</typeparam>
  112. /// <param name="container">The set to remove values from.</param>
  113. /// <param name="other">The collection to compare with.</param>
  114. public static void ExceptWith<T>(this UnsafeHashSet<T> container, FixedList128Bytes<T> other)
  115. where T : unmanaged, IEquatable<T>
  116. {
  117. foreach (var item in other)
  118. {
  119. container.Remove(item);
  120. }
  121. }
  122. /// <summary>
  123. /// Removes the values from this set which are absent in another collection.
  124. /// </summary>
  125. /// <typeparam name="T">The type of values.</typeparam>
  126. /// <param name="container">The set to remove values from.</param>
  127. /// <param name="other">The collection to compare with.</param>
  128. public static void IntersectWith<T>(this UnsafeHashSet<T> container, FixedList128Bytes<T> other)
  129. where T : unmanaged, IEquatable<T>
  130. {
  131. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  132. foreach (var item in other)
  133. {
  134. if (container.Contains(item))
  135. {
  136. result.Add(item);
  137. }
  138. }
  139. container.Clear();
  140. container.UnionWith(result);
  141. result.Dispose();
  142. }
  143. /// <summary>
  144. /// Adds all values from a collection to this set.
  145. /// </summary>
  146. /// <typeparam name="T">The type of values.</typeparam>
  147. /// <param name="container">The set to add values to.</param>
  148. /// <param name="other">The collection to copy values from.</param>
  149. public static void UnionWith<T>(this UnsafeHashSet<T> container, FixedList128Bytes<T> other)
  150. where T : unmanaged, IEquatable<T>
  151. {
  152. foreach (var item in other)
  153. {
  154. container.Add(item);
  155. }
  156. }
  157. /// <summary>
  158. /// Removes the values from this set which are also present in another collection.
  159. /// </summary>
  160. /// <typeparam name="T">The type of values.</typeparam>
  161. /// <param name="container">The set to remove values from.</param>
  162. /// <param name="other">The collection to compare with.</param>
  163. public static void ExceptWith<T>(this UnsafeHashSet<T> container, FixedList32Bytes<T> other)
  164. where T : unmanaged, IEquatable<T>
  165. {
  166. foreach (var item in other)
  167. {
  168. container.Remove(item);
  169. }
  170. }
  171. /// <summary>
  172. /// Removes the values from this set which are absent in another collection.
  173. /// </summary>
  174. /// <typeparam name="T">The type of values.</typeparam>
  175. /// <param name="container">The set to remove values from.</param>
  176. /// <param name="other">The collection to compare with.</param>
  177. public static void IntersectWith<T>(this UnsafeHashSet<T> container, FixedList32Bytes<T> other)
  178. where T : unmanaged, IEquatable<T>
  179. {
  180. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  181. foreach (var item in other)
  182. {
  183. if (container.Contains(item))
  184. {
  185. result.Add(item);
  186. }
  187. }
  188. container.Clear();
  189. container.UnionWith(result);
  190. result.Dispose();
  191. }
  192. /// <summary>
  193. /// Adds all values from a collection to this set.
  194. /// </summary>
  195. /// <typeparam name="T">The type of values.</typeparam>
  196. /// <param name="container">The set to add values to.</param>
  197. /// <param name="other">The collection to copy values from.</param>
  198. public static void UnionWith<T>(this UnsafeHashSet<T> container, FixedList32Bytes<T> other)
  199. where T : unmanaged, IEquatable<T>
  200. {
  201. foreach (var item in other)
  202. {
  203. container.Add(item);
  204. }
  205. }
  206. /// <summary>
  207. /// Removes the values from this set which are also present in another collection.
  208. /// </summary>
  209. /// <typeparam name="T">The type of values.</typeparam>
  210. /// <param name="container">The set to remove values from.</param>
  211. /// <param name="other">The collection to compare with.</param>
  212. public static void ExceptWith<T>(this UnsafeHashSet<T> container, FixedList4096Bytes<T> other)
  213. where T : unmanaged, IEquatable<T>
  214. {
  215. foreach (var item in other)
  216. {
  217. container.Remove(item);
  218. }
  219. }
  220. /// <summary>
  221. /// Removes the values from this set which are absent in another collection.
  222. /// </summary>
  223. /// <typeparam name="T">The type of values.</typeparam>
  224. /// <param name="container">The set to remove values from.</param>
  225. /// <param name="other">The collection to compare with.</param>
  226. public static void IntersectWith<T>(this UnsafeHashSet<T> container, FixedList4096Bytes<T> other)
  227. where T : unmanaged, IEquatable<T>
  228. {
  229. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  230. foreach (var item in other)
  231. {
  232. if (container.Contains(item))
  233. {
  234. result.Add(item);
  235. }
  236. }
  237. container.Clear();
  238. container.UnionWith(result);
  239. result.Dispose();
  240. }
  241. /// <summary>
  242. /// Adds all values from a collection to this set.
  243. /// </summary>
  244. /// <typeparam name="T">The type of values.</typeparam>
  245. /// <param name="container">The set to add values to.</param>
  246. /// <param name="other">The collection to copy values from.</param>
  247. public static void UnionWith<T>(this UnsafeHashSet<T> container, FixedList4096Bytes<T> other)
  248. where T : unmanaged, IEquatable<T>
  249. {
  250. foreach (var item in other)
  251. {
  252. container.Add(item);
  253. }
  254. }
  255. /// <summary>
  256. /// Removes the values from this set which are also present in another collection.
  257. /// </summary>
  258. /// <typeparam name="T">The type of values.</typeparam>
  259. /// <param name="container">The set to remove values from.</param>
  260. /// <param name="other">The collection to compare with.</param>
  261. public static void ExceptWith<T>(this UnsafeHashSet<T> container, FixedList512Bytes<T> other)
  262. where T : unmanaged, IEquatable<T>
  263. {
  264. foreach (var item in other)
  265. {
  266. container.Remove(item);
  267. }
  268. }
  269. /// <summary>
  270. /// Removes the values from this set which are absent in another collection.
  271. /// </summary>
  272. /// <typeparam name="T">The type of values.</typeparam>
  273. /// <param name="container">The set to remove values from.</param>
  274. /// <param name="other">The collection to compare with.</param>
  275. public static void IntersectWith<T>(this UnsafeHashSet<T> container, FixedList512Bytes<T> other)
  276. where T : unmanaged, IEquatable<T>
  277. {
  278. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  279. foreach (var item in other)
  280. {
  281. if (container.Contains(item))
  282. {
  283. result.Add(item);
  284. }
  285. }
  286. container.Clear();
  287. container.UnionWith(result);
  288. result.Dispose();
  289. }
  290. /// <summary>
  291. /// Adds all values from a collection to this set.
  292. /// </summary>
  293. /// <typeparam name="T">The type of values.</typeparam>
  294. /// <param name="container">The set to add values to.</param>
  295. /// <param name="other">The collection to copy values from.</param>
  296. public static void UnionWith<T>(this UnsafeHashSet<T> container, FixedList512Bytes<T> other)
  297. where T : unmanaged, IEquatable<T>
  298. {
  299. foreach (var item in other)
  300. {
  301. container.Add(item);
  302. }
  303. }
  304. /// <summary>
  305. /// Removes the values from this set which are also present in another collection.
  306. /// </summary>
  307. /// <typeparam name="T">The type of values.</typeparam>
  308. /// <param name="container">The set to remove values from.</param>
  309. /// <param name="other">The collection to compare with.</param>
  310. public static void ExceptWith<T>(this UnsafeHashSet<T> container, FixedList64Bytes<T> other)
  311. where T : unmanaged, IEquatable<T>
  312. {
  313. foreach (var item in other)
  314. {
  315. container.Remove(item);
  316. }
  317. }
  318. /// <summary>
  319. /// Removes the values from this set which are absent in another collection.
  320. /// </summary>
  321. /// <typeparam name="T">The type of values.</typeparam>
  322. /// <param name="container">The set to remove values from.</param>
  323. /// <param name="other">The collection to compare with.</param>
  324. public static void IntersectWith<T>(this UnsafeHashSet<T> container, FixedList64Bytes<T> other)
  325. where T : unmanaged, IEquatable<T>
  326. {
  327. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  328. foreach (var item in other)
  329. {
  330. if (container.Contains(item))
  331. {
  332. result.Add(item);
  333. }
  334. }
  335. container.Clear();
  336. container.UnionWith(result);
  337. result.Dispose();
  338. }
  339. /// <summary>
  340. /// Adds all values from a collection to this set.
  341. /// </summary>
  342. /// <typeparam name="T">The type of values.</typeparam>
  343. /// <param name="container">The set to add values to.</param>
  344. /// <param name="other">The collection to copy values from.</param>
  345. public static void UnionWith<T>(this UnsafeHashSet<T> container, FixedList64Bytes<T> other)
  346. where T : unmanaged, IEquatable<T>
  347. {
  348. foreach (var item in other)
  349. {
  350. container.Add(item);
  351. }
  352. }
  353. /// <summary>
  354. /// Removes the values from this set which are also present in another collection.
  355. /// </summary>
  356. /// <typeparam name="T">The type of values.</typeparam>
  357. /// <param name="container">The set to remove values from.</param>
  358. /// <param name="other">The collection to compare with.</param>
  359. public static void ExceptWith<T>(this UnsafeHashSet<T> container, NativeArray<T> other)
  360. where T : unmanaged, IEquatable<T>
  361. {
  362. foreach (var item in other)
  363. {
  364. container.Remove(item);
  365. }
  366. }
  367. /// <summary>
  368. /// Removes the values from this set which are absent in another collection.
  369. /// </summary>
  370. /// <typeparam name="T">The type of values.</typeparam>
  371. /// <param name="container">The set to remove values from.</param>
  372. /// <param name="other">The collection to compare with.</param>
  373. public static void IntersectWith<T>(this UnsafeHashSet<T> container, NativeArray<T> other)
  374. where T : unmanaged, IEquatable<T>
  375. {
  376. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  377. foreach (var item in other)
  378. {
  379. if (container.Contains(item))
  380. {
  381. result.Add(item);
  382. }
  383. }
  384. container.Clear();
  385. container.UnionWith(result);
  386. result.Dispose();
  387. }
  388. /// <summary>
  389. /// Adds all values from a collection to this set.
  390. /// </summary>
  391. /// <typeparam name="T">The type of values.</typeparam>
  392. /// <param name="container">The set to add values to.</param>
  393. /// <param name="other">The collection to copy values from.</param>
  394. public static void UnionWith<T>(this UnsafeHashSet<T> container, NativeArray<T> other)
  395. where T : unmanaged, IEquatable<T>
  396. {
  397. foreach (var item in other)
  398. {
  399. container.Add(item);
  400. }
  401. }
  402. /// <summary>
  403. /// Removes the values from this set which are also present in another collection.
  404. /// </summary>
  405. /// <typeparam name="T">The type of values.</typeparam>
  406. /// <param name="container">The set to remove values from.</param>
  407. /// <param name="other">The collection to compare with.</param>
  408. public static void ExceptWith<T>(this UnsafeHashSet<T> container, NativeHashSet<T> other)
  409. where T : unmanaged, IEquatable<T>
  410. {
  411. foreach (var item in other)
  412. {
  413. container.Remove(item);
  414. }
  415. }
  416. /// <summary>
  417. /// Removes the values from this set which are absent in another collection.
  418. /// </summary>
  419. /// <typeparam name="T">The type of values.</typeparam>
  420. /// <param name="container">The set to remove values from.</param>
  421. /// <param name="other">The collection to compare with.</param>
  422. public static void IntersectWith<T>(this UnsafeHashSet<T> container, NativeHashSet<T> other)
  423. where T : unmanaged, IEquatable<T>
  424. {
  425. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  426. foreach (var item in other)
  427. {
  428. if (container.Contains(item))
  429. {
  430. result.Add(item);
  431. }
  432. }
  433. container.Clear();
  434. container.UnionWith(result);
  435. result.Dispose();
  436. }
  437. /// <summary>
  438. /// Adds all values from a collection to this set.
  439. /// </summary>
  440. /// <typeparam name="T">The type of values.</typeparam>
  441. /// <param name="container">The set to add values to.</param>
  442. /// <param name="other">The collection to copy values from.</param>
  443. public static void UnionWith<T>(this UnsafeHashSet<T> container, NativeHashSet<T> other)
  444. where T : unmanaged, IEquatable<T>
  445. {
  446. foreach (var item in other)
  447. {
  448. container.Add(item);
  449. }
  450. }
  451. /// <summary>
  452. /// Removes the values from this set which are also present in another collection.
  453. /// </summary>
  454. /// <typeparam name="T">The type of values.</typeparam>
  455. /// <param name="container">The set to remove values from.</param>
  456. /// <param name="other">The collection to compare with.</param>
  457. public static void ExceptWith<T>(this UnsafeHashSet<T> container, NativeList<T> other)
  458. where T : unmanaged, IEquatable<T>
  459. {
  460. foreach (var item in other)
  461. {
  462. container.Remove(item);
  463. }
  464. }
  465. /// <summary>
  466. /// Removes the values from this set which are absent in another collection.
  467. /// </summary>
  468. /// <typeparam name="T">The type of values.</typeparam>
  469. /// <param name="container">The set to remove values from.</param>
  470. /// <param name="other">The collection to compare with.</param>
  471. public static void IntersectWith<T>(this UnsafeHashSet<T> container, NativeList<T> other)
  472. where T : unmanaged, IEquatable<T>
  473. {
  474. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  475. foreach (var item in other)
  476. {
  477. if (container.Contains(item))
  478. {
  479. result.Add(item);
  480. }
  481. }
  482. container.Clear();
  483. container.UnionWith(result);
  484. result.Dispose();
  485. }
  486. /// <summary>
  487. /// Adds all values from a collection to this set.
  488. /// </summary>
  489. /// <typeparam name="T">The type of values.</typeparam>
  490. /// <param name="container">The set to add values to.</param>
  491. /// <param name="other">The collection to copy values from.</param>
  492. public static void UnionWith<T>(this UnsafeHashSet<T> container, NativeList<T> other)
  493. where T : unmanaged, IEquatable<T>
  494. {
  495. foreach (var item in other)
  496. {
  497. container.Add(item);
  498. }
  499. }
  500. /// <summary>
  501. /// Removes the values from this set which are also present in another collection.
  502. /// </summary>
  503. /// <typeparam name="T">The type of values.</typeparam>
  504. /// <param name="container">The set to remove values from.</param>
  505. /// <param name="other">The collection to compare with.</param>
  506. public static void ExceptWith<T>(this UnsafeHashSet<T> container, UnsafeHashSet<T> other)
  507. where T : unmanaged, IEquatable<T>
  508. {
  509. foreach (var item in other)
  510. {
  511. container.Remove(item);
  512. }
  513. }
  514. /// <summary>
  515. /// Removes the values from this set which are absent in another collection.
  516. /// </summary>
  517. /// <typeparam name="T">The type of values.</typeparam>
  518. /// <param name="container">The set to remove values from.</param>
  519. /// <param name="other">The collection to compare with.</param>
  520. public static void IntersectWith<T>(this UnsafeHashSet<T> container, UnsafeHashSet<T> other)
  521. where T : unmanaged, IEquatable<T>
  522. {
  523. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  524. foreach (var item in other)
  525. {
  526. if (container.Contains(item))
  527. {
  528. result.Add(item);
  529. }
  530. }
  531. container.Clear();
  532. container.UnionWith(result);
  533. result.Dispose();
  534. }
  535. /// <summary>
  536. /// Adds all values from a collection to this set.
  537. /// </summary>
  538. /// <typeparam name="T">The type of values.</typeparam>
  539. /// <param name="container">The set to add values to.</param>
  540. /// <param name="other">The collection to copy values from.</param>
  541. public static void UnionWith<T>(this UnsafeHashSet<T> container, UnsafeHashSet<T> other)
  542. where T : unmanaged, IEquatable<T>
  543. {
  544. foreach (var item in other)
  545. {
  546. container.Add(item);
  547. }
  548. }
  549. /// <summary>
  550. /// Removes the values from this set which are also present in another collection.
  551. /// </summary>
  552. /// <typeparam name="T">The type of values.</typeparam>
  553. /// <param name="container">The set to remove values from.</param>
  554. /// <param name="other">The collection to compare with.</param>
  555. public static void ExceptWith<T>(this UnsafeHashSet<T> container, UnsafeList<T> other)
  556. where T : unmanaged, IEquatable<T>
  557. {
  558. foreach (var item in other)
  559. {
  560. container.Remove(item);
  561. }
  562. }
  563. /// <summary>
  564. /// Removes the values from this set which are absent in another collection.
  565. /// </summary>
  566. /// <typeparam name="T">The type of values.</typeparam>
  567. /// <param name="container">The set to remove values from.</param>
  568. /// <param name="other">The collection to compare with.</param>
  569. public static void IntersectWith<T>(this UnsafeHashSet<T> container, UnsafeList<T> other)
  570. where T : unmanaged, IEquatable<T>
  571. {
  572. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  573. foreach (var item in other)
  574. {
  575. if (container.Contains(item))
  576. {
  577. result.Add(item);
  578. }
  579. }
  580. container.Clear();
  581. container.UnionWith(result);
  582. result.Dispose();
  583. }
  584. /// <summary>
  585. /// Adds all values from a collection to this set.
  586. /// </summary>
  587. /// <typeparam name="T">The type of values.</typeparam>
  588. /// <param name="container">The set to add values to.</param>
  589. /// <param name="other">The collection to copy values from.</param>
  590. public static void UnionWith<T>(this UnsafeHashSet<T> container, UnsafeList<T> other)
  591. where T : unmanaged, IEquatable<T>
  592. {
  593. foreach (var item in other)
  594. {
  595. container.Add(item);
  596. }
  597. }
  598. }
  599. }