All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.lucene.facet.search.FloatArrayAllocator Maven / Gradle / Ivy

There is a newer version: 9.11.1
Show newest version
package org.apache.lucene.facet.search;

import java.util.Arrays;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * An FloatArrayAllocator is an object which manages float array objects
 * of a certain size. These float arrays are needed temporarily during
 * faceted search (see {@link FacetsAccumulator} and can be reused across searches
 * instead of being allocated afresh on every search.
 * 

* An FloatArrayAllocator is thread-safe. * * @lucene.experimental */ public final class FloatArrayAllocator extends TemporaryObjectAllocator { // An FloatArrayAllocater deals with integer arrays of a fixed size, size. private int size; /** * Construct an allocator for float arrays of size size, * keeping around a pool of up to maxArrays old arrays. *

* Note that the pool size only restricts the number of arrays that hang * around when not needed, but not the maximum number of arrays * that are allocated when actually is use: If a number of concurrent * threads ask for an allocation, all of them will get a counter array, * even if their number is greater than maxArrays. If an application wants * to limit the number of concurrent threads making allocations, it needs * to do so on its own - for example by blocking new threads until the * existing ones have finished. *

* In particular, when maxArrays=0, this object behaves as a trivial * allocator, always allocating a new array and never reusing an old one. */ public FloatArrayAllocator(int size, int maxArrays) { super(maxArrays); this.size = size; } @Override public float[] create() { return new float[size]; } @Override public void clear(float[] array) { Arrays.fill(array, 0); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy