net.algart.arrays.FloatArray Maven / Gradle / Ivy
Show all versions of algart Show documentation
/*
* The MIT License (MIT)
*
* Copyright (c) 2007-2024 Daniel Alievsky, AlgART Laboratory (http://algart.net)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.algart.arrays;
/*Repeat.SectionStart all*/
import java.util.Objects;
/**
* AlgART array of float
values, read-only access.
*
* @author Daniel Alievsky
*/
public interface FloatArray extends PFloatingArray {
Class extends FloatArray> type();
Class extends UpdatableFloatArray> updatableType();
Class extends MutableFloatArray> mutableType();
/**
* Returns the element #index
.
*
* @param index index of element to get.
* @return the element at the specified position in this array.
* @throws IndexOutOfBoundsException if index
is out of range 0..length()-1
.
*/
float getFloat(long index);
default float[] newJavaArray(int length) {
return new float[length];
}
/**
* Returns the minimal index k
, so that
* lowIndex<=k<min(highIndex,thisArray.{@link #length() length()})
* and {@link #getFloat(long) getFloat}(k)==value
,
* or -1
if there is no such array element.
*
* In particular, if lowIndex>=thisArray.{@link #length() length()}}
* or lowIndex>=highIndex
, this method returns -1
,
* and if lowIndex<0
, the result is the same as if lowIndex==0
.
*
*
You may specify lowIndex=0
and highIndex=Long.MAX_VALUE
to search
* through all array elements.
*
* @param lowIndex the low index in the array for search (inclusive).
* @param highIndex the high index in the array for search (exclusive).
* @param value the value to be found.
* @return the index of the first occurrence of this value in this array
* in range lowIndex<=index<highIndex
,
* or -1
if this value does not occur in this range.
*/
long indexOf(long lowIndex, long highIndex, float value);
/**
* Returns the maximal index k
, so that highIndex>k>=max(lowIndex,0)
* and {@link #getFloat(long) getFloat}(k)==value
,
* or -1
if there is no such array element.
*
*
In particular, if highIndex<=0
or highIndex<=lowIndex
,
* this method returns -1
,
* and if highIndex>=thisArray.{@link #length() length()}
,
* the result is the same as if highIndex==thisArray.{@link #length() length()}
.
*
*
You may specify lowIndex=0
and highIndex=Long.MAX_VALUE
to search
* through all array elements.
*
* @param lowIndex the low index in the array for search (inclusive).
* @param highIndex the high index in the array for search (exclusive).
* @param value the value to be found.
* @return the index of the last occurrence of this value in this array
* in range lowIndex<=index<highIndex
,
* or -1
if this value does not occur in this range.
*/
long lastIndexOf(long lowIndex, long highIndex, float value);
/*Repeat.SectionStart resultTypes*/
DataFloatBuffer buffer(DataBuffer.AccessMode mode, long capacity);
DataFloatBuffer buffer(DataBuffer.AccessMode mode);
DataFloatBuffer buffer(long capacity);
DataFloatBuffer buffer();
FloatArray asImmutable();
FloatArray asTrustedImmutable();
MutableFloatArray mutableClone(MemoryModel memoryModel);
UpdatableFloatArray updatableClone(MemoryModel memoryModel);
default float[] toJavaArray() {
final long len = length();
if (len != (int) len) {
throw new TooLargeArrayException("Cannot convert AlgART array to float[] Java array, "
+ "because it is too large: " + this);
}
var result = newJavaArray((int) len);
getData(0, result);
return result;
}
float[] ja();
default Matrix extends FloatArray> matrix(long... dim) {
return Matrices.matrix(this, dim);
}
/*Repeat.SectionEnd resultTypes*/
@Override
default float[] jaFloat() {
return ja();
}
/**
* Equivalent to {@link MemoryModel#newUnresizableFloatArray(long)
* memoryModel.newUnresizableFloatArray(length)}
.
*
* @param memoryModel the memory model, used for allocation new array.
* @param length the length and capacity of the array.
* @return created unresizable AlgART array.
* @throws NullPointerException if memoryModel
argument is {@code null}.
* @throws IllegalArgumentException if the specified length is negative.
* @throws UnsupportedElementTypeException if float
element type
* is not supported by this memory model.
* @throws TooLargeArrayException if the specified length is too large for this memory model.
*/
static UpdatableFloatArray newArray(MemoryModel memoryModel, long length) {
Objects.requireNonNull(memoryModel, "Null memory model");
return memoryModel.newUnresizableFloatArray(length);
}
/**
* Equivalent to {@link Arrays#SMM Arrays.SMM}.{@link MemoryModel#newUnresizableFloatArray(long)
* newUnresizableFloatArray(length)}
.
*
* @param length the length and capacity of the array.
* @return created unresizable AlgART array.
* @throws IllegalArgumentException if the specified length is negative.
* @throws TooLargeArrayException if the specified length is too large for {@link SimpleMemoryModel}.
*/
static UpdatableFloatArray newArray(long length) {
return Arrays.SMM.newUnresizableFloatArray(length);
}
/*Repeat.SectionEnd all*/
/**
* Equivalent to {@link SimpleMemoryModel#asUpdatableFloatArray(float[])
* SimpleMemoryModel.asUpdatableFloatArray}(array)
.
*
* @param array the source Java array.
* @return an unresizable AlgART array backed by the specified Java array.
* @throws NullPointerException if array
argument is {@code null}.
*/
static UpdatableFloatArray as(float[] array) {
return SimpleMemoryModel.asUpdatableFloatArray(array);
}
}