allocateMoreSpace method
void
allocateMoreSpace()
Implementation
void allocateMoreSpace() {
//
// The variable size always indicates the maximum number of
// elements that has been allocated for the array.
// Initially, it is set to 0 to indicate that the array is empty.
// The pool of available elements is divided into segments of size
// 2**log_blksize each. Each segment is pointed to by a slot in
// the array base.
//
// By dividing size by the size of the segment we obtain the
// index for the next segment in base. If base is full, it is
// reallocated.
//
//
var k = _size >> log_blksize; /* which segment? */
//
// If the base is overflowed, reallocate it and initialize the new
// elements to NULL.
// Otherwise, allocate a new segment and place its adjusted address
// in base[k]. The adjustment allows us to index the segment directly,
// instead of having to perform a subtraction for each reference.
// See operator[] below.
//
//
if (k == base_size) {
base_size *= 2;
ArrayList.copy(base, 0, base = List.filled(base_size, []), 0, k);
}
base[k] = List.filled(1 << log_blksize, 0);
//
// Finally, we update SIZE.
//
_size += (1 << log_blksize);
return;
}