public interface FloatIndexable extends PrimitiveFloatIterable, Sizeable
The EMPTY
constant or emptyIndexable()
method provide the same
useful return value to indicate emptiness.
Simple implementations should extend FloatIndexable.Base
because
that provides useful implementations for standard Object methods and implements
Comparable
.
FastFloatSequenceSearch
Modifier and Type | Interface and Description |
---|---|
static class |
FloatIndexable.Base
Abstract base class which provides useful implementations
for
Object.equals(Object) , Object.hashCode() ,
Object.toString() . |
Modifier and Type | Field and Description |
---|---|
static FloatIndexable.Base |
EMPTY
An empty indexable.
|
static FloatIndexable |
SINGLE_0
Float indexable which contains the single value
0.0f . |
EMPTY_FLOAT_ITERATOR
Modifier and Type | Method and Description |
---|---|
default void |
addAllTo(java.util.Collection<? super java.lang.Float> collection)
Add all elements of this indexable to the given collection.
|
default int |
addToArray(float[] array,
int pos)
Add the content of this indexable to the given array.
|
default int |
addToArray(float[] array,
int arrayPos,
int index,
int length)
Add a part of the content of this indexable to the given array.
|
default FloatIndexable.Base |
asBase()
Make this float indexable usable as a class with defined standard Object methods.
|
default java.util.Collection<java.lang.Float> |
asCollection()
Get a view on this indexable as an unmodifiable collection.
|
default DoubleIndexable.Base |
asDoubleIndexable()
View this float indexable as a double indexable.
|
default Indexable<java.lang.Float> |
asIndexable()
Get a view of this indexable as a standard object-based indexable.
|
default java.util.List<java.lang.Float> |
asList()
Get a view on this indexable as an unmodifiable list.
|
static FloatIndexable.Base |
based(FloatIndexable indexable)
Wrap any indexable with a based indexable which provides
useful implementations for standard methods.
|
default int |
binarySearch(float value)
Do a binary search in an indexable ordered in natural ascending order.
|
default int |
binarySearch(float value,
FloatOrdering order)
Do a binary search in an ordered indexable.
|
static int |
compare(FloatIndexable indexable1,
FloatIndexable indexable2)
Compare two float indexables.
|
default java.util.PrimitiveIterator.OfDouble |
doubleIterator()
Get an primitive double iterator.
|
static FloatIndexable.Base |
emptyIndexable()
Get an empty indexable set.
|
static boolean |
equal(FloatIndexable indexable1,
FloatIndexable indexable2)
Are two float indexables equal?
|
static boolean |
equal(FloatIndexable indexable1,
FloatIndexable indexable2,
FloatPredicate2 checker)
Are two float indexables equal?
|
static boolean |
equal(FloatIndexable indexable1,
java.lang.Object indexable2)
Are two float indexables equal?
|
static boolean |
equalStandard(FloatIndexable indexable1,
FloatIndexable indexable2)
Are two float indexables equal?
|
default int |
firstMatch(FloatPredicate1 check)
Get the first index for which the given check is fulfilled.
|
default PrimitiveFloatIterator |
floatIterator()
Get an primitive float iterator.
|
default PrimitiveFloatIterator |
floatIterator(int from,
int to)
Get a float iterator from the given sub set.
|
default float |
foldLeft(float initialValue,
FloatOperator2 foldOperation)
Go over all values and do a cumulative calculation.
|
default FloatIndexable |
frozen()
Get a frozen version of this indexable.
|
float |
get(int index)
Get the element at the given index.
|
default float |
getMod(int index)
Get an element modulo size.
|
default float |
gyt(int index)
Pythonesque get.
|
static int |
hash(FloatIndexable indexable)
Calculate a hashcode for a float indexable.
|
default FloatIndexable.Base |
headSet(int toIndex)
Create an indexable subset from the last elements of this indexable set.
|
default java.lang.Iterable<java.lang.Integer> |
indexes()
Get the indexes of this indexable as an iterable range.
|
static FloatIndexable.Base |
init(int size,
float value)
Get a float indexable of a given size which always returns the same value.
|
static FloatIndexable |
initByIndex(int size,
IntToFloatFunction1 producer)
Get a float indexable of a given size which returns elements created by index.
|
default IntIndexable |
intIndexes()
Get the indexes of this indexable as an integer indexable.
|
default boolean |
isEmpty()
Is this indexable empty?
|
default boolean |
isOrdered(FloatOrdering order)
Is this indexable sorted according to the given ordering?
|
default boolean |
isStrictlyOrdered(FloatOrdering order)
Is this indexable strictly sorted according to the given ordering?
|
default java.util.Iterator<java.lang.Float> |
iterator()
Returns an iterator over elements of type
T . |
default int |
lastMatch(FloatPredicate1 check)
Get the last index for which the given check is fulfilled.
|
default java.util.ListIterator<java.lang.Float> |
listIterator()
Returns a list iterator over elements of type
T . |
default int |
nextMatch(int startIndex,
FloatPredicate1 check)
Get the next index for which the given check is fulfilled.
|
default MutableFloatIndexable |
ordered()
Create a (mutable) double indexable from the values of this indexable
which is ordered in natural order.
|
default MutableFloatIndexable |
ordered(FloatOrdering order)
Create a (mutable) float indexable from the values of this indexable
which is ordered as defined by the given ordering.
|
default int |
previousMatch(int startIndex,
FloatPredicate1 check)
Get the previous index for which the given check is fulfilled.
|
default FloatIndexable.Base |
reverse()
Get this indexable but with inverted order.
|
default FloatIndexable |
rotated(int steps)
Get a rotated view of this float indexable.
|
static FloatIndexable.Base |
singleton(float value)
View a single float value as a float indexable of size 1.
|
default FloatIndexable.Base |
subSet(int fromIndex,
int toIndex)
Get an indexable subset.
|
default FloatIndexable.Base |
sybSet(int fromIndex,
int toIndex)
Get an indexable subset.
|
default FloatIndexable.Base |
tailSet(int fromIndex)
Create an indexable subset from the last elements of this indexable set.
|
default float[] |
toArray()
Convert this indexable into a Java array.
|
default java.util.ArrayList<java.lang.Float> |
toList()
Create a list from this float indexable.
|
static java.lang.String |
toString(FloatIndexable indexable)
Create a string representation of the given indexable.
|
default <T> Indexable<T> |
view(FloatFunction1<? extends T> mapper)
Return a mapped view on this float indexable.
|
static FloatIndexable.Base |
viewArray(float... array)
View a float array as an Indexable.
|
static FloatIndexable.Base |
viewArray(float[] array,
int start,
int length)
View part of a float array as an Indexable.
|
static <T> FloatIndexable.Base |
viewArray(T[] array,
ToFloatFunction<? super T> valueExtract)
View an object array as a float indexable.
|
default BooleanIndexable |
viewAsBoolean(FloatPredicate1 convert)
View this indexable as a boolean indexable while using a conversion for
each value.
|
default ByteIndexable |
viewAsByte()
View this float indexable as a byte integer indexable.
|
default DoubleIndexable |
viewAsDouble()
View this float indexable as a double indexable.
|
default IntIndexable |
viewAsInt()
View this float indexable as a short integer indexable.
|
default LongIndexable |
viewAsLong()
View this float indexable as a long integer indexable.
|
default ShortIndexable |
viewAsShort()
View this float indexable as a short integer indexable.
|
static FloatIndexable.Base |
viewByIndex(int size,
IntToFloatFunction1 producer)
Get a float indexable of a given size which returns elements created by index.
|
static FloatIndexable.Base |
viewIndexable(Indexable<? extends java.lang.Number> indexable)
View a generic Number indexable as float indexable.
|
static FloatIndexable.Base |
viewIndexable(Indexable<? extends java.lang.Number> indexable,
float nullFallback)
View a generic Number indexable as float indexable.
|
static <T> FloatIndexable.Base |
viewIndexable(Indexable<T> indexable,
ToFloatFunction<? super T> extractor)
View a generic indexable as a float indexable.
|
static FloatIndexable.Base |
viewList(java.util.List<? extends java.lang.Number> list)
View a list as an Indexable.
|
static FloatIndexable.Base |
viewList(java.util.List<? extends java.lang.Number> list,
float nullValue)
View a list as an Indexable.
|
static <T> FloatIndexable.Base |
viewList(java.util.List<T> list,
ToFloatFunction<? super T> extractor)
View a generic list as a float indexable.
|
static FloatIndexable.Base |
viewNumberArray(java.lang.Number... array)
View a Number array as an Indexable.
|
default FloatIndexable |
viewOp(FloatOperator1 op)
View this float indexable transformed by an operator.
|
default FloatIndexable |
withAppendedValue(float value)
Create a view with of this indexable with another value added at the end.
|
static FloatIndexable.Base |
withCachedHash(FloatIndexable indexable)
Wrap an indexable with one which caches the hash value.
|
default FloatIndexable |
withExchangedValueAt(int index,
float value)
Create a view of this float indexable with an exchanged value.
|
default FloatIndexable |
withInsertedValueAt(int index,
float value)
Create a view of this float indexable with an inserted value.
|
default FloatIndexable |
withRemovedValueAt(int index)
Create a view of this indexable with one value removed.
|
default FloatIndexable |
withSwappedValuesAt(int index1,
int index2)
Create a view of this float indexable with two values swapped.
|
asDoubleIterable, containsFloat, containsFloat, forEachFloat, forEachFloatFragile
static final FloatIndexable SINGLE_0
0.0f
.@NotNull static final FloatIndexable.Base EMPTY
float get(int index)
index
- index between 0
and size() - 1
default float gyt(int index)
-1
references the last element, -2
its predecessor, and so on.index
- index between -size()
and size() - 1
default float getMod(int index)
This maps the given index
into the range of this indexable
by applying a modulo Sizeable.size()
operation. For empty indexable
this will throw an IndexOutOfBoundsException
as there is no
possible index to get.
index
- index, possibly out of range, possibly even negative
for Pythonesque access@NotNull default FloatIndexable.Base reverse()
default boolean isEmpty()
true
: there are no elements in this indexablefalse
: this indexable has elements@NotNull default java.util.PrimitiveIterator.OfDouble doubleIterator()
@NotNull default PrimitiveFloatIterator floatIterator()
floatIterator
in interface PrimitiveFloatIterable
float
iterator which iterates over this indexable@NotNull default PrimitiveFloatIterator floatIterator(int from, int to)
from
- first index of iteratorto
- one past last index of iterator@NotNull default java.util.Iterator<java.lang.Float> iterator()
T
.iterator
in interface java.lang.Iterable<java.lang.Float>
iterator
in interface PrimitiveFloatIterable
@NotNull default java.util.ListIterator<java.lang.Float> listIterator()
T
.@NotNull default FloatIndexable.Base subSet(int fromIndex, int toIndex)
fromIndex
to toIndex - 1
.fromIndex
- start index of sub settoIndex
- index after last index@NotNull default FloatIndexable.Base sybSet(int fromIndex, int toIndex)
fromIndex
- start index of sub settoIndex
- end index of sub set@NotNull default FloatIndexable.Base tailSet(int fromIndex)
fromIndex
- index to start with, negative counts from the back@NotNull default FloatIndexable.Base headSet(int toIndex)
toIndex
- index one after the end (equal to the length of the returned set),
negative counts from the back@NotNull default <T> Indexable<T> view(@NotNull FloatFunction1<? extends T> mapper)
T
- result type pf mappermapper
- mapper@NotNull default java.util.Collection<java.lang.Float> asCollection()
Collection.addAll(Collection)
.@NotNull default java.util.List<java.lang.Float> asList()
Collection.addAll(Collection)
.toList()
@NotNull default java.util.ArrayList<java.lang.Float> toList()
asList()
default void addAllTo(@NotNull java.util.Collection<? super java.lang.Float> collection)
collection
- collection to add to@NotNull default Indexable<java.lang.Float> asIndexable()
Float
values@NotNull default float[] toArray()
default int addToArray(@NotNull float[] array, int pos)
array
- array where the content is addedpos
- position in the array where the content of this indexable is addeddefault int addToArray(@NotNull float[] array, int arrayPos, int index, int length)
array
- array where the content is addedarrayPos
- position in hte array where the content is addedindex
- start index of this indexable which is added firstlength
- number of entries of this indexable added to the array@NotNull default java.lang.Iterable<java.lang.Integer> indexes()
intIndexes()
,
Range.indexes(int)
@NotNull default IntIndexable intIndexes()
indexes()
,
IntIndexable.rangeFromSize(int)
@NotNull default DoubleIndexable.Base asDoubleIndexable()
default float foldLeft(float initialValue, @NotNull FloatOperator2 foldOperation)
initialValue
- start value for the operation, will be returned if this iterable is emptyfoldOperation
- operation applied to each value, will get the accumulated value as its
first and the current element value as its second argument@NotNull default FloatIndexable withInsertedValueAt(int index, float value)
ExpandableDoubleIndexable
if you want to carry out more
stuff like this.
As this creates a view of this indexable, changes to this indexable might result in a disaster when using the returned indexable!
index
- index where the value is inserted before the current index
(not Pythonesque, because it is possible to add an value at index == size()
,
and it is expected that most insertion will happen at 0 or at the end)value
- inserted value at that indexwithAppendedValue(float)
@NotNull default FloatIndexable withAppendedValue(float value)
value
- value to addwithInsertedValueAt(int, float)
@NotNull default FloatIndexable withExchangedValueAt(int index, float value)
ExpandableDoubleIndexable
if you want to carry out more
stuff like this.
As this creates a view of this indexable, changes to this indexable could lead to unexpected results when using the returned indexable!
index
- index where the element is exchanged, hiding the current element.
(Pythonesque)value
- exchanged value at that index@NotNull default FloatIndexable withRemovedValueAt(int index)
index
- index of the removed value (Pythonesque)@NotNull default FloatIndexable withSwappedValuesAt(int index1, int index2)
index1
- index of the first value (Pythonesque)index2
- index of the second value (Pythonesque)@NotNull default FloatIndexable rotated(int steps)
steps
will rotate left, i.e. any index will be accessed
as if the number of steps is added before extraction (modulo length).
E.g. a rotation of -1
will return the last element when index 0
is
requested, and the first element for index 1
.steps
- steps to rotatefrozen()
to create an indexable which no longer depends on this one@NotNull default FloatIndexable viewOp(@NotNull FloatOperator1 op)
op
- transforming operator@NotNull default DoubleIndexable viewAsDouble()
frozen()
on the result to create an independent copy
if this seems like a problem to you.@NotNull default LongIndexable viewAsLong()
frozen()
on the result to create an independent copy
if this seems like a problem to you.@NotNull default IntIndexable viewAsInt()
frozen()
on the result to create an independent copy
if this seems like a problem to you.@NotNull default ShortIndexable viewAsShort()
frozen()
on the result to create an independent copy
if this seems like a problem to you.@NotNull default ByteIndexable viewAsByte()
frozen()
on the result to create an independent copy
if this seems like a problem to you.@NotNull default BooleanIndexable viewAsBoolean(@NotNull FloatPredicate1 convert)
Use frozen()
on the result to decouple it from this indexable.
convert
- converter applied to each value of this indexable before
it is returned from the resulting indexable@NotNull static FloatIndexable.Base viewList(@NotNull java.util.List<? extends java.lang.Number> list)
list
- list used as a base, required to have only non-null elements@NotNull static FloatIndexable.Base viewList(@NotNull java.util.List<? extends java.lang.Number> list, float nullValue)
list
- list used as a base, required to have only non-null elementsnullValue
- value returned for null
elements in the list@NotNull static <T> FloatIndexable.Base viewList(@NotNull java.util.List<T> list, @NotNull ToFloatFunction<? super T> extractor)
T
- element type of listlist
- generic listextractor
- extractor function which extracts a float from the elements of list
list
@NotNull static FloatIndexable.Base viewIndexable(@NotNull Indexable<? extends java.lang.Number> indexable)
indexable
- generic indexable with Number elements, required to have only non-null elements@NotNull static FloatIndexable.Base viewIndexable(@NotNull Indexable<? extends java.lang.Number> indexable, float nullFallback)
indexable
- generic indexable with Number elementsnullFallback
- fallback for null
elements@NotNull static <T> FloatIndexable.Base viewIndexable(@NotNull Indexable<T> indexable, @NotNull ToFloatFunction<? super T> extractor)
T
- element type of indexableindexable
- generic indexableextractor
- extractor function which extracts a float from the elements of indexable
indexable
@NotNull static FloatIndexable.Base viewNumberArray(@NotNull java.lang.Number... array)
subSet(int, int)
.array
- array used as base, required to hold only non-null values@NotNull static FloatIndexable.Base viewArray(@NotNull float... array)
viewArray(float[], int, int)
.array
- array used as base@NotNull static FloatIndexable.Base viewArray(@NotNull float[] array, int start, int length)
array
- array used as basestart
- index of first float to use from the arraylength
- number of elements to use from the array@NotNull static <T> FloatIndexable.Base viewArray(@NotNull T[] array, @NotNull ToFloatFunction<? super T> valueExtract)
T
- array element typearray
- viewed arrayvalueExtract
- converter from array elements to the float values of this indexable@NotNull static FloatIndexable.Base singleton(float value)
value
- single value@NotNull static FloatIndexable.Base init(int size, float value)
size
- size of the returned indexablevalue
- value returned for each elementsize
with always the same element@NotNull static FloatIndexable.Base viewByIndex(int size, @NotNull IntToFloatFunction1 producer)
producer
when an element is requested.
Use frozen()
on the result to create an indexable which avoids this.size
- size of the returned indexableproducer
- producer which is called with an index and expected to return the associated valueproducer
with the given index when an element is requestedinitByIndex(int, IntToFloatFunction1)
@NotNull static FloatIndexable initByIndex(int size, @NotNull IntToFloatFunction1 producer)
size
- size of the returned indexableproducer
- producer which is called with an index and expected to return the associated valueproducer
viewByIndex(int, IntToFloatFunction1)
@NotNull static FloatIndexable.Base emptyIndexable()
@NotNull static java.lang.String toString(@NotNull FloatIndexable indexable)
indexable
- indexablestatic boolean equal(@NotNull FloatIndexable indexable1, @NotNull FloatIndexable indexable2)
This handles NaN values specially so that two of them are considered equal,
compare FloatPredicate2.EQUAL_EVEN_NAN
.
indexable1
- first indexableindexable2
- second indexabletrue
if both indexables contain the same values in the same sequencefalse
if sizes or values differstatic boolean equalStandard(@NotNull FloatIndexable indexable1, @NotNull FloatIndexable indexable2)
This handles NaN values according to the standard so that two of them are considered non-equal,
compare FloatPredicate2.EQUAL_STANDARD
.
indexable1
- first indexableindexable2
- second indexabletrue
if both indexables contain the same values in the same sequencefalse
if sizes or values differstatic boolean equal(@NotNull FloatIndexable indexable1, @NotNull FloatIndexable indexable2, @NotNull FloatPredicate2 checker)
indexable1
- first indexableindexable2
- second indexablechecker
- equality checker, this can be FloatPredicate2.EQUAL_STANDARD
pr
FloatPredicate2.EQUAL_EVEN_NAN
which handle NaN differently,
or allow for a small epsilon differencetrue
if both indexables contain the same values as defined by the checker in the same sequencefalse
if sizes or values differstatic boolean equal(@NotNull FloatIndexable indexable1, @Nullable java.lang.Object indexable2)
Object.equals(Object)
method.indexable1
- first indexableindexable2
- object expected to be an indexable itselftrue
if both indexables contain the same values in the same sequencefalse
if the second object is not an indexable, of if sizes or values differstatic int compare(@NotNull FloatIndexable indexable1, @NotNull FloatIndexable indexable2)
Float.compareTo(Float)
until either the first difference is found (smaller of the two
values define the lower indexable) or the end of one is met
(shorter indexable is less).indexable1
- first indexableindexable2
- second indexable< 0>
if indexable1 < indxable2
,
0
if indexable1 == indexable2
, or
> 0
if indexable1 > indexable2
static int hash(@NotNull FloatIndexable indexable)
indexable
- indexable for which the hash code is required@NotNull static FloatIndexable.Base withCachedHash(@NotNull FloatIndexable indexable)
The wrapped indexable must not change after it is wrapped, otherwise strange things are expected to happen.
indexable
- wrapped indexable, must not changeindexable
, but also provides
useful implementations for Object.hashCode()
, Object.equals(Object)
,
and Object.toString()
default int nextMatch(int startIndex, @NotNull FloatPredicate1 check)
startIndex
- start index for checking, Pythonesque
indexing supportedcheck
- check to perform on elements of this indexable until true
startIndex
for which the check returns true
,
Pythonesque.UNMAPPABLE
if nonedefault int firstMatch(@NotNull FloatPredicate1 check)
check
- check to perform on elements of this indexable until true
true
,
-1
if nonedefault int previousMatch(int startIndex, @NotNull FloatPredicate1 check)
startIndex
- start index for checking, Pythonesque
indexing supportedcheck
- check to perform on elements of this indexable until true
startIndex
for which the check returns true
,
Pythonesque.UNMAPPABLE
if nonedefault int lastMatch(@NotNull FloatPredicate1 check)
check
- check to perform on elements of this indexable until true
true
,
-1
if none@NotNull default FloatIndexable frozen()
Often Indexables are used as a view to underlying collections. Although this interface is immutable, the underlying colelction might nevertheless change. This copies the current state of this indexable into an unmodifiable state, and returns an Indexable which is stable in size and will return always the same element for a given index. Beware: it is still possible that any element itself changes when the elements are mutable.
Calling frozen()
again on the returned object will just return
the object itself, so you can safely call this method more than once.
default boolean isOrdered(@NotNull FloatOrdering order)
order
- expected orderingtrue
if this indexable is sorted as defined by order
false
if notdefault boolean isStrictlyOrdered(@NotNull FloatOrdering order)
order
- expected orderingtrue
if this indexable is sorted as defined by order
false
if notdefault int binarySearch(float value)
standard ascending order
,
i.e. isOrdered(FloatOrdering) has to return true
for this ordering.
For efficiency this prerequisite is not checked, but not fulfilling
it will make this method return bogus results. If this indexable is only ordered,
but not strictly ordered
it is not defined
which index is returned when the looked up value appears in a sequence of equal values.value
- value to look up-(insertIndex + 1)
.default int binarySearch(float value, @NotNull FloatOrdering order)
order
,
i.e. isOrdered(FloatOrdering) has to return true
for this order.
For efficiency this prerequisite is not checked, but not fulfilling
it will make this method return bogus results. If this indexable is only ordered,
but not strictly ordered
it is not defined
which index is returned when the looked up value appears in a sequence of equal values.value
- value to look uporder
- sort order-(insertIndex + 1)
.@NotNull default MutableFloatIndexable ordered(@NotNull FloatOrdering order)
If natural ordering is required prefer calling ordered()
because that typically runs 1.5 times faster.
order
- sort order@NotNull default MutableFloatIndexable ordered()
This can be some 1.5x faster than using ordered(FloatOrdering)
with natural order
.
@NotNull default FloatIndexable.Base asBase()
@NotNull static FloatIndexable.Base based(@NotNull FloatIndexable indexable)
indexable
- indexable to wrap