Interface GeneralizedBitProcessing.SliceOperation
- Enclosing class:
GeneralizedBitProcessing
GeneralizedBitProcessing
class.-
Method Summary
Modifier and TypeMethodDescriptionboolean
Indicates whether this algorithm can work in place.void
processBits
(ArrayContext context, UpdatableBitArray destBits, BitArray srcBits, long sliceIndex, int threadIndex, int numberOfThreads) Processes the source bit array srcBits and saves the results in destBits bit array.
-
Method Details
-
processBits
void processBits(ArrayContext context, UpdatableBitArray destBits, BitArray srcBits, long sliceIndex, int threadIndex, int numberOfThreads) Processes the source bit array srcBits and saves the results in destBits bit array. This method is called byGeneralizedBitProcessing.process(UpdatablePArray, PArray, Range, long)
method for everybit slice
of the source non-bit array. It is the main method, which you should implement to generalize some bit algorithm for non-bit case.The destBits and srcBits arrays will be different bit arrays, allocated by
process
method (according to the memory model, recommended by thecontext
), if theisInPlaceProcessingAllowed()
method returns false. If that method returns true, the destBits and srcBits arguments will be references to the same bit array.The index i of the slice, processed by this method, is passed via sliceIndex argument. In other words, the threshold, corresponding to this slice, is
ti = amin + i * (amax−amin)/n, i = sliceIndex
(here amin..amax is the range of processed values and n+1 is the desired number of slices, passed via range and numberOfSlices arguments of
process
method). In the round-down mode sliceIndex is always in range 1..n, and in the round-up mode it is always in range 0..n-1. The slice with index i=0 (round-down mode) or i=n (round-up mode) is never processed, because the end result does not depend on it. See comments toGeneralizedBitProcessing
class for more details.Please note that this method can be called simultaneously in different threads, when
GeneralizedBitProcessing
class uses multithreading optimization. In this case, threadIndex argument will be the index of the thread, in which this method is called, i.e. an integer in0..min(n-1,
GeneralizedBitProcessing.numberOfTasks()
−1)range, where n+1 is the desired number of slices. The high bound of this range, increased by 1, is also passed via numberOfThreads argument. The threadIndex can be very useful if your algorithm requires some work memory or other objects: in this case, your should allocate different work memory for different threads.
If multithreading optimization is not used, in particular, if the arrays, processed by
process
method, arebit arrays
, then threadIndex=0 and numberOfThreads=1.- Parameters:
context
- the context of execution. It will be null, if (and only if) the same argument ofprocess
method is null; in this case, the context should be ignored. The main purpose of the context is to allow interruption of this method viaArrayContext.checkInterruption()
and to allocate work memory viaArrayContext.getMemoryModel()
.destBits
- the destination bit array, where results of processing should be stored.srcBits
- the source bit array for processing.sliceIndex
- the index of the currently processed slice, from 1 to n in the round-down mode or from 0 to n-1 the round-up mode (n is the desired number of slices minus 1).threadIndex
- the index of the current thread (different for different threads in a case of multithreading optimization).numberOfThreads
- the maximal possible value of threadIndex+1: equal tomin(numberOfSlices−1, , where numberOfSlices=n+1 is the argument ofGeneralizedBitProcessing.numberOfTasks()
)process
method.- Throws:
NullPointerException
- if srcBits or destBits argument is null.
-
isInPlaceProcessingAllowed
boolean isInPlaceProcessingAllowed()Indicates whether this algorithm can work in place.Some algorithms, processing bit arrays, can work in place, when the results are stored in the source array. In this case, this method should return true. If it returns true,
GeneralizedBitProcessing.process(UpdatablePArray, PArray, Range, long)
method saves memory and time by passing the same bit array as destBits and srcBits arguments ofprocessBits
method. If it returns false,GeneralizedBitProcessing.process(UpdatablePArray, PArray, Range, long)
method allocates 2 different bit arrays for source and resulting bit arrays and passes them as destBits and srcBits arguments ofprocessBits
method.- Returns:
- true if
processBits
method can work correctly when destBits==srcBits or false if that method requires different source and destination arrays.
-