1 package org.apache.lucene.facet.search;
3 import java.util.Arrays;
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements. See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * An IntArrayAllocator is an object which manages counter array objects
24 * of a certain length. These counter arrays are needed temporarily during
25 * faceted search (see {@link FacetsAccumulator} and can be reused across searches
26 * instead of being allocated afresh on every search.
28 * An IntArrayAllocator is thread-safe.
30 * @lucene.experimental
32 public final class IntArrayAllocator extends TemporaryObjectAllocator<int[]> {
34 // An IntArrayAllocater deals with integer arrays of a fixed length.
38 * Construct an allocator for counter arrays of length <CODE>length</CODE>,
39 * keeping around a pool of up to <CODE>maxArrays</CODE> old arrays.
41 * Note that the pool size only restricts the number of arrays that hang
42 * around when not needed, but <I>not</I> the maximum number of arrays
43 * that are allocated when actually is use: If a number of concurrent
44 * threads ask for an allocation, all of them will get a counter array,
45 * even if their number is greater than maxArrays. If an application wants
46 * to limit the number of concurrent threads making allocations, it needs
47 * to do so on its own - for example by blocking new threads until the
48 * existing ones have finished.
50 * In particular, when maxArrays=0, this object behaves as a trivial
51 * allocator, always allocating a new array and never reusing an old one.
53 public IntArrayAllocator(int length, int maxArrays) {
59 public int[] create() {
60 return new int[length];
64 public void clear(int[] array) {
65 Arrays.fill(array, 0);