Class AbstractUpdatableBitArray
- All Implemented Interfaces:
Cloneable
,Array
,ArrayExchanger
,BitArray
,PArray
,PFixedArray
,UpdatableArray
,UpdatableBitArray
,UpdatablePArray
,UpdatablePFixedArray
Implementation of almost all basic functions of UpdatableBitArray
interface.
The only BitArray.getBit(long)
and UpdatableBitArray.setBit(long, boolean)
methods
are not defined in this class;
all other methods are implemented via calls of these 2 methods.
- Author:
- Daniel Alievsky
-
Field Summary
Fields inherited from class net.algart.arrays.AbstractArray
capacity, length, underlyingArrays
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractUpdatableBitArray
(long initialCapacityAndLength, boolean underlyingArraysAreParallel, Array... underlyingArrays) Equivalent to the constructorAbstractUpdatableBitArray(long, long, boolean, Array...)
, where both initialCapacity and initialLength arguments are equal to initialCapacityAndLength.protected
AbstractUpdatableBitArray
(long initialCapacity, long initialLength, boolean underlyingArraysAreParallel, Array... underlyingArrays) Creates an updatable array with the given initial capacity and length. -
Method Summary
Modifier and TypeMethodDescriptionThis implementation returnsupdatableClone
(Arrays.SMM
).This implementation returns an instance of the subclass ofAbstractBitArray
, where the following method are overridden and call the same methods of this instance:AbstractBitArray.getBit(long)
,AbstractBitArray.getData(long, Object, int, int)
,AbstractBitArray.getData(long, Object)
,AbstractBitArray.loadResources(ArrayContext, long, long)
,AbstractBitArray.flushResources(ArrayContext, long, long, boolean)
andAbstractBitArray.freeResources(ArrayContext, long, long, boolean)
.This implementation returns this object.void
clearBit
(long index) Clears the bit #index to 0 (false).void
copy
(long destIndex, long srcIndex) This implementation calls setBit(destIndex, getBit(srcIndex)).void
copy
(long destIndex, long srcIndex, long count) This implementation is based on a loop of calls ofcopy(long, long)
method.This implementation callsdefaultCopy(thisInstance, src)
.final UpdatableBitArray
fill
(boolean value) This implementation just callsfill
(0, thisArray.length(), value).final UpdatableBitArray
fill
(double value) This implementation just callsfill
(0, thisArray.length(), value).final UpdatableBitArray
fill
(long value) This implementation just callsfill
(0, thisArray.length(), value).fill
(long position, long count, boolean value) This implementation does the following:subArr
(position, count).copy
(Arrays.nBitCopies
(count, value)).fill
(long position, long count, double value) This implementation just callsfill
(position, count, (boolean)value).fill
(long position, long count, long value) This implementation just callsfill
(position, count, (boolean)value).boolean
This implementation returns false.void
setBit
(long index) Sets the bit #index to 1 (true).abstract void
setBit
(long index, boolean value) Sets the element #index to specified value.setBits
(long arrayPos, long[] srcArray, long srcArrayOffset, long count) This implementation is based on a loop of calls ofsetBit(long, boolean)
method.This implementation callssetData(long, Object, int, int)
with corresponding arguments.This implementation is based on a loop of calls ofsetBit(long, boolean)
method.void
setDouble
(long index, double value) Sets the element #index with conversion from double, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0.0 for boolean element type.void
setElement
(long index, Object value) This implementation calls setBit(index, (Boolean)value).booleanValue()).void
setInt
(long index, int value) Sets the element #index with conversion from int, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.void
setLong
(long index, long value) Sets the element #index with conversion from long, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.void
This implementation callssetNewStatus(false)
.This implementation returns (UpdatableArray)super.shallowClone()
.subArr
(long position, long count) This implementation returnssubArray
(position, position + count).subArray
(long fromIndex, long toIndex) This implementation returns new instance ofAbstractUpdatableBitArray
with the same memory model and underlying arrays, that were passed to the constructor of this instance, and with overridden methodsAbstractBitArray.getBit(long)
,setBit(long, boolean)
,AbstractBitArray.getData(long, Object, int, int)
andsetData(long, Object, int, int)
calling the same methods of this instance with corresponding corrections of the arguments.void
swap
(long firstIndex, long secondIndex) This implementation swaps two elements byAbstractBitArray.getBit(long)
andsetBit(long, boolean)
methods.void
swap
(long firstIndex, long secondIndex, long count) This implementation is based on a loop of calls ofswap(long, long)
method.swap
(UpdatableArray another) This implementation callsdefaultSwap(thisInstance, another)
.toString()
Returns a brief string description of this object.Methods inherited from class net.algart.arrays.AbstractBitArray
asTrustedImmutable, bitsPerElement, buffer, buffer, buffer, buffer, checkUnallowedMutation, elementType, flushResources, flushResources, freeResources, freeResources, getBit, getBits, getData, getData, getDouble, getElement, getInt, getLong, indexOf, indexOf, indexOf, isCopyOnNextWrite, isUnresizable, ja, lastIndexOf, lastIndexOf, lastIndexOf, loadResources, loadResources, maxPossibleValue, maxPossibleValue, minPossibleValue, minPossibleValue, mutableClone, mutableType, nextQuickPosition, type, updatableClone, updatableType
Methods inherited from class net.algart.arrays.AbstractArray
byteOrder, capacity, checkCopyArguments, checkSubArrArguments, checkSubArrayArguments, checkSwapArguments, defaultAppend, defaultBuffer, defaultBufferCapacity, defaultCopy, defaultCopy, defaultSwap, equals, equals, flushResources, freeResources, hashCode, hashCode, isLazy, isNew, isNewReadOnlyView, isZeroFilled, length, newJavaArray, setNewReadOnlyViewStatus, setNewStatus, standardObjectClone
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.algart.arrays.Array
byteOrder, capacity, checkUnallowedMutation, elementType, equals, flushResources, flushResources, freeResources, freeResources, getData, getData, getElement, hashCode, isCopyOnNextWrite, isEmpty, isLazy, isNew, isNewReadOnlyView, isUnresizable, length, length32, loadResources, newJavaArray
Methods inherited from interface net.algart.arrays.BitArray
asTrustedImmutable, buffer, buffer, buffer, buffer, getBit, getBits, getInt, indexOf, ja, lastIndexOf, mutableClone, mutableType, nextQuickPosition, type, updatableClone, updatableType
Methods inherited from interface net.algart.arrays.PArray
bitsPerElement, getDouble, indexOf, isZeroFilled, jaByte, jaDouble, jaFloat, jaInt, jaLong, jaShort, lastIndexOf, maxPossibleValue, minPossibleValue
Methods inherited from interface net.algart.arrays.PFixedArray
getLong, indexOf, lastIndexOf, maxPossibleValue, minPossibleValue
Methods inherited from interface net.algart.arrays.UpdatableBitArray
matrix
Methods inherited from interface net.algart.arrays.UpdatablePArray
updatableType
-
Constructor Details
-
AbstractUpdatableBitArray
protected AbstractUpdatableBitArray(long initialCapacity, long initialLength, boolean underlyingArraysAreParallel, Array... underlyingArrays) Creates an updatable array with the given initial capacity and length.This array is not
new
by default. This is correct usually, because this class is often used for creating a view of another data. However, if the instance if this class does not depend on any other data sources, you may callsetNewStatus(true)
in the constructor of your subclass.- Parameters:
initialCapacity
- initial capacity of the array.initialLength
- initial length of the array.underlyingArraysAreParallel
- see the same argument ofAbstractBitArray(long, long, boolean, Array...)
.underlyingArrays
- see the same argument ofAbstractArray(long, long, Array...)
.- Throws:
NullPointerException
- if underlyingArrays argument or some of underlyingArrays[k] elements is null.IllegalArgumentException
- if the initialCapacity or initialLength arguments are illegal (negative, or capacity < length).SizeMismatchException
- if underlyingArraysAreParallel=true, underlyingArrays.length>1 and some of passed arrays have different lengths.
-
AbstractUpdatableBitArray
protected AbstractUpdatableBitArray(long initialCapacityAndLength, boolean underlyingArraysAreParallel, Array... underlyingArrays) Equivalent to the constructorAbstractUpdatableBitArray(long, long, boolean, Array...)
, where both initialCapacity and initialLength arguments are equal to initialCapacityAndLength.- Parameters:
initialCapacityAndLength
- initial capacity and length of the array.underlyingArraysAreParallel
- seeAbstractUpdatableBitArray(long, long, boolean, Array...)
.underlyingArrays
- seeAbstractUpdatableBitArray(long, long, boolean, Array...)
- Throws:
IllegalArgumentException
- if the passed argument are illegal (negative).
-
-
Method Details
-
subArray
This implementation returns new instance ofAbstractUpdatableBitArray
with the same memory model and underlying arrays, that were passed to the constructor of this instance, and with overridden methodsAbstractBitArray.getBit(long)
,setBit(long, boolean)
,AbstractBitArray.getData(long, Object, int, int)
andsetData(long, Object, int, int)
calling the same methods of this instance with corresponding corrections of the arguments.The returned instance also have overridden methods
AbstractBitArray.loadResources(ArrayContext, long, long)
,AbstractBitArray.flushResources(ArrayContext, long, long, boolean)
andAbstractBitArray.freeResources(ArrayContext, long, long, boolean)
, that also call the same methods of this instance with corresponding correction of their fromIndex argument.The returned instance also have overridden method
AbstractArray.isLazy()
, that just calls the same methods of this instance with the same arguments.- Specified by:
subArray
in interfaceArray
- Specified by:
subArray
in interfaceUpdatableArray
- Specified by:
subArray
in interfaceUpdatableBitArray
- Specified by:
subArray
in interfaceUpdatablePArray
- Specified by:
subArray
in interfaceUpdatablePFixedArray
- Overrides:
subArray
in classAbstractBitArray
- Parameters:
fromIndex
- low endpoint (inclusive) of the subarray.toIndex
- high endpoint (exclusive) of the subarray.- Returns:
- a view of the specified range within this array.
- Throws:
IndexOutOfBoundsException
- for illegal fromIndex and toIndex (fromIndex < 0 || toIndex > length() || fromIndex > toIndex).- See Also:
-
subArr
Description copied from class:AbstractArray
This implementation returnssubArray
(position, position + count). Please note that the exception message can be not fully correct for the very exotic case position+count>Long.MAX_VALUE.- Specified by:
subArr
in interfaceArray
- Specified by:
subArr
in interfaceUpdatableArray
- Specified by:
subArr
in interfaceUpdatableBitArray
- Specified by:
subArr
in interfaceUpdatablePArray
- Specified by:
subArr
in interfaceUpdatablePFixedArray
- Overrides:
subArr
in classAbstractArray
- Parameters:
position
- start position (inclusive) of the subarray.count
- number of elements in the subarray.- Returns:
- a view of the specified range within this array.
- See Also:
-
setDouble
public void setDouble(long index, double value) Description copied from interface:UpdatablePArray
Sets the element #index with conversion from double, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0.0 for boolean element type.Depending on the specific subinterface implemented by the object, this method is equivalent to one of the following calls:
- for
UpdatableBitArray
:setBit
(index, value != 0.0); - for
UpdatableCharArray
:setChar
(index, (char) value); - for
UpdatableByteArray
:setByte
(index, (byte) value); - for
UpdatableShortArray
:setShort
(index, (short) value); - for
UpdatableLongArray
:setLong
(index, (long) value); - for
UpdatableFloatArray
:setFloat
(index, (float) value); - for
UpdatableDoubleArray
: the same method is already declared in this interface.
- Specified by:
setDouble
in interfaceUpdatablePArray
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- See Also:
- for
-
setLong
public void setLong(long index, long value) Description copied from interface:UpdatablePArray
Sets the element #index with conversion from long, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.Depending on the specific subinterface implemented by the object, this method is equivalent to one of the following calls:
- for
UpdatableBitArray
:setBit
(index, value != 0); - for
UpdatableCharArray
:setChar
(index, (char) value); - for
UpdatableByteArray
:setByte
(index, (byte) value); - for
UpdatableShortArray
:setShort
(index, (short) value); - for
UpdatableLongArray
: the same method is already declared in this interface; - for
UpdatableFloatArray
:setFloat
(index, (float) value); - for
UpdatableDoubleArray
:setDouble
(index, (double) value).
- Specified by:
setLong
in interfaceUpdatablePArray
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- See Also:
- for
-
setInt
public void setInt(long index, int value) Description copied from interface:UpdatablePArray
Sets the element #index with conversion from int, as (xxx)value for numeric element type xxx (byte, short, int, long, float, double or char), or as value!=0 for boolean element type.This method is equivalent to both
setLong(index, (long) value)
andsetDouble(index, (double) value)
, but can work little faster.- Specified by:
setInt
in interfaceUpdatablePArray
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- See Also:
-
setBit
public abstract void setBit(long index, boolean value) Description copied from interface:UpdatableBitArray
Sets the element #index to specified value.- Specified by:
setBit
in interfaceUpdatableBitArray
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.
-
fill
This implementation just callsfill
(0, thisArray.length(), value).- Specified by:
fill
in interfaceUpdatablePArray
- Parameters:
value
- the value to be stored in all elements of the array.- Returns:
- a reference to this array.
- See Also:
-
fill
This implementation just callsfill
(position, count, (boolean)value).- Specified by:
fill
in interfaceUpdatablePArray
- Parameters:
position
- start index (inclusive) to be filled.count
- number of filled elements.value
- the value to be stored in the elements of the array.- Returns:
- a reference to this array.
- Throws:
IndexOutOfBoundsException
- for illegal position and count (position < 0 || count < 0 || position + count > length()).- See Also:
-
fill
This implementation just callsfill
(0, thisArray.length(), value).- Specified by:
fill
in interfaceUpdatablePArray
- Parameters:
value
- the value to be stored in all elements of the array.- Returns:
- a reference to this array.
- See Also:
-
fill
This implementation just callsfill
(position, count, (boolean)value).- Specified by:
fill
in interfaceUpdatablePArray
- Parameters:
position
- start index (inclusive) to be filled.count
- number of filled elements.value
- the value to be stored in the elements of the array.- Returns:
- a reference to this array.
- Throws:
IndexOutOfBoundsException
- for illegal position and count (position < 0 || count < 0 || position + count > length()).- See Also:
-
fill
This implementation just callsfill
(0, thisArray.length(), value).- Specified by:
fill
in interfaceUpdatableBitArray
- Parameters:
value
- the value to be stored in all elements of the array.- Returns:
- a reference to this array.
- See Also:
-
fill
This implementation does the following:subArr
(position, count).copy
(Arrays.nBitCopies
(count, value)). Please override this method if it's possible to perform the same task more efficiently.- Specified by:
fill
in interfaceUpdatableBitArray
- Parameters:
position
- start index (inclusive) to be filled.count
- number of filled elements.value
- the value to be stored in the elements of the array.- Returns:
- a reference to this array.
- Throws:
IndexOutOfBoundsException
- for illegal position and count (position < 0 || count < 0 || position + count > length()).- See Also:
-
isImmutable
public boolean isImmutable()This implementation returns false.- Specified by:
isImmutable
in interfaceArray
- Overrides:
isImmutable
in classAbstractBitArray
- Returns:
- true if this instance is immutable.
- See Also:
-
asImmutable
This implementation returns an instance of the subclass ofAbstractBitArray
, where the following method are overridden and call the same methods of this instance:AbstractBitArray.getBit(long)
,AbstractBitArray.getData(long, Object, int, int)
,AbstractBitArray.getData(long, Object)
,AbstractBitArray.loadResources(ArrayContext, long, long)
,AbstractBitArray.flushResources(ArrayContext, long, long, boolean)
andAbstractBitArray.freeResources(ArrayContext, long, long, boolean)
.The returned instance also have overridden method
AbstractArray.isLazy()
, that just calls the same methods of this instance with the same arguments.- Specified by:
asImmutable
in interfaceArray
- Specified by:
asImmutable
in interfaceBitArray
- Specified by:
asImmutable
in interfacePArray
- Specified by:
asImmutable
in interfacePFixedArray
- Overrides:
asImmutable
in classAbstractBitArray
- Returns:
- an immutable view of this array.
- See Also:
-
shallowClone
This implementation returns (UpdatableArray)super.shallowClone()
.- Specified by:
shallowClone
in interfaceArray
- Specified by:
shallowClone
in interfaceUpdatableArray
- Overrides:
shallowClone
in classAbstractArray
- Returns:
- a shallow copy of this object.
- See Also:
-
setElement
This implementation calls setBit(index, (Boolean)value).booleanValue()).- Specified by:
setElement
in interfaceUpdatableArray
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- Throws:
IndexOutOfBoundsException
- if index is out of range 0..length()-1.NullPointerException
- if value == null and it is an array of primitive elementsClassCastException
- if it is an array of primitive elements and value is not a corresponding wrapped class (Boolean, Integer, etc.)ArrayStoreException
- if it is an array of non-primitive elements and value is not an instance ofAbstractBitArray.elementType()
class
-
setData
This implementation is based on a loop of calls ofsetBit(long, boolean)
method. Please override this method if it's possible to perform the same task more efficiently than such a loop.- Specified by:
setData
in interfaceUpdatableArray
- Parameters:
arrayPos
- starting position in this AlgART array.srcArray
- the source Java array.srcArrayOffset
- starting position in the source Java array.count
- the number of elements to be copied.- Returns:
- a reference to this AlgART array.
- Throws:
NullPointerException
- if srcArray argument is null.IllegalArgumentException
- if srcArray argument is not an array.IndexOutOfBoundsException
- if copying would cause access of data outside this array or source Java array.ArrayStoreException
- if destArray element type mismatches with this arrayelementType()
.ClassCastException
- if destArray element type mismatches with this arrayelementType()
(both this and ArrayStoreException are possible, depending on implementation).- See Also:
-
setData
This implementation callssetData(long, Object, int, int)
with corresponding arguments.- Specified by:
setData
in interfaceUpdatableArray
- Parameters:
arrayPos
- starting position in this AlgART array.srcArray
- the source Java array.- Returns:
- a reference to this AlgART array.
- Throws:
NullPointerException
- if srcArray argument is null.IllegalArgumentException
- if srcArray argument is not an array.IndexOutOfBoundsException
- if copying would cause access of data outside this array or source Java array.ArrayStoreException
- if destArray element type mismatches with this arrayAbstractBitArray.elementType()
.ClassCastException
- if destArray element type mismatches with this arrayAbstractBitArray.elementType()
(both this and ArrayStoreException are possible, depending on implementation).- See Also:
-
copy
public void copy(long destIndex, long srcIndex) This implementation calls setBit(destIndex, getBit(srcIndex)).- Specified by:
copy
in interfaceUpdatableArray
- Parameters:
destIndex
- index of element to replace.srcIndex
- index of element to be copied.- Throws:
IndexOutOfBoundsException
- if one of indexes is out of range 0..length()-1.
-
copy
public void copy(long destIndex, long srcIndex, long count) This implementation is based on a loop of calls ofcopy(long, long)
method.- Specified by:
copy
in interfaceUpdatableArray
- Parameters:
destIndex
- starting index of element to replace.srcIndex
- starting index of element to be copied.count
- the number of elements to be copied.- Throws:
IndexOutOfBoundsException
- if one of indexes is out of range 0..length()-1.
-
swap
public void swap(long firstIndex, long secondIndex) This implementation swaps two elements byAbstractBitArray.getBit(long)
andsetBit(long, boolean)
methods.- Specified by:
swap
in interfaceArrayExchanger
- Specified by:
swap
in interfaceUpdatableArray
- Parameters:
firstIndex
- first index of element to exchange.secondIndex
- second index of element to exchange.- Throws:
IndexOutOfBoundsException
- if one of indexes is out of range 0..length()-1.
-
swap
public void swap(long firstIndex, long secondIndex, long count) This implementation is based on a loop of calls ofswap(long, long)
method.- Specified by:
swap
in interfaceUpdatableArray
- Parameters:
firstIndex
- starting first index of element to exchange.secondIndex
- starting second index of element to exchange.count
- the number of elements to be exchanged.- Throws:
IndexOutOfBoundsException
- if one of indexes is out of range 0..length()-1.
-
copy
This implementation callsdefaultCopy(thisInstance, src)
.- Specified by:
copy
in interfaceUpdatableArray
- Parameters:
src
- the source array.- Returns:
- a reference to this array.
- Throws:
NullPointerException
- if src argument is null.IllegalArgumentException
- if the source and this element types do not match.- See Also:
-
swap
This implementation callsdefaultSwap(thisInstance, another)
.- Specified by:
swap
in interfaceUpdatableArray
- Parameters:
another
- another array.- Returns:
- a reference to this array.
- Throws:
NullPointerException
- if another argument is null.IllegalArgumentException
- if another and this element types do not match.
-
setNonNew
public void setNonNew()This implementation callssetNewStatus(false)
.- Specified by:
setNonNew
in interfaceUpdatableArray
-
asCopyOnNextWrite
This implementation returnsupdatableClone
(Arrays.SMM
).- Specified by:
asCopyOnNextWrite
in interfaceArray
- Specified by:
asCopyOnNextWrite
in interfaceUpdatableArray
- Overrides:
asCopyOnNextWrite
in classAbstractBitArray
- Returns:
- a copy of this object.
- See Also:
-
asUnresizable
This implementation returns this object. Should be overridden if the inheritor is resizable.- Specified by:
asUnresizable
in interfaceUpdatableArray
- Specified by:
asUnresizable
in interfaceUpdatableBitArray
- Specified by:
asUnresizable
in interfaceUpdatablePArray
- Specified by:
asUnresizable
in interfaceUpdatablePFixedArray
- Returns:
- an unresizable view of this array.
- See Also:
-
toString
Description copied from interface:Array
Returns a brief string description of this object.The result of this method may depend on implementation and usually contains a short description of the array length, capacity, element type.
Note: for
character arrays
, unlike CharSequence.toString(), this method works as for all other array types. If you need to convert a character array to a string, containing all characters of the array, you may useArrays.toString(CharArray)
method.- Specified by:
toString
in interfaceArray
- Overrides:
toString
in classAbstractBitArray
- Returns:
- a brief string description of this object.
-
setBit
public void setBit(long index) Description copied from interface:UpdatableBitArray
Sets the bit #index to 1 (true).- Specified by:
setBit
in interfaceUpdatableBitArray
- Parameters:
index
- index of element to replace.
-
clearBit
public void clearBit(long index) Clears the bit #index to 0 (false).- Specified by:
clearBit
in interfaceUpdatableBitArray
- Parameters:
index
- index of element to replace.- Throws:
IndexOutOfBoundsException
- if index out of range 0..length()-1.
-
setBits
This implementation is based on a loop of calls ofsetBit(long, boolean)
method. Please override this method if it's possible to perform the same task more efficiently than such a loop.- Specified by:
setBits
in interfaceUpdatableBitArray
- Parameters:
arrayPos
- starting position in this AlgART array.srcArray
- the source packed bit array.srcArrayOffset
- starting position in the source packed bit array.count
- the number of bits to be copied.- Returns:
- a reference to this AlgART array.
- Throws:
NullPointerException
- if srcArray argument is null.IndexOutOfBoundsException
- if copying would cause access of data outside this array or source Java array.- See Also:
-