Interface GeneralizedBitProcessing.SliceOperation

Enclosing class:
GeneralizedBitProcessing

public static interface GeneralizedBitProcessing.SliceOperation
Algorithm of processing bit arrays, that should be generalized for another element types via GeneralizedBitProcessing class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    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 by GeneralizedBitProcessing.process(UpdatablePArray, PArray, Range, long) method for every bit 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 the context), if the isInPlaceProcessingAllowed() 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 * (amaxamin)/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 to GeneralizedBitProcessing 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 in

      0..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, are bit arrays, then threadIndex=0 and numberOfThreads=1.

      Parameters:
      context - the context of execution. It will be null, if (and only if) the same argument of process method is null; in this case, the context should be ignored. The main purpose of the context is to allow interruption of this method via ArrayContext.checkInterruption() and to allocate work memory via ArrayContext.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 to min(numberOfSlices−1,GeneralizedBitProcessing.numberOfTasks()), where numberOfSlices=n+1 is the argument of 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 of processBits 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 of processBits method.

      Returns:
      true if processBits method can work correctly when destBits==srcBits or false if that method requires different source and destination arrays.