Allocate a run of pages (>=1)

@param normCapacity normalized capacity
@return index in memoryMap
179428
private long allocateRun(int normCapacity) {
        int d = maxOrder - (log2(normCapacity) - pageShifts);
        int id = allocateNode(d);
        if (id < 0) {
            return id;
        }
        freeBytes -= runLength(id);
        return id;
    }
348416
private void ensureCapacity(int minCapacity) {
		long currentCapacity = data.length;

		if (minCapacity <= currentCapacity) {
			return;
		}

		// increase capacity by at least ~50%
		long expandedCapacity = Math.max(minCapacity, currentCapacity + (currentCapacity >> 1));
		int newCapacity = (int) Math.min(MAX_ARRAY_SIZE, expandedCapacity);

		if (newCapacity < minCapacity) {
			// throw exception as unbounded arrays are not expected to fill
			throw new RuntimeException("Requested array size " + minCapacity + " exceeds limit of " + MAX_ARRAY_SIZE);
		}

		data = Arrays.copyOf(data, newCapacity);
	}
265423
@Override
    public PagedPointer alloc(long requiredMemory, MemoryKind kind, DataType dataType, boolean initialize) {
        throw new UnsupportedOperationException("DummyWorkspace shouldn't be used for allocation");
    }
961454
public static <E> Page<E> startPage(int pageNum, int pageSize, boolean count, Boolean reasonable, Boolean pageSizeZero) {
        Page<E> page = new Page<E>(pageNum, pageSize, count);
        page.setReasonable(reasonable);
        page.setPageSizeZero(pageSizeZero);
        //当已经执行过orderBy的时候
        Page<E> oldPage = getLocalPage();
        if (oldPage != null && oldPage.isOrderByOnly()) {
            page.setOrderBy(oldPage.getOrderBy());
        }
        setLocalPage(page);
        return page;
    }
1354804
public <T extends CacheSpec<K, V>> T initialCapacity(int initialCapacity) {
      checkArgument(initialCapacity > 0, "Capacity must be > 0");
      this.initialCapacity = initialCapacity;
      return Cast.as(this);
   }
1126294
public static LinkedBuffer allocate(int size, LinkedBuffer previous)
    {
        if (size < MIN_BUFFER_SIZE)
            throw new IllegalArgumentException(MIN_BUFFER_SIZE + " is the minimum buffer size.");

        return new LinkedBuffer(size, previous);
    }
404200
public PooledByteBuffer allocate() {
        final Queue<Slice> sliceQueue = this.sliceQueue;
        final Slice slice = sliceQueue.poll();
        if (slice == null && (maxRegions <= 0 || regionUpdater.getAndIncrement(this) < maxRegions)) {
            final int bufferSize = this.bufferSize;
            final int buffersPerRegion = this.buffersPerRegion;
            final ByteBuffer region = allocator.allocate(buffersPerRegion * bufferSize);
            int idx = bufferSize;
            for (int i = 1; i < buffersPerRegion; i ++) {
                sliceQueue.add(new Slice(region, idx, bufferSize));
                idx += bufferSize;
            }
            final Slice newSlice = new Slice(region, 0, bufferSize);
            return new PooledByteBuffer(newSlice, newSlice.slice(), sliceQueue);
        }
        if (slice == null) {
            return null;
        }
        return new PooledByteBuffer(slice, slice.slice(), sliceQueue);
    }
380443
public static <K, V> HashMap<K, V> createHashMap(int initialCapacity) {
        return new HashMap<K, V>(initialCapacity);
    }
10238
protected int chooseShrinkCapacity(int size, double minLoad, double maxLoad) {
    return nextPrime(Math.max(size+1, (int) ((4*size / (minLoad+3*maxLoad)))));
  }
12903
public QueryPlus<T> withMaxQueuedBytes(long maxQueuedBytes)
  {
    return new QueryPlus<>(
        query.withOverriddenContext(ImmutableMap.of(QueryContexts.MAX_QUEUED_BYTES_KEY, maxQueuedBytes)),
        queryMetrics,
        identity
    );
  }
631311
public Storage<S> storageDelegate(StorableIndex<S> index) {
        if (mAllIndexInfoMap.get(index) instanceof ManagedIndex) {
            // Index is managed by this storage, which is typical.
            return null;
        }
        // Index is managed by master storage, most likely a primary key index.
        return mMasterStorage;
    }
972744
public int getCurrentPageSize() {
        if (buffer.isEmpty()) return OggPage.getMinimumPageSize();

        OggPage p = buffer.get( buffer.size()-1 );
        return p.getPageSize();
    }
681158
public static BinaryInMemorySortBuffer createBuffer(
			NormalizedKeyComputer normalizedKeyComputer,
			AbstractRowSerializer<BaseRow> inputSerializer,
			BinaryRowSerializer serializer,
			RecordComparator comparator,
			List<MemorySegment> memory) throws IOException {
		checkArgument(memory.size() >= MIN_REQUIRED_BUFFERS);
		int totalNumBuffers = memory.size();
		ListMemorySegmentPool pool = new ListMemorySegmentPool(memory);
		ArrayList<MemorySegment> recordBufferSegments = new ArrayList<>(16);
		return new BinaryInMemorySortBuffer(
				normalizedKeyComputer, inputSerializer, serializer, comparator, recordBufferSegments,
				new SimpleCollectingOutputView(recordBufferSegments, pool, pool.pageSize()),
				pool, totalNumBuffers);
	}
422724
@Nonnull
  @ReturnsMutableCopy
  @OverrideOnDemand
  @CodingStyleguideUnaware
  protected ICommonsMap <KEYTYPE, VALUETYPE> createCache ()
  {
    return hasMaxSize () ? new SoftLinkedHashMap <> (m_nMaxSize) : new SoftHashMap <> ();
  }
839467
protected void ensureCapacity(int minNbRuns) {
    final int minCapacity = 2 * minNbRuns;
    if (valueslength.length < minCapacity) {
      int newCapacity = valueslength.length;
      while (newCapacity < minCapacity) {
        newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE
            : newCapacity < 64 ? newCapacity * 2
                : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4;
      }
      short[] nv = new short[newCapacity];
      copyValuesLength(valueslength, 0, nv, 0, nbrruns);
      valueslength = nv;
    }
  }
178495
@SuppressWarnings("unchecked")
    public List<Map>  getPage(int pageNumber) {

        if (pageNumber < 1) {
            throw new IllegalArgumentException("minimum page index == 1");
        }

        String select = subQuery == null ?
                dialect.formSelect(tableName, columns, null, orderBys, pageSize, (pageNumber - 1) * pageSize) :
                dialect.formSelect(tableName, columns, subQuery, orderBys, pageSize, (pageNumber - 1) * pageSize);

        currentPage = pageNumber;
        return new DB(dbName).findAll(select, params);
    }
718861
public static <K, V> ArrayMap<K, V> create(int initialCapacity) {
    ArrayMap<K, V> result = create();
    result.ensureCapacity(initialCapacity);
    return result;
  }