@@ -65,22 +65,22 @@ namespace RabbitMQ.Util
65
65
66
66
67
67
/**
68
- * A class for allocating integer IDs in a given range.
69
- */
68
+ * A class for allocating integer IDs in a given range.
69
+ */
70
70
public class IntAllocator {
71
71
72
72
private IntervalList Base ;
73
73
74
74
private readonly int [ ] unsorted ;
75
75
private int unsortedCount = 0 ;
76
76
77
- /**
77
+ /**
78
78
* A class representing a list of inclusive intervals
79
79
*/
80
80
public class IntervalList {
81
81
public IntervalList ( int start , int end ) {
82
82
this . Start = start ;
83
- this . End = end ;
83
+ this . End = end ;
84
84
}
85
85
86
86
public int Start ;
@@ -93,13 +93,13 @@ public IntervalList(int start, int end){
93
93
// Invariant: None of the Intervals in the two lists may overlap
94
94
// intervals in this list.
95
95
public static IntervalList Merge ( IntervalList x , IntervalList y )
96
- {
96
+ {
97
97
if ( x == null ) return y ;
98
98
if ( y == null ) return x ;
99
99
100
100
if ( x . End > y . Start ) return Merge ( y , x ) ;
101
101
102
- Debug . Assert ( x . End != y . Start ) ;
102
+ Debug . Assert ( x . End != y . Start ) ;
103
103
104
104
// We now have x, y non-null and x.End < y.Start.
105
105
@@ -138,7 +138,7 @@ public static IntervalList FromArray(int[] xs, int length)
138
138
result = interval ;
139
139
current = interval ;
140
140
}
141
- else
141
+ else
142
142
{
143
143
current . Next = interval ;
144
144
current = interval ;
@@ -149,7 +149,7 @@ public static IntervalList FromArray(int[] xs, int length)
149
149
}
150
150
}
151
151
152
- /**
152
+ /**
153
153
* Creates an IntAllocator allocating integer IDs within the inclusive range [start, end]
154
154
*/
155
155
public IntAllocator ( int start , int end )
@@ -163,7 +163,7 @@ public IntAllocator(int start, int end)
163
163
164
164
/**
165
165
* Allocate a fresh integer from the range, or return -1 if no more integers
166
- * are available. This operation is guaranteed to run in O(1)
166
+ * are available. This operation is guaranteed to run in O(1)
167
167
*/
168
168
public int Allocate ( )
169
169
{
@@ -188,12 +188,12 @@ private void Flush()
188
188
}
189
189
190
190
191
- /**
192
- * Make the provided integer available for allocation again. This operation
193
- * runs in amortized O(sqrt(range size)) time: About every sqrt(range size)
194
- * operations will take O(range_size + number of intervals) to complete and
191
+ /**
192
+ * Make the provided integer available for allocation again. This operation
193
+ * runs in amortized O(sqrt(range size)) time: About every sqrt(range size)
194
+ * operations will take O(range_size + number of intervals) to complete and
195
195
* the rest run in constant time.
196
- *
196
+ *
197
197
* No error checking is performed, so if you double Free or Free an integer
198
198
* that was not originally Allocated the results are undefined. Sorry.
199
199
*/
@@ -211,7 +211,7 @@ public bool Reserve(int id)
211
211
// We always flush before reserving because the only way to determine
212
212
// if an ID is in the unsorted array is through a linear scan. This leads
213
213
// us to the potentially expensive situation where there is a large unsorted
214
- // array and we reserve several IDs, incurring the cost of the scan each time.
214
+ // array and we reserve several IDs, incurring the cost of the scan each time.
215
215
// Flushing makes sure the array is always empty and does no additional work if
216
216
// reserve is called twice.
217
217
Flush ( ) ;
@@ -228,18 +228,18 @@ public bool Reserve(int id)
228
228
else if ( current . Start > id )
229
229
{
230
230
return false ;
231
- }
231
+ }
232
232
else if ( current . End == id )
233
233
{
234
234
current . End -- ;
235
- }
235
+ }
236
236
else if ( current . Start == id )
237
237
{
238
238
current . Start ++ ;
239
- }
240
- else
239
+ }
240
+ else
241
241
{
242
- // The ID is in the middle of this interval.
242
+ // The ID is in the middle of this interval.
243
243
// We need to split the interval into two.
244
244
IntervalList rest = new IntervalList ( id + 1 , current . End ) ;
245
245
current . End = id - 1 ;
0 commit comments