@@ -36,143 +36,6 @@ namespace DiscUtils.Internal;
3636
3737public static class Utilities
3838{
39- /// <summary>
40- /// Indicates if two ranges overlap.
41- /// </summary>
42- /// <typeparam name="T">The type of the ordinals.</typeparam>
43- /// <param name="xFirst">The lowest ordinal of the first range (inclusive).</param>
44- /// <param name="xLast">The highest ordinal of the first range (exclusive).</param>
45- /// <param name="yFirst">The lowest ordinal of the second range (inclusive).</param>
46- /// <param name="yLast">The highest ordinal of the second range (exclusive).</param>
47- /// <returns><c>true</c> if the ranges overlap, else <c>false</c>.</returns>
48- public static bool RangesOverlap < T > ( T xFirst , T xLast , T yFirst , T yLast ) where T : IComparable < T >
49- {
50- return ! ( ( xLast . CompareTo ( yFirst ) <= 0 ) || ( xFirst . CompareTo ( yLast ) >= 0 ) ) ;
51- }
52-
53- #region Bit Twiddling
54-
55- public static bool IsAllZeros ( byte [ ] buffer , int offset , int count )
56- {
57- #if NET8_0_OR_GREATER
58- return ! buffer . AsSpan ( offset , count ) . ContainsAnyExcept ( ( byte ) 0 ) ;
59- #else
60- var end = offset + count ;
61- for ( var i = offset ; i < end ; ++ i )
62- {
63- if ( buffer [ i ] != 0 )
64- {
65- return false ;
66- }
67- }
68-
69- return true ;
70- #endif
71- }
72-
73- public static bool IsAllZeros ( ReadOnlySpan < byte > buffer )
74- {
75- #if NET8_0_OR_GREATER
76- return ! buffer . ContainsAnyExcept ( ( byte ) 0 ) ;
77- #else
78- for ( var i = 0 ; i < buffer . Length ; ++ i )
79- {
80- if ( buffer [ i ] != 0 )
81- {
82- return false ;
83- }
84- }
85-
86- return true ;
87- #endif
88- }
89-
90- public static bool IsPowerOfTwo ( uint val )
91- {
92- if ( val == 0 )
93- {
94- return false ;
95- }
96-
97- while ( ( val & 1 ) != 1 )
98- {
99- val >>= 1 ;
100- }
101-
102- return val == 1 ;
103- }
104-
105- public static bool IsPowerOfTwo ( long val )
106- {
107- if ( val == 0 )
108- {
109- return false ;
110- }
111-
112- while ( ( val & 1 ) != 1 )
113- {
114- val >>= 1 ;
115- }
116-
117- return val == 1 ;
118- }
119-
120- public static bool AreEqual ( byte [ ] a , byte [ ] b )
121- {
122- if ( a . Length != b . Length )
123- {
124- return false ;
125- }
126-
127- if ( ReferenceEquals ( a , b ) )
128- {
129- return true ;
130- }
131-
132- for ( var i = 0 ; i < a . Length ; ++ i )
133- {
134- if ( a [ i ] != b [ i ] )
135- {
136- return false ;
137- }
138- }
139-
140- return true ;
141- }
142-
143- public static ushort BitSwap ( ushort value )
144- {
145- return ( ushort ) ( ( ( value & 0x00FF ) << 8 ) | ( ( value & 0xFF00 ) >> 8 ) ) ;
146- }
147-
148- public static uint BitSwap ( uint value )
149- {
150- return ( ( value & 0xFF ) << 24 ) | ( ( value & 0xFF00 ) << 8 ) | ( ( value & 0x00FF0000 ) >> 8 ) |
151- ( ( value & 0xFF000000 ) >> 24 ) ;
152- }
153-
154- public static ulong BitSwap ( ulong value )
155- {
156- return ( ( ulong ) BitSwap ( ( uint ) ( value & 0xFFFFFFFF ) ) << 32 ) | BitSwap ( ( uint ) ( value >> 32 ) ) ;
157- }
158-
159- public static short BitSwap ( short value )
160- {
161- return ( short ) BitSwap ( ( ushort ) value ) ;
162- }
163-
164- public static int BitSwap ( int value )
165- {
166- return ( int ) BitSwap ( ( uint ) value ) ;
167- }
168-
169- public static long BitSwap ( long value )
170- {
171- return ( long ) BitSwap ( ( ulong ) value ) ;
172- }
173-
174- #endregion
175-
17639 #region Path Manipulation
17740
17841 /// <summary>
0 commit comments