BitArrayExtensions.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections;
  3. namespace MonoGame.Extended.ECS
  4. {
  5. public static class BitArrayExtensions
  6. {
  7. public static bool IsEmpty(this BitArray bitArray)
  8. {
  9. for (var i = 0; i < bitArray.Length; i++)
  10. {
  11. if (bitArray[i])
  12. return false;
  13. }
  14. return true;
  15. }
  16. public static bool ContainsAll(this BitArray bitArray, BitArray other)
  17. {
  18. var otherBitsLength = other.Length;
  19. var bitsLength = bitArray.Length;
  20. for (var i = bitsLength; i < otherBitsLength; i++)
  21. {
  22. if (other[i])
  23. return false;
  24. }
  25. var s = Math.Min(bitsLength, otherBitsLength);
  26. for (var i = 0; s > i; i++)
  27. {
  28. if ((bitArray[i] & other[i]) != other[i])
  29. return false;
  30. }
  31. return true;
  32. }
  33. public static bool Intersects(this BitArray bitArray, BitArray other)
  34. {
  35. var s = Math.Min(bitArray.Length, other.Length);
  36. for (var i = 0; s > i; i++)
  37. {
  38. if (bitArray[i] & other[i])
  39. return true;
  40. }
  41. return false;
  42. }
  43. }
  44. }