processSegment method

  1. @visibleForTesting
Future<void> processSegment({
  1. required int iteration,
  2. required int slice,
  3. required int lane,
})

Implementation

@visibleForTesting
Future<void> processSegment({
  required int iteration,
  required int slice,
  required int lane,
}) async {
  final blocksPerLane = blockCount ~/ parallelism;
  final blocksPerSegment = blocksPerLane ~/ 4;
  var firstIndex = 0;
  if (iteration == 0 && slice == 0) {
    firstIndex = 2;
  }

  //
  // For each block in the segment
  //
  for (var index = firstIndex; index < blocksPerSegment; index++) {
    // Give time to other tasks after 500 blocks
    final blocksPerProcessingChunk = this.blocksPerProcessingChunk ?? 500;
    if (blocksPerProcessingChunk > 0 &&
        index % blocksPerProcessingChunk == 0 &&
        index > 0) {
      await Future.delayed(const Duration(microseconds: 1));
    }

    // Get previous block
    final previousBlock = getBlock(
      lane: lane,
      slice: index == 0 ? (slice - 1) % 4 : slice,
      index: (index - 1) % blocksPerSegment,
    );

    // Get reference block
    final referenceBlock = _getReferenceBlock(
      iteration: iteration,
      slice: slice,
      lane: lane,
      index: index,
      previousBlock: previousBlock,
    );

    // The new block will be computed from the previous block and
    // a pseudo-randomly chosen block [l,z].
    final outputBlock = getBlock(
      lane: lane,
      slice: slice,
      index: index,
    );

    processBlock(
      output: outputBlock,
      input0: previousBlock,
      input1: referenceBlock,
      isXorred: iteration > 0,
    );
  }
}