3737 */
3838public class IntAllocator {
3939
40- // Invariant: Sorted in order of first element. Non-overlapping, non-adjacent.
41- // This could really use being a balanced binary tree. However for normal usages
42- // it doesn't actually matter.
40+ // Invariant: Sorted in order of first element.
41+ // Invariant: Intervals are non-overlapping, non-adjacent.
42+ // This could really use being a balanced binary tree. However for normal
43+ // usages it doesn't actually matter.
4344 private IntervalList base ;
4445
4546 private final int [] unsorted ;
@@ -115,10 +116,13 @@ public static IntervalList fromArray(int[] xs, int length){
115116
116117
117118 /**
118- * Creates an IntAllocator allocating integer IDs within the inclusive range [start, end]
119+ * Creates an IntAllocator allocating integer IDs within the inclusive range
120+ * [start, end]
119121 */
120122 public IntAllocator (int start , int end ){
121- if (start > end ) throw new IllegalArgumentException ("illegal range [" + start +", " + end + "]" );
123+ if (start > end )
124+ throw new IllegalArgumentException ("illegal range [" + start +
125+ ", " + end + "]" );
122126
123127 // Fairly arbitrary heuristic for a good size for the unsorted set.
124128 unsorted = new int [Math .max (32 , (int )Math .sqrt (end - start ))];
@@ -144,8 +148,8 @@ public int allocate(){
144148 /**
145149 * Make the provided integer available for allocation again. This operation
146150 * runs in amortized O(sqrt(range size)) time: About every sqrt(range size)
147- * operations will take O(range_size + number of intervals) to complete and
148- * the rest run in constant time.
151+ * operations will take O(range_size + number of intervals) to complete
152+ * and the rest run in constant time.
149153 *
150154 * No error checking is performed, so if you double free or free an integer
151155 * that was not originally allocated the results are undefined. Sorry.
@@ -158,12 +162,12 @@ public void free(int id){
158162 }
159163
160164 /**
161- * Attempt to reserve the provided ID as if it had been allocated. Returns true
162- * if it is available, false otherwise.
165+ * Attempt to reserve the provided ID as if it had been allocated. Returns
166+ * true if it is available, false otherwise.
163167 *
164- * This operation runs in O(id) in the worst case scenario, though it can usually
165- * be expected to perform better than that unless a great deal of fragmentation
166- * has occurred.
168+ * This operation runs in O(id) in the worst case scenario, though it can
169+ * usually be expected to perform better than that unless a great deal of
170+ * fragmentation has occurred.
167171 */
168172 public boolean reserve (int id ){
169173 flush ();
0 commit comments