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 FloatArrayAllocator is an object which manages float array objects
24 * of a certain size. These float 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 FloatArrayAllocator is thread-safe.
30 * @lucene.experimental
32 public final class FloatArrayAllocator extends TemporaryObjectAllocator<float[]> {
34 // An FloatArrayAllocater deals with integer arrays of a fixed size, size.
38 * Construct an allocator for float arrays of size <CODE>size</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 FloatArrayAllocator(int size, int maxArrays) {
59 public float[] create() {
60 return new float[size];
64 public void clear(float[] array) {
65 Arrays.fill(array, 0);